
Xcode MCP Server
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.
Features
Project Management
- Set active projects and get detailed project information
- Create new Xcode projects from templates (iOS, macOS, watchOS, tvOS)
- Add files to Xcode projects with target and group specification
- Parse workspace documents to find associated projects
- List available schemes in projects and workspaces
File Operations
- Read/write files with support for different encodings
- Handle binary files with base64 encoding/decoding
- Search for text content within files using patterns and regex
- Check file existence and get file metadata
- Create directory structures automatically
Build & Testing
- Build projects with customizable options
- Run tests with detailed failure reporting
- Analyze code for potential issues
- Clean build directories
- Archive projects for distribution
CocoaPods Integration
- Initialize CocoaPods in projects
- Install and update pods
- Add and remove pod dependencies
- Execute arbitrary pod commands
Swift Package Manager
- Initialize new Swift packages
- Add and remove package dependencies with various version requirements
- Update packages and resolve dependencies
- Generate documentation for Swift packages using DocC
- Run tests and build Swift packages
iOS Simulator Tools
- List available simulators with detailed information
- Boot and shut down simulators
- Install and launch apps on simulators
- Take screenshots and record videos
- Manage simulator settings and state
Xcode Utilities
- Execute Xcode commands via xcrun
- Compile asset catalogs
- Generate app icon sets from source images
- Trace app performance
- Export and validate archives for App Store submission
- Switch between different Xcode versions
Installation
Prerequisites
- macOS with Xcode 14.0 or higher installed
- Node.js 16 or higher
- npm or yarn
- Swift 5.5+ for Swift Package Manager features
- CocoaPods (optional, for CocoaPods integration)
Setup
Option 1: Automated Setup (Recommended)
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:
- Checks that you're running on macOS
- Verifies Xcode is installed and accessible
- Confirms Node.js (v16+) and npm are available
- Checks for Ruby installation
- Verifies CocoaPods installation (offers to install if missing)
-
Dependency Installation:
- Runs
npm install to install all required Node.js packages
- Executes
npm run build to compile the TypeScript code
-
Configuration Setup:
- Creates a
.env file if one doesn't exist
- Prompts for your projects base directory
- Asks if you want to enable debug logging
- Saves your configuration preferences
-
Claude Desktop Integration (Optional):
- Offers to configure the server for Claude Desktop
- Creates or updates the Claude Desktop configuration file
- Sets up the proper command and arguments to launch the server
When to Use the Setup Script:
- First-time installation to ensure all prerequisites are met
- When you want guided configuration with interactive prompts
- If you want to quickly set up Claude Desktop integration
- To verify your environment has all necessary components
The script will guide you through the configuration process with clear prompts and helpful feedback.
Option 2: Manual Setup
When to Use Manual Setup:
- You prefer explicit control over each installation step
- You have a custom environment or non-standard configuration
- You're setting up in a CI/CD pipeline or automated environment
- You want to customize specific aspects of the installation process
- You're an experienced developer familiar with Node.js projects
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):
- Xcode and Xcode Command Line Tools
- Node.js v16 or higher
- npm
- Ruby (for CocoaPods support)
- CocoaPods (optional, for pod-related features)
-
Install dependencies:
-
Build the project:
-
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):
- Edit or create
~/Library/Application Support/Claude/claude_desktop_config.json
- Add the following configuration (adjust paths as needed):
{
"mcpServers": {
"xcode": {
"command": "node",
"args": ["/path/to/xcode-mcp-server/dist/index.js"]
}
}
}
Setup Troubleshooting
Common Setup Issues:
-
Build Errors:
- Ensure you have the correct Node.js version (v16+)
- Try deleting
node_modules and running npm install again
- Check for TypeScript errors with
npx tsc --noEmit
- Make sure all imports in the code are properly resolved
-
Missing Dependencies:
- If you see errors about missing modules, run
npm install again
- For native dependencies, you may need Xcode Command Line Tools:
xcode-select --install
-
Permission Issues:
- Ensure you have write permissions to the installation directory
- For CocoaPods installation, you may need to use
sudo gem install cocoapods
-
Configuration Problems:
- Verify your
.env file has the correct format and valid paths
- Make sure
PROJECTS_BASE_DIR points to an existing directory
- Check that the path doesn't contain special characters that need escaping
-
Claude Desktop Integration:
- Ensure the path in the Claude configuration points to the correct location of
index.js
- Restart Claude Desktop after making configuration changes
- Check that the server is running before attempting to use it with Claude
Usage
Starting the Server
For development mode with automatic restarts:
Configuration Options
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
Key Configuration Parameters
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)
Connecting to AI Assistants
The server implements the Model Context Protocol (MCP), making it compatible with various AI assistants that support this protocol. To connect:
- Start the Xcode MCP server
- Configure your AI assistant to use the server URL (typically
http://localhost:3000)
- The AI assistant will now have access to all the Xcode tools provided by the server
Tool Documentation
For a comprehensive overview of all available tools and their usage, see Tools Overview.
For detailed usage examples and best practices, see User Guide.
Common Workflows
Setting Up a New Project
// 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"
});
Working with Files
// 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
});
Building and Testing
// Build the project
await tools.build_project({
scheme: "MyAwesomeApp",
configuration: "Debug"
});
// Run tests
await tools.test_project({
scheme: "MyAwesomeApp",
testPlan: "MyAwesomeAppTests"
});
Project Structure