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: add duration parameter to longpress (#247)

Gil Megidish6495aff23da0
diff --git a/package-lock.json b/package-lock.json
index ec99c1a..7639b41 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -44,7 +44,7 @@
"node": ">=18"
},
"optionalDependencies": {
- "@mobilenext/mobilecli": "0.0.46"
+ "@mobilenext/mobilecli": "0.0.49"
}
},
"node_modules/@babel/code-frame": {
@@ -717,9 +717,9 @@
}
},
"node_modules/@mobilenext/mobilecli": {
- "version": "0.0.46",
- "resolved": "https://registry.npmjs.org/@mobilenext/mobilecli/-/mobilecli-0.0.46.tgz",
- "integrity": "sha512-opdmd+kQTGwgl4y9d9Y78BQQNHM/3k6R3ZvvEOKTFb3iJbifRvfQZsGsSgGJqA+ZCbNaWnlt+M8pH+oILRpJXQ==",
+ "version": "0.0.49",
+ "resolved": "https://registry.npmjs.org/@mobilenext/mobilecli/-/mobilecli-0.0.49.tgz",
+ "integrity": "sha512-+Ex8W+21ud35eHeTheLNl+MrNlHyiMI5nHfsJeFeQV9mdTOrs/aU+uaSxpOjwQtbhFtT05wtuvBBRjf2RyTXFw==",
"license": "MIT",
"optional": true,
"bin": {
@@ -5461,9 +5461,9 @@
}
},
"node_modules/qs": {
- "version": "6.14.0",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz",
- "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==",
+ "version": "6.14.1",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz",
+ "integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.1.0"
diff --git a/package.json b/package.json
index 57aba73..af099d3 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,7 @@
"zod-to-json-schema": "3.25.0"
},
"optionalDependencies": {
- "@mobilenext/mobilecli": "0.0.46"
+ "@mobilenext/mobilecli": "0.0.49"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
diff --git a/src/android.ts b/src/android.ts
index 0b6d73e..49c156d 100644
--- a/src/android.ts
+++ b/src/android.ts
@@ -438,9 +438,9 @@ export class AndroidRobot implements Robot {
this.adb("shell", "input", "tap", `${x}`, `${y}`);
}
- public async longPress(x: number, y: number): Promise<void> {
+ public async longPress(x: number, y: number, duration: number): Promise<void> {
// a long press is a swipe with no movement and a long duration
- this.adb("shell", "input", "swipe", `${x}`, `${y}`, `${x}`, `${y}`, "500");
+ this.adb("shell", "input", "swipe", `${x}`, `${y}`, `${x}`, `${y}`, `${duration}`);
}
public async doubleTap(x: number, y: number): Promise<void> {
diff --git a/src/ios.ts b/src/ios.ts
index 4021367..07b5f54 100644
--- a/src/ios.ts
+++ b/src/ios.ts
@@ -196,9 +196,9 @@ export class IosRobot implements Robot {
await wda.doubleTap(x, y);
}
- public async longPress(x: number, y: number): Promise<void> {
+ public async longPress(x: number, y: number, duration: number): Promise<void> {
const wda = await this.wda();
- await wda.longPress(x, y);
+ await wda.longPress(x, y, duration);
}
public async getElementsOnScreen(): Promise<ScreenElement[]> {
diff --git a/src/iphone-simulator.ts b/src/iphone-simulator.ts
index bca830e..b427376 100644
--- a/src/iphone-simulator.ts
+++ b/src/iphone-simulator.ts
@@ -245,9 +245,9 @@ export class Simctl implements Robot {
await wda.doubleTap(x, y);
}
- public async longPress(x: number, y: number) {
+ public async longPress(x: number, y: number, duration: number) {
const wda = await this.wda();
- return wda.longPress(x, y);
+ return wda.longPress(x, y, duration);
}
public async pressButton(button: Button) {
diff --git a/src/mobile-device.ts b/src/mobile-device.ts
index bd068ab..f1ab039 100644
--- a/src/mobile-device.ts
+++ b/src/mobile-device.ts
@@ -187,8 +187,8 @@ export class MobileDevice implements Robot {
await this.tap(x, y);
}
- public async longPress(x: number, y: number): Promise<void> {
- this.runCommand(["io", "longpress", `${x},${y}`]);
+ public async longPress(x: number, y: number, duration: number): Promise<void> {
+ this.runCommand(["io", "longpress", `${x},${y}`, "--duration", `${duration}`]);
}
public async getElementsOnScreen(): Promise<ScreenElement[]> {
diff --git a/src/robot.ts b/src/robot.ts
index d6fec4f..173d812 100644
--- a/src/robot.ts
+++ b/src/robot.ts
@@ -121,8 +121,11 @@ export interface Robot {
/**
* Long press on a specific coordinate on the screen.
+ * @param x - The x coordinate to long press
+ * @param y - The y coordinate to long press
+ * @param duration - Duration of the long press in milliseconds
*/
- longPress(x: number, y: number): Promise<void>;
+ longPress(x: number, y: number, duration: number): Promise<void>;
/**
* Get all elements on the screen. Works only on native apps (not webviews). Will
diff --git a/src/server.ts b/src/server.ts
index 0c5f4dc..3c7d7b5 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -392,12 +392,14 @@ export const createMcpServer = (): McpServer => {
device: z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."),
x: z.number().describe("The x coordinate to long press on the screen, in pixels"),
y: z.number().describe("The y coordinate to long press on the screen, in pixels"),
+ duration: z.number().min(1).max(10000).optional().describe("Duration of the long press in milliseconds. Defaults to 500ms."),
},
{ destructiveHint: true },
- async ({ device, x, y }) => {
+ async ({ device, x, y, duration }) => {
const robot = getRobotFromDevice(device);
- await robot.longPress(x, y);
- return `Long pressed on screen at coordinates: ${x}, ${y}`;
+ const pressDuration = duration ?? 500;
+ await robot.longPress(x, y, pressDuration);
+ return `Long pressed on screen at coordinates: ${x}, ${y} for ${pressDuration}ms`;
}
);
diff --git a/src/webdriver-agent.ts b/src/webdriver-agent.ts
index fd96af1..a46a0c3 100644
--- a/src/webdriver-agent.ts
+++ b/src/webdriver-agent.ts
@@ -206,7 +206,7 @@ export class WebDriverAgent {
});
}
- public async longPress(x: number, y: number) {
+ public async longPress(x: number, y: number, duration: number) {
await this.withinSession(async sessionUrl => {
const url = `${sessionUrl}/actions`;
await fetch(url, {
@@ -223,7 +223,7 @@ export class WebDriverAgent {
actions: [
{ type: "pointerMove", duration: 0, x, y },
{ type: "pointerDown", button: 0 },
- { type: "pause", duration: 500 },
+ { type: "pause", duration },
{ type: "pointerUp", button: 0 }
]
}