Skip to main content
Glama

execute_script

Run custom JavaScript code within Firefox browser tabs using Playwright for automation, enabling multi-tab debugging and browser control via MCP-enabled applications.

Instructions

Execute JavaScript in the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYes
tabIdNo

Implementation Reference

  • The core handler function for the 'execute_script' tool. It retrieves the target page, ensures the browser is running, evaluates the provided JavaScript script using Playwright's page.evaluate(), and returns the execution result.
    async executeScript(args) {
      this.ensureBrowserRunning();
      const { script, tabId } = args;
      const page = this.getPage(tabId);
      
      const result = await page.evaluate(script);
      
      return {
        content: [{
          type: 'text',
          text: `Script executed in tab '${tabId || this.activeTabId}'. Result: ${JSON.stringify(result)}`
        }]
      };
    }
  • Registers the 'execute_script' tool in the ListTools response, including its name, description, and input schema specifying required 'script' parameter and optional 'tabId'.
    {
      name: 'execute_script',
      description: 'Execute JavaScript in the browser',
      inputSchema: {
        type: 'object',
        properties: {
          script: { type: 'string' },
          tabId: { type: 'string' }
        },
        required: ['script']
      }
    },
  • Input schema for the 'execute_script' tool, defining properties 'script' (required string) and 'tabId' (optional string).
    inputSchema: {
      type: 'object',
      properties: {
        script: { type: 'string' },
        tabId: { type: 'string' }
      },
      required: ['script']
  • Helper method used by executeScript to retrieve the Playwright Page object for the specified or active tabId.
    getPage(tabId) {
      if (tabId) {
        if (!this.pages.has(tabId)) {
          throw new Error(`Tab '${tabId}' not found`);
        }
        return this.pages.get(tabId);
      } else {
        if (!this.activeTabId || !this.pages.has(this.activeTabId)) {
          throw new Error('No active tab. Use create_tab or set_active_tab first.');
        }
        return this.pages.get(this.activeTabId);
      }
    }
  • Helper method called by executeScript to ensure the Firefox browser instance is launched before executing scripts.
    ensureBrowserRunning() {
      if (!this.browser) {
        throw new Error('Firefox browser is not running. Please launch it first using the launch_firefox_multi tool.');
      }
    }
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 mentions execution but doesn't specify whether this is a read-only evaluation, if it modifies page state, requires specific permissions, has side effects like page reloads, or handles errors. This leaves critical behavioral traits unclear for a tool that interacts with a browser.

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 extremely concise with just four words, front-loading the core action without any fluff. Every word earns its place by directly conveying the tool's function, making it efficient and easy to parse.

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, the lack of annotations, no output schema, and low schema coverage, the description is insufficient. It doesn't cover execution context, return values, error handling, or safety considerations, leaving significant gaps for an agent to use this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'JavaScript' and 'browser', which loosely relate to the 'script' and 'tabId' parameters, but provides no details on script format, tabId usage, or whether tabId is optional. This adds minimal semantic value beyond the schema's basic structure.

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 verb ('Execute') and resource ('JavaScript in the browser'), making the purpose immediately understandable. However, it doesn't distinguish this tool from potential alternatives like 'inject_debugging_helpers' or clarify if this is for evaluation vs. injection, which prevents 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?

No guidance is provided on when to use this tool versus alternatives like 'inject_debugging_helpers' or 'get_javascript_errors', nor does it mention prerequisites such as needing an active browser session or tab. The description only states what it does, not when it's appropriate.

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/JediLuke/firefox-mcp-server'

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