Skip to main content
Glama

playwright_press_key

Simulate keyboard key presses in a browser environment. Specify the key and optionally a CSS selector to focus on an element before pressing the key. Useful for automating web interactions.

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 implementing the tool logic: optionally focuses a selector then presses the specified key using Playwright's keyboard API.
    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 'selector' (optional).
    {
      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 registration in handleToolCall function dispatching execution to the PressKeyTool instance.
    case "playwright_press_key":
      return await pressKeyTool.execute(args, context);
  • Lazy initialization of the 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 the full burden of behavioral disclosure. 'Press a keyboard key' implies a simulated user action but doesn't specify whether this requires a focused element, what happens if the selector is invalid, or any side effects like page navigation. For a tool with potential interaction consequences, this is inadequate.

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 with a single sentence ('Press a keyboard key'), which is front-loaded and wastes no words. It efficiently communicates the core action without unnecessary elaboration, making it easy to parse quickly.

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 lack of annotations and output schema, the description is incomplete for a tool that simulates keyboard input. It doesn't explain return values, error conditions, or behavioral nuances like key combinations or focus requirements. For a user interaction tool in a complex environment like Playwright, more context is needed.

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 selector). The description adds no additional meaning beyond what the schema provides, such as examples of key sequences or selector usage. Baseline 3 is appropriate since the schema handles parameter documentation effectively.

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 purpose immediately understandable. However, it doesn't distinguish this from sibling tools like playwright_click or playwright_fill, which also involve user interactions but with different mechanisms.

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. With many sibling tools for user interactions (e.g., playwright_click, playwright_fill, playwright_select), there's no indication of when keyboard pressing is preferred over clicking or other methods, nor any prerequisites or context for usage.

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

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

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