Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_evaluate

Execute JavaScript code directly in a browser console to automate web interactions, scrape content, or test functionality using Playwright's browser automation capabilities.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The EvaluateTool class implements the core logic for the playwright_evaluate tool. It executes JavaScript using page.evaluate() on the browser page and formats the result for display.
    export class EvaluateTool extends BrowserToolBase {
      /**
       * Execute the evaluate tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          const result = await page.evaluate(args.script);
          
          // Convert result to string for display
          let resultStr: string;
          try {
            resultStr = JSON.stringify(result, null, 2);
          } catch (error) {
            resultStr = String(result);
          }
          
          return createSuccessResponse([
            `Executed JavaScript:`,
            `${args.script}`,
            `Result:`,
            `${resultStr}`
          ]);
        });
      }
  • Defines the tool name, description, and input schema (requiring a 'script' string) for registration in the MCP tools list.
    {
      name: "playwright_evaluate",
      description: "Execute JavaScript in the browser console",
      inputSchema: {
        type: "object",
        properties: {
          script: { type: "string", description: "JavaScript code to execute" },
        },
        required: ["script"],
      },
  • Switch case in the main tool handler that dispatches calls to the EvaluateTool instance.
    case "playwright_evaluate":
      return await evaluateTool.execute(args, context);
  • Instantiation of the EvaluateTool class instance used for handling tool calls.
    if (!evaluateTool) evaluateTool = new EvaluateTool(server);
  • src/tools.ts:460-460 (registration)
    Inclusion in BROWSER_TOOLS array for conditional browser launch logic.
    "playwright_evaluate",
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks critical details: it doesn't specify execution context (e.g., current page, frame), error handling, return values, or side effects (e.g., whether it waits for page loads). This is inadequate for a tool that executes arbitrary code in a browser environment.

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, clear sentence with zero wasted words. It's front-loaded with the core action and context, making it immediately understandable without unnecessary elaboration or redundancy.

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?

For a tool that executes JavaScript in a browser—a potentially complex operation with no annotations or output schema—the description is insufficient. It misses key details: execution scope, return behavior, error cases, and how it integrates with other Playwright tools. This leaves significant gaps for an agent to use it effectively and safely.

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?

The description adds no parameter-specific information beyond what the schema provides. Since schema description coverage is 100% (the 'script' parameter is fully documented), the baseline score of 3 applies. The description doesn't elaborate on script constraints, examples, or execution nuances, so it doesn't add value over the structured schema.

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 clearly states the action ('Execute JavaScript') and the context ('in the browser console'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'playwright_console_logs' which might also interact with the console, leaving room for ambiguity about when to use one versus the other.

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 prerequisites (e.g., needing an active browser session), exclusions, or compare it to other JavaScript execution methods in the sibling list, leaving the agent to infer usage context solely from the tool name and description.

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