iOS 模拟器屏幕截图 MCP 服务器
一个使用模型上下文协议 (MCP) 从 iOS 模拟器捕获屏幕截图的服务器。
概述
该项目实现了一个基于 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"
]
}
}
}
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"
}
}
}
注意:serverConfig.commandLineArgs.outputDir
字段仅在服务器启动时指定 --output-dir
参数时包含在响应中。
{
"success": false,
"message": "捕获 iOS 模拟器屏幕截图失败: [错误信息]",
"error": {
"code": "ENOENT",
"command": "xcrun simctl io booted screenshot --type=png -",
"stderr": "没有匹配的设备。"
}
}
故障排除
-
如果无法捕获屏幕截图:
- 检查 iOS 模拟器是否正在运行
- 检查 Xcode 命令行工具是否已安装
- 检查是否可以直接执行
xcrun simctl io booted screenshot
命令
-
如果出现权限错误:
要求
- Node.js 16.0.0 或更高版本
- macOS(iOS 模拟器需要)
- Xcode 命令行工具
技术栈
许可证
[此处指定许可证信息]
如何使用
-
克隆仓库:
git clone [仓库地址]
cd mcp-ios-simulator-screenshot
-
安装依赖项:
npm install
-
启动服务器:
node build/index.js
-
使用 MCP 客户端调用 get_screenshot
方法。
示例
使用 Postman 或 curl 发送请求:
curl http://localhost:port/mcp/methods/get_screenshot
确保配置正确的参数和输出目录。