fix(index): flush stderr before exit on Node 26+ guard

Per CodeRabbit review on #59: process.stderr.write() is async when
stderr is piped (every MCP host captures stderr to surface server
logs), so a bare `process.exit(1)` immediately after the write
terminates synchronously without draining I/O — risking truncation
of the compatibility warning that this guard exists to surface.

Move the exit into the write callback so the message is guaranteed
to flush before the process terminates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Shai Tourchin
2026-05-12 11:06:51 +03:00
parent c23120e6c0
commit 5cd9db07e6
+10 -6
View File
@@ -16,13 +16,17 @@
// upper bound in package.json's `engines.node` and remove this check.
const nodeMajor = Number.parseInt(process.versions.node.split(".")[0], 10);
if (Number.isFinite(nodeMajor) && nodeMajor >= 26) {
process.stderr.write(
// Write-then-exit-in-callback: stderr writes are async when piped (every MCP host
// captures stderr), and a bare `process.exit(1)` terminates the process synchronously
// without draining I/O, risking truncation of this message.
const msg =
`socraticode: Node ${process.versions.node} is not supported.\n` +
" @qdrant/js-client-rest is incompatible with the undici bundled in Node 26+.\n" +
" Use Node 22.x (via nvm: `nvm install 22 && nvm use 22`, or `brew install node@22` on macOS).\n" +
" See https://github.com/qdrant/qdrant-js/issues/134.\n",
);
process.exit(1);
" @qdrant/js-client-rest is incompatible with the undici bundled in Node 26+.\n" +
" Use Node 22.x (via nvm: `nvm install 22 && nvm use 22`, or `brew install node@22` on macOS).\n" +
" See https://github.com/qdrant/qdrant-js/issues/134.\n";
process.stderr.write(msg, () => {
process.exit(1);
});
}
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";