Skip to main content
Glama

press_button

Simulate a button press on a connected Android device to trigger actions like navigation, power, or volume control.

Instructions

Simulate a button press on the connected Android device using an Enum button

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
buttonYes

Implementation Reference

  • The main handler function for the 'press_button' tool. It is registered via @mcp.tool() decorator and simulates pressing an Android hardware button using ADB by sending a keyevent based on the Button enum value.
    @mcp.tool()
    def press_button(button: Button) -> str:
        """Simulate a button press on the connected Android device using an Enum button"""
        result = subprocess.run(
            ["adb", "shell", "input", "keyevent", button.value],
            capture_output=True,
            text=True,
        )
        if result.returncode != 0:
            raise RuntimeError(f"Error pressing button '{button.name}': {result.stderr}")
        return f"Button '{button.name}' has been pressed."
  • Enum type 'Button' used as input parameter for press_button tool, defining key codes for various Android buttons.
    class Button(Enum):
        HOME = "3"
        BACK = "4"
        MENU = "82"
        POWER = "26"
        VOLUME_UP = "24"
        VOLUME_DOWN = "25"
        CAMERA = "27"
        ENTER = "66"
  • Registration of the press_button tool using the @mcp.tool() decorator.
    @mcp.tool()

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/vs4vijay/espresso-mcp'

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