Skip to main content
Glama

android_touch

Simulate touch interactions on Android devices by specifying screen coordinates and duration for automated testing or remote control.

Instructions

Simulate a touch event at specific screen coordinates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xYesX coordinate
yYesY coordinate
durationNoTouch duration in milliseconds (default: 100)
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • The main handler function for the 'android_touch' tool. It validates input arguments and calls the ADB wrapper's touch method to simulate the touch event.
    export async function touchHandler(
      adb: ADBWrapper,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const { x, y, duration = 100, deviceSerial } = args as TouchArgs;
    
      if (typeof x !== 'number' || typeof y !== 'number') {
        throw new Error('Invalid coordinates: x and y must be numbers');
      }
    
      if (x < 0 || y < 0) {
        throw new Error('Invalid coordinates: x and y must be positive');
      }
    
      try {
        await adb.touch(x, y, duration, deviceSerial);
    
        return {
          content: [
            {
              type: 'text',
              text: `Touch executed at (${x}, ${y}) with duration ${duration}ms`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Touch failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • The input schema and metadata for the 'android_touch' tool, registered in the ListTools response.
    {
      name: 'android_touch',
      description: 'Simulate a touch event at specific screen coordinates',
      inputSchema: {
        type: 'object',
        properties: {
          x: {
            type: 'number',
            description: 'X coordinate',
          },
          y: {
            type: 'number',
            description: 'Y coordinate',
          },
          duration: {
            type: 'number',
            description: 'Touch duration in milliseconds (default: 100)',
            default: 100,
          },
          deviceSerial: {
            type: 'string',
            description: 'Specific device serial number to target (optional)',
          },
        },
        required: ['x', 'y'],
      },
    },
  • src/index.ts:466-467 (registration)
    The switch case that registers and routes 'android_touch' tool calls to the touchHandler function.
    case 'android_touch':
      return await touchHandler(this.adb, args);
  • The ADBWrapper.touch method that implements the actual touch simulation using ADB 'input tap' or 'input swipe' shell commands.
    async touch(
      x: number,
      y: number,
      duration: number = 100,
      deviceSerial?: string
    ): Promise<void> {
      const device = await this.getTargetDevice(deviceSerial);
    
      if (duration <= 100) {
        // Simple tap
        await this.exec(['shell', 'input', 'tap', String(x), String(y)], device);
      } else {
        // Long press using swipe with same start/end coordinates
        await this.exec(
          ['shell', 'input', 'swipe', String(x), String(y), String(x), String(y), String(duration)],
          device
        );
      }
    }

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