Skip to main content
Glama

android_uiautomator_scroll_in_element

Scroll within a specific UI element on Android devices using resource ID and direction parameters to navigate content within scrollable containers.

Instructions

Scroll within a specific UI element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resourceIdYesResource ID of the scrollable element
directionYesDirection to scroll
distanceNoDistance to scroll in pixels (default: 500)
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • Main tool handler that performs input validation and delegates to ADBWrapper.scrollInElement for execution.
    export async function uiautomatorScrollInElementHandler(
      adb: ADBWrapper,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { resourceId, direction, distance = 500, deviceSerial } = args as UIAutomatorScrollInElementArgs;
    
      if (!resourceId || typeof resourceId !== 'string') {
        throw new Error('Invalid resource ID: resourceId must be a non-empty string');
      }
    
      if (!direction || !['up', 'down', 'left', 'right'].includes(direction)) {
        throw new Error('Invalid direction: must be one of "up", "down", "left", "right"');
      }
    
      try {
        await adb.scrollInElement(resourceId, direction, distance, deviceSerial);
    
        return {
          content: [
            {
              type: 'text',
              text: `Successfully scrolled ${direction} in element with resource-id: ${resourceId}\nDistance: ${distance}px`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`UIAutomator scroll in element failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Core implementation: Dumps UI hierarchy XML, parses bounds of target element, computes relative swipe start/end points from element center based on direction, performs swipe gesture.
    async scrollInElement(
      resourceId: string,
      direction: 'up' | 'down' | 'left' | 'right',
      distance: number = 500,
      deviceSerial?: string
    ): Promise<void> {
      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);
      await this.exec(['shell', 'rm', hierarchyFile], device);
      
      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);
        
        const centerX = Math.floor((x1 + x2) / 2);
        const centerY = Math.floor((y1 + y2) / 2);
        
        let startX = centerX, startY = centerY, endX = centerX, endY = centerY;
        
        switch (direction) {
          case 'up':
            startY = centerY + distance;
            endY = centerY - distance;
            break;
          case 'down':
            startY = centerY - distance;
            endY = centerY + distance;
            break;
          case 'left':
            startX = centerX + distance;
            endX = centerX - distance;
            break;
          case 'right':
            startX = centerX - distance;
            endX = centerX + distance;
            break;
        }
        
        await this.swipe(startX, startY, endX, endY, 300, device);
      } else {
        throw new Error(`Element with resource-id ${resourceId} not found in UI hierarchy`);
      }
    }
  • JSON schema defining input parameters for the tool, registered in listTools response.
    inputSchema: {
      type: 'object',
      properties: {
        resourceId: {
          type: 'string',
          description: 'Resource ID of the scrollable element',
        },
        direction: {
          type: 'string',
          enum: ['up', 'down', 'left', 'right'],
          description: 'Direction to scroll',
        },
        distance: {
          type: 'number',
          description: 'Distance to scroll in pixels (default: 500)',
          default: 500,
        },
        deviceSerial: {
          type: 'string',
          description: 'Specific device serial number to target (optional)',
        },
      },
      required: ['resourceId', 'direction'],
  • src/index.ts:492-493 (registration)
    Tool name dispatch in the switch statement handling CallToolRequestSchema.
    case 'android_uiautomator_scroll_in_element':
      return await uiautomatorScrollInElementHandler(this.adb, args);
  • TypeScript interface for input argument validation in the handler.
    interface UIAutomatorScrollInElementArgs {
      resourceId: string;
      direction: 'up' | 'down' | 'left' | 'right';
      distance?: number;
      deviceSerial?: string;
    }
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 states the action but lacks details on permissions needed, whether it's destructive (e.g., could cause unintended UI changes), error handling, or performance implications. This is inadequate for a tool with potential side effects.

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 functionality ('Scroll within a specific UI element') with zero wasted words. It's appropriately sized for the tool's complexity.

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 and no output schema, the description is incomplete. It lacks behavioral context (e.g., safety, side effects) and doesn't explain return values or errors. For a UI automation tool with potential mutations, this leaves significant gaps for an AI agent.

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 all parameters. The description adds no additional meaning beyond what's in the schema, such as explaining 'resourceId' as a UI element identifier or 'distance' in practical terms. Baseline 3 is appropriate as the schema handles parameter documentation.

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 ('Scroll') and target ('within a specific UI element'), providing a specific verb+resource combination. It distinguishes from sibling tools like 'android_swipe' (general swipe) by specifying scrolling within an element, though it doesn't explicitly contrast with all siblings.

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_swipe' for general scrolling or other UI automation tools. The description implies usage for scrolling within elements but offers no explicit context, 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/jduartedj/android-mcp-server'

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