Skip to main content
Glama

get_all_text_on_screen

Extract visible text from Android device screens to verify content matches designs during UI testing and visual QA workflows.

Instructions

Extract all visible text from current screen. Useful for verifying text content matches designs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_serialNo

Implementation Reference

  • Handler function decorated with @mcp.tool(), which registers and implements the get_all_text_on_screen tool. Parses UI hierarchy XML to extract all visible text elements with their bounds and positions.
    @mcp.tool() def get_all_text_on_screen(device_serial: str | None = None) -> list[dict]: """ Extract all visible text from current screen. Useful for verifying text content matches designs. """ xml = get_ui_hierarchy(device_serial) texts = [] for match in re.finditer(r'<node[^>]*>', xml): node = match.group() text_match = re.search(r'text="([^"]*)"', node) if text_match and text_match.group(1).strip(): text_info = {'text': text_match.group(1)} bounds_match = re.search(r'bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"', node) if bounds_match: x1, y1 = int(bounds_match.group(1)), int(bounds_match.group(2)) x2, y2 = int(bounds_match.group(3)), int(bounds_match.group(4)) text_info['bounds'] = {'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2} text_info['position'] = {'x': (x1 + x2) // 2, 'y': (y1 + y2) // 2} class_match = re.search(r'class="([^"]*)"', node) if class_match: text_info['element_type'] = class_match.group(1).split('.')[-1] texts.append(text_info) return texts
  • The @mcp.tool() decorator registers the get_all_text_on_screen function as an MCP tool.
    @mcp.tool()
  • Helper tool get_ui_hierarchy used by get_all_text_on_screen to dump UI XML for parsing.
    @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

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/rahulkr/r_adb_mcp_server'

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