Skip to main content
Glama

execute_function

Run custom JavaScript functions within a browser environment to automate web interactions, extract data, or manipulate page content programmatically.

Instructions

Execute custom JavaScript function in browser context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
contextNo

Implementation Reference

  • src/index.ts:135-146 (registration)
    Registration of the 'execute_function' tool including name, description, and input schema in the ListTools response.
    {
      name: 'execute_function',
      description: 'Execute custom JavaScript function in browser context',
      inputSchema: {
        type: 'object',
        properties: {
          code: { type: 'string' },
          context: { type: 'object' },
        },
        required: ['code'],
      },
    },
  • The main handler for the 'execute_function' tool in the MCP server, which calls the BrowserlessClient.executeFunction and formats the response as MCP content.
    case 'execute_function': {
      if (!args) throw new Error('Arguments are required');
      const result = await this.client!.executeFunction(args as any);
      if (result.success && result.data) {
        return {
          content: [
            {
              type: 'text',
              text: `Function executed successfully. Result type: ${result.data.type}`,
            },
            {
              type: 'text',
              text: JSON.stringify(result.data.result, null, 2),
            },
          ],
        };
      } else {
        throw new Error(result.error || 'Failed to execute function');
      }
    }
  • Helper method in BrowserlessClient that performs the actual HTTP POST request to the Browserless server '/function' endpoint to execute the provided JavaScript code.
    async executeFunction(request: FunctionRequest): Promise<BrowserlessResponse<FunctionResponse>> {
      try {
        const response: AxiosResponse<FunctionResponse> = await this.httpClient.post('/function', request, {
          headers: {
            'Content-Type': 'application/javascript',
          },
        });
    
        return {
          success: true,
          data: response.data,
        };
      } catch (error) {
        return this.handleError(error);
      }
    }
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 doesn't cover critical aspects like security implications, execution timeouts, error handling, or whether it modifies browser state. This is a significant gap 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, clear sentence with zero wasted words. It's appropriately sized and front-loaded, efficiently conveying the core purpose 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 arbitrary JavaScript in a browser, lack of annotations, 0% schema coverage, and no output schema, the description is incomplete. It doesn't address safety, performance, or result handling, making it inadequate for informed tool selection.

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?

Schema description coverage is 0%, so the description must compensate but fails to do so. It doesn't explain what 'code' or 'context' parameters represent, their expected formats, or examples. For a tool with 2 parameters (one required) and nested objects, this leaves the agent guessing about proper usage.

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') and target ('custom JavaScript function in browser context'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'execute_browserql' or 'run_performance_audit' which might also involve browser execution, leaving room for ambiguity.

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 like 'execute_browserql' or other browser-related siblings. The description implies a general-purpose execution context but doesn't specify prerequisites, limitations, or typical use cases, leaving the agent with minimal direction.

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/Lizzard-Solutions/browserless-mcp'

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