Skip to main content
Glama

evaluate_javascript

Execute custom JavaScript code within a browser context using the MCP Browser Server, enabling automation for web interactions, data extraction, and dynamic content manipulation.

Instructions

Execute JavaScript in the browser context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The handler function for evaluate_javascript tool. It checks for currentPage, parses args with schema, evaluates the JS script on the page using Playwright's evaluate method, and returns the result as JSON stringified text.
    case 'evaluate_javascript': {
      if (!currentPage) {
        throw new Error('No browser page available. Launch a browser first.');
      }
    
      const params = EvaluateJavaScriptSchema.parse(args);
      const result = await currentPage.evaluate(params.script);
    
      return {
        content: [
          {
            type: 'text',
            text: `JavaScript result: ${JSON.stringify(result, null, 2)}`
          }
        ]
      };
    }
  • Defines the input schema for the evaluate_javascript tool using Zod, requiring a 'script' string.
    const EvaluateJavaScriptSchema = z.object({
      script: z.string()
    });
  • src/index.ts:281-294 (registration)
    Registers the evaluate_javascript tool in the list of available tools, including name, description, and input schema.
    {
      name: 'evaluate_javascript',
      description: 'Execute JavaScript in the browser context',
      inputSchema: {
        type: 'object',
        properties: {
          script: {
            type: 'string',
            description: 'JavaScript code to execute'
          }
        },
        required: ['script']
      }
    },
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 lacks critical details: it doesn't specify whether execution is synchronous/asynchronous, error handling, security implications, or what happens if the browser isn't open. For a tool that executes arbitrary code in a browser context, this is a significant gap in transparency.

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, efficient sentence with zero wasted words. It's front-loaded with the core action ('Execute JavaScript') and includes essential context ('in the browser context'). Every word earns its place, making it highly concise and well-structured.

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 (e.g., potential side effects, security risks, dependency on browser state) and the absence of both annotations and an output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., script results, errors), behavioral constraints, or integration with sibling tools like 'launch_browser'. This leaves significant gaps for an AI agent.

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 input schema has 100% description coverage, with the 'script' parameter clearly documented as 'JavaScript code to execute'. The description adds no additional parameter semantics beyond what the schema provides, such as examples of valid scripts or constraints. With high schema coverage, the baseline score of 3 is appropriate.

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 'Execute JavaScript in the browser context' clearly states the action (execute) and target (JavaScript), and specifies the execution context (browser). It distinguishes from siblings like 'get_element_text' or 'navigate' by focusing on script execution. However, it doesn't explicitly differentiate from potential similar tools like 'evaluate_script' if they existed, keeping it at 4 rather than 5.

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 scenarios where JavaScript execution is preferable to built-in tools like 'click_element' or 'get_element_text', nor does it specify prerequisites like requiring an active browser session. The agent must infer usage from the tool name and context 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/Wladastic/mcp-browser-server'

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