Skip to main content
Glama

evaluate

Execute JavaScript code directly on web pages to automate interactions, extract data, or modify content during browser automation sessions.

Instructions

Run JavaScript code on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • Handler function for the 'evaluate' tool. Takes a JavaScript script as input and delegates execution to the browser instance, returning the result in a structured format.
    handler: async ({ script }) => {
      const result = await browser.evaluate(script);
      return { success: true, data: { result }, message: 'JavaScript executed successfully' };
    }
  • Input schema for the 'evaluate' tool, defining the required 'script' parameter as a string.
    inputSchema: {
      type: 'object',
      properties: {
        script: { type: 'string', description: 'JavaScript code to execute' }
      },
      required: ['script']
    },
  • Complete tool object registration for 'evaluate' in the createPlaywrightTools function's return array, including name, description, schema, and handler.
    {
      name: 'evaluate',
      description: 'Run JavaScript code on the page',
      inputSchema: {
        type: 'object',
        properties: {
          script: { type: 'string', description: 'JavaScript code to execute' }
        },
        required: ['script']
      },
      handler: async ({ script }) => {
        const result = await browser.evaluate(script);
        return { success: true, data: { result }, message: 'JavaScript executed successfully' };
      }
    },
  • Supporting 'evaluate' method in SimpleBrowser class that ensures the browser is launched and executes the provided JavaScript on the current page using Playwright's page.evaluate.
    async evaluate(script) {
      await this.ensureLaunched();
      return await this.page.evaluate(script);
    }
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. 'Run JavaScript code' implies execution capability but doesn't disclose critical behavioral traits: whether it runs in page context, returns results, handles errors, has security restrictions, affects page state, or requires specific permissions. This is inadequate for a tool that executes arbitrary code.

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 appropriately sized for a tool with one parameter and gets straight to the point without unnecessary elaboration.

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 code on a page (potentially destructive, security-sensitive) with no annotations and no output schema, the description is incomplete. It doesn't explain what happens after execution, whether results are returned, error handling, or safety considerations - critical gaps for this type of tool.

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 the single parameter 'script' documented as 'JavaScript code to execute'. The description adds no additional parameter semantics beyond what the schema provides, so baseline 3 is appropriate when the schema does the heavy lifting.

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 'Run JavaScript code on the page' clearly states the action (run) and target (JavaScript code on page). It's specific enough to understand the basic function, though it doesn't explicitly differentiate from sibling tools like 'get_text' or 'select' which might also involve page interaction.

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 about when to use this tool versus alternatives. With siblings like 'get_text', 'click', and 'type', there's no indication whether this is for complex page manipulation, debugging, or automation tasks that other tools can't handle.

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/zypin-testing/zypin-mcp'

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