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
| Name | Required | Description | Default |
|---|---|---|---|
| device_serial | No |
Implementation Reference
- src/adb_mcp_server/server.py:1179-1208 (handler)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
- src/adb_mcp_server/server.py:1179-1179 (registration)The @mcp.tool() decorator registers the get_all_text_on_screen function as an MCP tool.@mcp.tool()
- src/adb_mcp_server/server.py:247-257 (helper)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