Skip to main content
Glama

swipe

Execute swipe gestures on Android devices to navigate interfaces or scroll content using directional inputs and customizable timing.

Instructions

Perform a swipe gesture in a specific direction on the connected Android device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directionYes
durationNo

Implementation Reference

  • The main handler function for the 'swipe' tool, decorated with @mcp.tool() for automatic registration. It performs swipe gestures on an Android device using ADB's input swipe command based on direction (up, down, left, right) and duration.
    @mcp.tool()
    def swipe(direction: str, duration: int = 500) -> str:
        """Perform a swipe gesture in a specific direction on the connected Android device"""
        directions = {
            "up": (500, 1500, 500, 500),
            "down": (500, 500, 500, 1500),
            "left": (1500, 500, 500, 500),
            "right": (500, 500, 1500, 500),
        }
        if direction not in directions:
            raise ValueError(
                f"Invalid direction '{direction}'. Valid directions are: {list(directions.keys())}"
            )
    
        start_x, start_y, end_x, end_y = directions[direction]
        result = subprocess.run(
            [
                "adb",
                "shell",
                "input",
                "swipe",
                str(start_x),
                str(start_y),
                str(end_x),
                str(end_y),
                str(duration),
            ],
            capture_output=True,
            text=True,
        )
        if result.returncode != 0:
            raise RuntimeError(f"Error performing swipe: {result.stderr}")
        return f"Swipe gesture performed in '{direction}' direction over {duration}ms."

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/vs4vijay/espresso-mcp'

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