This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
XcodeBuildMCP is a Model Context Protocol (MCP) server that exposes Xcode operations as tools for AI assistants. It enables programmatic interaction with Xcode projects, simulators, devices, and Swift packages through a standardized interface.
- Entry Point:
src/index.ts- Server initialization, tool registration, and lifecycle management - Server Configuration:
src/server/server.ts- MCP server setup and transport configuration - Tool Organization: Platform-specific tools in
src/tools/grouped by functionality:- Build tools:
build_*.ts - Simulator management:
simulator.ts,screenshot.ts,axe.ts - Device management:
device.ts,device_log.ts - Swift Package Manager:
*-swift-package.ts - Project utilities:
discover_projects.ts,scaffold.ts,clean.ts
- Build tools:
- Shared Utilities:
src/utils/- Command execution, validation, logging, and error handling - Type Definitions:
src/types/common.ts- Shared interfaces and type definitions
- Tool Registration: Tools are registered in
src/utils/register-tools.tsusing a centralized system with workflow-based grouping - Schema Validation: All tools use Zod schemas for parameter validation before execution
- Command Execution: Standardized pattern using
src/utils/command.tsfor external command execution - Error Handling: Consistent error wrapping and logging through
src/utils/errors.ts - Selective Tool Enablement: Environment variables control which tools are exposed (see
src/utils/tool-groups.ts)
# Install dependencies
npm install
# Build the project
npm run build
# Watch mode for development
npm run build:watch
# Run linting
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Check formatting
npm run format:check
# Test the server with MCP Inspector
npm run inspect
# Run diagnostic tool
npm run diagnosticWhen adding a new tool:
- Create the tool implementation in
src/tools/ - Define Zod schema for parameters
- Follow the existing pattern:
export async function myNewTool(params: z.infer<typeof MyToolSchema>): Promise<{ output: string }> { // Validate parameters const validated = MyToolSchema.parse(params); // Execute command using command.ts utilities const result = await exec(...); // Return standardized output return { output: result }; }
- Register the tool in
src/utils/register-tools.ts - Add to appropriate tool group in
src/utils/tool-groups.ts - Update TOOL_OPTIONS.md if adding a new group
- Update TOOLS.md with the new tool's name, MCP tool name, and description in the appropriate category
Currently, testing is primarily done through:
- Manual testing with example projects in
example_projects/ - MCP Inspector for interactive testing (
npm run inspect) - Diagnostic tool for environment validation
- Experimental feature using
xcodemakeinstead ofxcodebuild - Enabled via
INCREMENTAL_BUILDS_ENABLEDenvironment variable - Implementation in
src/utils/xcodemake.ts
- Uses bundled AXe tool (
bundled/axe) for simulator UI interaction - Coordinates are obtained from UI hierarchy, not screenshots
- Implementation in
src/tools/axe.ts
- Requires proper code signing configuration in Xcode
- Uses FB frameworks bundled in
bundled/Frameworks/ - Supports both USB and Wi-Fi connected devices
- Project scaffolding templates are external and versioned
- Downloaded on-demand from GitHub releases
- Managed by
src/utils/template-manager.ts
- Server Logs: Set
LOG_LEVEL=debugenvironment variable - MCP Inspector: Use
npm run inspectfor interactive debugging - Diagnostic Tool: Run
npm run diagnosticto check environment - Client Logs: Check MCP client logs (e.g., Cursor logs in
~/Library/Application Support/Cursor/logs)
- Follow existing code patterns and structure
- Use TypeScript strictly - no
anytypes - Add proper error handling and logging
- Update documentation for new features
- Update TOOLS.md when adding, modifying, or removing tools
- Test with example projects before submitting
- Run lint and format checks before committing
All available tools are comprehensively documented in TOOLS.md, which provides:
- Complete list of all 81 tools organized by category
- Tool names and MCP tool names
- Detailed descriptions and parameter requirements
- Common workflow patterns
- Environment variable configuration
- macOS:
build_mac_ws,build_mac_proj - iOS Simulator:
build_sim_name_ws,build_sim_id_ws - iOS Device:
build_dev_ws,build_dev_proj - Swift Package:
swift_package_build
- macOS:
launch_mac_app - iOS Simulator:
launch_app_sim - iOS Device:
launch_app_device - Swift Package:
swift_package_run
- macOS:
test_macos_ws,test_macos_proj - iOS Simulator:
test_sim_name_ws,test_sim_id_ws - iOS Device:
test_device_ws,test_device_proj - Swift Package:
swift_package_test