Skip to content

Mobile MCP: let AI agents drive your iOS and Android apps. MCP server for simulators, emulators and real devices. Works with Claude Code, Codex, Cursor and any MCP client.

feat: support for swipe up

gmegidishe7abbe7bf5fb
diff --git a/src/android.ts b/src/android.ts
index 60d5adc..4fcffa0 100644
--- a/src/android.ts
+++ b/src/android.ts
@@ -122,16 +122,29 @@ export const getElementCoordinates = (text: string): ElementCoordinates => {
}
export const swipe = (direction: "up" | "down" | "left" | "right") => {
- if (direction !== "down") {
- throw new Error(`Swipe direction "${direction}" is not supported`);
- }
const screenSize = getScreenSize();
- const center = screenSize[0] / 2;
- const y0 = screenSize[1] * 0.10;
- const y1 = screenSize[1] * 0.90;
+ const centerX = screenSize[0] >> 1;
+ const centerY = screenSize[1] >> 1;
+
+ let x0, y0, x1, y1: number;
+
+ switch (direction) {
+ case "down":
+ x0 = x1 = centerX;
+ y0 = Math.floor(screenSize[1] * 0.80);
+ y1 = Math.floor(screenSize[1] * 0.20);
+ break;
+ case "up":
+ x0 = x1 = centerX;
+ y0 = Math.floor(screenSize[1] * 0.20);
+ y1 = Math.floor(screenSize[1] * 0.80);
+ break;
+ default:
+ throw new Error(`Swipe direction "${direction}" is not supported`);
+ }
- execSync(`adb shell input swipe ${center} ${y1} ${center} ${y0} 1000`);
+ execSync(`adb shell input swipe ${x0} ${y0} ${x1} ${y1} 1000`);
}
export const takeScreenshot = async (): Promise<Buffer> => {
diff --git a/src/server.ts b/src/server.ts
index cfb2273..45e4155 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -139,12 +139,14 @@ export const createMcpServer = (): McpServer => {
);
tool(
- "swipe-down-on-screen",
- "Swipe down on the screen",
- {},
- async ({}) => {
- swipe("down");
- return `Swiped down on screen`;
+ "swipe-on-screen",
+ "Swipe on the screen",
+ {
+ direction: z.enum(["up", "down"]).describe("The direction to swipe"),
+ },
+ async ({ direction }) => {
+ swipe(direction);
+ return `Swiped ${direction} on screen`;
}
);