Skip to main content
Glama

evaluate

Execute JavaScript code in a browser to automate tasks, test web functionality, or extract data during browser automation sessions.

Instructions

Execute JavaScript in the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The core handler function for the 'evaluate' tool. It ensures the Chromium browser is running, sends a Chrome DevTools Protocol (CDP) 'Runtime.evaluate' command with the provided script, and returns the result as a formatted text response.
    async evaluate(script) {
      await this.ensureChromium();
      
      const result = await this.sendCDPCommand('Runtime.evaluate', {
        expression: script,
        returnByValue: true,
      });
      
      return {
        content: [{ type: 'text', text: `Result: ${JSON.stringify(result.result.value)}` }],
      };
    }
  • The input schema definition for the 'evaluate' tool, specifying that it requires a 'script' string parameter.
    name: 'evaluate',
    description: 'Execute JavaScript in the browser (read-only operations)',
    inputSchema: {
      type: 'object',
      properties: {
        script: {
          type: 'string',
          description: 'JavaScript code to execute (for reading page info)',
        },
      },
      required: ['script'],
    },
  • Registration of the 'evaluate' tool in the ListTools response, including name, description, and schema.
        {
          name: 'evaluate',
          description: 'Execute JavaScript in the browser (read-only operations)',
          inputSchema: {
            type: 'object',
            properties: {
              script: {
                type: 'string',
                description: 'JavaScript code to execute (for reading page info)',
              },
            },
            required: ['script'],
          },
        },
        {
          name: 'close_browser',
          description: 'Close the browser instance',
          inputSchema: {
            type: 'object',
            properties: {},
          },
        },
      ],
    }));
  • Dispatch/registration of the 'evaluate' tool handler in the CallToolRequestSchema switch statement.
    case 'evaluate':
      return await this.evaluate(args.script);
  • Helper function used by the evaluate handler to send CDP commands over WebSocket to the browser.
    async sendCDPCommand(method, params = {}) {
      return new Promise((resolve, reject) => {
        if (!wsConnection || wsConnection.readyState !== WebSocket.OPEN) {
          reject(new Error('No browser connection available'));
          return;
        }
    
        const commandId = Date.now();
        const command = { id: commandId, method, params };
    
        const timeout = setTimeout(() => {
          reject(new Error(`CDP command timeout: ${method}`));
        }, 10000);
    
        const messageHandler = (data) => {
          try {
            const response = JSON.parse(data.toString());
            if (response.id === commandId) {
              clearTimeout(timeout);
              wsConnection.off('message', messageHandler);
              if (response.error) {
                reject(new Error(`CDP error: ${response.error.message}`));
              } else {
                resolve(response.result);
              }
            }
          } catch (error) {
            // Ignore parsing errors for non-matching messages
          }
        };
    
        wsConnection.on('message', messageHandler);
        wsConnection.send(JSON.stringify(command));
      });
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states what the tool does but doesn't disclose risks (e.g., potential side effects, security implications), execution environment details, or error handling. This is inadequate for a tool that executes arbitrary code in a browser context.

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, direct sentence with zero wasted words. It's front-loaded with the core action and context, making it highly efficient and easy to parse for an AI agent.

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 cases, execution scope, or interaction with sibling tools (e.g., how it relates to get_console_logs). This leaves significant gaps for safe and effective use.

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 one parameter ('JavaScript code to execute'), so the schema already documents the parameter adequately. The description doesn't add any meaningful semantics beyond what the schema provides, such as examples or constraints on the script content, warranting the baseline score of 3.

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' clearly states the action (execute) and target (JavaScript in browser), distinguishing it from siblings like click or navigate. However, it doesn't explicitly differentiate from tools like get_console_logs that also involve JavaScript execution context, making it a 4 rather than a 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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., browser must be open), limitations (e.g., execution context), or when to prefer other tools like get_content for data extraction. This leaves the agent with minimal context for decision-making.

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/nfodor/claude-arm64-browser'

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