swipe
Simulate swipe gestures on mobile screens for automated testing, supporting any direction and distance on iOS and Android.
Instructions
Fait un geste de swipe sur l'écran. Fonctionne sur iOS et Android.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | Yes | Direction du swipe | |
| distance | No | Distance du swipe | medium |
Implementation Reference
- src/tools/swipe.ts:8-76 (handler)Main handler for the 'swipe' tool. Resolves device, gets screen size, calculates start/end coordinates based on direction and distance, then dispatches to iosSwipe or androidSwipe.
export function registerSwipe(server: McpServer): void { server.tool( "swipe", "Fait un geste de swipe sur l'écran. Fonctionne sur iOS et Android.", { direction: z.enum(["up", "down", "left", "right"]).describe("Direction du swipe"), distance: z.enum(["short", "medium", "long"]).optional().default("medium").describe("Distance du swipe"), }, async ({ direction, distance }) => { const result = await resolveDevice(); if ("error" in result) return { content: [{ type: "text", text: result.error }], isError: true }; const dev = result.device; try { let screenWidth: number, screenHeight: number; if (dev.platform === "ios") { const wda = await ensureWdaRunning(dev); if (!wda.ready) return { content: [{ type: "text", text: wda.message ?? "WDA indisponible." }], isError: true }; const size = await iosGetScreenSize(); screenWidth = size.width; screenHeight = size.height; } else { const size = await androidGetScreenSize(); screenWidth = size.width; screenHeight = size.height; } const multiplier = distance === "short" ? 0.25 : distance === "long" ? 0.75 : 0.5; const centerX = screenWidth / 2; const centerY = screenHeight / 2; let fromX: number, fromY: number, toX: number, toY: number; switch (direction) { case "up": fromX = centerX; fromY = centerY + (screenHeight * multiplier) / 2; toX = centerX; toY = centerY - (screenHeight * multiplier) / 2; break; case "down": fromX = centerX; fromY = centerY - (screenHeight * multiplier) / 2; toX = centerX; toY = centerY + (screenHeight * multiplier) / 2; break; case "left": fromX = centerX + (screenWidth * multiplier) / 2; fromY = centerY; toX = centerX - (screenWidth * multiplier) / 2; toY = centerY; break; case "right": fromX = centerX - (screenWidth * multiplier) / 2; fromY = centerY; toX = centerX + (screenWidth * multiplier) / 2; toY = centerY; break; } if (dev.platform === "ios") { await iosSwipe(fromX, fromY, toX, toY); } else { await androidSwipe(fromX, fromY, toX, toY); } const successMsg = `Swipe ${direction} (${distance}) — de (${Math.round(fromX)},${Math.round(fromY)}) à (${Math.round(toX)},${Math.round(toY)})`; logAction("swipe", successMsg, false, dev.platform, dev.id, dev.name); return { content: [{ type: "text", text: successMsg }] }; } catch (err) { const msg = err instanceof Error ? err.message : String(err); logAction("swipe", `Erreur: ${msg}`, true, dev.platform, dev.id, dev.name); return { content: [{ type: "text", text: `Erreur swipe: ${msg}` }], isError: true }; } } ); } - src/tools/swipe.ts:13-14 (schema)Zod schema for the swipe tool's input parameters: direction (required enum) and distance (optional enum, defaults to medium).
direction: z.enum(["up", "down", "left", "right"]).describe("Direction du swipe"), distance: z.enum(["short", "medium", "long"]).optional().default("medium").describe("Distance du swipe"), - src/index.ts:51-51 (registration)Registration of the swipe tool in the MCP server (alongside other interaction tools).
registerSwipe(server); - src/platforms/ios/wda.ts:369-371 (helper)iOS swipe helper: sends a drag-from-to-for-duration command via WDA (WebDriverAgent) with 0.5s duration.
export async function iosSwipe(fromX: number, fromY: number, toX: number, toY: number): Promise<void> { await wdaPost("/wda/dragfromtoforduration", { fromX, fromY, toX, toY, duration: 0.5 }); } - src/platforms/android/adb.ts:333-339 (helper)Android swipe helper: executes ADB shell input swipe command with coordinates and duration.
export async function androidSwipe(fromX: number, fromY: number, toX: number, toY: number, durationMs: number = 500): Promise<void> { await adb(["shell", "input", "swipe", String(Math.round(fromX)), String(Math.round(fromY)), String(Math.round(toX)), String(Math.round(toY)), String(durationMs), ]); }