@context-engine-bridge/context-engine-mcp-bridge 0.0.3 → 0.0.4
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/package.json +1 -1
- package/src/mcpServer.js +46 -4
package/package.json
CHANGED
package/src/mcpServer.js
CHANGED
|
@@ -94,6 +94,22 @@ function withTimeout(promise, ms, label) {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
function getBridgeToolTimeoutMs() {
|
|
98
|
+
try {
|
|
99
|
+
const raw = process.env.CTXCE_TOOL_TIMEOUT_MSEC;
|
|
100
|
+
if (!raw) {
|
|
101
|
+
return 300000;
|
|
102
|
+
}
|
|
103
|
+
const parsed = Number.parseInt(String(raw), 10);
|
|
104
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
105
|
+
return 300000;
|
|
106
|
+
}
|
|
107
|
+
return parsed;
|
|
108
|
+
} catch {
|
|
109
|
+
return 300000;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
97
113
|
function selectClientForTool(name, indexerClient, memoryClient) {
|
|
98
114
|
if (!name) {
|
|
99
115
|
return indexerClient;
|
|
@@ -300,10 +316,15 @@ async function createBridgeServer(options) {
|
|
|
300
316
|
throw new Error(`Tool ${name} not available on any configured MCP server`);
|
|
301
317
|
}
|
|
302
318
|
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
319
|
+
const timeoutMs = getBridgeToolTimeoutMs();
|
|
320
|
+
const result = await targetClient.callTool(
|
|
321
|
+
{
|
|
322
|
+
name,
|
|
323
|
+
arguments: args,
|
|
324
|
+
},
|
|
325
|
+
undefined,
|
|
326
|
+
{ timeout: timeoutMs },
|
|
327
|
+
);
|
|
307
328
|
return result;
|
|
308
329
|
});
|
|
309
330
|
|
|
@@ -314,6 +335,27 @@ export async function runMcpServer(options) {
|
|
|
314
335
|
const server = await createBridgeServer(options);
|
|
315
336
|
const transport = new StdioServerTransport();
|
|
316
337
|
await server.connect(transport);
|
|
338
|
+
|
|
339
|
+
const exitOnStdinClose = process.env.CTXCE_EXIT_ON_STDIN_CLOSE !== "0";
|
|
340
|
+
if (exitOnStdinClose) {
|
|
341
|
+
const handleStdioClosed = () => {
|
|
342
|
+
try {
|
|
343
|
+
debugLog("[ctxce] Stdio transport closed; exiting MCP bridge process.");
|
|
344
|
+
} catch {
|
|
345
|
+
// ignore
|
|
346
|
+
}
|
|
347
|
+
// Allow any in-flight logs to flush, then exit.
|
|
348
|
+
setTimeout(() => {
|
|
349
|
+
process.exit(0);
|
|
350
|
+
}, 10).unref();
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
if (process.stdin && typeof process.stdin.on === "function") {
|
|
354
|
+
process.stdin.on("end", handleStdioClosed);
|
|
355
|
+
process.stdin.on("close", handleStdioClosed);
|
|
356
|
+
process.stdin.on("error", handleStdioClosed);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
317
359
|
}
|
|
318
360
|
|
|
319
361
|
export async function runHttpMcpServer(options) {
|