Skip to main content
Glama

android_uiautomator_wait

Wait for a specific UI element to appear on an Android device by its resource ID, with configurable timeout for automated testing and interaction.

Instructions

Wait for a UI element to appear by resource ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceIdYesResource ID of the element to wait for
timeoutMsNoMaximum time to wait in milliseconds (default: 5000)
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • The primary handler function that executes the android_uiautomator_wait tool. It validates input arguments and delegates to the ADB wrapper's waitForElement method to perform the polling logic.
    export async function uiautomatorWaitHandler(
      adb: ADBWrapper,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { resourceId, timeoutMs = 5000, deviceSerial } = args as UIAutomatorWaitArgs;
    
      if (!resourceId || typeof resourceId !== 'string') {
        throw new Error('Invalid resource ID: resourceId must be a non-empty string');
      }
    
      try {
        const found = await adb.waitForElement(resourceId, timeoutMs, deviceSerial);
    
        return {
          content: [
            {
              type: 'text',
              text: found
                ? `Element with resource-id "${resourceId}" found within ${timeoutMs}ms`
                : `Element with resource-id "${resourceId}" not found after ${timeoutMs}ms`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`UIAutomator wait failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Core helper method in ADBWrapper that implements the polling logic: repeatedly dumps the UI hierarchy using uiautomator and checks for the presence of the specified resourceId until timeout.
    async waitForElement(
      resourceId: string,
      timeoutMs: number = 5000,
      deviceSerial?: string
    ): Promise<boolean> {
      const device = await this.getTargetDevice(deviceSerial);
      const startTime = Date.now();
      const pollInterval = 500; // Check every 500ms
    
      while (Date.now() - startTime < timeoutMs) {
        try {
          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);
          
          if (stdout.includes(`resource-id="${resourceId}"`)) {
            return true;
          }
        } catch (error) {
          // Continue polling on error
        }
    
        // Wait before next poll
        await new Promise(resolve => setTimeout(resolve, pollInterval));
      }
    
      return false;
    }
  • The JSON schema definition for the tool's input parameters, registered in the ListTools response.
      name: 'android_uiautomator_wait',
      description: 'Wait for a UI element to appear by resource ID',
      inputSchema: {
        type: 'object',
        properties: {
          resourceId: {
            type: 'string',
            description: 'Resource ID of the element to wait for',
          },
          timeoutMs: {
            type: 'number',
            description: 'Maximum time to wait in milliseconds (default: 5000)',
            default: 5000,
          },
          deviceSerial: {
            type: 'string',
            description: 'Specific device serial number to target (optional)',
          },
        },
        required: ['resourceId'],
      },
    },
  • src/index.ts:480-481 (registration)
    Tool handler registration in the switch statement within the CallToolRequest handler.
    case 'android_uiautomator_wait':
      return await uiautomatorWaitHandler(this.adb, args);
  • TypeScript interface defining the expected arguments for the handler function.
    interface UIAutomatorWaitArgs {
      resourceId: string;
      timeoutMs?: number;
      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 the full burden. It states the tool waits for an element to appear, implying a blocking operation with a timeout, but doesn't disclose behavioral details like what happens on timeout (e.g., returns error or null), whether it polls continuously, or if it requires specific device states. For a tool with no annotations, 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: 'Wait for a UI element to appear by resource ID.' It's front-loaded with the core action and resource, with zero wasted words. Every part of the sentence contributes directly to understanding the tool's purpose.

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 no annotations, no output schema, and a tool that performs a potentially complex waiting operation, the description is incomplete. It doesn't explain return values (e.g., success/failure, element details), error conditions, or dependencies like device connectivity. For a 3-parameter tool with behavioral implications, 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%, so the schema fully documents the three parameters (resourceId, timeoutMs, deviceSerial). The description adds no additional meaning beyond implying resourceId is the key input. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't enhance 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: 'Wait for a UI element to appear by resource ID.' It specifies the verb ('wait') and resource ('UI element'), but doesn't explicitly differentiate from siblings like android_uiautomator_find, which might also locate elements. The description is specific but lacks sibling comparison.

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, such as needing an active Android device connection, or compare it to siblings like android_uiautomator_find for immediate element retrieval. Usage context is implied but not explicit.

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