Skip to main content
Glama
pvinis
by pvinis

playwright_press_key

Simulate key presses on web pages to interact with elements, test functionality, or automate tasks. Optionally focus on specific elements using CSS selectors for precise control.

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

  • The PressKeyTool class provides the core implementation for the 'playwright_press_key' tool. Its execute method optionally focuses on 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}`);
        });
      }
    } 
  • Defines the tool name, description, and input schema (parameters: key (required), selector (optional)) for validation and documentation.
      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"],
      },
    },
  • The switch case in handleToolCall dispatches calls to the 'playwright_press_key' tool to the PressKeyTool instance's execute method.
    case "playwright_press_key":
      return await pressKeyTool.execute(args, context);
  • src/tools.ts:423-423 (registration)
    Includes 'playwright_press_key' in the BROWSER_TOOLS array, used to identify browser-requiring tools and conditionally launch browser.
    "playwright_press_key",
  • Instantiates the PressKeyTool instance during tool initialization in toolHandler.ts.
    if (!pressKeyTool) pressKeyTool = new PressKeyTool(server);
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.

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

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