Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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

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/vs4vijay/espresso-mcp'

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