Labsco
r-huijts logo

Xcode MCP

โ˜… 380

from r-huijts

Integrate with Xcode to build and manage your projects.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

MseeP.ai Security Assessment Badge

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

Project Structure

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)

How It Works

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:

Core Components

  1. Server Implementation: The main MCP server that handles tool registration and request processing.

  2. Path Management: Ensures secure file access by validating all paths against allowed directories.

  3. Project Management: Detects, loads, and manages different types of Xcode projects:

    • Standard Xcode projects (.xcodeproj)
    • Xcode workspaces (.xcworkspace)
    • Swift Package Manager projects (Package.swift)
  4. Directory State: Maintains the active directory context for relative path resolution.

  5. Tool Registry: Organizes tools into logical categories for different Xcode operations.

Request Flow

  1. An AI assistant sends a tool execution request to the MCP server.

  2. The server validates the request parameters and permissions.

  3. The appropriate tool handler is invoked with the validated parameters.

  4. The tool executes the requested operation, often using native Xcode commands.

  5. Results are formatted and returned to the AI assistant.

  6. Comprehensive error handling provides meaningful feedback for troubleshooting.

Safety Features

  • Path Validation: All file operations are restricted to allowed directories.
  • Error Handling: Detailed error messages help diagnose issues.
  • Parameter Validation: Input parameters are validated using Zod schemas.
  • Process Management: External processes are executed safely with proper error handling.

Project Type Support

The server intelligently handles different project types:

  • Standard Projects: Direct .xcodeproj manipulation
  • Workspaces: Manages multiple projects within a workspace
  • SPM Projects: Handles Swift Package Manager specific operations

This architecture allows AI assistants to seamlessly work with any type of Xcode project while maintaining security and providing detailed feedback.