Labsco
lapfelix logo

XcodeMCP

β˜… 57

from lapfelix

An MCP server to control Xcode on macOS using JavaScript for Automation (JXA).

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

Using with Apple's Official Xcode MCP: Apple now provides an official Xcode MCP server. XcodeMCP can run alongside it in sidekick mode (--sidekick-only), providing complementary tools like project management and XCResult analysis. In a future version, XcodeMCP will transition to sidekick-only mode by default. See configuration below.

XcodeMCP

npm version Test Status

Model Context Protocol (MCP) server that controls Xcode directly through JavaScript for Automation (JXA). Available as both an MCP server and a standalone CLI.

What it does

  • Controls Xcode directly through JavaScript for Automation (not xcodebuild CLI)
  • Opens projects, builds, runs, tests, and debugs from within Xcode
  • Parses build logs with precise error locations using XCLogParser
  • Provides comprehensive environment validation and health checks
  • Supports graceful degradation when optional dependencies are missing
  • NEW: Includes a full-featured CLI with 100% MCP server feature parity

Available Tools

Project Management:

  • xcode_open_project - Open projects and workspaces
  • xcode_get_workspace_info - Get workspace status and details
  • xcode_get_projects - List projects in workspace
  • xcode_open_file - Open files with optional line number

Build Operations:

  • xcode_build - Build with detailed error parsing
  • xcode_clean - Clean build artifacts
  • xcode_test - Run tests with optional arguments
  • xcode_build_and_run - Build and run the active scheme
  • xcode_debug - Start debugging session
  • xcode_stop - Stop current operation

Configuration:

  • xcode_get_schemes - List available schemes
  • xcode_set_active_scheme - Switch active scheme
  • xcode_get_run_destinations - List simulators and devices

XCResult Analysis:

  • xcresult_browse - Browse test results and analyze failures
  • xcresult_browser_get_console - Get console output for specific tests
  • xcresult_summary - Quick overview of test results
  • xcresult_get_screenshot - Extract screenshots from test failures
  • xcresult_get_ui_hierarchy - Get UI hierarchy as AI-readable JSON with timestamp selection
  • xcresult_get_ui_element - Get detailed properties of specific UI elements by index
  • xcresult_list_attachments - List all attachments for a test
  • xcresult_export_attachment - Export specific attachments from test results

Diagnostics:

  • xcode_health_check - Environment validation and troubleshooting

XCResult Analysis Features

XcodeMCP provides comprehensive tools for analyzing Xcode test results (.xcresult files), making it easy to debug test failures and extract valuable information:

Test Result Analysis

  • Browse Results: Navigate through test hierarchies, view pass/fail status, and examine detailed test information
  • Console Logs: Extract console output and test activities with precise timestamps for debugging
  • Quick Summaries: Get overview statistics including pass rates, failure counts, and duration

Visual Debugging

  • Screenshot Extraction: Extract PNG screenshots from test failures using ffmpeg frame extraction from video attachments
  • Timestamp Precision: Specify exact timestamps to capture UI state at specific moments during test execution

UI Hierarchy Analysis

  • AI-Readable Format: Extract UI hierarchies as compressed JSON with single-letter properties (t=type, l=label, f=frame, c=children, j=index)
  • Timestamp Selection: Automatically find the closest UI hierarchy capture to any specified timestamp
  • Element Deep-Dive: Use index references to get full details of any UI element, including accessibility properties and frame information
  • Size Optimization: 75%+ size reduction compared to full hierarchy data while maintaining all essential information

Attachment Management

  • Complete Inventory: List all attachments (screenshots, videos, debug descriptions, UI hierarchies) for any test
  • Selective Export: Export specific attachments by index or type
  • Smart Detection: Automatically identify and categorize different attachment types

Usage Examples

Copy & paste β€” that's it
# Browse test results
xcresult_browse "/path/to/TestResults.xcresult"

# Get console output to find failure timestamps
xcresult_browser_get_console "/path/to/TestResults.xcresult" "MyTest/testMethod()"

# Get UI hierarchy at specific timestamp (AI-readable slim version)
xcresult_get_ui_hierarchy "/path/to/TestResults.xcresult" "MyTest/testMethod()" 45.25

# Get full UI hierarchy (with size warning)
xcresult_get_ui_hierarchy "/path/to/TestResults.xcresult" "MyTest/testMethod()" 45.25 true

# Get detailed properties of a specific UI element
xcresult_get_ui_element "/path/to/ui_hierarchy_full.json" 15

# Extract screenshot at failure point
xcresult_get_screenshot "/path/to/TestResults.xcresult" "MyTest/testMethod()" 30.71

Example Output

Build with errors:

Copy & paste β€” that's it
❌ BUILD FAILED (2 errors)

ERRORS:
  β€’ /path/HandsDownApp.swift:7:18: Expected 'func' keyword in instance method declaration
  β€’ /path/MenuBarManager.swift:98:13: Invalid redeclaration of 'toggleItem'

Health check:

Copy & paste β€” that's it
βœ… All systems operational

βœ… OS: macOS environment detected
βœ… XCODE: Xcode found at /Applications/Xcode.app (version 16.4)
βœ… XCLOGPARSER: XCLogParser found (XCLogParser 0.2.41)
βœ… OSASCRIPT: JavaScript for Automation (JXA) is available
βœ… PERMISSIONS: Xcode automation permissions are working