Skip to content

Commit ab6c367

Browse files
fix(mcp-server.sj): delete console.log and console.error statements (#11)
* fix(mcp-server.js): delete `console.log` and `console.error` * fix(index.js): delete `console.log` and `console.error` * chore(package.json): bump minor version * chore(mcp-server.js): add missing bracket * chore(mcp-server.js): add try-catch * chore(mcp-server.js): delete empty space * chore(package.json): bump patch version
1 parent 9af16c5 commit ab6c367

File tree

4 files changed

+16
-51
lines changed

4 files changed

+16
-51
lines changed

index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,4 @@
44
// When installed globally or run with npx, this file will be executed
55

66
// Import and run the MCP server
7-
import './src/mcp-server.js';
8-
9-
// The server is started in the imported file
10-
console.log('MCP Debugger started. Connected to Node.js Inspector protocol.');
7+
import './src/mcp-server.js';

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperdrive-eng/mcp-nodejs-debugger",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "An MCP server to debug Node.js at runtime",
55
"main": "index.js",
66
"bin": "./index.js",

src/mcp-server.js

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { z } from "zod";
44
import WebSocket from 'ws';
55
import fetch from 'node-fetch';
66

7+
// Disable console output for MCP compatibility
8+
console.log = function() {};
9+
console.error = function() {};
10+
711
// Create an MCP server
812
const server = new McpServer({
913
name: "NodeJS Debugger",
10-
version: "0.2.0",
14+
version: "0.2.2",
1115
description: `Advanced Node.js debugger for runtime analysis and troubleshooting. This tool connects to Node.js's built-in Inspector Protocol to provide powerful debugging capabilities directly through Claude Code.
1216
1317
DEBUGGING STRATEGY:
@@ -54,28 +58,23 @@ class Inspector {
5458
const debuggerUrl = data[0]?.webSocketDebuggerUrl;
5559

5660
if (!debuggerUrl) {
57-
console.error('No WebSocket debugger URL found');
5861
this.scheduleRetry();
5962
return;
6063
}
6164

62-
console.log(`Connecting to debugger at: ${debuggerUrl}`);
6365
this.ws = new WebSocket(debuggerUrl);
6466

6567
this.ws.on('open', () => {
66-
console.log('WebSocket connection established');
6768
this.connected = true;
6869
this.retryCount = 0;
6970
this.enableDebugger();
7071
});
7172

7273
this.ws.on('error', (error) => {
73-
console.error('WebSocket error:', error.message);
7474
this.scheduleRetry();
7575
});
7676

7777
this.ws.on('close', () => {
78-
console.log('WebSocket connection closed');
7978
this.connected = false;
8079
this.scheduleRetry();
8180
});
@@ -102,7 +101,6 @@ class Inspector {
102101
}
103102
});
104103
} catch (error) {
105-
console.error('Error initializing inspector:', error.message);
106104
this.scheduleRetry();
107105
}
108106
}
@@ -112,53 +110,39 @@ class Inspector {
112110
if (this.retryCount < this.retryOptions.maxRetries || this.continuousRetryEnabled) {
113111
this.retryCount++;
114112

115-
// If we're in continuous retry mode and have exceeded the initial retry count
116-
if (this.continuousRetryEnabled && this.retryCount > this.retryOptions.maxRetries) {
117-
// Only log every 10 attempts to avoid flooding the console
118-
if (this.retryCount % 10 === 0) {
119-
console.log(`Waiting for debugger connection... (retry ${this.retryCount})`);
120-
}
121-
} else {
122-
console.log(`Retrying connection (${this.retryCount}/${this.retryOptions.maxRetries})...`);
123-
}
124-
125113
// Use a longer interval for continuous retries to reduce resource usage
126114
const interval = this.continuousRetryEnabled && this.retryCount > this.retryOptions.maxRetries
127115
? Math.min(this.retryOptions.retryInterval * 5, 10000) // Max 10 seconds between retries
128116
: this.retryOptions.retryInterval;
129117

130118
setTimeout(() => this.initialize(), interval);
131-
} else {
132-
console.error(`Failed to connect after ${this.retryOptions.maxRetries} attempts`);
133119
}
134120
}
135121

136122
async enableDebugger() {
137-
if (!this.debuggerEnabled && this.connected) {
138-
try {
123+
try {
124+
if (!this.debuggerEnabled && this.connected) {
125+
139126
await this.send('Debugger.enable', {});
140-
console.log('Debugger enabled');
141127
this.debuggerEnabled = true;
142128

143129
// Setup event listeners
144130
await this.send('Runtime.enable', {});
145131

146132
// Also activate possible domains we'll need
147133
await this.send('Runtime.runIfWaitingForDebugger', {});
148-
} catch (err) {
149-
console.error('Failed to enable debugger:', err);
150134
}
151-
}
135+
} catch (error) {
136+
this.scheduleRetry();
137+
}
152138
}
153139

154140
handleEvent(event) {
155-
// console.log('Event received:', event.method, event.params);
156141

157142
switch (event.method) {
158143
case 'Debugger.paused':
159144
this.paused = true;
160145
this.currentCallFrames = event.params.callFrames;
161-
console.log('Execution paused at breakpoint');
162146

163147
// Notify any registered callbacks for pause events
164148
if (this.callbackHandlers.has('paused')) {
@@ -170,7 +154,6 @@ class Inspector {
170154
case 'Debugger.resumed':
171155
this.paused = false;
172156
this.currentCallFrames = [];
173-
console.log('Execution resumed');
174157

175158
// Notify any registered callbacks for resume events
176159
if (this.callbackHandlers.has('resumed')) {
@@ -184,9 +167,6 @@ class Inspector {
184167
break;
185168

186169
case 'Runtime.exceptionThrown':
187-
console.log('Exception thrown:',
188-
event.params.exceptionDetails.text,
189-
event.params.exceptionDetails.exception?.description || '');
190170
break;
191171

192172
case 'Runtime.consoleAPICalled':
@@ -224,7 +204,6 @@ class Inspector {
224204
this.consoleOutput.shift();
225205
}
226206

227-
console.log(`[Console.${event.params.type}]`, args);
228207
break;
229208
}
230209
}
@@ -299,7 +278,6 @@ class Inspector {
299278
});
300279
return response.scriptSource;
301280
} catch (err) {
302-
console.error('Error getting script source:', err);
303281
return null;
304282
}
305283
}
@@ -320,7 +298,6 @@ class Inspector {
320298
generatePreview: true
321299
});
322300
} catch (err) {
323-
console.error('Error evaluating expression:', err);
324301
throw err;
325302
}
326303
}
@@ -334,7 +311,6 @@ class Inspector {
334311
generatePreview: true
335312
});
336313
} catch (err) {
337-
console.error('Error getting properties:', err);
338314
throw err;
339315
}
340316
}
@@ -372,7 +348,6 @@ server.tool(
372348
try {
373349
${js_code}
374350
} catch (e) {
375-
console.error('Execution error:', e);
376351
e; // Return the error
377352
}
378353
`;
@@ -896,7 +871,6 @@ server.tool(
896871
try {
897872
${expression}
898873
} catch (e) {
899-
console.error('Evaluation error:', e);
900874
e; // Return the error
901875
}
902876
`;
@@ -1159,7 +1133,6 @@ server.tool(
11591133
// If a new port is specified, update the inspector's port
11601134
if (port && port !== inspector.port) {
11611135
inspector.port = port;
1162-
console.log(`Updated debugger port to ${port}`);
11631136
}
11641137

11651138
// If already connected, disconnect first
@@ -1191,9 +1164,4 @@ server.tool(
11911164

11921165
// Start receiving messages on stdin and sending messages on stdout
11931166
const transport = new StdioServerTransport();
1194-
await server.connect(transport);
1195-
1196-
console.log("Inspector server ready...");
1197-
console.log("MCP Debugger started. Connected to Node.js Inspector protocol.");
1198-
console.log("The server will continuously try to connect to any Node.js debugging session on port 9229.");
1199-
console.log("You can start a Node.js app with debugging enabled using: node --inspect yourapp.js");
1167+
await server.connect(transport);

0 commit comments

Comments
 (0)