Skip to main content
Glama

android_uiautomator_find

Locate Android UI elements by resource ID or text content for automation testing and device control.

Instructions

Find UI elements by resource ID or text using UIAutomator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceIdNoResource ID to search for (e.g., com.example.app:id/button_submit)
textNoText content to search for
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • src/index.ts:168-188 (registration)
    Tool registration in MCP server tools array: defines name, description, and input schema for 'android_uiautomator_find'.
    {
      name: 'android_uiautomator_find',
      description: 'Find UI elements by resource ID or text using UIAutomator',
      inputSchema: {
        type: 'object',
        properties: {
          resourceId: {
            type: 'string',
            description: 'Resource ID to search for (e.g., com.example.app:id/button_submit)',
          },
          text: {
            type: 'string',
            description: 'Text content to search for',
          },
          deviceSerial: {
            type: 'string',
            description: 'Specific device serial number to target (optional)',
          },
        },
      },
    },
  • src/index.ts:476-477 (registration)
    Tool dispatch registration in the main switch statement for handling tool calls.
    case 'android_uiautomator_find':
      return await uiautomatorFindHandler(this.adb, args);
  • Main handler function that validates input, selects the appropriate ADB method based on resourceId or text, executes it, and formats the response.
    export async function uiautomatorFindHandler(
      adb: ADBWrapper,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { resourceId, text, deviceSerial } = args as UIAutomatorFindArgs;
    
      if (!resourceId && !text) {
        throw new Error('Either resourceId or text must be provided');
      }
    
      try {
        let result: string;
        if (resourceId) {
          result = await adb.findElementByResourceId(resourceId, deviceSerial);
        } else {
          result = await adb.findElementByText(text!, deviceSerial);
        }
    
        return {
          content: [
            {
              type: 'text',
              text: result,
            },
          ],
        };
      } catch (error) {
        throw new Error(`UIAutomator find failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Core helper function that dumps UI hierarchy XML using uiautomator dump, reads it, and checks if the specified resource-id exists in the XML.
    async findElementByResourceId(resourceId: string, deviceSerial?: string): Promise<string> {
      const device = await this.getTargetDevice(deviceSerial);
      // Get the UI hierarchy as XML
      const hierarchyFile = '/sdcard/window_dump.xml';
      await this.exec(['shell', 'uiautomator', 'dump', hierarchyFile], device);
      
      // Read the XML file
      const { stdout } = await this.exec(['shell', 'cat', hierarchyFile], device);
      
      // Clean up
      await this.exec(['shell', 'rm', hierarchyFile], device);
      
      // Parse and search for resource ID
      if (stdout.includes(`resource-id="${resourceId}"`)) {
        return `Found element with resource-id: ${resourceId}`;
      } else {
        return `Element with resource-id: ${resourceId} not found`;
      }
    }
  • Core helper function for text-based search: dumps UI XML and checks for matching text attribute.
    async findElementByText(text: string, deviceSerial?: string): Promise<string> {
      const device = await this.getTargetDevice(deviceSerial);
      const hierarchyFile = '/sdcard/window_dump.xml';
      await this.exec(['shell', 'uiautomator', 'dump', hierarchyFile], device);
      
      const { stdout } = await this.exec(['shell', 'cat', hierarchyFile], device);
      
      // Clean up
      await this.exec(['shell', 'rm', hierarchyFile], device);
      
      // Search for text
      if (stdout.includes(`text="${text}"`) || stdout.includes(`>${text}</`)) {
        return `Found element with text: ${text}`;
      } else {
        return `Element with text: ${text} not found`;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the search mechanism (UIAutomator) but lacks critical details: whether this is a read-only operation, if it requires device permissions, how it handles multiple matching elements, error conditions (e.g., no matches), or performance implications. For a tool with potential side effects or constraints, this is a significant gap.

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 a single, efficient sentence that front-loads the core purpose ('Find UI elements') and includes key details (search criteria and mechanism). There is no redundant information or unnecessary elaboration, making it highly concise and well-structured for quick understanding.

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 UI automation, no annotations, and no output schema, the description is incomplete. It doesn't explain return values (e.g., element identifiers or error messages), behavioral traits like idempotency or side effects, or integration with sibling tools (e.g., how found elements might be used with android_uiautomator_click). For a tool in a rich sibling set, more context is needed.

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 100%, with clear parameter descriptions in the input schema. The description adds minimal value by naming the search criteria ('resource ID or text') but doesn't elaborate on syntax, precedence (if both parameters are provided), or practical examples beyond what the schema provides. With high schema coverage, the baseline score of 3 is appropriate.

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 ('Find UI elements') and the mechanism ('using UIAutomator'), with specific search criteria ('by resource ID or text'). It distinguishes itself from sibling tools like android_uiautomator_click or android_uiautomator_set_text by focusing on element discovery rather than interaction. However, it doesn't explicitly differentiate from android_uiautomator_dump, which might also involve element discovery, making it slightly less specific.

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 prerequisites (e.g., needing an active device connection), compare it to sibling tools like android_uiautomator_dump for broader element discovery, or specify scenarios where resource ID vs. text searching is preferred. 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/jduartedj/android-mcp-server'

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