gitnexus 1.1.3 → 1.1.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/dist/cli/mcp.js +0 -28
- package/dist/mcp/core/embedder.js +13 -4
- package/dist/mcp/core/kuzu-adapter.js +13 -2
- package/package.json +1 -1
package/dist/cli/mcp.js
CHANGED
|
@@ -8,35 +8,7 @@
|
|
|
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
|
-
}
|
|
37
11
|
export const mcpCommand = async () => {
|
|
38
|
-
// Must be first — before any library can pollute stdout
|
|
39
|
-
installStdoutGuard();
|
|
40
12
|
// Load all registered repos
|
|
41
13
|
const entries = await listRegisteredRepos({ validate: true });
|
|
42
14
|
if (entries.length === 0) {
|
|
@@ -31,10 +31,19 @@ export const initEmbedder = async () => {
|
|
|
31
31
|
const devicesToTry = ['webgpu', 'cpu'];
|
|
32
32
|
for (const device of devicesToTry) {
|
|
33
33
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// Silence stdout during model load — ONNX Runtime and transformers.js
|
|
35
|
+
// may write progress/init messages to stdout which corrupts MCP stdio protocol.
|
|
36
|
+
const origWrite = process.stdout.write;
|
|
37
|
+
process.stdout.write = (() => true);
|
|
38
|
+
try {
|
|
39
|
+
embedderInstance = await pipeline('feature-extraction', MODEL_ID, {
|
|
40
|
+
device: device,
|
|
41
|
+
dtype: 'fp32',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
process.stdout.write = origWrite;
|
|
46
|
+
}
|
|
38
47
|
console.error(`GitNexus: Embedding model loaded (${device})`);
|
|
39
48
|
return embedderInstance;
|
|
40
49
|
}
|
|
@@ -82,8 +82,19 @@ export const initKuzu = async (repoId, dbPath) => {
|
|
|
82
82
|
throw new Error(`KuzuDB not found at ${dbPath}. Run: gitnexus analyze`);
|
|
83
83
|
}
|
|
84
84
|
evictLRU();
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
// Silence stdout during KuzuDB init — native module may write to stdout
|
|
86
|
+
// which corrupts the MCP stdio protocol.
|
|
87
|
+
const origWrite = process.stdout.write;
|
|
88
|
+
process.stdout.write = (() => true);
|
|
89
|
+
let db;
|
|
90
|
+
let conn;
|
|
91
|
+
try {
|
|
92
|
+
db = new kuzu.Database(dbPath);
|
|
93
|
+
conn = new kuzu.Connection(db);
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
process.stdout.write = origWrite;
|
|
97
|
+
}
|
|
87
98
|
pool.set(repoId, { db, conn, lastUsed: Date.now(), dbPath });
|
|
88
99
|
ensureIdleTimer();
|
|
89
100
|
};
|
package/package.json
CHANGED