mobile_press_button
Trigger device button presses like HOME, VOLUME, or ENTER using the Mobile Next MCP server for precise mobile automation across iOS and Android platforms.
Instructions
Press a button on device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| button | Yes | The button to press. Supported buttons: BACK (android only), HOME, VOLUME_UP, VOLUME_DOWN, ENTER, DPAD_CENTER (android tv only), DPAD_UP (android tv only), DPAD_DOWN (android tv only), DPAD_LEFT (android tv only), DPAD_RIGHT (android tv only) |
Implementation Reference
- src/server.ts:314-325 (handler)MCP tool handler for mobile_press_button: validates input, requires active robot/device, calls robot.pressButton(button), returns confirmation messagetool( "mobile_press_button", "Press a button on device", { button: z.string().describe("The button to press. Supported buttons: BACK (android only), HOME, VOLUME_UP, VOLUME_DOWN, ENTER, DPAD_CENTER (android tv only), DPAD_UP (android tv only), DPAD_DOWN (android tv only), DPAD_LEFT (android tv only), DPAD_RIGHT (android tv only)"), }, async ({ button }) => { requireRobot(); await robot!.pressButton(button); return `Pressed the button: ${button}`; } );
- src/server.ts:317-318 (schema)Zod input schema for the tool: button (string) with description of supported buttons{ button: z.string().describe("The button to press. Supported buttons: BACK (android only), HOME, VOLUME_UP, VOLUME_DOWN, ENTER, DPAD_CENTER (android tv only), DPAD_UP (android tv only), DPAD_DOWN (android tv only), DPAD_LEFT (android tv only), DPAD_RIGHT (android tv only)"),
- src/server.ts:314-325 (registration)Registration of the mobile_press_button tool using server.tool() wrappertool( "mobile_press_button", "Press a button on device", { button: z.string().describe("The button to press. Supported buttons: BACK (android only), HOME, VOLUME_UP, VOLUME_DOWN, ENTER, DPAD_CENTER (android tv only), DPAD_UP (android tv only), DPAD_DOWN (android tv only), DPAD_LEFT (android tv only), DPAD_RIGHT (android tv only)"), }, async ({ button }) => { requireRobot(); await robot!.pressButton(button); return `Pressed the button: ${button}`; } );
- src/android.ts:296-302 (helper)AndroidRobot.pressButton implementation: maps button to Android keycode and executes via adb shell input keyeventpublic async pressButton(button: Button) { if (!BUTTON_MAP[button]) { throw new ActionableError(`Button "${button}" is not supported`); } this.adb("shell", "input", "keyevent", BUTTON_MAP[button]); }
- src/webdriver-agent.ts:115-146 (helper)WebDriverAgent.pressButton for iOS/simulator: handles ENTER specially, maps others and sends POST to /wda/pressButton endpointpublic async pressButton(button: string) { const _map = { "HOME": "home", "VOLUME_UP": "volumeup", "VOLUME_DOWN": "volumedown", }; if (button === "ENTER") { await this.sendKeys("\n"); return; } // Type assertion to check if button is a key of _map if (!(button in _map)) { throw new ActionableError(`Button "${button}" is not supported`); } await this.withinSession(async sessionUrl => { const url = `${sessionUrl}/wda/pressButton`; const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ name: button, }), }); return response.json(); }); }