Skip to main content
Glama

get_console_logs

Retrieve and filter browser console logs by level (log, info, warn, error, debug) with an option to clear logs afterward. Enhances debugging and monitoring capabilities in Playwright-based browser automation.

Instructions

Get console logs from the browser

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clearNoClear console logs after retrieving
levelNoFilter logs by level

Implementation Reference

  • Main handler function for the get_console_logs tool, which filters console logs by optional level, formats them with timestamps, returns as text response, and optionally clears the log storage.
    case 'get_console_logs': {
      if (!currentPage) {
        throw new Error('No browser page available. Launch a browser first.');
      }
    
      const params = GetConsoleLogsSchema.parse(args);
      
      // Filter logs by level if specified
      const filteredLogs = params.level 
        ? consoleLogs.filter(log => log.level === params.level)
        : consoleLogs;
    
      // Clear logs if requested
      if (params.clear) {
        consoleLogs = [];
      }
    
      const logText = filteredLogs.length > 0 
        ? filteredLogs.map(log => `[${log.timestamp.toISOString()}] ${log.level.toUpperCase()}: ${log.message}`).join('\n')
        : '(no console logs)';
    
      return {
        content: [
          {
            type: 'text',
            text: `Console Logs:\n${logText}`
          }
        ]
      };
    }
  • Zod schema for validating input parameters: optional level filter and clear flag.
    const GetConsoleLogsSchema = z.object({
      level: z.enum(['log', 'info', 'warn', 'error', 'debug']).optional(),
      clear: z.boolean().default(false)
    });
  • src/index.ts:295-313 (registration)
    Registration of the tool in the ListTools response, providing name, description, and JSON input schema.
    {
      name: 'get_console_logs',
      description: 'Get console logs from the browser',
      inputSchema: {
        type: 'object',
        properties: {
          level: {
            type: 'string',
            enum: ['log', 'info', 'warn', 'error', 'debug'],
            description: 'Filter logs by level'
          },
          clear: {
            type: 'boolean',
            default: false,
            description: 'Clear console logs after retrieving'
          }
        }
      }
    },
  • Global storage array for console logs captured from the browser page.
    let consoleLogs: Array<{level: string, message: string, timestamp: Date}> = [];
  • Page event listener that captures console messages and stores them in the global consoleLogs array. Set up during browser launch.
    currentPage.on('console', (msg) => {
      consoleLogs.push({
        level: msg.type(),
        message: msg.text(),
        timestamp: new Date()
      });
    });
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. While 'Get' implies a read operation, it doesn't address whether this requires specific browser state, what happens if no logs exist, potential rate limits, or authentication needs. The description is too minimal for a tool that interacts with browser console data.

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 extremely concise at just four words, with zero wasted language. It's front-loaded with the core purpose and contains no unnecessary elaboration, making it efficient for quick understanding.

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?

For a browser interaction tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what format the logs return in, whether this works only on specific pages, or what errors might occur. The minimal description leaves too many operational questions unanswered.

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?

With 100% schema description coverage, the schema already documents both parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, so it meets the baseline for adequate but unremarkable coverage.

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 ('Get') and resource ('console logs from the browser'), making the tool's function immediately understandable. However, it doesn't distinguish this tool from potential sibling tools that might also retrieve logs or browser data, which prevents a perfect 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 sibling tools like 'get_page_info' or 'evaluate_javascript' that might overlap in browser context, there's no indication of when this specific log retrieval is appropriate or what prerequisites might be needed.

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

Related 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/Wladastic/mcp-browser-server'

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