TEXT

xcode-mcp (for pi agent)

Contributed by ilkerulusoy

Improved by Laravel Company · 2026-09-07

Xcode MCP Tool Usage Guide

Xcode MCP tools offer efficient access to Xcode functionality via the mcporter command-line interface (CLI). This guide clarifies the appropriate use cases for Xcode MCP tools and standard command-line tools.

Prerequisites

Before using Xcode MCP, ensure you have configured the mcporter configuration file located at ~/.mcporter/mcporter.json:

json
{
  "mcpServers": {
    "xcode": {
      "command": "xcrun",
      "args": ["mcpbridge"],
      "env": {}
    }
  }
}

Verify the connection by running:

bash
mcporter list xcode

Calling Xcode MCP Tools

All Xcode MCP tools are accessed via the mcporter CLI. There are two calling conventions:

  1. Parameter-based syntax:
bash
# List available tools
mcporter list xcode

# Call a tool with key:value arguments
mcporter call xcode.<tool_name> param1:value1 param2:value2
  1. Function-call syntax:
bash
# Call with function-call syntax
mcporter call 'xcode.<tool_name>(param1: "value1", param2: "value2")'

Complete Xcode MCP Tool Reference

Window & Project Management

Tool Name mcporter Call Token Cost Description
XcodeListWindows mcporter call xcode.XcodeListWindows Low ✓ Lists open Xcode windows and returns tab identifiers

Build Operations

Tool Name mcporter Call Token Cost Description
BuildProject mcporter call xcode.BuildProject Medium ✓ Compiles the Xcode project
GetBuildLog mcporter call xcode.GetBuildLog Medium ✓ Retrieves the build log with errors and warnings

Testing

Tool Name mcporter Call Token Cost Description
GetTestList mcporter call xcode.GetTestList Low ✓ Retrieves a list of available tests from the test plan
RunAllTests mcporter call xcode.RunAllTests Medium Runs all tests in the project
RunSomeTests mcporter call xcode.RunSomeTests Medium ✓ Runs specific tests based on test target and method

Preview & Execution

Tool Name mcporter Call Token Cost Description
RenderPreview mcporter call xcode.RenderPreview Medium ✓ Renders a SwiftUI preview snapshot

Diagnostics

Tool Name mcporter Call Token Cost Description
XcodeRefreshCodeIssuesInFile mcporter call xcode.XcodeRefreshCodeIssuesInFile Low ✓ Retrieves compiler diagnostics for a specific file
getDiagnostics mcporter call xcode.getDiagnostics Low ✓ Retrieves SourceKit diagnostics for all open files

Documentation

Tool Name mcporter Call Token Cost Description
DocumentationSearch mcporter call xcode.DocumentationSearch Low ✓ Searches the Apple Developer Documentation

File Operations (High Token Consumption - Never Use)

MCP Tool Standard Tool Reason
XcodeRead Read tool / cat High token consumption for file reading
XcodeWrite Write tool High token consumption for file writing
XcodeUpdate Edit tool High token consumption for file updates
XcodeGrep rg / grep High token consumption for searching files
XcodeGlob find / glob High token consumption for file globbing
XcodeLS ls command High token consumption for listing files
XcodeRM rm command High token consumption for file removal
XcodeMakeDir mkdir command High token consumption for directory creation
XcodeMV mv command High token consumption for file moving

Recommended Workflows

1. Code Change & Build Flow

php
1. Search code      → Use `rg` or `grep` for pattern matching
2. Read file        → Use `Read` tool or `cat` for file reading
3. Edit file        → Use `Edit` tool for file editing
4. Syntax check     → Use `mcporter call xcode.getDiagnostics` for diagnostics
5. Build            → Use `mcporter call xcode.BuildProject` for project building
6. Check errors     → Use `mcporter call xcode.GetBuildLog` for build log retrieval (if build fails)

2. Test Writing & Running Flow

php
1. Read test file   → Use `Read` tool or `cat` for file reading
2. Write/edit test  → Use `Edit` tool for file writing and editing
3. Get test list    → Use `mcporter call xcode.GetTestList` for test listing
4. Run tests        → Use `mcporter call xcode.RunSomeTests` for specific test running
5. Check results    → Review the test output

3. SwiftUI Preview Flow

php
1. Edit view        → Use `Edit` tool for view editing
2. Render preview   → Use `mcporter call xcode.RenderPreview` for preview rendering
3. Iterate          → Repeat the process as needed

4. Debug Flow

php
1. Check diagnostics → Use `mcporter call xcode.getDiagnostics` for diagnostics
2. Build project     → Use `mcporter call xcode.BuildProject` for project building
3. Get build log     → Use `mcporter call xcode.GetBuildLog` for build log retrieval
4. Fix issues        → Use `Edit` tool for issue fixing
5. Rebuild           → Use `mcporter call xcode.BuildProject` for project rebuilding

5. Documentation Search

php
1. Search docs       → Use `mcporter call xcode.DocumentationSearch` for documentation searching
2. Review results    → Use the information in the implementation

Fallback Commands (When MCP or mcporter Unavailable)

If Xcode MCP is disconnected, mcporter is not installed, or the connection fails, use these xcodebuild commands directly:

Build Commands

bash
# Debug build (simulator) - replace <SchemeName> with your project's scheme
xcodebuild -scheme <SchemeName> -configuration Debug -sdk iphonesimulator build

# Release build (device)
xcodebuild -scheme <SchemeName> -configuration Release -sdk iphoneos build

# Build with workspace (for CocoaPods projects)
xcodebuild -workspace <ProjectName>.xcworkspace -scheme <SchemeName> -configuration Debug -sdk iphonesimulator build

# Build with project file
xcodebuild -project <ProjectName>.xcodeproj -scheme <SchemeName> -configuration Debug -sdk iphonesimulator build

# List available schemes
xcodebuild -list

Test Commands

bash
# Run all tests
xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \
  -destination "platform=iOS Simulator,name=iPhone 16" \
  -configuration Debug

# Run specific test class
xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \
  -destination "platform=iOS Simulator,name=iPhone 16" \
  -only-testing:<TestTarget>/<TestClassName>

# Run specific test method
xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \
  -destination "platform=iOS Simulator,name=iPhone 16" \
  -only-testing:<TestTarget>/<TestClassName>/<testMethodName>

# Run with code coverage
xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \
  -configuration Debug -enableCodeCoverage YES

# List available simulators
xcrun simctl list devices available

Clean Build

bash
xcodebuild clean -scheme <SchemeName>

Quick Reference

USE mcporter + Xcode MCP For:

  • BuildProject — Building projects
  • GetBuildLog — Retrieving build logs
  • RunSomeTests — Running specific tests
  • GetTestList — Listing available tests
  • RenderPreview — Rendering SwiftUI previews
  • getDiagnostics — Retrieving SourceKit diagnostics
  • XcodeListWindows — Retrieving tab identifiers

NEVER USE Xcode MCP For:

  • ❌ XcodeRead → Use Read tool or cat for file reading
  • ❌ XcodeWrite → Use Write tool for file writing
  • ❌ XcodeUpdate →
Original prompt (before our improvements)

--- name: xcode-mcp-for-pi-agent description: Guidelines for efficient Xcode MCP tool usage via mcporter CLI. This skill should be used to understand when to use Xcode MCP tools vs standard tools. Xcode MCP consumes many tokens - use only for build, test, simulator, preview, and SourceKit diagnostics. Never use for file read/write/grep operations. Use this skill whenever working with Xcode projects, iOS/macOS builds, SwiftUI previews, or Apple platform development. --- # Xcode MCP Usage Guidelines Xcode MCP tools are accessed via `mcporter` CLI, which bridges MCP servers to standard command-line tools. This skill defines when to use Xcode MCP and when to prefer standard tools. ## Setup Xcode MCP must be configured in `~/.mcporter/mcporter.json`: ```json { "mcpServers": { "xcode": { "command": "xcrun", "args": ["mcpbridge"], "env": {} } } } ``` Verify the connection: ```bash mcporter list xcode ``` --- ## Calling Tools All Xcode MCP tools are called via mcporter: ```bash # List available tools mcporter list xcode # Call a tool with key:value args mcporter call xcode.<tool_name> param1:value1 param2:value2 # Call with function-call syntax mcporter call 'xcode.<tool_name>(param1: "value1", param2: "value2")' ``` --- ## Complete Xcode MCP Tools Reference ### Window & Project Management | Tool | mcporter call | Token Cost | |------|---------------|------------| | List open Xcode windows (get tabIdentifier) | `mcporter call xcode.XcodeListWindows` | Low ✓ | ### Build Operations | Tool | mcporter call | Token Cost | |------|---------------|------------| | Build the Xcode project | `mcporter call xcode.BuildProject` | Medium ✓ | | Get build log with errors/warnings | `mcporter call xcode.GetBuildLog` | Medium ✓ | | List issues in Issue Navigator | `mcporter call xcode.XcodeListNavigatorIssues` | Low ✓ | ### Testing | Tool | mcporter call | Token Cost | |------|---------------|------------| | Get available tests from test plan | `mcporter call xcode.GetTestList` | Low ✓ | | Run all tests | `mcporter call xcode.RunAllTests` | Medium | | Run specific tests (preferred) | `mcporter call xcode.RunSomeTests` | Medium ✓ | ### Preview & Execution | Tool | mcporter call | Token Cost | |------|---------------|------------| | Render SwiftUI Preview snapshot | `mcporter call xcode.RenderPreview` | Medium ✓ | | Execute code snippet in file context | `mcporter call xcode.ExecuteSnippet` | Medium ✓ | ### Diagnostics | Tool | mcporter call | Token Cost | |------|---------------|------------| | Get compiler diagnostics for specific file | `mcporter call xcode.XcodeRefreshCodeIssuesInFile` | Low ✓ | | Get SourceKit diagnostics (all open files) | `mcporter call xcode.getDiagnostics` | Low ✓ | ### Documentation | Tool | mcporter call | Token Cost | |------|---------------|------------| | Search Apple Developer Documentation | `mcporter call xcode.DocumentationSearch` | Low ✓ | ### File Operations (HIGH TOKEN - NEVER USE) | MCP Tool | Use Instead | Why | |----------|-------------|-----| | `xcode.XcodeRead` | `Read` tool / `cat` | High token consumption | | `xcode.XcodeWrite` | `Write` tool | High token consumption | | `xcode.XcodeUpdate` | `Edit` tool | High token consumption | | `xcode.XcodeGrep` | `rg` / `grep` | High token consumption | | `xcode.XcodeGlob` | `find` / `glob` | High token consumption | | `xcode.XcodeLS` | `ls` command | High token consumption | | `xcode.XcodeRM` | `rm` command | High token consumption | | `xcode.XcodeMakeDir` | `mkdir` command | High token consumption | | `xcode.XcodeMV` | `mv` command | High token consumption | --- ## Recommended Workflows ### 1. Code Change & Build Flow ``` 1. Search code → rg "pattern" --type swift 2. Read file → Read tool / cat 3. Edit file → Edit tool 4. Syntax check → mcporter call xcode.getDiagnostics 5. Build → mcporter call xcode.BuildProject 6. Check errors → mcporter call xcode.GetBuildLog (if build fails) ``` ### 2. Test Writing & Running Flow ``` 1. Read test file → Read tool / cat 2. Write/edit test → Edit tool 3. Get test list → mcporter call xcode.GetTestList 4. Run tests → mcporter call xcode.RunSomeTests (specific tests) 5. Check results → Review test output ``` ### 3. SwiftUI Preview Flow ``` 1. Edit view → Edit tool 2. Render preview → mcporter call xcode.RenderPreview 3. Iterate → Repeat as needed ``` ### 4. Debug Flow ``` 1. Check diagnostics → mcporter call xcode.getDiagnostics 2. Build project → mcporter call xcode.BuildProject 3. Get build log → mcporter call xcode.GetBuildLog severity:error 4. Fix issues → Edit tool 5. Rebuild → mcporter call xcode.BuildProject ``` ### 5. Documentation Search ``` 1. Search docs → mcporter call xcode.DocumentationSearch query:"SwiftUI NavigationStack" 2. Review results → Use information in implementation ``` --- ## Fallback Commands (When MCP or mcporter Unavailable) If Xcode MCP is disconnected, mcporter is not installed, or the connection fails, use these xcodebuild commands directly: ### Build Commands ```bash # Debug build (simulator) - replace <SchemeName> with your project's scheme xcodebuild -scheme <SchemeName> -configuration Debug -sdk iphonesimulator build # Release build (device) xcodebuild -scheme <SchemeName> -configuration Release -sdk iphoneos build # Build with workspace (for CocoaPods projects) xcodebuild -workspace <ProjectName>.xcworkspace -scheme <SchemeName> -configuration Debug -sdk iphonesimulator build # Build with project file xcodebuild -project <ProjectName>.xcodeproj -scheme <SchemeName> -configuration Debug -sdk iphonesimulator build # List available schemes xcodebuild -list ``` ### Test Commands ```bash # Run all tests xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \ -destination "platform=iOS Simulator,name=iPhone 16" \ -configuration Debug # Run specific test class xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \ -destination "platform=iOS Simulator,name=iPhone 16" \ -only-testing:<TestTarget>/<TestClassName> # Run specific test method xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \ -destination "platform=iOS Simulator,name=iPhone 16" \ -only-testing:<TestTarget>/<TestClassName>/<testMethodName> # Run with code coverage xcodebuild test -scheme <SchemeName> -sdk iphonesimulator \ -configuration Debug -enableCodeCoverage YES # List available simulators xcrun simctl list devices available ``` ### Clean Build ```bash xcodebuild clean -scheme <SchemeName> ``` --- ## Quick Reference ### USE mcporter + Xcode MCP For: - ✅ `xcode.BuildProject` — Building - ✅ `xcode.GetBuildLog` — Build errors - ✅ `xcode.RunSomeTests` — Running specific tests - ✅ `xcode.GetTestList` — Listing tests - ✅ `xcode.RenderPreview` — SwiftUI previews - ✅ `xcode.ExecuteSnippet` — Code execution - ✅ `xcode.DocumentationSearch` — Apple docs - ✅ `xcode.XcodeListWindows` — Get tabIdentifier - ✅ `xcode.getDiagnostics` — SourceKit errors ### NEVER USE Xcode MCP For: - ❌ `xcode.XcodeRead` → Use `Read` tool / `cat` - ❌ `xcode.XcodeWrite` → Use `Write` tool - ❌ `xcode.XcodeUpdate` → Use `Edit` tool - ❌ `xcode.XcodeGrep` → Use `rg` or `grep` - ❌ `xcode.XcodeGlob` → Use `find` / `glob` - ❌ `xcode.XcodeLS` → Use `ls` command - ❌ File operations → Use standard tools --- ## Token Efficiency Summary | Operation | Best Choice | Token Impact | |-----------|-------------|--------------| | Quick syntax check | `mcporter call xcode.getDiagnostics` | 🟢 Low | | Full build | `mcporter call xcode.BuildProject` | 🟡 Medium | | Run specific tests | `mcporter call xcode.RunSomeTests` | 🟡 Medium | | Run all tests | `mcporter call xcode.RunAllTests` | 🟠 High | | Read file | `Read` tool / `cat` | 🟢 Low | | Edit file | `Edit` tool | 🟢 Low | | Search code | `rg` / `grep` | 🟢 Low | | List files | `ls` / `find` | 🟢 Low |