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';

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

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