Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
directionYesDirection du swipe
distanceNoDistance du swipemedium

Implementation Reference

  • 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 };
          }
        }
      );
    }
  • 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);
  • 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 });
    }
  • 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),
      ]);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description should disclose behavioral traits. It fails to mention starting position, duration, or effect on UI elements. The description is too sparse to guide the agent on tool behavior.

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?

Two short, clear sentences with no superfluous information. Every word contributes to understanding the tool's basic function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool is simple with only two parameters and no output schema. The description is adequate for a basic gesture but lacks details like coordinate point or effect on UI, which could be inferred from sibling tool names.

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 covers both parameters with enum descriptions (100% coverage). The description adds no extra value beyond confirming the gesture direction and distance. Baseline 3 is appropriate since no additional context is needed.

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 (swipe gesture on screen) and platform compatibility (iOS and Android). However, it does not differentiate from sibling tools like tap or scroll, missing a chance to clarify its specific purpose.

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 on when to use swipe versus alternatives such as tap, long_press, or scroll. The description provides no context about typical use cases or when not to use it.

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/nthImpulse/phantom-mcp'

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