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.

fix: round a fractional long-press duration before passing it to mobilecli (#476)

Mobile Kevin Bot!92da989c2e99
diff --git a/src/mobile-device.ts b/src/mobile-device.ts
index a73c316..12cc1f5 100644
--- a/src/mobile-device.ts
+++ b/src/mobile-device.ts
@@ -284,11 +284,12 @@ export class MobileDevice implements Robot {
}
public async longPress(x: number, y: number, duration: number): Promise<void> {
- this.runCommand(["io", "longpress", `${Math.round(x)},${Math.round(y)}`, "--duration", `${duration}`]);
+ // mobilecli rejects fractional coordinates and durations, both are parsed as integers
+ this.runCommand(["io", "longpress", `${Math.round(x)},${Math.round(y)}`, "--duration", `${Math.round(duration)}`]);
}
public async longPressByRef(ref: string, duration: number): Promise<void> {
- this.runCommand(["io", "longpress", ref, "--duration", `${duration}`]);
+ this.runCommand(["io", "longpress", ref, "--duration", `${Math.round(duration)}`]);
}
public async getElementsOnScreen(): Promise<ScreenElement[]> {
diff --git a/test/mobile-device.test.ts b/test/mobile-device.test.ts
index 17fc7c4..b68fffc 100644
--- a/test/mobile-device.test.ts
+++ b/test/mobile-device.test.ts
@@ -36,6 +36,21 @@ test.describe("MobileDevice", () => {
expect(calls[0]).toEqual(["io", "longpress", "100,201", "--duration", "500", "--device", "test-device"]);
});
+ // mobilecli parses --duration as an integer and rejects "250.5"
+ test("longPress should round a fractional duration before calling mobilecli", async () => {
+ const { device, calls } = createMockMobileDevice("");
+ await device.longPress(100, 200, 250.5);
+
+ expect(calls[0]).toEqual(["io", "longpress", "100,200", "--duration", "251", "--device", "test-device"]);
+ });
+
+ test("longPressByRef should round a fractional duration before calling mobilecli", async () => {
+ const { device, calls } = createMockMobileDevice("");
+ await device.longPressByRef("@e5", 799.4);
+
+ expect(calls[0]).toEqual(["io", "longpress", "@e5", "--duration", "799", "--device", "test-device"]);
+ });
+
test("swipeFromCoordinate should round fractional coordinates before calling mobilecli", async () => {
const { device, calls } = createMockMobileDevice("");
await device.swipeFromCoordinate(100.5, 300.2, "up", 400);