Skip to main content
Glama

list_console_messages

Retrieve browser console messages with filtering options for debugging web applications. Supports filtering by level, time, text content, and source to isolate specific issues.

Instructions

List console messages. Supports filtering by level, time, text, source.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
levelNoFilter by level
limitNoMax messages (default: 50)
sinceMsNoOnly last N ms
textContainsNoText filter (case-insensitive)
sourceNoFilter by source
formatNoOutput format (default: text)

Implementation Reference

  • Core handler function that fetches console messages from Firefox, applies filters (level, time, text, source), truncates long messages, limits results, and returns formatted text or JSON response.
    export async function handleListConsoleMessages(args: unknown): Promise<McpToolResponse> {
      try {
        const {
          level,
          limit,
          sinceMs,
          textContains,
          source,
          format = 'text',
        } = (args as {
          level?: string;
          limit?: number;
          sinceMs?: number;
          textContains?: string;
          source?: string;
          format?: 'text' | 'json';
        }) || {};
    
        const { getFirefox } = await import('../index.js');
        const firefox = await getFirefox();
    
        let messages = await firefox.getConsoleMessages();
        const totalCount = messages.length;
    
        // Apply filters
        if (level) {
          messages = messages.filter((msg) => msg.level.toLowerCase() === level.toLowerCase());
        }
    
        if (sinceMs !== undefined) {
          const cutoffTime = Date.now() - sinceMs;
          messages = messages.filter((msg) => msg.timestamp && msg.timestamp >= cutoffTime);
        }
    
        if (textContains) {
          const textLower = textContains.toLowerCase();
          messages = messages.filter((msg) => msg.text.toLowerCase().includes(textLower));
        }
    
        if (source) {
          messages = messages.filter((msg) => msg.source?.toLowerCase() === source.toLowerCase());
        }
    
        // Truncate individual message texts to prevent token overflow
        messages = messages.map((msg) => ({
          ...msg,
          text: truncateText(msg.text, TOKEN_LIMITS.MAX_CONSOLE_MESSAGE_CHARS, '...[truncated]'),
        }));
    
        // Apply limit
        const maxLimit = limit ?? DEFAULT_LIMIT;
        const filteredCount = messages.length;
        const truncated = messages.length > maxLimit;
        messages = messages.slice(0, maxLimit);
    
        if (messages.length === 0) {
          const filterInfo = [];
          if (level) {
            filterInfo.push(`level=${level}`);
          }
          if (sinceMs) {
            filterInfo.push(`sinceMs=${sinceMs}`);
          }
          if (textContains) {
            filterInfo.push(`textContains="${textContains}"`);
          }
          if (source) {
            filterInfo.push(`source="${source}"`);
          }
    
          if (format === 'json') {
            return jsonResponse({
              total: totalCount,
              filtered: 0,
              showing: 0,
              filters: filterInfo.length > 0 ? filterInfo.join(', ') : null,
              messages: [],
            });
          }
    
          return successResponse(
            `No console messages found matching filters.\n` +
              `Total messages: ${totalCount}${filterInfo.length > 0 ? `, Filters: ${filterInfo.join(', ')}` : ''}`
          );
        }
    
        // JSON format
        if (format === 'json') {
          const filterInfo = [];
          if (level) {
            filterInfo.push(`level=${level}`);
          }
          if (sinceMs) {
            filterInfo.push(`sinceMs=${sinceMs}`);
          }
          if (textContains) {
            filterInfo.push(`textContains="${textContains}"`);
          }
          if (source) {
            filterInfo.push(`source="${source}"`);
          }
    
          return jsonResponse({
            total: totalCount,
            filtered: filteredCount,
            showing: messages.length,
            hasMore: truncated,
            filters: filterInfo.length > 0 ? filterInfo.join(', ') : null,
            messages: messages.map((msg) => ({
              level: msg.level,
              text: msg.text,
              source: msg.source || null,
              timestamp: msg.timestamp || null,
            })),
          });
        }
    
        // Format messages as text
        let output = `Console messages (showing ${messages.length}`;
        if (filteredCount > messages.length) {
          output += ` of ${filteredCount} matching`;
        }
        output += `, ${totalCount} total):\n`;
    
        if (level || sinceMs || textContains || source) {
          output += `Filters:`;
          if (level) {
            output += ` level=${level}`;
          }
          if (sinceMs) {
            output += ` sinceMs=${sinceMs}`;
          }
          if (textContains) {
            output += ` textContains="${textContains}"`;
          }
          if (source) {
            output += ` source="${source}"`;
          }
          output += '\n';
        }
        output += '\n';
    
        for (const msg of messages) {
          const emoji = LEVEL_EMOJI[msg.level.toLowerCase()] || '📝';
          const timestamp = msg.timestamp ? new Date(msg.timestamp).toISOString() : '';
          const source = msg.source ? ` [${msg.source}]` : '';
          const time = timestamp ? `[${timestamp}] ` : '';
    
          output += `${emoji} ${time}${msg.level.toUpperCase()}${source}: ${msg.text}\n`;
        }
    
        if (truncated) {
          output += `\n[+${filteredCount - messages.length} more]`;
        }
    
        return successResponse(output);
      } catch (error) {
        return errorResponse(error as Error);
      }
    }
  • Tool schema definition including name, description, and detailed inputSchema for filtering parameters.
    export const listConsoleMessagesTool = {
      name: 'list_console_messages',
      description: 'List console messages. Supports filtering by level, time, text, source.',
      inputSchema: {
        type: 'object',
        properties: {
          level: {
            type: 'string',
            enum: ['debug', 'info', 'warn', 'error'],
            description: 'Filter by level',
          },
          limit: {
            type: 'number',
            description: 'Max messages (default: 50)',
          },
          sinceMs: {
            type: 'number',
            description: 'Only last N ms',
          },
          textContains: {
            type: 'string',
            description: 'Text filter (case-insensitive)',
          },
          source: {
            type: 'string',
            description: 'Filter by source',
          },
          format: {
            type: 'string',
            enum: ['text', 'json'],
            description: 'Output format (default: text)',
          },
        },
      },
    };
  • src/index.ts:118-118 (registration)
    Maps the tool name to its handler function in the MCP server's toolHandlers for execution.
    ['list_console_messages', tools.handleListConsoleMessages],
  • src/index.ts:162-162 (registration)
    Includes the tool definition in the allTools array for the MCP server's listTools endpoint.
    tools.listConsoleMessagesTool,
  • Re-exports the tool definition and handler from console.ts for centralized import in src/index.ts.
    export {
      listConsoleMessagesTool,
      clearConsoleMessagesTool,
      handleListConsoleMessages,
      handleClearConsoleMessages,
    } from './console.js';
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions filtering capabilities but doesn't describe important behaviors like pagination, rate limits, authentication requirements, or what happens when no messages match filters. It doesn't specify whether this is a read-only operation or has side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured in two sentences: a clear purpose statement followed by filtering capabilities. There's no wasted language, though it could be slightly more front-loaded with the most critical information about what the tool returns.

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 tool with 6 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'console messages' are in this context, what format they return in, or provide behavioral context needed for proper tool selection. The lack of output schema means the description should ideally mention return format expectations.

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?

The description mentions filtering by level, time, text, and source, which maps to some parameters. However, with 100% schema description coverage, the schema already documents all 6 parameters thoroughly. The description adds minimal value beyond what's in the schema, meeting the baseline for high schema 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 verb ('List') and resource ('console messages'), making the purpose immediately understandable. It distinguishes from some siblings like 'clear_console_messages' by indicating retrieval rather than modification, though it doesn't explicitly differentiate from other list tools like 'list_network_requests' or 'list_pages'.

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. It doesn't mention prerequisites, appropriate contexts, or compare with sibling tools like 'list_network_requests' for different data types. The filtering capabilities are listed but without context for when each filter is appropriate.

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/mozilla/firefox-devtools-mcp'

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