press_back
Simulate pressing the back button on an Android device to navigate within apps or return to previous screens during development and testing.
Instructions
Press the back button
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_serial | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/adb_mcp_server/server.py:541-544 (handler)Handler function for the press_back tool. Registered via @mcp.tool() decorator. Executes by calling press_key helper with BACK key.
@mcp.tool() def press_back(device_serial: str | None = None) -> str: """Press the back button""" return press_key("BACK", device_serial) - src/adb_mcp_server/server.py:516-539 (helper)Core helper function that maps key names to Android keycodes and executes the input keyevent ADB command. Directly used by press_back to simulate the BACK button press.
@mcp.tool() def press_key(keycode: str, device_serial: str | None = None) -> str: """ Press a key by keycode name or number. Common keycodes: - HOME (3), BACK (4), CALL (5), ENDCALL (6) - VOLUME_UP (24), VOLUME_DOWN (25), POWER (26) - CAMERA (27), ENTER (66), DEL/BACKSPACE (67) - TAB (61), SPACE (62), MENU (82) - SEARCH (84), MEDIA_PLAY_PAUSE (85) - PAGE_UP (92), PAGE_DOWN (93) """ # Handle common names key_map = { 'HOME': '3', 'BACK': '4', 'ENTER': '66', 'DELETE': '67', 'DEL': '67', 'TAB': '61', 'SPACE': '62', 'MENU': '82', 'SEARCH': '84', 'VOLUME_UP': '24', 'VOLUME_DOWN': '25', 'POWER': '26', 'PAGE_UP': '92', 'PAGE_DOWN': '93', 'ESCAPE': '111', 'ESC': '111' } key = key_map.get(keycode.upper(), keycode) return run_adb(["shell", "input", "keyevent", key], device_serial) - src/adb_mcp_server/server.py:541-541 (registration)The @mcp.tool() decorator registers the press_back function as an MCP tool.
@mcp.tool()