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

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

No annotations are provided, so the description carries full burden for behavioral disclosure. 'Press a keyboard key' implies a simulated user action but doesn't specify whether it requires a focused element, what happens if no selector is provided, or if it triggers page events. For a tool with potential side effects and no annotation coverage, this leaves significant behavioral gaps.

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 with zero wasted words. It's front-loaded with the core action and resource, making it immediately scannable. Every word earns its place by conveying essential information without redundancy or fluff.

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 no annotations, no output schema, and a tool that performs an interactive action (key press), the description is incomplete. It doesn't address behavioral aspects like focus requirements, error conditions, or what constitutes success. For a tool with potential side effects in a browser automation context, more context is needed to guide safe and effective use.

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%, with clear documentation for both parameters (key and optional selector). The description adds no additional parameter semantics beyond what the schema provides, such as key combination examples or selector interaction details. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't detract either.

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 'Press a keyboard key' clearly states the action (press) and resource (keyboard key), making the tool's purpose immediately understandable. It distinguishes from sibling tools like playwright_click or playwright_fill by focusing on keyboard input rather than mouse interactions or form filling. However, it doesn't specify whether this simulates a single keypress or a combination, which prevents a perfect score.

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. It doesn't mention scenarios like form submission (vs playwright_fill), navigation (vs playwright_click), or text input, nor does it reference sibling tools. Without context about appropriate use cases, the agent must infer usage from the tool name alone.

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/aakashH242/mcp-playwright'

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