Skip to main content
Glama

android_uiautomator_dump

Extract the UI hierarchy from Android devices as XML to analyze screen elements and structure for automated testing or accessibility purposes.

Instructions

Dump the UI hierarchy using UIAutomator and return as XML

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • The main handler function that executes the android_uiautomator_dump tool logic. It extracts deviceSerial from args, calls adb.getUIHierarchyXml to dump the UI hierarchy, and returns the XML as text content.
    export async function uiautomatorDumpHandler( adb: ADBWrapper, args: any ): Promise<{ content: Array<{ type: string; text: string }> }> { const { deviceSerial } = args as UIAutomatorDumpArgs; try { const xml = await adb.getUIHierarchyXml(deviceSerial); return { content: [ { type: 'text', text: xml, }, ], }; } catch (error) { throw new Error(`UIAutomator dump failed: ${error instanceof Error ? error.message : String(error)}`); } }
  • Core helper method in ADBWrapper that performs the UIAutomator dump: runs 'uiautomator dump' via ADB shell, reads the XML file, cleans up, and returns the hierarchy XML string.
    async getUIHierarchyXml(deviceSerial?: string): Promise<string> { const device = await this.getTargetDevice(deviceSerial); const hierarchyFile = '/sdcard/window_dump.xml'; await this.exec(['shell', 'uiautomator', 'dump', hierarchyFile], device); const { stdout } = await this.exec(['shell', 'cat', hierarchyFile], device); await this.exec(['shell', 'rm', hierarchyFile], device); return stdout; }
  • Tool schema definition in the ListTools response, including name, description, and inputSchema for optional deviceSerial.
    name: 'android_uiautomator_dump', description: 'Dump the UI hierarchy using UIAutomator and return as XML', inputSchema: { type: 'object', properties: { deviceSerial: { type: 'string', description: 'Specific device serial number to target (optional)', }, }, }, },
  • src/index.ts:474-475 (registration)
    Tool registration in the CallToolRequestSchema switch statement, dispatching to the uiautomatorDumpHandler function.
    case 'android_uiautomator_dump': return await uiautomatorDumpHandler(this.adb, args);

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/jduartedj/android-mcp-server'

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