capture_ui_dump
Capture UI hierarchy dumps from Android devices for debugging and testing purposes. Analyze app layouts and identify UI elements through ADB automation.
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 main handler function for the 'capture_ui_dump' tool. It calls the captureUIContent helper with raw XML included and returns the formatted content.capture_ui_dump: async (args: any) => { const content = await captureUIContent(true); return { content: content, }; },
- src/tools/handlers.ts:8-46 (helper)The core helper function that performs the ADB UI dump, parses the XML using parseUIAutomatorXML, formats it, and constructs the response content including optional raw XML.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)The schema definition for the 'capture_ui_dump' tool, specifying no input parameters.{ name: 'capture_ui_dump', description: 'Capture UI hierarchy dump from the device', inputSchema: { type: 'object', properties: {}, }, },
- src/index.ts:26-30 (registration)Tool list registration that exposes the toolDefinitions array, including the capture_ui_dump schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolDefinitions, }; });
- src/index.ts:32-46 (registration)Tool execution registration that looks up and invokes the handler from toolHandlers based on tool name, enabling capture_ui_dump execution.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}`); } });