From 332f8a3b77afccf0cc024edf6fb26341c390bb99 Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Wed, 19 Mar 2025 13:48:38 +0000 Subject: [PATCH 1/4] feat: add first mcp-server implementation --- index.js | 10 + package.json | 46 ++ src/mcp-server.js | 1133 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1189 insertions(+) create mode 100644 index.js create mode 100644 package.json create mode 100644 src/mcp-server.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..f25a018 --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +#!/usr/bin/env node + +// This file serves as the entry point for the MCP debugger +// When installed globally or run with npx, this file will be executed + +// Import and run the MCP server +import './src/mcp-server.js'; + +// The server is started in the imported file +console.log('MCP Debugger started. Connected to Node.js Inspector protocol.'); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..144d01e --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "mcp-nodejs-debugger", + "version": "0.1.0-beta.1", + "description": "An MCP server to debug Node.js at runtime", + "main": "index.js", + "bin": { + "mcp-debugger": "./index.js" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Hyperdrive", + "license": "MIT", + "keywords": [ + "claude", + "claude-code", + "mcp", + "model-context-protocol", + "inspector", + "debugger", + "nodejs" + ], + "dependencies": { + "@modelcontextprotocol/sdk": "^1.7.0", + "node-fetch": "^3.3.2", + "ws": "^8.16.0", + "zod": "^3.24.2" + }, + "files": [ + "index.js", + "src/", + "README.md" + ], + "type": "module", + "engines": { + "node": ">=18.0.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/hyperdrive-eng/mcp-debugger" + }, + "bugs": { + "url": "https://github.com/hyperdrive-eng/mcp-debugger/issues" + }, + "homepage": "https://hyperdrive.engineering" +} diff --git a/src/mcp-server.js b/src/mcp-server.js new file mode 100644 index 0000000..491d9d5 --- /dev/null +++ b/src/mcp-server.js @@ -0,0 +1,1133 @@ +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; +import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; +import { z } from "zod"; +import WebSocket from 'ws'; +import fetch from 'node-fetch'; + +// Create an MCP server +const server = new McpServer({ + name: "Inspector", + version: "1.0.0", + description: `Node.js debugger that allows setting breakpoints and inspecting variables. + When using debugging capabilities, always instruct the user to navigate to their + website after setting breakpoints. Breakpoints will only be triggered when the user + interacts with their website in a way that causes the code at the breakpoint location to execute. + When user requests debugging, always use the following format: + 1. Set breakpoint + 2. Wait for user to navigate to their website and trigger breakpoint + 3. Inspect variables + 4. Execute code + 5. Step over + 6. Step into + 7. Step out + 8. Continue execution + 9. Delete breakpoint + 10. List breakpoints + 11. Get current location + 12. Evaluate expression + 13. Get script source + 14. Get properties` +}); + +class Inspector { + constructor(port = 9229, retryOptions = { maxRetries: 5, retryInterval: 1000 }) { + this.port = port; + this.connected = false; + this.pendingRequests = new Map(); + this.debuggerEnabled = false; + this.breakpoints = new Map(); + this.paused = false; + this.currentCallFrames = []; + this.retryOptions = retryOptions; + this.retryCount = 0; + this.callbackHandlers = new Map(); + this.initialize(); + } + + async initialize() { + try { + // First, get the WebSocket URL from the inspector JSON API + // Use 127.0.0.1 instead of localhost to avoid IPv6 issues + const response = await fetch(`http://127.0.0.1:${this.port}/json`); + const data = await response.json(); + const debuggerUrl = data[0]?.webSocketDebuggerUrl; + + if (!debuggerUrl) { + console.error('No WebSocket debugger URL found'); + this.scheduleRetry(); + return; + } + + console.log(`Connecting to debugger at: ${debuggerUrl}`); + this.ws = new WebSocket(debuggerUrl); + + this.ws.on('open', () => { + console.log('WebSocket connection established'); + this.connected = true; + this.retryCount = 0; + this.enableDebugger(); + }); + + this.ws.on('error', (error) => { + console.error('WebSocket error:', error.message); + this.scheduleRetry(); + }); + + this.ws.on('close', () => { + console.log('WebSocket connection closed'); + this.connected = false; + this.scheduleRetry(); + }); + + this.ws.on('message', (data) => { + const response = JSON.parse(data.toString()); + + // Handle events + if (response.method) { + this.handleEvent(response); + return; + } + + // Handle response for pending request + if (response.id && this.pendingRequests.has(response.id)) { + const { resolve, reject } = this.pendingRequests.get(response.id); + this.pendingRequests.delete(response.id); + + if (response.error) { + reject(response.error); + } else { + resolve(response.result); + } + } + }); + } catch (error) { + console.error('Error initializing inspector:', error.message); + this.scheduleRetry(); + } + } + + scheduleRetry() { + if (this.retryCount < this.retryOptions.maxRetries) { + this.retryCount++; + console.log(`Retrying connection (${this.retryCount}/${this.retryOptions.maxRetries})...`); + setTimeout(() => this.initialize(), this.retryOptions.retryInterval); + } else { + console.error(`Failed to connect after ${this.retryOptions.maxRetries} attempts`); + } + } + + async enableDebugger() { + if (!this.debuggerEnabled && this.connected) { + try { + await this.send('Debugger.enable', {}); + console.log('Debugger enabled'); + this.debuggerEnabled = true; + + // Setup event listeners + await this.send('Runtime.enable', {}); + + // Also activate possible domains we'll need + await this.send('Runtime.runIfWaitingForDebugger', {}); + } catch (err) { + console.error('Failed to enable debugger:', err); + } + } + } + + handleEvent(event) { + // console.log('Event received:', event.method, event.params); + + switch (event.method) { + case 'Debugger.paused': + this.paused = true; + this.currentCallFrames = event.params.callFrames; + console.log('Execution paused at breakpoint'); + + // Notify any registered callbacks for pause events + if (this.callbackHandlers.has('paused')) { + this.callbackHandlers.get('paused').forEach(callback => + callback(event.params)); + } + break; + + case 'Debugger.resumed': + this.paused = false; + this.currentCallFrames = []; + console.log('Execution resumed'); + + // Notify any registered callbacks for resume events + if (this.callbackHandlers.has('resumed')) { + this.callbackHandlers.get('resumed').forEach(callback => + callback()); + } + break; + + case 'Debugger.scriptParsed': + // Script parsing might be useful for source maps + break; + + case 'Runtime.exceptionThrown': + console.log('Exception thrown:', + event.params.exceptionDetails.text, + event.params.exceptionDetails.exception?.description || ''); + break; + + 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(); + } + + console.log(`[Console.${event.params.type}]`, args); + break; + } + } + + registerCallback(event, callback) { + if (!this.callbackHandlers.has(event)) { + this.callbackHandlers.set(event, []); + } + this.callbackHandlers.get(event).push(callback); + } + + unregisterCallback(event, callback) { + if (this.callbackHandlers.has(event)) { + const callbacks = this.callbackHandlers.get(event); + const index = callbacks.indexOf(callback); + if (index !== -1) { + callbacks.splice(index, 1); + } + } + } + + async send(method, params) { + return new Promise((resolve, reject) => { + const timeout = setTimeout(() => { + reject(new Error(`Request timed out: ${method}`)); + this.pendingRequests.delete(id); + }, 5000); + + const checkConnection = () => { + if (this.connected) { + try { + const id = Math.floor(Math.random() * 1000000); + this.pendingRequests.set(id, { + resolve: (result) => { + clearTimeout(timeout); + resolve(result); + }, + reject: (err) => { + clearTimeout(timeout); + reject(err); + } + }); + + this.ws.send(JSON.stringify({ + id, + method, + params + })); + } catch (err) { + clearTimeout(timeout); + reject(err); + } + } else { + const connectionCheckTimer = setTimeout(checkConnection, 100); + // If still not connected after 3 seconds, reject the promise + setTimeout(() => { + clearTimeout(connectionCheckTimer); + clearTimeout(timeout); + reject(new Error('Not connected to debugger')); + }, 3000); + } + }; + + checkConnection(); + }); + } + + async getScriptSource(scriptId) { + try { + const response = await this.send('Debugger.getScriptSource', { + scriptId + }); + return response.scriptSource; + } catch (err) { + console.error('Error getting script source:', err); + return null; + } + } + + async evaluateOnCallFrame(callFrameId, expression) { + if (!this.paused) { + throw new Error('Debugger is not paused'); + } + + try { + return await this.send('Debugger.evaluateOnCallFrame', { + callFrameId, + expression, + objectGroup: 'console', + includeCommandLineAPI: true, + silent: false, + returnByValue: true, + generatePreview: true + }); + } catch (err) { + console.error('Error evaluating expression:', err); + throw err; + } + } + + async getProperties(objectId, ownProperties = true) { + try { + return await this.send('Runtime.getProperties', { + objectId, + ownProperties, + accessorPropertiesOnly: false, + generatePreview: true + }); + } catch (err) { + console.error('Error getting properties:', err); + throw err; + } + } +} + +// Create the inspector instance +const inspector = new Inspector(9229); + +// Initialize console output storage +inspector.consoleOutput = []; + +// Execute JavaScript code +server.tool( + "nodejs_inspect", + "Executes JavaScript code in the debugged process", + { + js_code: z.string().describe("JavaScript code to execute") + }, + async ({ js_code }) => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + // Capture the current console output length to know where to start capturing new output + const consoleStartIndex = inspector.consoleOutput.length; + + // Wrap the code in a try-catch with explicit console logging for errors + let codeToExecute = ` + try { + ${js_code} + } catch (e) { + console.error('Execution error:', e); + e; // Return the error + } + `; + + const response = await inspector.send('Runtime.evaluate', { + expression: codeToExecute, + contextId: 1, + objectGroup: 'console', + includeCommandLineAPI: true, + silent: false, + returnByValue: true, + generatePreview: true, + awaitPromise: true // This will wait for promises to resolve + }); + + // Give some time for console logs to be processed + await new Promise(resolve => setTimeout(resolve, 200)); + + // Get any console output that was generated during execution + const consoleOutputs = inspector.consoleOutput.slice(consoleStartIndex); + const consoleText = consoleOutputs.map(output => + `[${output.type}] ${output.message}` + ).join('\n'); + + // Process the return value + let result; + if (response.result) { + if (response.result.type === 'object') { + if (response.result.value) { + // If we have a value, use it + result = response.result.value; + } else if (response.result.objectId) { + // If we have an objectId but no value, the object was too complex to serialize directly + // Get more details about the object + try { + const objectProps = await inspector.getProperties(response.result.objectId); + const formattedObject = {}; + + for (const prop of objectProps.result) { + if (prop.value) { + if (prop.value.type === 'object' && prop.value.subtype !== 'null') { + // For nested objects, try to get their details too + if (prop.value.objectId) { + try { + const nestedProps = await inspector.getProperties(prop.value.objectId); + const nestedObj = {}; + for (const nestedProp of nestedProps.result) { + if (nestedProp.value) { + if (nestedProp.value.value !== undefined) { + nestedObj[nestedProp.name] = nestedProp.value.value; + } else { + nestedObj[nestedProp.name] = nestedProp.value.description || + `[${nestedProp.value.subtype || nestedProp.value.type}]`; + } + } + } + formattedObject[prop.name] = nestedObj; + } catch (nestedErr) { + formattedObject[prop.name] = prop.value.description || + `[${prop.value.subtype || prop.value.type}]`; + } + } else { + formattedObject[prop.name] = prop.value.description || + `[${prop.value.subtype || prop.value.type}]`; + } + } else if (prop.value.type === 'function') { + formattedObject[prop.name] = '[function]'; + } else if (prop.value.value !== undefined) { + formattedObject[prop.name] = prop.value.value; + } else { + formattedObject[prop.name] = `[${prop.value.type}]`; + } + } + } + + result = formattedObject; + } catch (propErr) { + // If we can't get properties, at least show the object description + result = response.result.description || `[${response.result.subtype || response.result.type}]`; + } + } else { + // Fallback for objects without value or objectId + result = response.result.description || `[${response.result.subtype || response.result.type}]`; + } + } else if (response.result.type === 'undefined') { + result = undefined; + } else if (response.result.value !== undefined) { + result = response.result.value; + } else { + result = `[${response.result.type}]`; + } + } + + let responseContent = []; + + // Add console output if there was any + if (consoleText.length > 0) { + responseContent.push({ + type: "text", + text: `Console output:\n${consoleText}` + }); + } + + // Add the result + responseContent.push({ + type: "text", + text: `Code executed successfully. Result: ${JSON.stringify(result, null, 2)}` + }); + + return { content: responseContent }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error executing code: ${err.message}` + }] + }; + } + } +); + +// Set breakpoint tool +server.tool( + "set_breakpoint", + "Sets a breakpoint at specified line and file", + { + file: z.string().describe("File path where to set breakpoint"), + line: z.number().describe("Line number for breakpoint") + }, + async ({ file, line }) => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + // Convert file path to a URL-like format that the debugger can understand + // For local files, typically file:///path/to/file.js + let fileUrl = file; + if (!file.startsWith('file://') && !file.startsWith('http://') && !file.startsWith('https://')) { + fileUrl = `file://${file.startsWith('/') ? '' : '/'}${file}`; + } + + const response = await inspector.send('Debugger.setBreakpointByUrl', { + lineNumber: line - 1, // Chrome DevTools Protocol uses 0-based line numbers + urlRegex: fileUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), // Escape special regex characters + columnNumber: 0 + }); + + // Store the breakpoint for future reference + inspector.breakpoints.set(response.breakpointId, { file, line, id: response.breakpointId }); + + return { + content: [{ + type: "text", + text: `Breakpoint set successfully. ID: ${response.breakpointId}` + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error setting breakpoint: ${err.message}` + }] + }; + } + } +); + +// Inspect variables tool +server.tool( + "inspect_variables", + "Inspects variables in current scope", + { + scope: z.string().optional().describe("Scope to inspect (local/global)") + }, + async ({ scope = 'local' }) => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + if (scope === 'global' || !inspector.paused) { + // For global scope or when not paused, use Runtime.globalProperties + const response = await inspector.send('Runtime.globalLexicalScopeNames', {}); + + // Get global object properties for a more complete picture + const globalObjResponse = await inspector.send('Runtime.evaluate', { + expression: 'this', + contextId: 1, + returnByValue: true + }); + + return { + content: [{ + type: "text", + text: JSON.stringify({ + lexicalNames: response.names, + globalThis: globalObjResponse.result.value + }, null, 2) + }] + }; + } else { + // For local scope when paused, get variables from the current call frame + if (inspector.currentCallFrames.length === 0) { + return { + content: [{ + type: "text", + text: "No active call frames. Debugger is not paused at a breakpoint." + }] + }; + } + + const frame = inspector.currentCallFrames[0]; // Get top frame + const scopeChain = frame.scopeChain; + + // Create a formatted output of variables in scope + const result = {}; + + for (const scopeObj of scopeChain) { + const { scope, type, name } = scopeObj; + + if (type === 'global') continue; // Skip global scope for local inspection + + const objProperties = await inspector.getProperties(scope.object.objectId); + const variables = {}; + + for (const prop of objProperties.result) { + if (prop.value && prop.configurable) { + if (prop.value.type === 'object' && prop.value.subtype !== 'null') { + variables[prop.name] = `[${prop.value.subtype || prop.value.type}]`; + } else if (prop.value.type === 'function') { + variables[prop.name] = '[function]'; + } else if (prop.value.value !== undefined) { + variables[prop.name] = prop.value.value; + } else { + variables[prop.name] = `[${prop.value.type}]`; + } + } + } + + result[type] = variables; + } + + return { + content: [{ + type: "text", + text: JSON.stringify(result, null, 2) + }] + }; + } + } catch (err) { + return { + content: [{ + type: "text", + text: `Error inspecting variables: ${err.message}` + }] + }; + } + } +); + +// Step over tool +server.tool( + "step_over", + "Steps over to the next line of code", + {}, + async () => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + if (!inspector.paused) { + return { + content: [{ + type: "text", + text: "Debugger is not paused at a breakpoint" + }] + }; + } + + await inspector.send('Debugger.stepOver', {}); + + return { + content: [{ + type: "text", + text: "Stepped over to next line" + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error stepping over: ${err.message}` + }] + }; + } + } +); + +// Step into tool +server.tool( + "step_into", + "Steps into function calls", + {}, + async () => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + if (!inspector.paused) { + return { + content: [{ + type: "text", + text: "Debugger is not paused at a breakpoint" + }] + }; + } + + await inspector.send('Debugger.stepInto', {}); + + return { + content: [{ + type: "text", + text: "Stepped into function call" + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error stepping into: ${err.message}` + }] + }; + } + } +); + +// Step out tool +server.tool( + "step_out", + "Steps out of current function", + {}, + async () => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + if (!inspector.paused) { + return { + content: [{ + type: "text", + text: "Debugger is not paused at a breakpoint" + }] + }; + } + + await inspector.send('Debugger.stepOut', {}); + + return { + content: [{ + type: "text", + text: "Stepped out of current function" + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error stepping out: ${err.message}` + }] + }; + } + } +); + +// Continue execution tool +server.tool( + "continue", + "Continues code execution", + {}, + async () => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + if (!inspector.paused) { + return { + content: [{ + type: "text", + text: "Debugger is not paused at a breakpoint" + }] + }; + } + + await inspector.send('Debugger.resume', {}); + + return { + content: [{ + type: "text", + text: "Execution resumed" + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error continuing execution: ${err.message}` + }] + }; + } + } +); + +// Delete breakpoint tool +server.tool( + "delete_breakpoint", + "Deletes a specified breakpoint", + { + breakpointId: z.string().describe("ID of the breakpoint to remove") + }, + async ({ breakpointId }) => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + await inspector.send('Debugger.removeBreakpoint', { + breakpointId: breakpointId + }); + + // Remove from our local tracking + inspector.breakpoints.delete(breakpointId); + + return { + content: [{ + type: "text", + text: `Breakpoint ${breakpointId} removed` + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error removing breakpoint: ${err.message}` + }] + }; + } + } +); + +// List all breakpoints tool +server.tool( + "list_breakpoints", + "Lists all active breakpoints", + {}, + async () => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + if (inspector.breakpoints.size === 0) { + return { + content: [{ + type: "text", + text: "No active breakpoints" + }] + }; + } + + const breakpointsList = Array.from(inspector.breakpoints.values()); + + return { + content: [{ + type: "text", + text: JSON.stringify(breakpointsList, null, 2) + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error listing breakpoints: ${err.message}` + }] + }; + } + } +); + +// Evaluate expression tool +server.tool( + "evaluate", + "Evaluates a JavaScript expression in the current context", + { + expression: z.string().describe("JavaScript expression to evaluate") + }, + async ({ expression }) => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + // Capture the current console output length to know where to start capturing new output + const consoleStartIndex = inspector.consoleOutput.length; + + // Wrap the expression in a try-catch to better handle errors + const wrappedExpression = ` + try { + ${expression} + } catch (e) { + console.error('Evaluation error:', e); + e; // Return the error + } + `; + + let result; + + if (inspector.paused && inspector.currentCallFrames.length > 0) { + // When paused at a breakpoint, evaluate in the context of the call frame + const frame = inspector.currentCallFrames[0]; + result = await inspector.evaluateOnCallFrame(frame.callFrameId, wrappedExpression); + } else { + // Otherwise, evaluate in the global context + result = await inspector.send('Runtime.evaluate', { + expression: wrappedExpression, + contextId: 1, + objectGroup: 'console', + includeCommandLineAPI: true, + silent: false, + returnByValue: true, + generatePreview: true, + awaitPromise: true // This will wait for promises to resolve + }); + } + + // Give some time for console logs to be processed + await new Promise(resolve => setTimeout(resolve, 200)); + + // Get any console output that was generated during execution + const consoleOutputs = inspector.consoleOutput.slice(consoleStartIndex); + const consoleText = consoleOutputs.map(output => + `[${output.type}] ${output.message}` + ).join('\n'); + + let valueRepresentation; + + if (result.result) { + if (result.result.type === 'object') { + if (result.result.value) { + // If we have a value, use it + valueRepresentation = JSON.stringify(result.result.value, null, 2); + } else if (result.result.objectId) { + // If we have an objectId but no value, the object was too complex to serialize directly + // Get more details about the object + try { + const objectProps = await inspector.getProperties(result.result.objectId); + const formattedObject = {}; + + for (const prop of objectProps.result) { + if (prop.value) { + if (prop.value.type === 'object' && prop.value.subtype !== 'null') { + // For nested objects, try to get their details too + if (prop.value.objectId) { + try { + const nestedProps = await inspector.getProperties(prop.value.objectId); + const nestedObj = {}; + for (const nestedProp of nestedProps.result) { + if (nestedProp.value) { + if (nestedProp.value.value !== undefined) { + nestedObj[nestedProp.name] = nestedProp.value.value; + } else { + nestedObj[nestedProp.name] = nestedProp.value.description || + `[${nestedProp.value.subtype || nestedProp.value.type}]`; + } + } + } + formattedObject[prop.name] = nestedObj; + } catch (nestedErr) { + formattedObject[prop.name] = prop.value.description || + `[${prop.value.subtype || prop.value.type}]`; + } + } else { + formattedObject[prop.name] = prop.value.description || + `[${prop.value.subtype || prop.value.type}]`; + } + } else if (prop.value.type === 'function') { + formattedObject[prop.name] = '[function]'; + } else if (prop.value.value !== undefined) { + formattedObject[prop.name] = prop.value.value; + } else { + formattedObject[prop.name] = `[${prop.value.type}]`; + } + } + } + + valueRepresentation = JSON.stringify(formattedObject, null, 2); + } catch (propErr) { + // If we can't get properties, at least show the object description + valueRepresentation = result.result.description || `[${result.result.subtype || result.result.type}]`; + } + } else { + // Fallback for objects without value or objectId + valueRepresentation = result.result.description || `[${result.result.subtype || result.result.type}]`; + } + } else if (result.result.type === 'undefined') { + valueRepresentation = 'undefined'; + } else if (result.result.value !== undefined) { + valueRepresentation = result.result.value.toString(); + } else { + valueRepresentation = `[${result.result.type}]`; + } + } else { + valueRepresentation = 'No result'; + } + + // Prepare the response content + let responseContent = []; + + // Add console output if there was any + if (consoleText.length > 0) { + responseContent.push({ + type: "text", + text: `Console output:\n${consoleText}` + }); + } + + // Add the evaluation result + responseContent.push({ + type: "text", + text: `Evaluation result: ${valueRepresentation}` + }); + + return { content: responseContent }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error evaluating expression: ${err.message}` + }] + }; + } + } +); + +// Get current location tool +server.tool( + "get_location", + "Gets the current execution location when paused", + {}, + async () => { + try { + // Ensure debugger is enabled + if (!inspector.debuggerEnabled) { + await inspector.enableDebugger(); + } + + if (!inspector.paused || inspector.currentCallFrames.length === 0) { + return { + content: [{ + type: "text", + text: "Debugger is not paused at a breakpoint" + }] + }; + } + + const frame = inspector.currentCallFrames[0]; + const { url, lineNumber, columnNumber } = frame.location; + + // Get call stack + const callstack = inspector.currentCallFrames.map(frame => { + return { + functionName: frame.functionName || '(anonymous)', + url: frame.url, + lineNumber: frame.location.lineNumber + 1, + columnNumber: frame.location.columnNumber + }; + }); + + // Get source code for context + let sourceContext = ''; + try { + const scriptSource = await inspector.getScriptSource(frame.location.scriptId); + if (scriptSource) { + const lines = scriptSource.split('\n'); + const startLine = Math.max(0, lineNumber - 3); + const endLine = Math.min(lines.length - 1, lineNumber + 3); + + for (let i = startLine; i <= endLine; i++) { + const prefix = i === lineNumber ? '> ' : ' '; + sourceContext += `${prefix}${i + 1}: ${lines[i]}\n`; + } + } + } catch (err) { + sourceContext = 'Unable to retrieve source code'; + } + + return { + content: [{ + type: "text", + text: JSON.stringify({ + url, + lineNumber: lineNumber + 1, + columnNumber, + callstack, + sourceContext + }, null, 2) + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error getting location: ${err.message}` + }] + }; + } + } +); + +// 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}` + }] + }; + } + } +); + +// Start receiving messages on stdin and sending messages on stdout +const transport = new StdioServerTransport(); +await server.connect(transport); + +console.log("Inspector server ready..."); \ No newline at end of file From 3c604bdfc696e69c084628cfe5e863c8f66a487a Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:13:51 +0000 Subject: [PATCH 2/4] chore: add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07e6e47 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules From 4a5d81d0f7fec30255f42141be98209d45a3280f Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:15:16 +0000 Subject: [PATCH 3/4] fix(package.json): fix bin entry point, postinstall hook to install dependencies --- package-lock.json | 1084 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 12 +- 2 files changed, 1090 insertions(+), 6 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6dddd90 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1084 @@ +{ + "name": "mcp-nodejs-debugger", + "version": "0.1.0-beta.5", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "mcp-nodejs-debugger", + "version": "0.1.0-beta.5", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "@modelcontextprotocol/sdk": "^1.7.0", + "node-fetch": "^3.3.2", + "ws": "^8.18.1", + "zod": "^3.24.2" + }, + "bin": { + "mcp-nodejs-debugger": "index.js" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@modelcontextprotocol/sdk": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.7.0.tgz", + "integrity": "sha512-IYPe/FLpvF3IZrd/f5p5ffmWhMc3aEMuM2wGJASDqC2Ge7qatVCdbfPx3n/5xFeb19xN0j/911M2AaFuircsWA==", + "dependencies": { + "content-type": "^1.0.5", + "cors": "^2.8.5", + "eventsource": "^3.0.2", + "express": "^5.0.1", + "express-rate-limit": "^7.5.0", + "pkce-challenge": "^4.1.0", + "raw-body": "^3.0.0", + "zod": "^3.23.8", + "zod-to-json-schema": "^3.24.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/body-parser": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.1.0.tgz", + "integrity": "sha512-/hPxh61E+ll0Ujp24Ilm64cykicul1ypfwjVttduAiEdtnJFvLePSrIPk+HMImtNv5270wOGCb1Tns2rybMkoQ==", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.0", + "http-errors": "^2.0.0", + "iconv-lite": "^0.5.2", + "on-finished": "^2.4.1", + "qs": "^6.14.0", + "raw-body": "^3.0.0", + "type-is": "^2.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/body-parser/node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/body-parser/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/body-parser/node_modules/qs": { + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.0.tgz", + "integrity": "sha512-Au9nRL8VNUut/XSzbQA38+M78dzP4D+eqg3gfJHMIHHYa3bg067xj1KxMUWj+VULbiZMowKngFFbKczUrNJ1mg==", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", + "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "engines": { + "node": ">= 12" + } + }, + "node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/eventsource": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.5.tgz", + "integrity": "sha512-LT/5J605bx5SNyE+ITBDiM3FxffBiq9un7Vx0EwMDM3vg8sWKx/tO2zC+LMqZ+smAM0F2hblaDZUVZF0te2pSw==", + "dependencies": { + "eventsource-parser": "^3.0.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.0.tgz", + "integrity": "sha512-T1C0XCUimhxVQzW4zFipdx0SficT651NnkR0ZSH3yQwh+mFMdLfgjABVi4YtMTtaL4s168593DaoaRLMqryavA==", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/express": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/express/-/express-5.0.1.tgz", + "integrity": "sha512-ORF7g6qGnD+YtUG9yx4DFoqCShNMmUKiXuT5oWMHiOvt/4WFbHC6yCwQMTSBMno7AqntNCAzzcnnjowRkTL9eQ==", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.0.1", + "content-disposition": "^1.0.0", + "content-type": "~1.0.4", + "cookie": "0.7.1", + "cookie-signature": "^1.2.1", + "debug": "4.3.6", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "^2.0.0", + "fresh": "2.0.0", + "http-errors": "2.0.0", + "merge-descriptors": "^2.0.0", + "methods": "~1.1.2", + "mime-types": "^3.0.0", + "on-finished": "2.4.1", + "once": "1.4.0", + "parseurl": "~1.3.3", + "proxy-addr": "~2.0.7", + "qs": "6.13.0", + "range-parser": "~1.2.1", + "router": "^2.0.0", + "safe-buffer": "5.2.1", + "send": "^1.1.0", + "serve-static": "^2.1.0", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "type-is": "^2.0.0", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/express-rate-limit": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-7.5.0.tgz", + "integrity": "sha512-eB5zbQh5h+VenMPM3fh+nw1YExi5nMr6HUCR62ELSP11huvxm/Uir1H1QEyTkk5QX6A58pX6NmaTMceKZ0Eodg==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": "^4.11 || 5 || ^5.0.0-beta.1" + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/finalhandler": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz", + "integrity": "sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q==", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/finalhandler/node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/finalhandler/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/iconv-lite": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.2.tgz", + "integrity": "sha512-kERHXvpSaB4aU3eANwidg79K8FlrN77m8G9V+0vOR3HYaRifrlwMEpT7ZBJqLSEIHnEgJTHcWK82wwLwwKwtag==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.0.tgz", + "integrity": "sha512-XqoSHeCGjVClAmoGFG3lVFqQFRIrTVw2OH3axRqAcfaw+gHWIfnASS92AV+Rl/mk0MupgZTRHQOjxY6YVnzK5w==", + "dependencies": { + "mime-db": "^1.53.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", + "integrity": "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==", + "engines": { + "node": ">=16" + } + }, + "node_modules/pkce-challenge": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-4.1.0.tgz", + "integrity": "sha512-ZBmhE1C9LcPoH9XZSdwiPtbPHZROwAnMy+kIFQVrnMCxY4Cudlz3gBOpzilgc0jOgRaiT3sIWfpMomW2ar2orQ==", + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "dependencies": { + "side-channel": "^1.0.6" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.0.tgz", + "integrity": "sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.6.3", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/raw-body/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/router": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.1.0.tgz", + "integrity": "sha512-/m/NSLxeYEgWNtyC+WtNHCF7jbGxOibVWKnn+1Psff4dJGOfoXP+MuC/f2CwSmyiHdOIzYnYFp4W6GxWfekaLA==", + "dependencies": { + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "node_modules/send": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/send/-/send-1.1.0.tgz", + "integrity": "sha512-v67WcEouB5GxbTWL/4NeToqcZiAWEq90N888fczVArY8A79J0L4FD7vj5hm3eUMua5EpoQ59wa/oovY6TLvRUA==", + "dependencies": { + "debug": "^4.3.5", + "destroy": "^1.2.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^0.5.2", + "http-errors": "^2.0.0", + "mime-types": "^2.1.35", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/send/node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/send/node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/send/node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/serve-static": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.1.0.tgz", + "integrity": "sha512-A3We5UfEjG8Z7VkDv6uItWw6HY2bBSBJT1KtVESn6EOoOr2jAxNhxWCLY3jDE2WcuHXByWju74ck3ZgLwL8xmA==", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.0.tgz", + "integrity": "sha512-gd0sGezQYCbWSbkZr75mln4YBidWUN60+devscpLF5mtRDUpiaTvKpBNrdaCvel1NdR2k6vclXybU5fBd2i+nw==", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "node_modules/ws": { + "version": "8.18.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.1.tgz", + "integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/zod": { + "version": "3.24.2", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz", + "integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-to-json-schema": { + "version": "3.24.4", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.24.4.tgz", + "integrity": "sha512-0uNlcvgabyrni9Ag8Vghj21drk7+7tp7VTwwR7KxxXXc/3pbXz2PHlDgj3cICahgF1kHm4dExBFj7BXrZJXzig==", + "peerDependencies": { + "zod": "^3.24.1" + } + } + } +} diff --git a/package.json b/package.json index 144d01e..fb8084f 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "mcp-nodejs-debugger", - "version": "0.1.0-beta.1", + "version": "0.1.0-beta.5", "description": "An MCP server to debug Node.js at runtime", "main": "index.js", - "bin": { - "mcp-debugger": "./index.js" - }, + "bin": "./index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node index.js", + "postinstall": "npm install @modelcontextprotocol/sdk node-fetch ws zod" }, "author": "Hyperdrive", "license": "MIT", @@ -23,7 +23,7 @@ "dependencies": { "@modelcontextprotocol/sdk": "^1.7.0", "node-fetch": "^3.3.2", - "ws": "^8.16.0", + "ws": "^8.18.1", "zod": "^3.24.2" }, "files": [ From 3b32d0b92ca5fa2a961b86bcbcf06e173dc72b8a Mon Sep 17 00:00:00 2001 From: arthurgousset <46296830+arthurgousset@users.noreply.github.com> Date: Wed, 19 Mar 2025 14:17:11 +0000 Subject: [PATCH 4/4] feat(mcp-server.js): add (silent) infinite retry connection retry --- index.js | 0 src/mcp-server.js | 80 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 73 insertions(+), 7 deletions(-) mode change 100644 => 100755 index.js diff --git a/index.js b/index.js old mode 100644 new mode 100755 diff --git a/src/mcp-server.js b/src/mcp-server.js index 491d9d5..d9ac949 100644 --- a/src/mcp-server.js +++ b/src/mcp-server.js @@ -30,7 +30,7 @@ const server = new McpServer({ }); class Inspector { - constructor(port = 9229, retryOptions = { maxRetries: 5, retryInterval: 1000 }) { + constructor(port = 9229, retryOptions = { maxRetries: 5, retryInterval: 1000, continuousRetry: true }) { this.port = port; this.connected = false; this.pendingRequests = new Map(); @@ -41,6 +41,7 @@ class Inspector { this.retryOptions = retryOptions; this.retryCount = 0; this.callbackHandlers = new Map(); + this.continuousRetryEnabled = retryOptions.continuousRetry; this.initialize(); } @@ -107,10 +108,26 @@ class Inspector { } scheduleRetry() { - if (this.retryCount < this.retryOptions.maxRetries) { + // If continuous retry is enabled, we'll keep trying after the initial attempts + if (this.retryCount < this.retryOptions.maxRetries || this.continuousRetryEnabled) { this.retryCount++; - console.log(`Retrying connection (${this.retryCount}/${this.retryOptions.maxRetries})...`); - setTimeout(() => this.initialize(), this.retryOptions.retryInterval); + + // If we're in continuous retry mode and have exceeded the initial retry count + if (this.continuousRetryEnabled && this.retryCount > this.retryOptions.maxRetries) { + // Only log every 10 attempts to avoid flooding the console + if (this.retryCount % 10 === 0) { + console.log(`Waiting for debugger connection... (retry ${this.retryCount})`); + } + } else { + console.log(`Retrying connection (${this.retryCount}/${this.retryOptions.maxRetries})...`); + } + + // Use a longer interval for continuous retries to reduce resource usage + const interval = this.continuousRetryEnabled && this.retryCount > this.retryOptions.maxRetries + ? Math.min(this.retryOptions.retryInterval * 5, 10000) // Max 10 seconds between retries + : this.retryOptions.retryInterval; + + setTimeout(() => this.initialize(), interval); } else { console.error(`Failed to connect after ${this.retryOptions.maxRetries} attempts`); } @@ -323,8 +340,12 @@ class Inspector { } } -// Create the inspector instance -const inspector = new Inspector(9229); +// Create the inspector instance with continuous retry enabled +const inspector = new Inspector(9229, { + maxRetries: 5, + retryInterval: 1000, + continuousRetry: true +}); // Initialize console output storage inspector.consoleOutput = []; @@ -1126,8 +1147,53 @@ server.tool( } ); +// Add a tool for manually retrying connection to the Node.js debugger +server.tool( + "retry_connect", + "Manually triggers a reconnection attempt to the Node.js debugger", + { + port: z.number().optional().describe("Optional port to connect to. Defaults to current port (9229)") + }, + async ({ port }) => { + try { + // If a new port is specified, update the inspector's port + if (port && port !== inspector.port) { + inspector.port = port; + console.log(`Updated debugger port to ${port}`); + } + + // If already connected, disconnect first + if (inspector.connected && inspector.ws) { + inspector.ws.close(); + inspector.connected = false; + } + + // Reset retry count and initialize + inspector.retryCount = 0; + inspector.initialize(); + + return { + content: [{ + type: "text", + text: `Attempting to connect to Node.js debugger on port ${inspector.port}...` + }] + }; + } catch (err) { + return { + content: [{ + type: "text", + text: `Error initiating connection retry: ${err.message}` + }] + }; + } + } +); + // Start receiving messages on stdin and sending messages on stdout const transport = new StdioServerTransport(); await server.connect(transport); -console.log("Inspector server ready..."); \ No newline at end of file +console.log("Inspector server ready..."); +console.log("MCP Debugger started. Connected to Node.js Inspector protocol."); +console.log("The server will continuously try to connect to any Node.js debugging session on port 9229."); +console.log("You can start a Node.js app with debugging enabled using: node --inspect yourapp.js"); \ No newline at end of file