这是一个使用模型上下文协议 (MCP) 从 iOS 模拟器捕获屏幕截图的服务器,能捕获当前 iOS 模拟器屏幕并将截图保存到指定目录。
使用该服务器,可按以下步骤操作:
git clone [仓库地址]
cd mcp-ios-simulator-screenshot
npm install
node build/index.js
get_screenshot 方法。对于 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,您需要指定 --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
确保配置正确的参数和输出目录。
从 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": "没有匹配的设备。"
}
}
xcrun simctl io booted screenshot 命令。[此处指定许可证信息]