monitor_console_events
Monitor console events from a browser tab. Start, stop, or retrieve captured logs filtered by severity level.
Instructions
Real-time console event monitoring. Start monitoring, get events since last read, or stop. Filter by log level.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Start, stop, or get events since last read | |
| levels | No | Log levels to capture | |
| tabId | No | Target tab ID (defaults to currently active tab) | |
| apiKey | No | API key for authentication if enabled |
Implementation Reference
- src/tools/monitoring.ts:53-75 (handler)The handler for 'monitor_console_events' - registers the tool with an async handler that sends a 'monitor_console_events' command via WebSocket bridge, accepting action, levels, tabId, and apiKey parameters.
server.tool( 'monitor_console_events', 'Real-time console event monitoring. Start monitoring, get events since last read, or stop. Filter by log level.', { action: z.enum(['start', 'stop', 'get']).describe('Start, stop, or get events since last read'), levels: z.array(z.enum(['log', 'warn', 'error', 'info'])).optional().default(['error', 'warn']).describe('Log levels to capture'), tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, async ({ action, levels, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'monitor_console_events', params: { action, levels }, tabId, apiKey, timeout: LONG_TIMEOUT, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } ); - src/tools/monitoring.ts:56-61 (schema)Input schema for 'monitor_console_events' - defines action (start/stop/get), levels (array of log/warn/error/info, defaults to error+warn), optional tabId, and optional apiKey.
{ action: z.enum(['start', 'stop', 'get']).describe('Start, stop, or get events since last read'), levels: z.array(z.enum(['log', 'warn', 'error', 'info'])).optional().default(['error', 'warn']).describe('Log levels to capture'), tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, - src/tools/monitoring.ts:53-55 (registration)Registration of the 'monitor_console_events' tool via server.tool() inside registerMonitoringTools().
server.tool( 'monitor_console_events', 'Real-time console event monitoring. Start monitoring, get events since last read, or stop. Filter by log level.', - src/tools/index.ts:50-50 (registration)registerMonitoringTools is called from registerAllTools(), which wires up all tools to the server.
registerMonitoringTools(server, bridge); - src/websocket-bridge.ts:63-103 (helper)The WebSocketBridge.sendCommand() method that dispatches the monitor_console_events command to the Chrome extension over WebSocket.
async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> { if (!this.isConnected()) { return { success: false, error: { code: 'NOT_CONNECTED', message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.', }, }; } const id = crypto.randomUUID(); const timeout = cmd.timeout ?? DEFAULT_TIMEOUT; return new Promise<BridgeResponse>((resolve, reject) => { const timer = setTimeout(() => { this.pending.delete(id); resolve({ success: false, error: { code: 'TIMEOUT', message: `Command '${cmd.command}' timed out after ${timeout}ms`, }, }); }, timeout); this.pending.set(id, { resolve, reject, timer }); const message = { id, type: 'request', command: cmd.command, params: cmd.params, tabId: cmd.tabId, apiKey: cmd.apiKey, timestamp: Date.now(), }; this.client!.send(JSON.stringify(message)); }); }