Skip to main content
Glama
Nam0101

android-mcp-toolkit

dump-ui-hierarchy

Capture Android UI hierarchy as XML using uiautomator for debugging and automation testing. Specify timeout to control capture duration.

Instructions

Capture the current UI hierarchy as XML using uiautomator.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeoutMsNoTimeout in milliseconds

Implementation Reference

  • Handler function that executes the dump-ui-hierarchy tool: runs 'adb shell uiautomator dump' to capture UI hierarchy as XML, reads the file, and returns the trimmed 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() }] }; }
  • Input schema for the dump-ui-hierarchy tool, defining optional timeoutMs parameter.
    const dumpUiSchema = z.object({ timeoutMs: z.number().int().min(1000).max(20000).default(10000).describe('Timeout in milliseconds') });
  • Registration of the dump-ui-hierarchy tool using server.registerTool, specifying name, metadata, inputSchema, and handler function.
    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() }] }; } );
  • Helper function runAdbCommand used by the handler to execute adb shell commands with timeout and error handling.
    async function runAdbCommand(args, timeoutMs, options = {}) { try { const { stdout } = await execFileAsync('adb', args, { timeout: timeoutMs, maxBuffer: 10 * 1024 * 1024, ...options }); return stdout; } catch (error) { const stderr = error && typeof error.stderr === 'string' ? error.stderr.trim() : ''; const message = [`adb ${args.join(' ')} failed`, error.message].filter(Boolean).join(': '); if (stderr) { throw new Error(`${message} | stderr: ${stderr}`); } throw new Error(message); } }
  • src/index.js:30-30 (registration)
    Invocation of registerDeviceTool which registers the dump-ui-hierarchy (among other device tools) to the MCP server.
    registerDeviceTool(server);

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/Nam0101/android-mcp-toolkit'

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