MCP Server implementation for Xcode integration
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.
No configuration available
This service may require manual configuration, please check the details on the left
Related projects feature coming soon
Will recommend related projects based on sub-categories