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()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action but doesn't mention what happens after pressing (e.g., navigation effects, potential app state changes), whether it requires device connectivity, or any side effects. This leaves significant behavioral gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that immediately conveys the tool's purpose without any wasted words. It's perfectly front-loaded and appropriately sized for this simple operation.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter mutation tool with no annotations and no output schema, the description adequately explains what the tool does but lacks important context about behavioral effects, return values, and parameter usage. It's minimally viable but has clear gaps in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description doesn't mention the 'device_id' parameter at all, but since there's only one parameter and schema description coverage is 0%, the description's focus on the core action provides adequate context. The tool's purpose is clear despite the undocumented parameter, meeting the baseline for 0-1 parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Press') and the target resource ('hardware back button on the Android device/emulator'). It distinguishes itself from sibling tools like 'press' (generic) and 'long_press' by specifying the exact hardware button being targeted.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context (Android device/emulator interaction) but provides no explicit guidance on when to use this tool versus alternatives like 'press' for other buttons or 'swipe' for navigation. No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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