Xcode Integration
STDIOMCP server providing comprehensive Xcode integration for AI assistants.
MCP server providing comprehensive Xcode integration for AI assistants.
An MCP (Model Context Protocol) server providing comprehensive Xcode integration for AI assistants. This server enables AI agents to interact with Xcode projects, manage iOS simulators, and perform various Xcode-related tasks with enhanced error handling and support for multiple project types.
Use the included setup script which automates the installation and configuration process:
# Make the script executable chmod +x setup.sh # Run the setup script ./setup.sh
What the Setup Script Does:
Environment Verification:
Dependency Installation:
npm install
to install all required Node.js packagesnpm run build
to compile the TypeScript codeConfiguration Setup:
.env
file if one doesn't existClaude Desktop Integration (Optional):
When to Use the Setup Script:
The script will guide you through the configuration process with clear prompts and helpful feedback.
When to Use Manual Setup:
Follow these steps for manual installation:
Clone the repository:
git clone https://github.com/r-huijts/xcode-mcp-server.git cd xcode-mcp-server
Verify prerequisites (these must be installed):
Install dependencies:
npm install
Build the project:
npm run build
Create a configuration file:
# Option A: Start with the example configuration cp .env.example .env # Option B: Create a minimal configuration echo "PROJECTS_BASE_DIR=/path/to/your/projects" > .env echo "DEBUG=false" >> .env
Edit the .env
file to set your preferred configuration.
For Claude Desktop integration (optional):
~/Library/Application Support/Claude/claude_desktop_config.json
{ "mcpServers": { "xcode": { "command": "node", "args": ["/path/to/xcode-mcp-server/dist/index.js"] } } }
Common Setup Issues:
Build Errors:
node_modules
and running npm install
againnpx tsc --noEmit
Missing Dependencies:
npm install
againxcode-select --install
Permission Issues:
sudo gem install cocoapods
Configuration Problems:
.env
file has the correct format and valid pathsPROJECTS_BASE_DIR
points to an existing directoryClaude Desktop Integration:
index.js
npm start
For development mode with automatic restarts:
npm run dev
You can configure the server in two ways:
Environment variables in .env
file:
PROJECTS_BASE_DIR=/path/to/your/projects
DEBUG=true
ALLOWED_PATHS=/path/to/additional/allowed/directory
PORT=8080
Command line arguments:
npm start -- --projects-dir=/path/to/your/projects --port=8080
PROJECTS_BASE_DIR
/ --projects-dir
: Base directory for projects (required)ALLOWED_PATHS
/ --allowed-paths
: Additional directories to allow access to (comma-separated)PORT
/ --port
: Port to run the server on (default: 3000)DEBUG
/ --debug
: Enable debug logging (default: false)LOG_LEVEL
/ --log-level
: Set logging level (default: info)The server implements the Model Context Protocol (MCP), making it compatible with various AI assistants that support this protocol. To connect:
http://localhost:3000
)For a comprehensive overview of all available tools and their usage, see Tools Overview.
For detailed usage examples and best practices, see User Guide.
// Create a new iOS app project await tools.create_xcode_project({ name: "MyAwesomeApp", template: "ios-app", outputDirectory: "~/Projects", organizationName: "My Organization", organizationIdentifier: "com.myorganization", language: "swift", includeTests: true, setAsActive: true }); // Add a Swift Package dependency await tools.add_swift_package({ url: "https://github.com/Alamofire/Alamofire.git", version: "from: 5.0.0" });
// Read a file with specific encoding const fileContent = await tools.read_file({ filePath: "MyAwesomeApp/AppDelegate.swift", encoding: "utf-8" }); // Write to a file await tools.write_file({ path: "MyAwesomeApp/NewFile.swift", content: "import Foundation\n\nclass NewClass {}\n", createIfMissing: true }); // Search for text in files const searchResults = await tools.search_in_files({ directory: "MyAwesomeApp", pattern: "*.swift", searchText: "class", isRegex: false });
// Build the project await tools.build_project({ scheme: "MyAwesomeApp", configuration: "Debug" }); // Run tests await tools.test_project({ scheme: "MyAwesomeApp", testPlan: "MyAwesomeAppTests" });
xcode-mcp-server/
├── src/
│ ├── index.ts # Entry point
│ ├── server.ts # MCP server implementation
│ ├── types/ # Type definitions
│ │ └── index.ts # Core type definitions
│ ├── utils/ # Utility functions
│ │ ├── errors.js # Error handling classes
│ │ ├── pathManager.ts # Path validation and management
│ │ ├── project.js # Project utilities
│ │ └── simulator.js # Simulator utilities
│ └── tools/ # Tool implementations
│ ├── project/ # Project management tools
│ │ └── index.ts # Project creation, detection, file adding
│ ├── file/ # File operation tools
│ │ └── index.ts # File reading, writing, searching
│ ├── build/ # Build and testing tools
│ │ └── index.ts # Building, testing, analyzing
│ ├── cocoapods/ # CocoaPods integration
│ │ └── index.ts # Pod installation and management
│ ├── spm/ # Swift Package Manager tools
│ │ └── index.ts # Package management and documentation
│ ├── simulator/ # iOS simulator tools
│ │ └── index.ts # Simulator control and interaction
│ └── xcode/ # Xcode utilities
│ └── index.ts # Xcode version management, asset tools
├── docs/ # Documentation
│ ├── tools-overview.md # Comprehensive tool documentation
│ └── user-guide.md # Usage examples and best practices
├── tests/ # Tests
└── dist/ # Compiled code (generated)
The Xcode MCP server uses the Model Context Protocol to provide a standardized interface for AI models to interact with Xcode projects. The server architecture is designed with several key components:
Server Implementation: The main MCP server that handles tool registration and request processing.
Path Management: Ensures secure file access by validating all paths against allowed directories.
Project Management: Detects, loads, and manages different types of Xcode projects:
Directory State: Maintains the active directory context for relative path resolution.
Tool Registry: Organizes tools into logical categories for different Xcode operations.
An AI assistant sends a tool execution request to the MCP server.
The server validates the request parameters and permissions.
The appropriate tool handler is invoked with the validated parameters.
The tool executes the requested operation, often using native Xcode commands.
Results are formatted and returned to the AI assistant.
Comprehensive error handling provides meaningful feedback for troubleshooting.
The server intelligently handles different project types:
This architecture allows AI assistants to seamlessly work with any type of Xcode project while maintaining security and providing detailed feedback.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)To add a new tool to the server:
src/tools/
directoryindex.ts
filenpm start -- --debug
This project is licensed under the MIT License - see the LICENSE file for details.