Skip to main content
Glama

get_ui_elements_info

Retrieve detailed information about all interactive UI elements on Android screens, including coordinates and properties, for automation and testing purposes.

Instructions

Get detailed information about all interactive UI elements on the screen including their coordinates and properties.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idNo

Implementation Reference

  • The main tool handler decorated with @mcp.tool(). It calls the get_ui_elements helper to fetch interactive UI elements and formats them into a standardized dictionary response with success status, elements list, and error handling.
    @mcp.tool()
    async def get_ui_elements_info(device_id: str = None) -> dict:
        """Get detailed information about all interactive UI elements on the screen including their coordinates and properties."""
        try:
            elements = get_ui_elements(device_id)
    
            elements_info = []
            for i, element in enumerate(elements):
                elements_info.append({
                    "index": i,
                    "name": element.name,
                    "center_coordinates": {
                        "x": element.coordinates.x,
                        "y": element.coordinates.y
                    },
                    "bounding_box": {
                        "x1": element.bounding_box.x1,
                        "y1": element.bounding_box.y1,
                        "x2": element.bounding_box.x2,
                        "y2": element.bounding_box.y2
                    },
                    "class_name": element.class_name,
                    "clickable": element.clickable,
                    "focusable": element.focusable
                })
    
            return {
                "success": True,
                "message": f"Found {len(elements)} interactive UI elements",
                "device_id": device_id or "default",
                "elements": elements_info,
                "count": len(elements)
            }
    
        except ConnectionError as e:
            return {
                "success": False,
                "error": f"Device connection failed: {e}",
                "elements": [],
                "count": 0
            }
        except Exception as e:
            return {
                "success": False,
                "error": f"Failed to get UI elements: {e}",
                "elements": [],
                "count": 0
            }
  • Key helper function that parses the Android UI hierarchy XML dump from uiautomator2, identifies interactive, visible, and enabled elements, extracts their bounds, names, and properties, and returns a list of ElementNode objects.
    def get_ui_elements(device_id: str = None) -> list[ElementNode]:
        """Get interactive UI elements from the device"""
        try:
            device = get_device_connection(device_id)
    
            # Get UI hierarchy XML
            tree_string = device.dump_hierarchy()
            element_tree = ElementTree.fromstring(tree_string)
    
            interactive_elements = []
            nodes = element_tree.findall('.//node[@visible-to-user="true"][@enabled="true"]')
    
            for node in nodes:
                if is_interactive(node):
                    coords = extract_coordinates(node)
                    if not coords:
                        continue
    
                    x1, y1, x2, y2 = coords
                    name = get_element_name(node)
    
                    if not name:
                        continue
    
                    x_center, y_center = get_center_coordinates((x1, y1, x2, y2))
    
                    interactive_elements.append(ElementNode(
                        name=name,
                        coordinates=CenterCord(x=x_center, y=y_center),
                        bounding_box=BoundingBox(x1=x1, y1=y1, x2=x2, y2=y2),
                        class_name=node.get('class', ''),
                        clickable=node.get('clickable') == 'true',
                        focusable=node.get('focusable') == 'true'
                    ))
    
            return interactive_elements
        except Exception as e:
            raise RuntimeError(f"Failed to get UI elements: {e}")
  • Dataclass defining the structure for UI element information used by get_ui_elements and the main handler.
    @dataclass
    class ElementNode:
        name: str
        coordinates: CenterCord
        bounding_box: BoundingBox
        class_name: str = ""
        clickable: bool = False
        focusable: bool = False
  • Helper function to determine if a UI node is interactive based on attributes or class name matching INTERACTIVE_CLASSES.
    def is_interactive(node) -> bool:
        """Check if a UI element is interactive"""
        attributes = node.attrib
        return (attributes.get('focusable') == "true" or
                attributes.get('clickable') == "true" or
                attributes.get('class') in INTERACTIVE_CLASSES)
  • puppeteer.py:560-560 (registration)
    The @mcp.tool() decorator registers the get_ui_elements_info function with the FastMCP server.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it implies a read-only operation by using 'Get,' it doesn't specify if this requires specific permissions, whether it returns real-time or cached data, potential performance impacts, or error conditions. The description lacks details on output format, pagination, or rate limits, which are critical for a tool that retrieves 'all' elements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. It avoids unnecessary words and directly states what the tool does, though it could be slightly more structured by separating high-level purpose from detailed attributes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of retrieving 'all interactive UI elements' with no annotations, no output schema, and an undocumented parameter, the description is incomplete. It doesn't address how the data is returned (e.g., list format, JSON structure), what 'properties' entail, or limitations (e.g., only visible elements). For a tool with such potential scope, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has one parameter (device_id) with 0% description coverage, and the tool description provides no information about parameters. The description doesn't mention device_id at all, leaving its purpose (e.g., targeting a specific device in multi-device contexts) unexplained. With low schema coverage, the description fails to compensate by adding meaning to the parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get detailed information') and the target ('all interactive UI elements on the screen'), including specific attributes like coordinates and properties. It distinguishes itself from siblings like get_device_dimensions (which focuses on device metrics) or take_screenshot (which captures visual output), though it doesn't explicitly name these alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it doesn't clarify if this is for debugging UI layouts versus interacting with elements (like press or scroll_element), or if it should be used before or after other actions. There's no mention of prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/pedro-rivas/android-puppeteer-mcp'

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