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.
TypeScript agentandroidandroid-automationappium-alternativeclaude-codecodexcursoremulatoriosios-automationmcpmcp-servermobilemobile-automationmobile-testingreal-devicesimulatorskills
feat: support long press
Gil Megidishfe7270105e9a
diff --git a/src/android.ts b/src/android.tsindex 4d31e9a..a8874bf 100644--- a/src/android.ts+++ b/src/android.ts@@ -313,19 +313,25 @@ export class AndroidRobot implements Robot {throw new ActionableError(`Button "${button}" is not supported`);}- this.adb("shell", "input", "keyevent", BUTTON_MAP[button]);+ const mapped = BUTTON_MAP[button];+ this.adb("shell", "input", "keyevent", mapped);}public async tap(x: number, y: number): Promise<void> {this.adb("shell", "input", "tap", `${x}`, `${y}`);}+ public async longPress(x: number, y: 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");+ }+public async setOrientation(orientation: Orientation): Promise<void> {- const orientationValue = orientation === "portrait" ? 0 : 1;+ const value = orientation === "portrait" ? 0 : 1;// disable auto-rotation prior to setting the orientationthis.adb("shell", "settings", "put", "system", "accelerometer_rotation", "0");- this.adb("shell", "content", "insert", "--uri", "content://settings/system", "--bind", "name:s:user_rotation", "--bind", `value:i:${orientationValue}`);+ this.adb("shell", "content", "insert", "--uri", "content://settings/system", "--bind", "name:s:user_rotation", "--bind", `value:i:${value}`);}public async getOrientation(): Promise<Orientation> {diff --git a/src/ios.ts b/src/ios.tsindex 1d274db..ca0d10b 100644--- a/src/ios.ts+++ b/src/ios.ts@@ -167,6 +167,11 @@ export class IosRobot implements Robot {await wda.tap(x, y);}+ public async longPress(x: number, y: number): Promise<void> {+ const wda = await this.wda();+ await wda.longPress(x, y);+ }+public async getElementsOnScreen(): Promise<ScreenElement[]> {const wda = await this.wda();return await wda.getElementsOnScreen();diff --git a/src/iphone-simulator.ts b/src/iphone-simulator.tsindex 41755f4..430f080 100644--- a/src/iphone-simulator.ts+++ b/src/iphone-simulator.ts@@ -155,6 +155,11 @@ export class Simctl implements Robot {return wda.tap(x, y);}+ public async longPress(x: number, y: number) {+ const wda = await this.wda();+ return wda.longPress(x, y);+ }+public async pressButton(button: Button) {const wda = await this.wda();return wda.pressButton(button);diff --git a/src/robot.ts b/src/robot.tsindex 87b7097..a7c3446 100644--- a/src/robot.ts+++ b/src/robot.ts@@ -104,6 +104,11 @@ export interface Robot {*/tap(x: number, y: number): Promise<void>;+ /**+ * Long press on a specific coordinate on the screen.+ */+ longPress(x: number, y: number): Promise<void>;+/*** Get all elements on the screen. Works only on native apps (not webviews). Will* return a filtered list of elements that make sense to interact with.diff --git a/src/server.ts b/src/server.tsindex 1c3bb10..4d56a82 100644--- a/src/server.ts+++ b/src/server.ts@@ -288,6 +288,20 @@ export const createMcpServer = (): McpServer => {});+ tool(+ "mobile_long_press_on_screen_at_coordinates",+ "Long press on the screen at given x,y coordinates. If long pressing on an element, use the list_elements_on_screen tool to find the coordinates.",+ {+ 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"),+ },+ async ({ x, y }) => {+ requireRobot();+ await robot!.longPress(x, y);+ return `Long pressed on screen at coordinates: ${x}, ${y}`;+ }+ );+tool("mobile_list_elements_on_screen","List elements on screen and their coordinates, with display text or accessibility label. Do not cache this result.",diff --git a/src/webdriver-agent.ts b/src/webdriver-agent.tsindex 31d121c..4a5305c 100644--- a/src/webdriver-agent.ts+++ b/src/webdriver-agent.ts@@ -173,6 +173,33 @@ export class WebDriverAgent {});}+ public async longPress(x: number, y: number) {+ await this.withinSession(async sessionUrl => {+ const url = `${sessionUrl}/actions`;+ await fetch(url, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ actions: [+ {+ type: "pointer",+ id: "finger1",+ parameters: { pointerType: "touch" },+ actions: [+ { type: "pointerMove", duration: 0, x, y },+ { type: "pointerDown", button: 0 },+ { type: "pause", duration: 500 },+ { type: "pointerUp", button: 0 }+ ]+ }+ ]+ }),+ });+ });+ }+private isVisible(rect: SourceTreeElementRect): boolean {return rect.x >= 0 && rect.y >= 0;}