README
🚀 iOS 模拟器屏幕截图 MCP 服务器
这是一个使用模型上下文协议 (MCP) 从 iOS 模拟器捕获屏幕截图的服务器,能捕获当前 iOS 模拟器屏幕并将截图保存到指定目录。
🚀 快速开始
使用该服务器,可按以下步骤操作:
- 克隆仓库:
git clone [仓库地址] cd mcp-ios-simulator-screenshot - 安装依赖项:
npm install - 启动服务器:
node build/index.js - 使用 MCP 客户端调用
get_screenshot方法。
✨ 主要特性
- 基于 MCP 协议,能从 iOS 模拟器捕获屏幕截图并保存到指定目录。
- 可通过参数配置输出文件名、子目录名称、图像缩放等。
📦 安装指南
Cline 和 Roo Code
对于 Cline 和 Roo Code,基本格式如下:
{
"mcpServers": {
"mcp-ios-simulator-screenshot": {
"command": "npx",
"args": ["-y", "mcp-ios-simulator-screenshot"]
}
}
}
如果您克隆了仓库,可以使用以下配置:
{
"mcpServers": {
"mcp-ios-simulator-screenshot": {
"command": "node",
"args": ["/path/to/mcp-ios-simulator-screenshot/build/index.js"]
}
}
}
Cursor 和 Claude Desktop
对于 Cursor 和 Claude Desktop,您需要指定 --output-dir 和输出目录:
{
"mcpServers": {
"mcp-ios-simulator-screenshot": {
"command": "npx",
"args": [
"mcp-ios-simulator-screenshot",
"--output-dir",
"/path/to/your/output/directory"
]
}
}
}
💻 使用示例
基础用法
使用 Postman 或 curl 发送请求:
curl http://localhost:port/mcp/methods/get_screenshot
确保配置正确的参数和输出目录。
📚 详细文档
MCP 工具参数
get_screenshot
从 iOS 模拟器捕获屏幕截图并保存到指定目录。 | 参数 | 类型 | 描述 | 默认值 | | ------------------- | ------- | ----------------------------------------------------- | ------------| | output_filename | string | 输出文件名 | timestamp.png | | output_directory_name | string | 屏幕截图的子目录名称 | .screenshots | | resize | boolean | 是否将图像缩放为大约 VGA 大小 | true | | max_width | integer | 缩放的最大宽度(像素) | 640 | | device_id | string | 指定一个模拟器设备 | 当前运行的设备 |
输出格式
成功时
{
"success": true,
"message": "iOS 模拟器屏幕截图保存成功",
"filePath": ".screenshots/simulator_2025-04-10T16-51-16-755Z.png",
"metadata": {
"width": 1170,
"height": 2532,
"format": "png",
"size": 382946,
"timestamp": "2025-04-10T16:51:16.755Z"
},
"serverConfig": {
"commandLineArgs": {
"outputDir": "/Users/username/Desktop" // 只在指定 --output-dir 时包含
}
}
}
注意:serverConfig.commandLineArgs.outputDir 字段仅在服务器启动时指定 --output-dir 参数时包含在响应中。
失败时
{
"success": false,
"message": "捕获 iOS 模拟器屏幕截图失败: [错误信息]",
"error": {
"code": "ENOENT",
"command": "xcrun simctl io booted screenshot --type=png -",
"stderr": "没有匹配的设备。"
}
}
🔧 技术细节
技术栈
- TypeScript
- MCP 协议
故障排除
- 如果无法捕获屏幕截图:
- 检查 iOS 模拟器是否正在运行。
- 检查 Xcode 命令行工具是否已安装。
- 检查是否可以直接执行
xcrun simctl io booted screenshot命令。
- 如果出现权限错误:
- 检查输出目录是否有写入权限。
要求
- Node.js 16.0.0 或更高版本。
- macOS(iOS 模拟器需要)。
- Xcode 命令行工具。
📄 许可证
[此处指定许可证信息]
Scan to join WeChat group