Skip to main content
Glama
rahulkr
by rahulkr

find_element_by_id

Locate Android UI elements by resource ID to obtain element details and tap coordinates for testing and debugging purposes.

Instructions

Find a UI element by its resource ID. Returns element details including tap coordinates.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resource_idYes
device_serialNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the 'find_element_by_id' tool. It is registered via the @mcp.tool() decorator. Dumps current UI hierarchy XML, parses nodes to find matching resource ID (supports partial matching), extracts relevant properties like text and bounds, computes tap center, and returns element dict or None.
    @mcp.tool()
    def find_element_by_id(
        resource_id: str,
        device_serial: str | None = None
    ) -> dict | None:
        """
        Find a UI element by its resource ID.
        Returns element details including tap coordinates.
        """
        xml = get_ui_hierarchy(device_serial)
        
        # Match partial resource ID (e.g., "button_submit" matches "com.app:id/button_submit")
        for match in re.finditer(r'<node[^>]*>', xml):
            node = match.group()
            
            id_match = re.search(r'resource-id="([^"]*)"', node)
            if id_match and resource_id in id_match.group(1):
                element = {'resource_id': id_match.group(1)}
                
                text_match = re.search(r'text="([^"]*)"', node)
                if text_match:
                    element['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))
                    element['center'] = {'x': (x1 + x2) // 2, 'y': (y1 + y2) // 2}
                    element['bounds'] = {'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2}
                
                return element
        
        return None
  • The @mcp.tool() decorator registers the find_element_by_id function as an MCP tool.
    @mcp.tool()
  • Usage of find_element_by_id within the tap_element tool.
    element = find_element_by_id(resource_id, device_serial=device_serial)
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. It mentions that the tool 'Returns element details including tap coordinates,' which adds some behavioral context beyond the basic purpose. However, it lacks critical details: whether this requires specific permissions (e.g., accessibility services), if it's read-only or has side effects, error handling, or performance characteristics. The disclosure is minimal for a tool interacting with UI elements.

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

Conciseness5/5

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

The description is extremely concise and front-loaded: the first sentence states the core purpose, and the second adds key behavioral information. Every sentence earns its place with no wasted words, making it easy for an agent to parse quickly.

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

Completeness3/5

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

Given the tool's moderate complexity (finding UI elements on a device), the description is somewhat complete but has gaps. An output schema exists, so return values don't need explanation. However, with no annotations and low schema coverage, the description should do more to cover behavioral aspects like permissions, side effects, and error cases. It's adequate but not fully comprehensive for safe and effective use.

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

Parameters3/5

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

Schema description coverage is 0%, so the schema provides no parameter descriptions. The description adds minimal semantics: it implies 'resource_id' is used to identify the UI element, but doesn't explain what a resource ID is, its format, or how to obtain it. It doesn't mention 'device_serial' at all. With low coverage, the description partially compensates but leaves significant gaps in parameter understanding.

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 tool's purpose: 'Find a UI element by its resource ID.' It specifies the verb ('Find') and resource ('UI element'), and distinguishes it from sibling tools like 'find_element_by_text' by mentioning the search method ('by its resource ID'). However, it doesn't explicitly differentiate from other element-finding tools beyond naming the method.

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. It doesn't mention when to prefer resource ID over text-based search (e.g., 'find_element_by_text'), nor does it discuss prerequisites like needing a running app or device connection. Usage is implied but not explicitly stated.

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

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