Skip to main content
Glama

getConsoleLogs

Retrieve and analyze browser console logs to monitor and debug web applications using Chrome extension integration with BrowserTools MCP.

Instructions

Check our browser logs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'getConsoleLogs' MCP tool. It ensures a connection to the browser connector server using withServerConnection, fetches the console logs from the '/console-logs' endpoint, parses the JSON response, and returns it formatted as a text content block.
    server.tool("getConsoleLogs", "Check our browser logs", async () => { return await withServerConnection(async () => { const response = await fetch( `http://${discoveredHost}:${discoveredPort}/console-logs` ); const json = await response.json(); return { content: [ { type: "text", text: JSON.stringify(json, null, 2), }, ], }; }); });
  • Helper wrapper function used by the getConsoleLogs handler (and other tools) to ensure a valid connection to the browser connector server via discovery and automatic reconnection on failure.
    async function withServerConnection<T>( apiCall: () => Promise<T> ): Promise<T | any> { // Attempt to discover server if not already discovered if (!serverDiscovered) { const discovered = await discoverServer(); if (!discovered) { return { content: [ { type: "text", text: "Failed to discover browser connector server. Please ensure it's running.", }, ], isError: true, }; } } // Now make the actual API call with discovered host/port try { return await apiCall(); } catch (error: any) { // If the request fails, try rediscovering the server once console.error( `API call failed: ${error.message}. Attempting rediscovery...` ); serverDiscovered = false; if (await discoverServer()) { console.error("Rediscovery successful. Retrying API call..."); try { // Retry the API call with the newly discovered connection return await apiCall(); } catch (retryError: any) { console.error(`Retry failed: ${retryError.message}`); return { content: [ { type: "text", text: `Error after reconnection attempt: ${retryError.message}`, }, ], isError: true, }; } } else { console.error("Rediscovery failed. Could not reconnect to server."); return { content: [ { type: "text", text: `Failed to reconnect to server: ${error.message}`, }, ], isError: true, }; } } }
  • Helper function for server discovery, used indirectly by getConsoleLogs via withServerConnection to locate the browser connector server by trying common hosts/ports and validating the identity endpoint.
    async function discoverServer(): Promise<boolean> { console.log("Starting server discovery process"); // Common hosts to try const hosts = [getDefaultServerHost(), "127.0.0.1", "localhost"]; // Ports to try (start with default, then try others) const defaultPort = getDefaultServerPort(); const ports = [defaultPort]; // Add additional ports (fallback range) for (let p = 3025; p <= 3035; p++) { if (p !== defaultPort) { ports.push(p); } } console.log(`Will try hosts: ${hosts.join(", ")}`); console.log(`Will try ports: ${ports.join(", ")}`); // Try to find the server for (const host of hosts) { for (const port of ports) { try { console.log(`Checking ${host}:${port}...`); // Use the identity endpoint for validation const response = await fetch(`http://${host}:${port}/.identity`, { signal: AbortSignal.timeout(1000), // 1 second timeout }); if (response.ok) { const identity = await response.json(); // Verify this is actually our server by checking the signature if (identity.signature === "mcp-browser-connector-24x7") { console.log(`Successfully found server at ${host}:${port}`); // Save the discovered connection discoveredHost = host; discoveredPort = port; serverDiscovered = true; return true; } } } catch (error: any) { // Ignore connection errors during discovery console.error(`Error checking ${host}:${port}: ${error.message}`); } } } console.error("No server found during discovery"); return false; }
  • Registration of the 'getConsoleLogs' tool on the MCP server using server.tool(), including the inline handler function.
    server.tool("getConsoleLogs", "Check our browser logs", async () => { return await withServerConnection(async () => { const response = await fetch( `http://${discoveredHost}:${discoveredPort}/console-logs` ); const json = await response.json(); return { content: [ { type: "text", text: JSON.stringify(json, null, 2), }, ], }; }); });

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/Sugatraj/Cursor-Browser-Tools-MCP'

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