使用说明
查找MCP
MCP(模型上下文协议)服务器,允许AI助手检查模拟器中运行的iOS应用程序的实时UI视图层次结构。
LookinMCP连接到 查找服务器 --嵌入在iOS应用程序中的框架,并将应用程序的视图层次结构、视图属性和布局信息作为MCP工具公开。这使Claude、GPT、Cursor和其他兼容MCP的AI助手能够了解屏幕上的内容,并帮助您调试UI问题。
运作原理
AI Assistant <--stdio/JSON-RPC--> LookinMCP <--TCP/Peertalk--> iOS Simulator App
(this project) (with LookinServer)
- 您的iOS应用程序包括 查找服务器 该框架监听模拟器中的TCP端口(47164-47169)。
- LookinMCP连接到该端口,并使用Peertalk二进制协议请求视图层次结构数据。
- AI助手调用MCP工具(通过stdio JSON-RPC)查询层次结构、搜索视图和检查单个视图属性。
先决条件
- macOS 13+ (文图拉或更高版本)
- Swift 6.0+ (Xcode 16+)
- iOS模拟器 使用集成了LookinServer的应用程序
建筑
swift build
二进制文件将位于 .build/debug/LookinMCP.
在iOS应用程序中集成LookinServer
将LookinServer添加到您的iOS应用程序中,以便LookinMCP可以连接到它。 仅在调试版本中包含它 --它永远不应该投入生产。
CocoaPods
pod 'LookinServer', :configurations => ['Debug']
Swift包管理器
https://github.com/nicklama/LookinServer
将其添加为依赖项,并仅将其链接到您的调试方案。
集成后,只需在iOS模拟器中运行您的应用程序。LookinServer会自动启动并侦听本地TCP端口。
配置您的AI助手
克劳德桌面版
添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"lookin": {
"command": "/path/to/LookinMCP"
}
}
}
光标
添加到MCP配置中:
{
"mcpServers": {
"lookin": {
"command": "/path/to/LookinMCP"
}
}
}
替换 /path/to/LookinMCP 与构建二进制文件的实际路径(例如 swift build --show-bin-path).
可用工具
| 工具 | 说明 |
|---|---|
lookin_connect |
连接到模拟器中的LookinServer。扫描端口47164-47169或连接到特定端口 |
lookin_disconnect |
断开与当前LookinServer的连接。 |
lookin_ping |
检查服务器是否处于活动状态,以及应用程序是否在前台。 |
lookin_app_info |
获取应用程序名称、捆绑包ID、设备型号、操作系统版本和屏幕信息。 |
lookin_hierarchy |
以缩进文本树的形式获取完整视图层次结构。每个节点都显示类名、帧、OID和标志。 |
lookin_view_detail |
通过OID(对象标识符)获取特定视图的详细属性。 |
lookin_search |
通过类名或视图控制器名称模糊搜索层次结构。返回匹配项的平面列表。 |
lookin_subtree |
通过OID获取特定节点及其完整子树。 |
工作流示例
You: "Connect to the app and show me the view hierarchy"
AI: [calls lookin_connect] → Connected on port 47164
AI: [calls lookin_hierarchy] → Returns the full view tree
You: "Find all UILabel views"
AI: [calls lookin_search with query "UILabel"] → Returns numbered list of matches
You: "Show me details for the label with oid 42"
AI: [calls lookin_view_detail with oid 42] → Returns frame, font, text color, etc.
You: "What's the subtree under the navigation bar?"
AI: [calls lookin_subtree with the nav bar's oid] → Returns that node and all its children
建筑
Sources/
├── LookinMCP/ # Swift executable
│ ├── LookinMCPApp.swift # Entry point, MCP tool handlers
│ ├── Connection/
│ │ ├── LookinConnection.swift # TCP + Peertalk frame protocol
│ │ ├── PortScanner.swift # Scans ports 47164-47169
│ │ └── RequestManager.swift # Request/response codec
│ └── Formatters/
│ ├── HierarchyFormatter.swift # View tree → text
│ └── ViewDetailFormatter.swift # View attributes → text
└── LookinShared/ # ObjC models from LookinServer
局限性
- 仅模拟器 --LookinServer通过localhost TCP进行通信,该TCP仅在模拟器中可用(不通过USB在物理设备上可用)。
- 一次一个连接 --LookinServer接受单个TCP客户端。连接前关闭Lookin桌面应用程序或其他MCP实例。
- 只读 --LookinMCP当前仅读取视图层次结构。它不会修改视图或调用方法。
积分
- 查找服务器 --使视图检查成为可能的iOS框架
- 看 --LookinServer的macOS桌面客户端
- MCP Swift SDK --用于模型上下文协议的官方Swift SDK
许可证
麻省理工学院