gitnexus 1.1.2 → 1.1.3
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/cli/mcp.js +28 -0
- package/package.json +1 -1
package/dist/cli/mcp.js
CHANGED
|
@@ -8,7 +8,35 @@
|
|
|
8
8
|
import { startMCPServer } from '../mcp/server.js';
|
|
9
9
|
import { LocalBackend } from '../mcp/local/local-backend.js';
|
|
10
10
|
import { listRegisteredRepos } from '../storage/repo-manager.js';
|
|
11
|
+
/**
|
|
12
|
+
* Protect MCP stdio protocol from library stdout pollution.
|
|
13
|
+
*
|
|
14
|
+
* Libraries like @huggingface/transformers, ONNX Runtime, and kuzu may
|
|
15
|
+
* write progress bars, warnings, or init messages to stdout.
|
|
16
|
+
* MCP uses stdout exclusively for JSON-RPC — any foreign output corrupts
|
|
17
|
+
* the protocol and causes Cursor to kill the connection.
|
|
18
|
+
*
|
|
19
|
+
* This intercept redirects all non-JSON-RPC stdout writes to stderr.
|
|
20
|
+
*/
|
|
21
|
+
function installStdoutGuard() {
|
|
22
|
+
const origWrite = process.stdout.write.bind(process.stdout);
|
|
23
|
+
process.stdout.write = ((chunk, encodingOrCb, cb) => {
|
|
24
|
+
const text = typeof chunk === 'string'
|
|
25
|
+
? chunk
|
|
26
|
+
: Buffer.isBuffer(chunk)
|
|
27
|
+
? chunk.toString('utf-8')
|
|
28
|
+
: '';
|
|
29
|
+
// MCP SDK messages always contain "jsonrpc" — let them through
|
|
30
|
+
if (text.includes('"jsonrpc"')) {
|
|
31
|
+
return origWrite(chunk, encodingOrCb, cb);
|
|
32
|
+
}
|
|
33
|
+
// Redirect everything else to stderr (library noise)
|
|
34
|
+
return process.stderr.write(chunk, encodingOrCb, cb);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
11
37
|
export const mcpCommand = async () => {
|
|
38
|
+
// Must be first — before any library can pollute stdout
|
|
39
|
+
installStdoutGuard();
|
|
12
40
|
// Load all registered repos
|
|
13
41
|
const entries = await listRegisteredRepos({ validate: true });
|
|
14
42
|
if (entries.length === 0) {
|
package/package.json
CHANGED