Periphery Code Audit

io.github.zyntx-lab由 GitHub 帳號 zyntx-lab 發布v1.0.0更新於 Oct 24, 2026

Swift code analysis with Periphery - detect unused code and improve code quality

發布方自己的服務:audit.domains - Domain Valuation

已驗證STDIO僅桌面開發者工具資料與分析

概覽

AI 產生的概覽

一個本機 MCP 伺服器,封裝 Periphery CLI,讓助理稽核 Swift 專案中未使用的程式碼、匯入與過度公開的宣告。

可以做什麼
檢查 Periphery CLI 是否已安裝,並回報其版本與路徑,以便及早發現設定問題。對 Xcode 專案或 Swift 套件執行基本掃描,回傳包含未使用宣告與摘要資訊的結構化 JSON 結果。可依 YAML 設定檔掃描,或使用進階參數,例如保留 public 或 @objc 宣告、關閉未使用匯入分析、指定索引儲存路徑與詳細輸出。針對特定檢查:未使用的匯入,以及可改為 internal 的 public 宣告。
適用情境
適合在整理 iOS 或 macOS 程式碼庫時使用,讓助理在 Xcode 專案或 Swift 套件中找出無用程式碼、未使用的匯入或不必要的公開 API,並在對話中說明結果。
執行需求
以本機二進位檔執行,需要 macOS 13.0 或更新版本以及 Swift 6.0 或更新版本。需另外安裝 Periphery CLI 並使其位於路徑中。專案需先建置以產生索引儲存,scheme 應設為共享。可透過 Homebrew、GitHub 發行版二進位檔、原始碼建置或 MCP 登錄檔安裝,並在用戶端的 MCP 設定檔中設定。
安裝前請注意
掃描會讀取專案目錄並呼叫 Periphery CLI,大型專案可能耗時數分鐘(預設逾時 5 分鐘)。結果依賴先前的 Xcode 建置與共享 scheme,因此可能出現空掃描。從原始碼安裝到系統路徑需使用 sudo。未宣告任何憑證或網路服務。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Periphery Code Audit,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Periphery MCP Server

A Model Context Protocol (MCP) server that wraps the Periphery tool, enabling AI assistants to perform Swift code audits and detect unused code in iOS/macOS projects.

Features

  • 7 MCP Tools for comprehensive code analysis
  • CLI Integration - Uses Periphery CLI for stability and version flexibility
  • JSON Output - Structured, parseable results perfect for AI interpretation
  • Flexible Scanning - Support for Xcode projects and Swift Packages
  • Advanced Options - Full control over Periphery scan configurations

Quick Start

Using Homebrew (Recommended):

bash
# 1. Install Peripherybrew install peripheryapp/periphery/periphery
# 2. Install Periphery MCP Serverbrew tap zyntx-lab/tapbrew install periphery-mcp-server
# 3. Configure Claude Desktop# Edit: ~/Library/Application Support/Claude/claude_desktop_config.json# Add:#   "periphery": {#     "command": "/opt/homebrew/bin/periphery-mcp-server"#   }
# 4. Restart Claude Desktop (Cmd+Q then reopen)
# 5. Test it# In Claude Desktop: "Check if Periphery is installed"

From Source:

bash
# 1. Install Peripherybrew install peripheryapp/periphery/periphery
# 2. Clone and build this servergit clone https://github.com/zyntx-lab/periphery-mcp-server.gitcd periphery-mcp-serverswift build -c release
# 3. Install to system pathsudo cp .build/release/periphery-mcp-server /usr/local/bin/sudo chmod +x /usr/local/bin/periphery-mcp-server
# 4. Configure Claude Desktop# Edit: ~/Library/Application Support/Claude/claude_desktop_config.json# Add:#   "periphery": {#     "command": "/usr/local/bin/periphery-mcp-server"#   }
# 5. Restart Claude Desktop (Cmd+Q then reopen)
# 6. Test it# In Claude Desktop: "Check if Periphery is installed"

Prerequisites

  • macOS 13.0 or later
  • Swift 6.0 or later
  • Periphery installed

Installing Periphery

bash
brew install peripheryapp/periphery/periphery

Or download from Periphery releases.

Installation

Option 1: Homebrew (Recommended)

bash
# Add the tapbrew tap zyntx-lab/tap
# Install the serverbrew install periphery-mcp-server
# Verify installationwhich periphery-mcp-server# Should output: /opt/homebrew/bin/periphery-mcp-server

Option 2: Download from GitHub Releases

Download the latest binary from Releases:

bash
# Download and installcurl -L https://github.com/zyntx-lab/periphery-mcp-server/releases/download/v1.0.0/periphery-mcp-server \  -o /usr/local/bin/periphery-mcp-serverchmod +x /usr/local/bin/periphery-mcp-server
# Verify installationwhich periphery-mcp-server# Should output: /usr/local/bin/periphery-mcp-server

Option 3: Build from Source

bash
# Clone the repositorygit clone https://github.com/zyntx-lab/periphery-mcp-server.gitcd periphery-mcp-server
# Build release versionswift build -c release
# Install to system path (requires password)sudo cp .build/release/periphery-mcp-server /usr/local/bin/sudo chmod +x /usr/local/bin/periphery-mcp-server
# Verify installationwhich periphery-mcp-server# Should output: /usr/local/bin/periphery-mcp-server

Option 4: Install from MCP Registry

The server is also available on the MCP Registry. Use your MCP-compatible client to install it directly.

Configuration

Claude Desktop

Step 1: Locate Your Config File

The config file is at: ~/Library/Application Support/Claude/claude_desktop_config.json

Step 2: Edit the Configuration

If you installed via Homebrew:

json
{  "mcpServers": {    "periphery": {      "command": "/opt/homebrew/bin/periphery-mcp-server"    }  }}

If you installed to /usr/local/bin:

json
{  "mcpServers": {    "periphery": {      "command": "/usr/local/bin/periphery-mcp-server"    }  }}

If you're using the build directory directly:

json
{  "mcpServers": {    "periphery": {      "command": "/FULL/PATH/TO/periphery-mcp-server/.build/release/periphery-mcp-server"    }  }}

If you already have other MCP servers configured:

json
{  "mcpServers": {    "xcode": {      "command": "node",      "args": ["/path/to/xcode-mcp-server/dist/index.js"]    },    "periphery": {      "command": "/usr/local/bin/periphery-mcp-server"    }  }}
Step 3: Restart Claude Desktop

Important: You must completely quit and restart Claude Desktop for changes to take effect.

  1. Quit Claude Desktop: Press Cmd+Q or use Claude Desktop → Quit
  2. Wait a few seconds
  3. Reopen Claude Desktop
Step 4: Verify It's Working

Open a new conversation in Claude Desktop and try:

"Check if Periphery is installed"

If configured correctly, Claude will use the check_periphery_installed tool and respond with installation status.

Testing with MCP Inspector

Before configuring Claude Desktop, you can test the server with the MCP Inspector:

bash
# Install MCP Inspector (if not already installed)npm install -g @modelcontextprotocol/inspector
# Test your servernpx @modelcontextprotocol/inspector /usr/local/bin/periphery-mcp-server
# Or if using build directorynpx @modelcontextprotocol/inspector /path/to/periphery-mcp-server/.build/release/periphery-mcp-server

The Inspector will open in your browser where you can test all tools interactively.

Other Editors

VS Code

Add to .vscode/mcp.json:

json
{  "mcpServers": {    "periphery": {      "type": "stdio",      "command": "/usr/local/bin/periphery-mcp-server"    }  }}
Cursor

Add to .cursor/mcp.json:

json
{  "mcpServers": {    "periphery": {      "type": "stdio",      "command": "/usr/local/bin/periphery-mcp-server"    }  }}

Available Tools

1. check_periphery_installed

Verify that Periphery CLI is installed and accessible.

Parameters: None

Example Response:

json
{  "installed": true,  "path": "/usr/local/bin/periphery",  "message": "Periphery is installed and ready"}

2. get_periphery_version

Get the installed version of Periphery.

Parameters: None

Example Response:

json
{  "version": "2.18.0",  "raw_output": "2.18.0"}

3. scan_project

Run a basic Periphery scan on a project.

Parameters:

  • project_path (required): Path to .xcodeproj or Package.swift
  • schemes (optional): Build schemes to scan (Xcode only)
  • targets (optional): Specific targets to analyze
  • format (optional): Output format: json, xcode, csv, checkstyle (default: json)

Example Response:

json
{  "success": true,  "results": [    {      "kind": "class",      "name": "UnusedClass",      "modifiers": ["public"],      "location": "Sources/MyApp/UnusedClass.swift:10:7"    }  ],  "summary": {    "total_unused": 5,    "by_kind": {"class": 2, "function": 3}  }}

4. scan_with_config

Run Periphery scan using a YAML configuration file.

Parameters:

  • config_path (required): Path to .periphery.yml config file

5. analyze_unused_imports

Focus specifically on detecting unused imports.

Parameters:

  • project_path (required): Path to .xcodeproj or Package.swift
  • schemes (optional): Build schemes to scan
  • targets (optional): Specific targets to analyze

6. find_redundant_public

Identify public declarations that could be internal.

Parameters:

  • project_path (required): Path to .xcodeproj or Package.swift
  • schemes (optional): Build schemes to scan
  • targets (optional): Specific targets to analyze

7. scan_with_options

Advanced scanning with custom Periphery flags.

Parameters:

  • project_path (required): Path to .xcodeproj or Package.swift
  • schemes (optional): Build schemes to scan
  • targets (optional): Specific targets to analyze
  • format (optional): Output format
  • retain_public (optional): Retain all public declarations
  • retain_objc_accessible (optional): Retain @objc declarations
  • disable_unused_import_analysis (optional): Disable unused import analysis
  • index_store_path (optional): Custom index store location
  • verbose (optional): Enable verbose output

Usage Examples

With Claude Desktop

Once configured, you can have natural conversations with Claude about your code:

Check Installation:

You: "Check if Periphery is installed"
Claude: [Uses check_periphery_installed]"Yes, Periphery is installed at /usr/local/bin/peripheryVersion: 2.18.0"

Scan a Project:

You: "Scan my iOS project at ~/Projects/MyApp/MyApp.xcodeproj for unused code"
Claude: [Uses scan_project]"I found 15 unused declarations in your project:
Classes (5):- UnusedViewController at MyApp/UnusedViewController.swift:10- OldDataManager at MyApp/Models/OldDataManager.swift:25...
Functions (8):- helperFunction at Utils/Helpers.swift:42...
Imports (2):- UIKit in DataModel.swift:1..."

Find Redundant Public:

You: "Check which public declarations could be made internal in ~/Projects/MyFramework"
Claude: [Uses find_redundant_public]"Found 12 public declarations that are only used internally and could be made internal:- public class InternalHelper (only used within the framework)- public func formatDate() (only called from within the module)..."

Analyze Unused Imports:

You: "Find unused imports in my Swift package"
Claude: [Uses analyze_unused_imports]"Found 8 unused imports that can be safely removed:- Foundation in Models/User.swift (not using any Foundation APIs)- Combine in ViewModels/ProfileViewModel.swift (Combine is imported but not used)..."

With Custom Configuration

Create .periphery.yml in your project:

yaml
project: MyApp.xcodeprojschemes:  - MyApptargets:  - MyApp  - MyAppKitformat: jsonretain_public: falseretain_objc_accessible: trueverbose: false

Then use scan_with_config:

You: "Scan my project using the custom config"

Troubleshooting

Server Not Appearing in Claude Desktop

Symptoms: Claude doesn't recognize Periphery tools after configuration

Solutions:

  1. Verify config file syntax:

    bash
    # Check for JSON syntax errorscat ~/Library/Application\ Support/Claude/claude_desktop_config.json | python3 -m json.tool
  2. Check the binary path is correct:

    bash
    # Test that the binary exists and runs/usr/local/bin/periphery-mcp-server# Or your custom path/path/to/.build/release/periphery-mcp-server
  3. Completely restart Claude Desktop:

    • Press Cmd+Q to quit (not just close the window)
    • Wait 5 seconds
    • Reopen Claude Desktop
    • Start a new conversation (old conversations won't see new servers)
  4. Check Claude Desktop logs:

    bash
    # View logs for errorstail -f ~/Library/Logs/Claude/mcp*.log

Periphery Not Found

If you get "Periphery is not installed":

  1. Install Periphery: brew install peripheryapp/periphery/periphery
  2. Verify installation: which periphery
  3. Restart Claude Desktop/VS Code/Cursor
  4. Try the check_periphery_installed tool again

MCP Inspector Connection Errors

If the Inspector can't connect to the server:

  1. Verify the server runs:

    bash
    # Server should wait for input, not exit immediately/usr/local/bin/periphery-mcp-server# Press Ctrl+C to exit
  2. Check for errors:

    bash
    # Run with verbose output/usr/local/bin/periphery-mcp-server 2>&1 | tee server.log
  3. Use the absolute path:

    bash
    npx @modelcontextprotocol/inspector $(which periphery-mcp-server)

Scan Timeout

Default timeout is 5 minutes. For large projects:

  1. Use scan_with_config with a focused configuration
  2. Scan specific targets instead of the entire project
  3. Use --index-store-path to reuse build artifacts
  4. Build your project in Xcode first to generate the index

No Results or Empty Scan

Periphery requires a compiled project with an index store:

  1. Build your project first in Xcode (Cmd+B)
  2. Ensure schemes are shared:
    • Xcode → Product → Scheme → Manage Schemes
    • Check the "Shared" checkbox for your scheme
  3. Verify the project path:
    bash
    # For Xcode projectsls /path/to/YourProject.xcodeproj
    # For Swift Packagesls /path/to/Package.swift
  4. Check Periphery can access the project:
    bash
    # Test Periphery directlyperiphery scan --project /path/to/YourProject.xcodeproj --schemes YourScheme

Permission Denied

If you get "Permission denied" when running the server:

bash
# Make the binary executablechmod +x /usr/local/bin/periphery-mcp-server
# Or for build directorychmod +x .build/release/periphery-mcp-server

Architecture

This server uses the CLI approach rather than importing Periphery as a library for maximum stability:

  • ✅ CLI interface is Periphery's public API contract
  • ✅ Survives internal Periphery refactorings
  • ✅ Users can update Periphery independently
  • ✅ Simpler dependency management

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

License

MIT License - see LICENSE file for details.

Related Projects

Distribution Channels

This server is available through multiple channels:

Support

來源:README.md,提交 cbb2a2f

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.0.0最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

其他 Audit 整合