mobile_press_button
Simulate button presses on mobile devices using the Mobile Next MCP Server. Execute commands like HOME, VOLUME_UP, or DPAD_LEFT to automate interactions on 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:414-426 (registration)Registration of the 'mobile_press_button' MCP tool, including input schema (device, button) and handler that retrieves the appropriate Robot and calls pressButtontool( "mobile_press_button", "Press a button on device", { device: z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."), 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 ({ device, button }) => { const robot = getRobotFromDevice(device); await robot.pressButton(button); return `Pressed the button: ${button}`; } );
- src/android.ts:428-435 (handler)AndroidRobot.pressButton implementation: maps button to Android keyevent and executes via adb shell inputpublic async pressButton(button: Button) { if (!BUTTON_MAP[button]) { throw new ActionableError(`Button "${button}" is not supported`); } const mapped = BUTTON_MAP[button]; this.adb("shell", "input", "keyevent", mapped); }
- src/ios.ts:184-187 (handler)IosRobot.pressButton: delegates to WebDriverAgent.pressButtonpublic async pressButton(button: Button): Promise<void> { const wda = await this.wda(); await wda.pressButton(button); }
- src/iphone-simulator.ts:264-267 (handler)iPhone Simulator (Simctl).pressButton: delegates to WebDriverAgent.pressButtonpublic async pressButton(button: Button) { const wda = await this.wda(); return wda.pressButton(button); }
- src/webdriver-agent.ts:116-147 (handler)WebDriverAgent.pressButton: handles ENTER specially, otherwise POST to /wda/pressButton endpoint on the agentpublic 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(); }); }