Skip to main content
Glama

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
NameRequiredDescriptionDefault
buttonYesThe 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

  • MCP tool handler for mobile_press_button: validates input, requires active robot/device, calls robot.pressButton(button), returns confirmation message
    tool( "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}`; } );
  • 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() wrapper
    tool( "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}`; } );
  • AndroidRobot.pressButton implementation: maps button to Android keycode and executes via adb shell input keyevent
    public async pressButton(button: Button) { if (!BUTTON_MAP[button]) { throw new ActionableError(`Button "${button}" is not supported`); } this.adb("shell", "input", "keyevent", BUTTON_MAP[button]); }
  • WebDriverAgent.pressButton for iOS/simulator: handles ENTER specially, maps others and sends POST to /wda/pressButton endpoint
    public 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(); }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/EmpathySlainLovers/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server