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
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No |
Implementation Reference
- puppeteer.py:650-688 (handler)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()