Skip to main content
Glama

list_console_messages

Retrieve browser console messages from the current tab with filtering options for level, time range, content, and source to debug web applications.

Instructions

List console messages for the selected tab since the last navigation. Use filters (level, limit, sinceMs, textContains, source) to focus on recent and relevant logs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format: text (default, human-readable) or json (structured data)
levelNoFilter by console message level
limitNoMaximum number of messages to return (default: 50)
sinceMsNoOnly show messages from the last N milliseconds (filters by timestamp)
sourceNoFilter messages by source (e.g., "console-api", "javascript", "network")
textContainsNoFilter messages by text content (case-insensitive substring match)

Implementation Reference

  • The core handler function that implements the list_console_messages tool. It retrieves console messages from Firefox, applies filters (level, limit, sinceMs, textContains, source), truncates long texts, and returns formatted output in text or JSON.
    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); } }
  • The tool definition object including name, description, and inputSchema for validation of 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:106-147 (registration)
    Registration of the handler function in the toolHandlers Map used by the MCP server for tool execution.
    >([ // Pages ['list_pages', tools.handleListPages], ['new_page', tools.handleNewPage], ['navigate_page', tools.handleNavigatePage], ['select_page', tools.handleSelectPage], ['close_page', tools.handleClosePage], // Script evaluation - DISABLED (see docs/future-features.md) // ['evaluate_script', tools.handleEvaluateScript], // Console ['list_console_messages', tools.handleListConsoleMessages], ['clear_console_messages', tools.handleClearConsoleMessages], // Network ['list_network_requests', tools.handleListNetworkRequests], ['get_network_request', tools.handleGetNetworkRequest], // Snapshot ['take_snapshot', tools.handleTakeSnapshot], ['resolve_uid_to_selector', tools.handleResolveUidToSelector], ['clear_snapshot', tools.handleClearSnapshot], // Input ['click_by_uid', tools.handleClickByUid], ['hover_by_uid', tools.handleHoverByUid], ['fill_by_uid', tools.handleFillByUid], ['drag_by_uid_to_uid', tools.handleDragByUidToUid], ['fill_form_by_uid', tools.handleFillFormByUid], ['upload_file_by_uid', tools.handleUploadFileByUid], // Screenshot ['screenshot_page', tools.handleScreenshotPage], ['screenshot_by_uid', tools.handleScreenshotByUid], // Utilities ['accept_dialog', tools.handleAcceptDialog], ['dismiss_dialog', tools.handleDismissDialog], ['navigate_history', tools.handleNavigateHistory], ['set_viewport_size', tools.handleSetViewportSize], ]);
  • src/index.ts:150-191 (registration)
    Registration of the tool definition in the allTools array returned by listTools request.
    const allTools = [ // Pages tools.listPagesTool, tools.newPageTool, tools.navigatePageTool, tools.selectPageTool, tools.closePageTool, // Script evaluation - DISABLED (see docs/future-features.md) // tools.evaluateScriptTool, // Console tools.listConsoleMessagesTool, tools.clearConsoleMessagesTool, // Network tools.listNetworkRequestsTool, tools.getNetworkRequestTool, // Snapshot tools.takeSnapshotTool, tools.resolveUidToSelectorTool, tools.clearSnapshotTool, // Input tools.clickByUidTool, tools.hoverByUidTool, tools.fillByUidTool, tools.dragByUidToUidTool, tools.fillFormByUidTool, tools.uploadFileByUidTool, // Screenshot tools.screenshotPageTool, tools.screenshotByUidTool, // Utilities tools.acceptDialogTool, tools.dismissDialogTool, tools.navigateHistoryTool, tools.setViewportSizeTool, ];
  • Re-export of the tool and handler from console.ts for central import in src/index.ts.
    // Console tools 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