MCP Server for iOS Simulator

Integrations

  • Built on top of appium-ios-simulator to provide iOS simulator interaction capabilities for controlling simulator lifecycle and performing actions.

  • Allows programmatic control of iOS simulators, including starting, stopping, booting, installing and launching apps, taking screenshots, and performing taps on coordinates.

  • Interacts with Xcode's iOS simulator infrastructure to manage simulator instances and perform operations on iOS devices.

📱 iOS 模拟器的 MCP 服务器

一个为 iOS 模拟器实现模型上下文协议 (MCP) 的服务器,建立在appium-ios-simulator之上并利用MCP TypeScript SDK

📋 概述

该项目在 iOS 模拟器和模型上下文协议 (MCP) 之间搭建了桥梁,允许与 iOS 模拟器实例进行标准化通信。它支持以编程方式控制 iOS 模拟器,同时利用 MCP 协议在不同环境中实现一致的接口。服务器使用 stdio 作为传输机制,非常适合与 Claude Desktop 和其他兼容 MCP 的客户端集成。

🎬 演示

演示如何使用 Claude AI Desktop 启动 iOS 模拟器

🏗️ 建筑

该服务器由三个主要组件组成:

  1. 🔄 模拟器管理层- 处理 iOS 模拟器生命周期和交互
  2. 🔌 MCP 协议实现- 使用带有 stdio 传输的 TypeScript SDK 实现模型上下文协议
  3. 📊 Logger 组件- 提供基于文件的日志记录,而不会干扰 stdio 传输
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ MCP Protocol │ │ Stdio │ │ Simulator │ │ Implementation │◄────┤ Transport │◄────┤ Management │ │ │ │ │ │ Layer │ └─────────────────┘ └─────────────────┘ └─────────────────┘ ▲ ▲ │ │ ▼ ▼ ┌─────────────────┐ ┌─────────────────┐ │ MCP Client │ │ iOS Simulator │ │ (e.g. Claude) │ │ │ └─────────────────┘ └─────────────────┘

✨ 特点

  • 🚀 启动、停止和管理 iOS 模拟器实例
  • 🔌 启动和关机模拟器
  • 📲 在模拟器上安装和启动应用程序
  • 📸 截取模拟器屏幕的屏幕截图
  • 👆 在坐标上执行点击
  • 🔄 支持多个并发模拟器会话
  • 📝 无需控制台输出的全面基于文件的日志记录
  • 🛡️ 容错操作

📋 先决条件

  • 🟢 Node.js(v16 或更高版本)
  • 🍎 macOS(iOS 模拟器必需)
  • 🛠️ 安装了 iOS 模拟器的 Xcode
  • 📜 TypeScript 4.5+

🔧 安装

# Clone the repository git clone https://github.com/atom2ueki/mcp-server-ios-simulator.git cd mcp-server-ios-simulator # Install dependencies npm install

⚙️ 配置

配置通过src/config.ts文件处理:

const config = { simulator: { defaultDevice: process.env.SIMULATOR_DEFAULT_DEVICE || 'iPhone 16', defaultOS: process.env.SIMULATOR_DEFAULT_OS || '18.2', timeout: parseInt(process.env.SIMULATOR_TIMEOUT || '30000', 10), } };

您可以通过设置环境变量来自定义这些设置:

SIMULATOR_DEFAULT_DEVICE=iPhone 16 SIMULATOR_DEFAULT_OS=18.2 SIMULATOR_TIMEOUT=30000

🚀 使用方法

🔨 构建并启动服务器

# Build the project npm run build # Start the server npm start

🧰 MCP 工具

服务器提供了两种不同的方法来控制 iOS 模拟器:

📱直接模拟器管理(推荐)

这些工具直接与模拟器 UDID 配合使用,不需要维护会话:

  • 📋 list-available-simulators - 列出所有可用的模拟器及其 UDID
  • ▶️ boot-simulator-by-udid - 使用其 UDID 直接启动模拟器
  • ⏹️ shutdown-simulator-by-udid - 使用其 UDID 直接关闭模拟器
  • 📊 list-booted-simulators - 列出所有当前启动的模拟器

**在以下情况下使用此方法:**您只想直接启动、使用和关闭模拟器。

📱基于会话的管理(高级)

这些工具使用会话层来跟踪具有自定义会话 ID 的模拟器:

  • 📋 list-simulator-sessions - 列出所有活动的模拟器会话
  • create-simulator-session - 创建一个新的模拟器会话
  • terminate-simulator-session - 终止会话(关闭模拟器并清理)
  • 🔄 create-and-boot-simulator - 创建新的模拟器会话并启动它
  • ▶️ boot-simulator - 为现有会话启动模拟器
  • ⏹️ shutdown-simulator - 关闭现有会话的模拟器

**在以下情况下使用此方法:**您需要跟踪模拟器元数据、通过自定义 ID 引用模拟器或使用更高级的管理功能。

📲 应用程序管理

  • 📥 install-app - 在模拟器上安装应用程序
  • 🚀 launch-app - 在模拟器上启动应用程序
  • 🛑 terminate-app - 终止模拟器上正在运行的应用程序

🖱️ 交互工具

  • 📷 take-screenshot - 截取模拟器屏幕的屏幕截图
  • 👆 tap-coordinate - 在指定坐标处执行点击

🤖 Claude Desktop 的使用示例

  1. 配置 Claude Desktop 以将此服务器用作 MCP 工具:
    • 打开 Claude 桌面
    • 前往“设置”>“高级”
    • 在“MCP 服务器”部分添加以下配置:
    { "mcpServers": { "simulator": { "command": "node", "args": [ "/path/to/your/mcp-server-ios-simulator/dist/index.js" ] } } }
    • /path/to/your替换为您安装此存储库的实际路径
    • 保存设置并重新启动Claude Desktop
  2. 使用提供的工具直接从 Claude Desktop 控制 iOS 模拟器:直接 UDID 方法(推荐):
    1. 首先,让 Claude 列出可用的模拟器:
      "Show me all available iOS simulators"
    2. 然后使用 UDID 启动特定的模拟器:
      "Boot the iOS simulator with UDID 5272EA61-5796-4372-86FE-3B33831D5CC1"
    3. 完成后,使用相同的 UDID 将其关闭:
      "Shut down the simulator with UDID 5272EA61-5796-4372-86FE-3B33831D5CC1"

    对于大多数用例来说,直接 UDID 方法更简单、更可靠。

    **基于会话的方法(高级):**仅当您需要会话跟踪的高级功能时才使用此方法:

    "Create a new simulator session for iPhone 16 Pro with iOS 18.2" "Boot the simulator for session abc-123" "Take a screenshot of the simulator for session abc-123" "Terminate the simulator session abc-123"

👨‍💻 开发

📁 项目结构

src/ ├── simulator/ # Simulator management layer ├── mcp/ # MCP protocol implementation ├── bridge/ # Bridge component ├── utils/ # Utility functions including logger ├── config.ts # Configuration handling └── index.ts # Entry point

🔨 构建项目

# Install development dependencies npm install # Run TypeScript compiler npm run build

📜 许可证

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。

🙏 致谢

ID: 18at56szif