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); } }

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