Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_press_key

Press keyboard keys in browser automation to simulate user input, interact with web elements, and navigate pages using Playwright's browser control capabilities.

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 contains the execute method that implements the core logic for the playwright_press_key tool: optionally focusing an element by selector and pressing the specified keyboard 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}`);
        });
      }
    } 
  • The 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"],
      },
    },
  • Registration in the main tool handler switch statement: dispatches to PressKeyTool instance's execute method.
    case "playwright_press_key":
      return await pressKeyTool.execute(args, context);
  • Instantiation of the PressKeyTool instance used for handling the tool calls.
    if (!pressKeyTool) pressKeyTool = new PressKeyTool(server);
  • src/tools.ts:470-470 (registration)
    The tool is listed in BROWSER_TOOLS array, used to determine if browser launch is required before execution.
    "playwright_press_key",
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 write/mutation operation but doesn't specify whether this requires a focused element, what happens if no selector is provided, or if there are any side effects like page navigation. It lacks context about permissions, rate limits, or error conditions.

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 just three words, front-loading the core action. Every word earns its place with zero waste, 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 no annotations, no output schema, and a mutation tool with behavioral implications, the description is incomplete. It doesn't explain what the tool returns, error conditions, or important usage constraints, leaving significant gaps for an AI agent to understand proper invocation.

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 both parameters ('key' and 'selector') well-documented in the schema. The description doesn't add any additional meaning beyond what's already in the schema, so it meets the baseline of 3 for high schema coverage without compensating value.

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 differentiate from sibling tools like playwright_click or playwright_fill, which are also input actions but for different types of 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. With many sibling tools for different input actions (click, fill, select, etc.), there's no indication of whether this is for general keyboard input, navigation, or specific contexts like form submission.

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/devskido/customed-playwright'

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