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);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the basic action and output format. It doesn't disclose behavioral traits such as whether this requires device connectivity, potential performance impacts, error conditions, or if it's read-only (implied by 'Dump' but not explicit). More context on operational constraints is needed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the key information: action, method, and output. There is no wasted text, making it easy to parse quickly for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (UI hierarchy dumping) and lack of annotations and output schema, the description is minimally adequate. It specifies the output as XML but doesn't explain the structure or content of the XML, which could be crucial for an agent to interpret results. More details on behavior or output would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the parameter 'deviceSerial' is well-documented in the schema. The description doesn't add extra param details, which is acceptable given high schema coverage. With only one optional parameter, the baseline is high, and the description doesn't detract from schema clarity.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Dump') and resource ('UI hierarchy using UIAutomator'), specifying the output format ('return as XML'). It distinguishes from siblings like android_screenshot or android_capture_frame_scrcpy by focusing on UI hierarchy extraction rather than visual capture, though it doesn't explicitly contrast with android_uiautomator_find which might also interact with UI hierarchy.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. For example, it doesn't mention if this is for debugging, automation setup, or when android_uiautomator_find might be preferred for specific element interactions. The description lacks context about prerequisites or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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