Skip to main content
Glama
ascript-cn
by ascript-cn

dump_ui_tree

Get the current UI control tree of a device, returning element attributes (id, text, desc, className, rect, clickable). Supports Android mode selection and iOS.

Instructions

获取设备当前界面的控件树(UI 层级结构)。返回所有控件的 id、text、desc、className、rect、clickable 等属性。

【Android】调用前必须先调 get_device_status 确认 run_mode,再选对应 mode,否则拿空树:

  • run_mode.code=accessibility(无障碍模式)→ mode=0/1(简单/复杂),或 2/3(过滤系统层变种)

  • run_mode.code=root(Root 或激活模式) → mode=9(root 控件)

  • run_mode.code=hid(HID 控件 / 辅助控件模式)→ mode=6(辅助控件)

  • run_mode.code=screen_only(图色模式) → 无控件树,跳过 dump,走 OCR/找图 ⚠ Android 命名陷阱:code="hid" 实际是 ASS 枚举(辅助控件,有控件树);code="screen_only" 才是图色模式(无控件树)。 Selector 实例化要传相同的 mode:node.Selector(mode=<dump 的 mode>)。

【iOS】只有 WebDriverAgent 一套引擎,不接 mode 参数(传了被忽略),返回 WDA XML。iOS Selector() 也不接 engine mode;它的 MODE_EQUAL/CONTAINS/MATCHES 是给单个条件的匹配运算符(如 selector.text("x", mode=MODE_CONTAINS)),别和 Android 混。

【写 selector 必看】控件树里有 text/id/desc/className 等属性的元素,必须用 node.Selector() 通过属性定位操作,不要用坐标点击。坐标只用于控件树中确实没有任何可识别属性的元素。 Selector 实例化时也要传相同的 mode:node.Selector(mode=<dump 的同一个 mode>)。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modeNo控件检索模式(Android),对应 get_device_status 返回的 run_mode.code: 0 = 无障碍 - 简单(仅重要控件,run_mode=accessibility 时常用) 1 = 无障碍 - 复杂(所有控件含布局节点) 2 = 无障碍 - 简单 + 过滤系统层(状态栏/导航栏,推荐) 3 = 无障碍 - 复杂 + 过滤系统层 6 = 辅助控件(run_mode=hid 时用,对应 Selector.MODE_ASS) 9 = Root 控件(run_mode=root 时用,对应 Selector.MODE_ROOT) Selector 类常量:MODE_ACC_SIMPLE=0 / MODE_ACC_ALL=1 / MODE_ASS=6 / MODE_ROOT=9。
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses that Android requires mode matching, iOS ignores mode, and that certain run_modes yield empty trees. Warns about the 'hid' naming trap. No annotations provided, so description carries full burden and does so thoroughly.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Description is lengthy but well-organized into sections (Android, iOS, selector notes). Each section earns its place. Could be slightly more concise, but the complexity warrants the detail. Structure aids readability.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Comprehensive coverage: explains return attributes, platform behavior, empty tree conditions, and how to use Selector. No output schema, but description conveys enough about return format. Fills all gaps given tool complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 100% coverage with detailed mode descriptions. The description adds value beyond schema by linking modes to device status, naming constants, and explaining platform differences. Some repetition of schema info, but overall adds context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the tool retrieves the UI control tree (hierarchy) of the current device interface, listing properties like id, text, desc, className, rect, clickable. Distinguished from siblings like scan_devices and screen_capture.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit prerequisites: call get_device_status first. Maps run_mode codes to mode parameter values. Differentiates Android vs iOS handling. Tells when not to use (screen_only mode) and warns about naming pitfalls. Includes Selector usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ascript-cn/ascript-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server