dump_ui_hierarchy
Extract the UI hierarchy of a connected Android device to analyze and debug its structure for testing and development purposes.
Instructions
Dump the UI hierarchy of the connected Android device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/espresso_mcp/server.py:67-86 (handler)The main handler function for the 'dump_ui_hierarchy' tool. It uses ADB to dump the UI hierarchy XML from the Android device, pulls the file locally, reads its contents, and returns the XML string. The @mcp.tool() decorator registers this function as an MCP tool.@mcp.tool() def dump_ui_hierarchy() -> str: """Dump the UI hierarchy of the connected Android device""" result = subprocess.run(["adb", "shell", "uiautomator", "dump"], capture_output=True, text=True) if result.returncode != 0: raise RuntimeError(f"Error dumping UI hierarchy: {result.stderr}") # The UI hierarchy is dumped to a file on the device /sdcard/window_dump.xml # Pull the file to the local machine and read its contents pull_result = subprocess.run( ["adb", "pull", "/sdcard/window_dump.xml", "window_dump.xml"], capture_output=True, text=True, ) if pull_result.returncode != 0: raise RuntimeError(f"Error pulling UI hierarchy file: {pull_result.stderr}") with open("window_dump.xml", encoding="utf-8") as f: ui_hierarchy = f.read() return ui_hierarchy