Skip to main content
Glama

evaluate

Run JavaScript code within a browser on ARM64 devices using the chromium-arm64 server, enabling web automation, testing, and dynamic script execution for efficient web interaction and debugging.

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. Ensures Chromium is running, sends the JavaScript script via CDP Runtime.evaluate, and returns the execution result as a JSON string.
    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)}` }], }; }
  • Input schema definition for the 'evaluate' tool, specifying that a 'script' string is required.
    { name: 'evaluate', description: 'Execute JavaScript in the browser', inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JavaScript code to execute', }, }, required: ['script'], }, },
  • index.js:359-360 (registration)
    Registration and dispatch logic in the MCP CallToolRequest handler that routes 'evaluate' tool calls to the evaluate handler method.
    case 'evaluate': return await this.evaluate(args.script);
  • index.js:103-344 (registration)
    Tool list registration in ListToolsRequest handler that includes the 'evaluate' tool with its schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'navigate', description: 'Navigate to a URL', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'The URL to navigate to', }, }, required: ['url'], }, }, { name: 'screenshot', description: 'Take a screenshot of the current page', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name for the screenshot file', default: 'screenshot.png', }, fullPage: { type: 'boolean', description: 'Capture full page', default: false, }, }, }, }, { name: 'click', description: 'Click an element on the page', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element to click', }, }, required: ['selector'], }, }, { name: 'fill', description: 'Fill an input field', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the input field', }, value: { type: 'string', description: 'Value to fill', }, }, required: ['selector', 'value'], }, }, { name: 'evaluate', description: 'Execute JavaScript in the browser', inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JavaScript code to execute', }, }, required: ['script'], }, }, { name: 'get_content', description: 'Get page content (HTML or text)', inputSchema: { type: 'object', properties: { type: { type: 'string', enum: ['html', 'text'], description: 'Type of content to get', default: 'text', }, }, }, }, { name: 'hover', description: 'Hover over an element on the page', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the element to hover', }, }, required: ['selector'], }, }, { name: 'select', description: 'Select an option from a dropdown', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'CSS selector for the select element', }, value: { type: 'string', description: 'Value to select', }, }, required: ['selector', 'value'], }, }, { name: 'get_console_logs', description: 'Get browser console logs', inputSchema: { type: 'object', properties: {}, }, }, { name: 'get_console_errors', description: 'Get browser console errors', inputSchema: { type: 'object', properties: {}, }, }, { name: 'get_network_logs', description: 'Get network activity logs', inputSchema: { type: 'object', properties: {}, }, }, { name: 'get_network_errors', description: 'Get network error logs', inputSchema: { type: 'object', properties: {}, }, }, { name: 'wipe_logs', description: 'Clear all stored logs from memory', inputSchema: { type: 'object', properties: {}, }, }, { name: 'get_selected_element', description: 'Get information about the currently selected element', inputSchema: { type: 'object', properties: {}, }, }, { name: 'run_accessibility_audit', description: 'Run an accessibility audit on the current page', inputSchema: { type: 'object', properties: {}, }, }, { name: 'run_performance_audit', description: 'Run a performance audit on the current page', inputSchema: { type: 'object', properties: {}, }, }, { name: 'run_seo_audit', description: 'Run an SEO audit on the current page', inputSchema: { type: 'object', properties: {}, }, }, { name: 'run_best_practices_audit', description: 'Run a best practices audit on the current page', inputSchema: { type: 'object', properties: {}, }, }, { name: 'run_nextjs_audit', description: 'Run a Next.js specific audit on the current page', inputSchema: { type: 'object', properties: {}, }, }, { name: 'run_debugger_mode', description: 'Run debugger mode to debug issues in the application', inputSchema: { type: 'object', properties: {}, }, }, { name: 'run_audit_mode', description: 'Run comprehensive audit mode for optimization', inputSchema: { type: 'object', properties: {}, }, }, { name: 'close_browser', description: 'Close the browser instance', inputSchema: { type: 'object', properties: {}, }, }, ], }));
  • Key helper function used by evaluate to send Chrome DevTools Protocol commands over WebSocket to the browser instance.
    async sendCDPCommand(method, params = {}) { if (!wsConnection || wsConnection.readyState !== WebSocket.OPEN) { throw new Error('WebSocket not ready for CDP command'); } return new Promise((resolve, reject) => { const id = Math.floor(Math.random() * 1000000); const command = { id, method, params }; const timeout = setTimeout(() => { wsConnection.removeListener('message', messageHandler); reject(new Error(`CDP command timeout: ${method}`)); }, 10000); const messageHandler = (data) => { try { const response = JSON.parse(data.toString()); if (response.id === id) { clearTimeout(timeout); wsConnection.removeListener('message', messageHandler); if (response.error) { reject(new Error(`CDP Error: ${response.error.message}`)); } else { resolve(response.result || {}); } } } catch (e) { // Ignore parse errors for events } }; wsConnection.on('message', messageHandler); wsConnection.send(JSON.stringify(command)); }); }

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