Skip to main content
Glama

press_back

Press the hardware back button on Android devices to navigate back in apps or exit screens during automated testing and interaction workflows.

Instructions

Press the hardware back button on the Android device/emulator.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idNo

Implementation Reference

  • The main handler function for the 'press_back' MCP tool. Decorated with @mcp.tool() for registration. Executes ADB command to press the Android hardware back button (KEYCODE_BACK). Handles errors and returns structured JSON response.
    @mcp.tool() async def press_back(device_id: str = None) -> dict: """Press the hardware back button on the Android device/emulator.""" try: # Build adb command for back button press cmd = ['adb'] if device_id: cmd.extend(['-s', device_id]) cmd.extend(['shell', 'input', 'keyevent', 'KEYCODE_BACK']) # Execute back button press command subprocess.run(cmd, capture_output=True, text=True, check=True) return { "success": True, "message": "Successfully pressed hardware back button", "action_type": "back_press", "device_id": device_id or "default" } except subprocess.CalledProcessError as e: return { "success": False, "error": f"Failed to press back button: {e}", "stderr": e.stderr if e.stderr else "", "action_type": "back_press" } except FileNotFoundError: return { "success": False, "error": "ADB not found. Please ensure Android SDK is installed and adb is in PATH.", "action_type": "back_press" } except Exception as e: return { "success": False, "error": f"Unexpected error: {e}", "action_type": "back_press" }
  • puppeteer.py:650-650 (registration)
    The @mcp.tool() decorator registers the press_back function as an MCP tool.
    @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/pedro-rivas/android-puppeteer-mcp'

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