Skip to main content
Glama

adb_press_key

Press a key on an Android device using key codes like BACK, HOME, or MENU to automate device interactions through the ADB MCP Server.

Instructions

Press a key on the device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyCodeYesKey code to press (e.g., "BACK", "HOME", "MENU", or numeric code)
deviceIdNoDevice ID (optional)

Implementation Reference

  • The pressKey method executes the ADB shell input keyevent command to simulate pressing the specified keycode on the Android device, with error handling and device connection checks.
    async pressKey(keyCode: string | number, deviceId?: string) {
      try {
        const connected = await this.adbClient.isDeviceConnected(deviceId);
        if (!connected) {
          return {
            success: false,
            error: 'Device not connected',
            message: 'Cannot press key - device is not connected'
          };
        }
    
        const command = `shell input keyevent ${keyCode}`;
        const result = await this.adbClient.executeCommand(command, deviceId);
        
        if (!result.success) {
          return {
            success: false,
            error: result.error,
            message: 'Failed to press key'
          };
        }
    
        return {
          success: true,
          data: { 
            keyCode,
            deviceId: deviceId || this.adbClient.getDefaultDevice()
          },
          message: `Pressed key: ${keyCode}`
        };
      } catch (error: any) {
        return {
          success: false,
          error: error.message,
          message: 'Failed to press key'
        };
      }
    }
  • Defines the tool name, description, and input schema (keyCode required as string or number, optional deviceId) for adb_press_key in the ListTools response.
    name: 'adb_press_key',
    description: 'Press a key on the device',
    inputSchema: {
      type: 'object',
      properties: {
        keyCode: {
          type: ['string', 'number'],
          description: 'Key code to press (e.g., "BACK", "HOME", "MENU", or numeric code)',
        },
        deviceId: {
          type: 'string',
          description: 'Device ID (optional)',
        },
      },
      required: ['keyCode'],
    },
  • src/index.ts:449-450 (registration)
    Registers the tool handler by dispatching adb_press_key calls to ScreenTools.pressKey method in the CallToolRequest switch statement.
    case 'adb_press_key':
      return await this.handleToolCall(this.screenTools.pressKey(args?.keyCode as string | number, args?.deviceId as string));
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without behavioral details. It doesn't mention whether this requires an active ADB connection, what happens if the device is locked, error conditions, or if it's synchronous/asynchronous. This is inadequate for a mutation tool with zero annotation coverage.

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 states the core functionality without any wasted words. It's perfectly front-loaded and appropriately sized for this simple tool.

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

Completeness2/5

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

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'press' means behaviorally (physical button simulation? software event?), what happens after pressing, error handling, or connection requirements. The context demands more completeness.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, meeting the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('press') and target ('a key on the device'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like adb_input_text or adb_click, which also involve device input interactions.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like adb_input_text for text input or adb_click for screen taps. There's no mention of prerequisites (e.g., device connection) or typical use cases for key presses.

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/richard0913/adb-mcp'

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