MCP 工具

这个 MCP 工具列出团队模拟器屏幕上与选择器匹配的每个元素,最匹配的在前,不触碰任何内容。

simulator_find 返回团队正在运行的模拟器屏幕上与选择器匹配的每个可用元素,最匹配的在前,还会返回匹配但被排除的元素及原因(隐藏、在屏幕外)。它不触碰任何内容,也不等待:还没出现的元素会得到空列表。它是只读的。在 simulator_tap 操作之前,用它检查选择器会命中什么。

只读 破坏性 幂等
是 否 是

选择器

元素工具(simulator_tap、simulator_find、simulator_wait、simulator_slider、simulator_adjust,以及 simulator_batch 的步骤)用选择器而不是坐标指定元素。元素会在 simulator_describe_ui 显示的辅助功能树中查找,每次都重新读取,所以无论布局把它放在哪里都能找到。不在辅助功能树中的内容无法被选择;请对它使用坐标。

字段 类型 匹配什么
text string 元素的可见文本:它的标签(或标题)或它的值。不区分大小写,忽略两端的空格,除非设置了 exact,否则只需匹配文本的一部分
id string 元素的 accessibilityIdentifier,完全匹配
value string 只匹配元素的值,例如输入框的文本。不区分大小写;除非设置了 exact,否则只需匹配一部分
role string 辅助功能角色,完全匹配,例如 AXButton、AXSlider、AXSwitch
nodeId string 来自 simulator_describe_ui 或本工具的 nodeId:恰好是那个元素,不会是其他元素
exact boolean text 和 value 必须与元素的文本完全相同,而不只是出现在其中
strict boolean 有多个可用元素匹配时失败,而不是取最匹配的那个

text、id、value、role 和 nodeId 至少提供一个;空字符串视为未提供。提供的每个字段都必须匹配。

排序。 有多个元素匹配时,最匹配的排在最前:文本与查询相同优先于文本包含查询;匹配标签优先于匹配值;按钮、链接、输入框、开关或单元格优先于文字相同的静态文本;然后是较小的元素;然后从上到下、从左到右。对单个元素操作的工具会取第一个,并报告 matchCount:大于 1 表示由排序决定。添加 id、role、exact 或 strict 可以确保选中目标。

排除。 匹配但无法使用的元素会列在 excluded 下,并带有 reason:hidden、empty-frame(没有尺寸)、off-screen(中心在屏幕外),对于点按还有 disabled。

nodeId。 nodeId 指称 App 当前运行状态下的一个元素。元素消失、被隐藏、移出屏幕或 App 重启后,它就会失效:这时请重新读取树。把它视为不透明的值,不要保存以备后用。

选择器错误(任何元素工具):

消息 何时出现 怎么办
Name the element: text, id, value, role or nodeId. 没有提供任何选择器字段 添加一个
invalid nodeId; use the opaque string returned by describe-ui nodeId 不是工具给出的值 从 simulator_describe_ui 原样复制
node_id_device_mismatch: nodeId belongs to a different device 该 nodeId 来自另一个模拟器 读取这台设备的树
stale_node: nodeId is absent, hidden, disabled, off-screen, or no longer matches; describe UI again 元素已消失或已改变 再次调用 simulator_describe_ui
ambiguous selector selector: n usable matches; add an id, role, or value filter 使用了 strict(或 nodeId),但有多个元素匹配 缩小选择器的范围
no usable element matching selector within ns 会等待的工具在时限内没有找到可用的元素;如果有元素匹配但无法使用,后面会附上 (matched but skipped: 1 hidden, …) 用 simulator_find 检查,用 simulator_scroll_to 滚动,或等待更长时间

输入

输入 类型 必填 默认值 作用
teamId 字符串(UUID) 是 — 团队,来自 list_teams
simulator string 否 团队的默认设备 哪种设备,使用 list_simulators 中的 id
text, id, value, role, nodeId, exact, strict 见 选择器 前五个中至少一个 — 选择器

结果

字段 说明
ok true
matches 可用的元素,最匹配的在前;没有时为空
matches[].element 元素:label、value、identifier、nodeId、role、frame(x、y、width、height)、enabled、interactive(接受输入)、hidden,某些控件还有 activationPoint、sliderTrack、adjustable、adjustmentActions
matches[].point x、y:点按它时落下的位置,使用 屏幕坐标
matches[].exact 它的文本是否与查询相同(对于 id 总是 true)
excluded 匹配但无法使用的元素
excluded[].element 元素,同上
excluded[].reason hidden、empty-frame、off-screen 或 disabled
{
  "ok": true,
  "matches": [
    { "element": { "label": "New note", "identifier": "new-note", "nodeId": "ax1:…", "role": "AXButton",
                   "frame": { "x": 16, "y": 120, "width": 370, "height": 52 }, "enabled": true, "interactive": true, "adjustable": false },
      "point": { "x": 201, "y": 146 }, "exact": true }
  ],
  "excluded": []
}

错误

上面的 选择器错误,以及每个模拟器工具都可能返回的错误:见 start_simulator。

示例

{"name": "simulator_find", "arguments": {"teamId": "00000000-0000-0000-0000-000000000000", "text": "New note"}}