Skip to main content
Glama

swipe_on_screen

Perform precise screen swipes in any direction (up, down, left, right) on iOS and Android devices. Specify start coordinates and swipe distance for accurate mobile app navigation and automation using the Mobile Next MCP server.

Instructions

Swipe on the screen

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directionYesThe direction to swipe
distanceNoThe distance to swipe in pixels. Defaults to 400 pixels for iOS or 30% of screen dimension for Android
xNoThe x coordinate to start the swipe from, in pixels. If not provided, uses center of screen
yNoThe y coordinate to start the swipe from, in pixels. If not provided, uses center of screen

Implementation Reference

  • The complete handler implementation for the 'swipe_on_screen' MCP tool. It validates input via Zod schema, requires a selected robot/device, and dispatches to either robot.swipe(direction) for center swipes or robot.swipeFromCoordinate(x, y, direction, distance) for coordinate-based swipes. Returns descriptive text.
    tool( "swipe_on_screen", "Swipe on the screen", { direction: z.enum(["up", "down", "left", "right"]).describe("The direction to swipe"), x: z.number().optional().describe("The x coordinate to start the swipe from, in pixels. If not provided, uses center of screen"), y: z.number().optional().describe("The y coordinate to start the swipe from, in pixels. If not provided, uses center of screen"), distance: z.number().optional().describe("The distance to swipe in pixels. Defaults to 400 pixels for iOS or 30% of screen dimension for Android"), }, async ({ direction, x, y, distance }) => { requireRobot(); if (x !== undefined && y !== undefined) { // Use coordinate-based swipe await robot!.swipeFromCoordinate(x, y, direction, distance); const distanceText = distance ? ` ${distance} pixels` : ""; return `Swiped ${direction}${distanceText} from coordinates: ${x}, ${y}`; } else { // Use center-based swipe await robot!.swipe(direction); return `Swiped ${direction} on screen`; } } );
  • Zod input schema for the swipe_on_screen tool defining parameters: direction (required enum), optional x/y coordinates, optional distance.
    { direction: z.enum(["up", "down", "left", "right"]).describe("The direction to swipe"), x: z.number().optional().describe("The x coordinate to start the swipe from, in pixels. If not provided, uses center of screen"), y: z.number().optional().describe("The y coordinate to start the swipe from, in pixels. If not provided, uses center of screen"), distance: z.number().optional().describe("The distance to swipe in pixels. Defaults to 400 pixels for iOS or 30% of screen dimension for Android"), },
  • Android-specific implementation of swipe(direction) using adb shell input swipe from calculated center-based start/end coordinates based on screen size.
    public async swipe(direction: SwipeDirection): Promise<void> { const screenSize = await this.getScreenSize(); const centerX = screenSize.width >> 1; let x0: number, y0: number, x1: number, y1: number; switch (direction) { case "up": x0 = x1 = centerX; y0 = Math.floor(screenSize.height * 0.80); y1 = Math.floor(screenSize.height * 0.20); break; case "down": x0 = x1 = centerX; y0 = Math.floor(screenSize.height * 0.20); y1 = Math.floor(screenSize.height * 0.80); break; case "left": x0 = Math.floor(screenSize.width * 0.80); x1 = Math.floor(screenSize.width * 0.20); y0 = y1 = Math.floor(screenSize.height * 0.50); break; case "right": x0 = Math.floor(screenSize.width * 0.20); x1 = Math.floor(screenSize.width * 0.80); y0 = y1 = Math.floor(screenSize.height * 0.50); break; default: throw new ActionableError(`Swipe direction "${direction}" is not supported`); } this.adb("shell", "input", "swipe", `${x0}`, `${y0}`, `${x1}`, `${y1}`, "1000"); }
  • Android-specific implementation of swipeFromCoordinate using adb shell input swipe from given (x,y) in the direction by calculated distance (default 30% screen).
    public async swipeFromCoordinate(x: number, y: number, direction: SwipeDirection, distance?: number): Promise<void> { const screenSize = await this.getScreenSize(); let x0: number, y0: number, x1: number, y1: number; // Use provided distance or default to 30% of screen dimension const defaultDistanceY = Math.floor(screenSize.height * 0.3); const defaultDistanceX = Math.floor(screenSize.width * 0.3); const swipeDistanceY = distance || defaultDistanceY; const swipeDistanceX = distance || defaultDistanceX; switch (direction) { case "up": x0 = x1 = x; y0 = y; y1 = Math.max(0, y - swipeDistanceY); break; case "down": x0 = x1 = x; y0 = y; y1 = Math.min(screenSize.height, y + swipeDistanceY); break; case "left": x0 = x; x1 = Math.max(0, x - swipeDistanceX); y0 = y1 = y; break; case "right": x0 = x; x1 = Math.min(screenSize.width, x + swipeDistanceX); y0 = y1 = y; break; default: throw new ActionableError(`Swipe direction "${direction}" is not supported`); } this.adb("shell", "input", "swipe", `${x0}`, `${y0}`, `${x1}`, `${y1}`, "1000"); }

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/EmpathySlainLovers/MCP'

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