Dump UI Hierarchy (XML)
dump-ui-hierarchyCapture the current Android UI hierarchy as XML using UIAutomator for analysis and debugging.
Instructions
Capture the current UI hierarchy as XML using uiautomator.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timeoutMs | No | Timeout in milliseconds |
Implementation Reference
- src/tools/deviceTool.js:86-91 (handler)The async handler that executes 'dump-ui-hierarchy': runs uiautomator dump on device, cats the result, and returns it as text content.
async (params) => { const devicePath = '/data/local/tmp/mcp_window_dump.xml'; await runAdbCommand(['shell', 'uiautomator', 'dump', devicePath], params.timeoutMs); const content = await runAdbCommand(['shell', 'cat', devicePath], params.timeoutMs); return { content: [{ type: 'text', text: content.trim() }] }; } - src/tools/deviceTool.js:16-18 (schema)Input schema for dump-ui-hierarchy: optional timeoutMs (1-20s, default 10s).
const dumpUiSchema = z.object({ timeoutMs: z.number().int().min(1000).max(20000).default(10000).describe('Timeout in milliseconds') }); - src/tools/deviceTool.js:79-92 (registration)Registration of the 'dump-ui-hierarchy' tool on the MCP server via registerDeviceTool().
server.registerTool( 'dump-ui-hierarchy', { title: 'Dump UI Hierarchy (XML)', description: 'Capture the current UI hierarchy as XML using uiautomator.', inputSchema: dumpUiSchema }, async (params) => { const devicePath = '/data/local/tmp/mcp_window_dump.xml'; await runAdbCommand(['shell', 'uiautomator', 'dump', devicePath], params.timeoutMs); const content = await runAdbCommand(['shell', 'cat', devicePath], params.timeoutMs); return { content: [{ type: 'text', text: content.trim() }] }; } ); - src/index.js:30-30 (registration)Top-level call that registers deviceTool (including dump-ui-hierarchy) on the MCP server.
registerDeviceTool(server);