dump_ui_hierarchy
Extract the UI hierarchy from a connected Android device to analyze screen structure and elements for testing or debugging 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 handler function decorated with @mcp.tool() that implements the dump_ui_hierarchy tool. It uses ADB to dump the UI hierarchy XML from the Android device, pulls the file locally, reads it, and returns the contents as a string.@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