Skip to main content
Glama
lxman

Safari MCP Server

by lxman

safari_execute_script

Execute JavaScript code within Safari browser sessions to automate tasks, manipulate web content, and interact with page elements programmatically.

Instructions

Execute JavaScript in the browser context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession identifier
scriptYesJavaScript code to execute
argsNoArguments to pass to the script

Implementation Reference

  • Core implementation of the tool: retrieves the Safari session and executes the JavaScript script using Selenium WebDriver's executeScript method, with error handling.
    async executeScript(sessionId: string, script: string, args: any[] = []): Promise<any> {
      const session = this.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found`);
      }
    
      try {
        return await session.driver.executeScript(script, ...args);
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new Error(`Script execution failed: ${errorMessage}`);
      }
    }
  • MCP server-side wrapper for the tool: parses input arguments, delegates to SafariDriverManager, and formats the result as a text response.
    private async executeScript(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> {
      const { sessionId, script, args: scriptArgs = [] } = args;
      
      const result = await this.driverManager.executeScript(sessionId, script, scriptArgs);
      
      return [
        {
          type: 'text',
          text: `Script execution result:\n${JSON.stringify(result, null, 2)}`
        }
      ];
    }
  • Input schema definition for the safari_execute_script tool, including required sessionId and script, optional args array.
    {
      name: 'safari_execute_script',
      description: 'Execute JavaScript in the browser context',
      inputSchema: {
        type: 'object',
        properties: {
          sessionId: { type: 'string', description: 'Session identifier' },
          script: { type: 'string', description: 'JavaScript code to execute' },
          args: { 
            type: 'array', 
            description: 'Arguments to pass to the script'
          }
        },
        required: ['sessionId', 'script']
      }
    },
  • Tool dispatch/registration in the handleToolCall switch statement, routing calls to the executeScript handler.
    case 'safari_execute_script':
      return await this.executeScript(args);
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions execution but doesn't disclose critical behavioral traits such as whether this requires an active session, potential side effects (e.g., modifying page state), error handling, or security implications. This is a significant gap for a tool that executes code in 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 a single, efficient sentence that directly states the tool's function without unnecessary words. It is front-loaded and wastes no space, 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, the description is insufficient. With no annotations, no output schema, and a lack of behavioral details (e.g., return values, error cases), it leaves the agent with incomplete information. This is inadequate for a tool that performs a potentially impactful operation.

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%, providing clear documentation for all parameters (sessionId, script, args). The description adds no additional meaning beyond the schema, such as examples of script usage or context for args. Baseline 3 is appropriate when the schema handles parameter documentation adequately.

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 context ('in the browser context'), which is specific and unambiguous. However, it doesn't differentiate from potential sibling tools like 'safari_inspect_element' that might also involve browser interaction, so it doesn't reach the highest 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. With siblings like 'safari_get_page_info' or 'safari_inspect_element', there's no indication of scenarios where executing JavaScript is preferred or required, leaving the agent without usage context.

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/lxman/safari-mcp-server'

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