Skip to main content
Glama

swipe

Perform swipe gestures on Android screens to scroll content, navigate between pages, or execute drag actions by specifying start and end coordinates.

Instructions

Swipe from one point to another on the Android screen. Useful for scrolling, swiping between pages, or drag gestures.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
x1YesStart X coordinate
y1YesStart Y coordinate
x2YesEnd X coordinate
y2YesEnd Y coordinate
durationNoSwipe duration in milliseconds (default: 300)
device_idNoDevice serial number

Implementation Reference

  • The actual implementation of the swipe logic using ADB commands.
    export async function swipe(
      x1: number, y1: number,
      x2: number, y2: number,
      durationMs: number = 300,
      deviceId?: string
    ): Promise<{ from: { x: number; y: number }; to: { x: number; y: number } }> {
      const resolved = await deviceManager.resolveDeviceId(deviceId);
      deviceManager.checkRateLimit(resolved);
    
      const from = await normalizeCoordinates(x1, y1, resolved);
      const to = await normalizeCoordinates(x2, y2, resolved);
    
      validateCoordinate(from.x, 'x1');
      validateCoordinate(from.y, 'y1');
      validateCoordinate(to.x, 'x2');
      validateCoordinate(to.y, 'y2');
    
      await adbShell([
        'input', 'swipe',
        String(from.x), String(from.y),
        String(to.x), String(to.y),
        String(Math.round(durationMs)),
      ], resolved);
    
      deviceManager.touchSession(resolved);
      log.info('Swipe performed', { from, to, durationMs, deviceId: resolved });
      return { from, to };
    }
  • The registration of the 'swipe' tool in the MCP server, including the handler wrapper and input schema.
    server.registerTool(
      'swipe',
      {
        description: 'Swipe from one point to another on the Android screen. Useful for scrolling, swiping between pages, or drag gestures.',
        inputSchema: {
          x1: z.number().describe('Start X coordinate'),
          y1: z.number().describe('Start Y coordinate'),
          x2: z.number().describe('End X coordinate'),
          y2: z.number().describe('End Y coordinate'),
          duration: z.number().optional().default(300).describe('Swipe duration in milliseconds (default: 300)'),
          device_id: z.string().optional().describe('Device serial number'),
        },
      },
      async ({ x1, y1, x2, y2, duration, device_id }) => {
        return await metrics.measure('swipe', device_id || 'default', async () => {
          const resolved = await deviceManager.resolveDeviceId(device_id);
          const execCtx = executionEngine.preExecutionCheck('swipe', { x1, y1, x2, y2, duration }, resolved);
    
          if (!execCtx.allowed) {
            return {
              content: [{
                type: 'text' as const,
                text: JSON.stringify({
                  success: false,
                  blocked: true,
                  reason: execCtx.blockReason,
                  _context: execCtx.recentContext,
                }, null, 2),
              }],
            };
          }
    
          const preHash = await capturePreActionState(resolved);
          const result = await swipe(x1, y1, x2, y2, duration, device_id);
          invalidateCaches(resolved);
          const verification = await verifyAction('swipe', resolved, preHash);
    
          return buildVerifiedResponse({ swipe: result }, execCtx, verification);
        });
      }
    );

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/divineDev-dotcom/android_mcp'

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