get_console_output
Retrieve the most recent console output from a Node.js process being debugged, with an option to limit the number of entries returned.
Instructions
Gets the most recent console output from the debugged process
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of console entries to return. Defaults to 20 |
Implementation Reference
- src/mcp-server.js:1084-1124 (registration)Registration of the 'get_console_output' tool on the MCP server with a 'limit' parameter (default 20)
// Add a tool specifically for getting console output 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:1091-1123 (handler)Handler function that retrieves the most recent console output entries from inspector.consoleOutput, formats them with timestamps and types, and returns them as text
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-1089 (schema)Input schema for the tool: optional 'limit' parameter (number, defaults to 20) defining max console entries to return
{ limit: z.number().optional().describe("Maximum number of console entries to return. Defaults to 20") - src/mcp-server.js:193-207 (helper)Console log capture in Inspector.handleEvent - stores Runtime.consoleAPICalled events into inspector.consoleOutput array (keeps last 100 entries)
// 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(); } - src/mcp-server.js:329-329 (helper)Initialization of the consoleOutput array on the inspector instance
inspector.consoleOutput = [];