mcp-optimizer 0.0.4-alpha.1 → 0.0.5-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcpServer.js +10 -1
- package/package.json +1 -1
- package/src/mcpServer.ts +10 -1
package/dist/mcpServer.js
CHANGED
|
@@ -246,10 +246,15 @@ async function startMcpServer() {
|
|
|
246
246
|
// launched as a stdio child by an MCP host and use the stdio transport.
|
|
247
247
|
const shouldUseStdio = (process.stdin && !process.stdin.isTTY) && (process.stdout && !process.stdout.isTTY);
|
|
248
248
|
if (shouldUseStdio) {
|
|
249
|
+
// Redirect console output to stderr to avoid corrupting the JSON stdio protocol
|
|
250
|
+
const _orig = { log: console.log, info: console.info, warn: console.warn };
|
|
251
|
+
console.log = (...args) => { process.stderr.write(args.map(String).join(' ') + '\n'); };
|
|
252
|
+
console.info = console.log;
|
|
253
|
+
console.warn = console.log;
|
|
249
254
|
try {
|
|
250
255
|
stdioTransport = new stdio_js_1.StdioServerTransport(process.stdin, process.stdout);
|
|
251
256
|
await mcp.connect(stdioTransport);
|
|
252
|
-
console.
|
|
257
|
+
console.error('Stdio: connected to parent process over stdio');
|
|
253
258
|
// When running over stdio we do not start the HTTP server; stay alive
|
|
254
259
|
// and let the parent coordinate messages. Return a promise that
|
|
255
260
|
// resolves when the transport closes.
|
|
@@ -261,6 +266,10 @@ async function startMcpServer() {
|
|
|
261
266
|
catch (err) {
|
|
262
267
|
console.error('Stdio: failed to start transport, falling back to HTTP:', err);
|
|
263
268
|
stdioTransport = null;
|
|
269
|
+
// restore console in case we fall back to HTTP server mode
|
|
270
|
+
console.log = _orig.log;
|
|
271
|
+
console.info = _orig.info;
|
|
272
|
+
console.warn = _orig.warn;
|
|
264
273
|
}
|
|
265
274
|
}
|
|
266
275
|
const pendingPosts = [];
|
package/package.json
CHANGED
package/src/mcpServer.ts
CHANGED
|
@@ -231,10 +231,15 @@ export async function startMcpServer(): Promise<void> {
|
|
|
231
231
|
// launched as a stdio child by an MCP host and use the stdio transport.
|
|
232
232
|
const shouldUseStdio = (process.stdin && !process.stdin.isTTY) && (process.stdout && !process.stdout.isTTY);
|
|
233
233
|
if (shouldUseStdio) {
|
|
234
|
+
// Redirect console output to stderr to avoid corrupting the JSON stdio protocol
|
|
235
|
+
const _orig = { log: console.log, info: console.info, warn: console.warn };
|
|
236
|
+
console.log = (...args: any[]) => { process.stderr.write(args.map(String).join(' ') + '\n'); };
|
|
237
|
+
console.info = console.log;
|
|
238
|
+
console.warn = console.log;
|
|
234
239
|
try {
|
|
235
240
|
stdioTransport = new StdioServerTransport(process.stdin, process.stdout);
|
|
236
241
|
await mcp.connect(stdioTransport as unknown as Transport);
|
|
237
|
-
console.
|
|
242
|
+
console.error('Stdio: connected to parent process over stdio');
|
|
238
243
|
// When running over stdio we do not start the HTTP server; stay alive
|
|
239
244
|
// and let the parent coordinate messages. Return a promise that
|
|
240
245
|
// resolves when the transport closes.
|
|
@@ -245,6 +250,10 @@ export async function startMcpServer(): Promise<void> {
|
|
|
245
250
|
} catch (err) {
|
|
246
251
|
console.error('Stdio: failed to start transport, falling back to HTTP:', err);
|
|
247
252
|
stdioTransport = null;
|
|
253
|
+
// restore console in case we fall back to HTTP server mode
|
|
254
|
+
console.log = _orig.log;
|
|
255
|
+
console.info = _orig.info;
|
|
256
|
+
console.warn = _orig.warn;
|
|
248
257
|
}
|
|
249
258
|
}
|
|
250
259
|
const pendingPosts: Array<{ body: string; url: string | undefined; headers: any }> = [];
|