get_ui_hierarchy
Dump the complete UI hierarchy as XML to show all visible elements, their properties, bounds, and content descriptions for Android device inspection.
Instructions
Dump the complete UI hierarchy as XML. Shows all visible elements, their properties, bounds, and content descriptions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_serial | No |
Implementation Reference
- src/adb_mcp_server/server.py:247-256 (handler)The handler function for the 'get_ui_hierarchy' tool, decorated with @mcp.tool() for automatic registration in the FastMCP server. It dumps the UI hierarchy using ADB uiautomator, reads the XML file, cleans up, and returns the XML string.@mcp.tool() def get_ui_hierarchy(device_serial: str | None = None) -> str: """ Dump the complete UI hierarchy as XML. Shows all visible elements, their properties, bounds, and content descriptions. """ run_adb(["shell", "uiautomator", "dump", "/sdcard/ui_dump.xml"], device_serial) output = run_adb(["shell", "cat", "/sdcard/ui_dump.xml"], device_serial) run_adb(["shell", "rm", "/sdcard/ui_dump.xml"], device_serial) return output