capture_ui_dump
Capture the UI hierarchy dump from an Android device for detailed analysis, enabling efficient debugging and testing through the Android Debug Bridge MCP.
Instructions
Capture UI hierarchy dump from the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/handlers.ts:131-136 (handler)The handler function for the 'capture_ui_dump' MCP tool. It calls the captureUIContent helper to perform the UI dump.capture_ui_dump: async (args: any) => { const content = await captureUIContent(true); return { content: content, }; },
- src/tools/handlers.ts:8-46 (helper)Core helper function implementing the UI dump logic: dumps via uiautomator, parses XML, formats output, handles errors.const captureUIContent = async (includeRawXML: boolean = true) => { await executeCommand('adb shell uiautomator dump /sdcard/window_dump.xml'); const xmlContent = await executeCommand('adb shell "cat /sdcard/window_dump.xml"'); try { const processedUI = await parseUIAutomatorXML(xmlContent); const formattedOutput = formatElementsForDisplay(processedUI); const result = [ { type: 'text', text: formattedOutput, }, ]; if (includeRawXML) { result.push({ type: 'text', text: `\n=== RAW XML UI Automator ===\n${xmlContent}`, }); } return result; } catch (error) { const result = [ { type: 'text', text: `Error processing UI dump: ${error}`, }, { type: 'text', text: `\n=== RAW XML DATA ===\n${xmlContent}`, } ]; return result; } };
- src/tools/definitions.ts:62-69 (schema)Tool schema definition including name, description, and empty input schema (no parameters required).{ name: 'capture_ui_dump', description: 'Capture UI hierarchy dump from the device', inputSchema: { type: 'object', properties: {}, }, },
- src/index.ts:26-30 (registration)MCP server registration for listing tools, which includes the capture_ui_dump schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolDefinitions, }; });
- src/index.ts:32-46 (registration)MCP server registration for calling tools, dispatching to toolHandlers[name] including capture_ui_dump.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const handler = toolHandlers[name as keyof typeof toolHandlers]; if (!handler) { throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } return await handler(args); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${errorMessage}`); } });