get_console_output
Retrieve recent console logs from a debugged Node.js process to monitor output and identify issues during debugging sessions.
Instructions
Gets the most recent console output from the debugged process
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of console entries to return. Defaults to 20 |
Implementation Reference
- src/mcp-server.js:1091-1123 (handler)The handler function for the 'get_console_output' tool. It slices the most recent console outputs from inspector.consoleOutput based on the limit, formats them with timestamps and types, and returns them as text content.async ({ limit = 20 }) => { try { if (!inspector.consoleOutput || inspector.consoleOutput.length === 0) { return { content: [{ type: "text", text: "No console output captured yet" }] }; } // Get the most recent console output entries const recentOutput = inspector.consoleOutput.slice(-limit); const formattedOutput = recentOutput.map(output => { const timestamp = new Date(output.timestamp).toISOString(); return `[${timestamp}] [${output.type}] ${output.message}`; }).join('\n'); return { content: [{ type: "text", text: `Console output (most recent ${recentOutput.length} entries):\n\n${formattedOutput}` }] }; } catch (err) { return { content: [{ type: "text", text: `Error getting console output: ${err.message}` }] }; } }
- src/mcp-server.js:1088-1090 (schema)Zod schema defining the optional 'limit' input parameter for the number of recent console entries to retrieve.{ limit: z.number().optional().describe("Maximum number of console entries to return. Defaults to 20") },
- src/mcp-server.js:1085-1124 (registration)Registration of the 'get_console_output' tool using server.tool(), including name, description, schema, and handler function.server.tool( "get_console_output", "Gets the most recent console output from the debugged process", { limit: z.number().optional().describe("Maximum number of console entries to return. Defaults to 20") }, async ({ limit = 20 }) => { try { if (!inspector.consoleOutput || inspector.consoleOutput.length === 0) { return { content: [{ type: "text", text: "No console output captured yet" }] }; } // Get the most recent console output entries const recentOutput = inspector.consoleOutput.slice(-limit); const formattedOutput = recentOutput.map(output => { const timestamp = new Date(output.timestamp).toISOString(); return `[${timestamp}] [${output.type}] ${output.message}`; }).join('\n'); return { content: [{ type: "text", text: `Console output (most recent ${recentOutput.length} entries):\n\n${formattedOutput}` }] }; } catch (err) { return { content: [{ type: "text", text: `Error getting console output: ${err.message}` }] }; } } );
- src/mcp-server.js:174-209 (helper)Part of Inspector.handleEvent method that captures 'Runtime.consoleAPICalled' events, processes arguments into a message string, and stores them in this.consoleOutput array (global as inspector.consoleOutput), which is used by the tool.case 'Runtime.consoleAPICalled': // Handle console logs from the debugged program const args = event.params.args.map(arg => { if (arg.type === 'string') return arg.value; if (arg.type === 'number') return arg.value; if (arg.type === 'boolean') return arg.value; if (arg.type === 'object') { if (arg.value) { return JSON.stringify(arg.value, null, 2); } else if (arg.objectId) { // We'll try to get properties later as we can't do async here return arg.description || `[${arg.subtype || arg.type}]`; } else { return arg.description || `[${arg.subtype || arg.type}]`; } } return JSON.stringify(arg); }).join(' '); // Store console logs to make them available to the MCP tools if (!this.consoleOutput) { this.consoleOutput = []; } this.consoleOutput.push({ type: event.params.type, message: args, timestamp: Date.now(), raw: event.params.args }); // Keep only the last 100 console messages to avoid memory issues if (this.consoleOutput.length > 100) { this.consoleOutput.shift(); } break;
- src/mcp-server.js:328-329 (helper)Initialization of the consoleOutput array on the inspector instance, providing the storage for captured console messages.// Initialize console output storage inspector.consoleOutput = [];