Skip to main content
Glama

playwright_press_key

Press keyboard keys during browser automation to simulate user input, interact with forms, navigate interfaces, or trigger actions in web applications.

Instructions

Press a keyboard key

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesKey to press (e.g. 'Enter', 'ArrowDown', 'a')
selectorNoOptional CSS selector to focus before pressing key

Implementation Reference

  • PressKeyTool class with execute method that optionally focuses a selector and presses the specified key using Playwright's page.keyboard.press.
    export class PressKeyTool extends BrowserToolBase {
      /**
       * Execute the key press tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          if (args.selector) {
            await page.waitForSelector(args.selector);
            await page.focus(args.selector);
          }
    
          await page.keyboard.press(args.key);
          return createSuccessResponse(`Pressed key: ${args.key}`);
        });
      }
    }
  • Input schema definition for the playwright_press_key tool, specifying parameters key (required) and optional selector.
    {
      name: "playwright_press_key",
      description: "Press a keyboard key",
      inputSchema: {
        type: "object",
        properties: {
          key: { type: "string", description: "Key to press (e.g. 'Enter', 'ArrowDown', 'a')" },
          selector: { type: "string", description: "Optional CSS selector to focus before pressing key" },
        },
        required: ["key"],
      },
    },
  • Switch case in handleToolCall that dispatches to PressKeyTool.execute for executing the tool.
    case "playwright_press_key":
      return await pressKeyTool.execute(args, context);
  • Instantiation of PressKeyTool instance in initializeTools function.
    if (!pressKeyTool) pressKeyTool = new PressKeyTool(server);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.7/5.0
Behavior2/5

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

With no annotations, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits like whether it waits for page readiness, handles focus, or has side effects (e.g., triggering events). This is inadequate for a tool that interacts with a browser, leaving key behaviors unspecified.

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 extremely concise—a single sentence with zero waste. It's front-loaded and to the point, making it easy to parse quickly. Every word earns its place, though this conciseness contributes to gaps in other dimensions.

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?

Given the complexity of browser automation and lack of annotations or output schema, the description is incomplete. It doesn't explain what happens after pressing the key (e.g., page updates, errors) or prerequisites like needing an active Playwright session. This leaves significant gaps for an agent to use the tool effectively.

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 (key and selector) well. The description adds no additional meaning beyond what's in the schema, such as examples or edge cases. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Press a keyboard key' states a clear action (press) and target (keyboard key), but it's vague about context—it doesn't specify this is for browser automation via Playwright or distinguish it from similar tools like playwright_click or playwright_fill. It's functional but lacks specificity compared to siblings.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention scenarios like form submission with 'Enter' or navigation with arrow keys, nor does it reference sibling tools for related actions. The agent must infer usage from the tool name and schema alone.

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