Skip to main content
Glama

android_uiautomator_click

Click Android UI elements by resource ID using UIAutomator for automated testing and device control.

Instructions

Click on a UI element by resource ID using UIAutomator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceIdYesResource ID of the element to click (e.g., com.example.app:id/button_submit)
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • The primary handler function for the android_uiautomator_click tool. Validates the resourceId input and delegates the click action to the ADBWrapper's clickElementByResourceId method.
    export async function uiautomatorClickHandler(
      adb: ADBWrapper,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { resourceId, deviceSerial } = args as UIAutomatorClickArgs;
    
      if (!resourceId || typeof resourceId !== 'string') {
        throw new Error('Invalid resource ID: resourceId must be a non-empty string');
      }
    
      try {
        await adb.clickElementByResourceId(resourceId, deviceSerial);
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully clicked element with resource-id: ${resourceId}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`UIAutomator click failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Core implementation that dumps the UI hierarchy using uiautomator, parses the XML to extract element bounds, computes the center coordinates, and performs a touch action at the center.
    async clickElementByResourceId(resourceId: string, deviceSerial?: string): Promise<void> {
      const device = await this.getTargetDevice(deviceSerial);
      // Get the hierarchy to find coordinates
      const hierarchyFile = '/sdcard/window_dump.xml';
      await this.exec(['shell', 'uiautomator', 'dump', hierarchyFile], device);
      
      const { stdout } = await this.exec(['shell', 'cat', hierarchyFile], device);
      await this.exec(['shell', 'rm', hierarchyFile], device);
      
      // Extract bounds from XML
      const boundsRegex = new RegExp(`resource-id="${resourceId}"[^>]*bounds="\\[(\\d+),(\\d+)\\]\\[(\\d+),(\\d+)\\]"`);
      const match = stdout.match(boundsRegex);
      
      if (match) {
        const x1 = parseInt(match[1], 10);
        const y1 = parseInt(match[2], 10);
        const x2 = parseInt(match[3], 10);
        const y2 = parseInt(match[4], 10);
        
        // Click at the center of the element
        const centerX = Math.floor((x1 + x2) / 2);
        const centerY = Math.floor((y1 + y2) / 2);
        
        await this.touch(centerX, centerY, 100, device);
      } else {
        throw new Error(`Element with resource-id ${resourceId} not found in UI hierarchy`);
      }
    }
  • MCP tool schema definition including input schema with required resourceId and optional deviceSerial.
    {
      name: 'android_uiautomator_click',
      description: 'Click on a UI element by resource ID using UIAutomator',
      inputSchema: {
        type: 'object',
        properties: {
          resourceId: {
            type: 'string',
            description: 'Resource ID of the element to click (e.g., com.example.app:id/button_submit)',
          },
          deviceSerial: {
            type: 'string',
            description: 'Specific device serial number to target (optional)',
          },
        },
        required: ['resourceId'],
      },
    },
  • src/index.ts:478-479 (registration)
    Registration of the tool handler in the CallToolRequestSchema switch statement.
    case 'android_uiautomator_click':
      return await uiautomatorClickHandler(this.adb, args);
  • TypeScript interface defining the input arguments for the handler.
    interface UIAutomatorClickArgs {
      resourceId: string;
      deviceSerial?: string;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'using UIAutomator' but doesn't disclose behavioral traits such as error handling (e.g., if element not found), performance implications (e.g., waiting times), or side effects (e.g., potential app state changes). For a UI interaction tool with zero annotation coverage, this is a significant gap in transparency.

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 action ('Click on a UI element') and method ('using UIAutomator'), with zero wasted words. It's appropriately sized for a straightforward tool.

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 (interactive, state-dependent) with no annotations and no output schema, the description is incomplete. It lacks details on success/failure outcomes, error conditions, dependencies (e.g., UIAutomator setup), or behavioral nuances, leaving significant gaps for an AI agent to use it correctly.

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 descriptions for both parameters in the schema itself. The description adds no additional meaning beyond what's in the schema (e.g., it doesn't explain format constraints or provide examples beyond the schema's example). Baseline 3 is appropriate as the schema does the heavy lifting.

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 ('Click on a UI element') and the method ('using UIAutomator'), with the resource ID as the targeting mechanism. It distinguishes from generic 'android_touch' by specifying UIAutomator-based clicking, but doesn't explicitly differentiate from 'android_uiautomator_double_click' or 'android_uiautomator_long_click' beyond the basic click action.

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?

No guidance is provided on when to use this tool versus alternatives like 'android_touch' (general touch), 'android_uiautomator_double_click', or 'android_uiautomator_long_click'. The description implies usage for clicking by resource ID with UIAutomator, but lacks explicit context about prerequisites (e.g., device accessibility enabled) or comparative scenarios.

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