Skip to main content
Glama
blackwhite084

Playwright Server MCP

playwright_evaluate

Execute JavaScript code directly in the browser console to automate web interactions, extract data, or manipulate page elements during web automation tasks.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The EvaluateToolHandler class provides the core implementation for executing JavaScript code in the browser context using Playwright's page.evaluate method.
    class EvaluateToolHandler(ToolHandler):
        async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
            if not self._sessions:
                return [types.TextContent(type="text", text="No active session. Please create a new session first.")]
            session_id = list(self._sessions.keys())[-1]
            page = self._sessions[session_id]["page"]
            script = arguments.get("script")
            result = await page.evaluate(script)
            return [types.TextContent(type="text", text=f"Evaluated script, result: {result}")]
  • The input schema defines the expected arguments for the playwright_evaluate tool, requiring a 'script' string.
    types.Tool(
        name="playwright_evaluate",
        description="Execute JavaScript in the browser console",
        inputSchema={
            "type": "object",
            "properties": {
                "script": {"type": "string", "description": "JavaScript code to execute"}
            },
            "required": ["script"]
        }
    ),
  • The tool_handlers dictionary registers an instance of EvaluateToolHandler for the 'playwright_evaluate' tool name, used by the call_tool handler.
    tool_handlers = {
        "playwright_navigate": NavigateToolHandler(),
        "playwright_screenshot": ScreenshotToolHandler(),
        "playwright_click": ClickToolHandler(),
        "playwright_fill": FillToolHandler(),
        "playwright_evaluate": EvaluateToolHandler(),
        "playwright_click_text": ClickTextToolHandler(),
        "playwright_get_text_content": GetTextContentToolHandler(),
        "playwright_get_html_content": GetHtmlContentToolHandler(),
        "playwright_new_session":NewSessionToolHandler(),
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
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 the action but fails to mention critical traits such as execution context (e.g., page scope), error handling, security implications, or whether it returns a value. This is inadequate for a tool that executes arbitrary JavaScript.

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 is front-loaded and efficiently conveys the core purpose without unnecessary elaboration, making it easy for an agent 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 complexity of executing JavaScript in a browser (with no annotations or output schema), the description is insufficient. It lacks details on return values, error behavior, or execution scope, which are crucial for safe and effective use. This leaves significant gaps in understanding the tool's full context.

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 schema description coverage is 100%, with the 'script' parameter fully documented in the schema. The description adds no additional meaning beyond what the schema provides, such as examples or constraints on the JavaScript code. This meets the baseline for high schema coverage.

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'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'playwright_console_logs' (which retrieves logs) or other JavaScript execution contexts, keeping it from 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. For example, it doesn't mention when to prefer this over other Playwright tools for interaction or how it relates to siblings like 'playwright_get_visible_html'. This lack of context leaves the agent without usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.