graph-indexer 1.2.0 → 2.0.0
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/CHANGELOG.md +412 -0
- package/README.md +216 -596
- package/SECURITY.md +68 -0
- package/TRADEMARK.md +31 -0
- package/cli-ui.mjs +78 -0
- package/config.mjs +179 -28
- package/daemon-ctl.mjs +175 -0
- package/daemon-lock.mjs +69 -0
- package/embedders/python/mlx_embed_server.py +61 -0
- package/embedders/python/requirements-mlx.txt +5 -0
- package/embedders/setup-mlx.mjs +110 -0
- package/embeddings.mjs +489 -0
- package/engine/binary.mjs +399 -0
- package/{core-engine.mjs → engine/memory.mjs} +107 -440
- package/{sqlite-store.mjs → engine/sqlite.mjs} +137 -42
- package/enrichment.mjs +111 -32
- package/git-signals.mjs +248 -0
- package/indexer.mjs +151 -42
- package/init.mjs +1603 -171
- package/layout.mjs +123 -0
- package/mcp/format.mjs +61 -0
- package/mcp/tools.mjs +1157 -0
- package/mcp/topology.mjs +551 -0
- package/mcp-server.mjs +55 -24
- package/package.json +44 -13
- package/parse/extractor.mjs +617 -0
- package/parse/imports.mjs +365 -0
- package/parse/languages.mjs +89 -0
- package/parse/metadata.mjs +655 -0
- package/parse/routes.mjs +327 -0
- package/prompts/CORE.md +86 -0
- package/prompts/DOMAIN_TEMPLATE.md +46 -0
- package/prompts/INTEGRATION.md +123 -0
- package/prompts/frameworks/ANDROID.md +17 -0
- package/prompts/frameworks/ASPNET_CORE.md +19 -0
- package/prompts/frameworks/FASTAPI_DJANGO.md +19 -0
- package/prompts/frameworks/LARAVEL_SYMFONY.md +22 -0
- package/prompts/frameworks/NODE_EXPRESS_NESTJS.md +18 -0
- package/prompts/frameworks/RAILS.md +20 -0
- package/prompts/frameworks/REACT.md +20 -0
- package/prompts/frameworks/SPRING_BOOT.md +19 -0
- package/prompts/languages/BASH.md +22 -0
- package/prompts/languages/C.md +21 -0
- package/prompts/languages/CSHARP.md +24 -0
- package/prompts/languages/CSS_SCSS.md +22 -0
- package/prompts/languages/GO.md +23 -0
- package/prompts/languages/JAVA.md +23 -0
- package/prompts/languages/JAVASCRIPT_TYPESCRIPT.md +24 -0
- package/prompts/languages/KOTLIN.md +24 -0
- package/prompts/languages/PHP.md +23 -0
- package/prompts/languages/PYTHON.md +23 -0
- package/prompts/languages/RUBY.md +23 -0
- package/prompts/languages/RUST.md +21 -0
- package/prompts/languages/SWIFT.md +21 -0
- package/search-core.mjs +254 -43
- package/storage.mjs +28 -3
- package/watch-daemon.mjs +69 -23
- package/PROMPT.md +0 -182
- package/mcp-tools.mjs +0 -545
- package/parser-utils.mjs +0 -1170
package/mcp-server.mjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* @file mcp-server.mjs
|
|
4
4
|
* @description MCP server bootstrap. Resolves configuration, selects the storage
|
|
5
5
|
* backend (in-memory by default, SQLite when configured), registers
|
|
6
|
-
* the tool surface (mcp
|
|
6
|
+
* the tool surface (mcp/tools.mjs) and connects over stdio. All
|
|
7
7
|
* retrieval logic lives in the store + search-core; all tool logic in
|
|
8
|
-
* mcp
|
|
8
|
+
* mcp/tools.mjs — this file is wiring only.
|
|
9
9
|
* @author MaquinaTech <https://github.com/MaquinaTech>
|
|
10
10
|
* @copyright (c) 2026 MaquinaTech. All rights reserved.
|
|
11
11
|
* @license MIT
|
|
@@ -13,18 +13,25 @@
|
|
|
13
13
|
import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
14
14
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
15
15
|
import fs from 'fs';
|
|
16
|
-
import path
|
|
16
|
+
import path from 'path';
|
|
17
17
|
import { fileURLToPath } from 'url';
|
|
18
18
|
import { spawn } from 'child_process';
|
|
19
|
-
import { resolveConfig } from './config.mjs';
|
|
19
|
+
import { resolveConfig, describeConfig, configNotices } from './config.mjs';
|
|
20
|
+
import { ensureDataDir, migrateLegacyLayout } from './layout.mjs';
|
|
21
|
+
import { daemonStatus } from './daemon-lock.mjs';
|
|
20
22
|
import { createStore } from './storage.mjs';
|
|
21
|
-
import { registerTools } from './mcp
|
|
23
|
+
import { registerTools } from './mcp/tools.mjs';
|
|
24
|
+
import { createEmbedder, readEmbedMeta } from './embeddings.mjs';
|
|
25
|
+
import { loadGitSignals } from './git-signals.mjs';
|
|
22
26
|
|
|
23
27
|
const config = resolveConfig();
|
|
24
28
|
const PROJECT_ROOT = config.projectRoot;
|
|
25
|
-
const PID_FILE =
|
|
29
|
+
const PID_FILE = config.pidFile;
|
|
26
30
|
const PACKAGE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
27
31
|
|
|
32
|
+
ensureDataDir(PROJECT_ROOT);
|
|
33
|
+
migrateLegacyLayout(PROJECT_ROOT);
|
|
34
|
+
|
|
28
35
|
function readPackageVersion() {
|
|
29
36
|
try {
|
|
30
37
|
return JSON.parse(fs.readFileSync(path.join(PACKAGE_DIR, 'package.json'), 'utf-8')).version || '0.0.0';
|
|
@@ -38,16 +45,17 @@ function readPackageVersion() {
|
|
|
38
45
|
// PRAGMA data_version). Either way, a long-running MCP server stays consistent
|
|
39
46
|
// with the working tree without restarts or full re-indexes.
|
|
40
47
|
function ensureDaemonRunning() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
48
|
+
// The daemon owns the PID lock exclusively (it acquires it atomically on
|
|
49
|
+
// startup — see daemon-lock.mjs). We only check whether one is already live;
|
|
50
|
+
// if not, we spawn it detached. Even if two servers race here, the losing
|
|
51
|
+
// daemon fails to acquire the lock and exits, so never more than one runs.
|
|
52
|
+
const { running, pid } = daemonStatus(PID_FILE);
|
|
53
|
+
if (running) { process.stderr.write(`✅ Daemon already active (PID: ${pid}).\n`); return; }
|
|
54
|
+
|
|
46
55
|
const daemonPath = path.join(PACKAGE_DIR, 'watch-daemon.mjs');
|
|
47
|
-
|
|
48
|
-
process.stderr.write(`🚀 Starting Watcher Daemon...\n Log: ${logPath}\n`);
|
|
56
|
+
process.stderr.write(`🚀 Starting Watcher Daemon...\n Log: ${config.logFile}\n`);
|
|
49
57
|
let logFd;
|
|
50
|
-
try { logFd = fs.openSync(
|
|
58
|
+
try { logFd = fs.openSync(config.logFile, 'a'); } catch { logFd = null; }
|
|
51
59
|
const child = spawn(process.execPath, [daemonPath], {
|
|
52
60
|
detached: true,
|
|
53
61
|
stdio: logFd !== null ? ['ignore', logFd, logFd] : 'ignore',
|
|
@@ -55,27 +63,29 @@ function ensureDaemonRunning() {
|
|
|
55
63
|
});
|
|
56
64
|
child.unref();
|
|
57
65
|
if (logFd !== null) fs.closeSync(logFd);
|
|
58
|
-
fs.writeFileSync(PID_FILE, child.pid.toString());
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
// ─── Boot ──────────────────────────────────────────────────────────────────────
|
|
62
69
|
|
|
63
|
-
if (config.storage === 'sqlite') {
|
|
64
|
-
process.stderr.write('🗄 Storage backend: SQLite (disk-backed, live daemon updates).\n');
|
|
65
|
-
}
|
|
66
70
|
ensureDaemonRunning();
|
|
67
71
|
|
|
68
72
|
const version = readPackageVersion();
|
|
69
73
|
const server = new McpServer({ name: 'graph-indexer', version });
|
|
70
74
|
|
|
71
75
|
const db = await createStore(config, { cacheEmbeddings: false });
|
|
76
|
+
const backend = db.backend;
|
|
77
|
+
|
|
78
|
+
process.stderr.write('⚙️ Effective configuration:\n');
|
|
79
|
+
for (const line of describeConfig(config, { backend })) process.stderr.write(` ${line}\n`);
|
|
80
|
+
for (const notice of configNotices(config)) process.stderr.write(`⚠️ ${notice}\n`);
|
|
81
|
+
|
|
72
82
|
try { db.load(); } catch (err) { process.stderr.write(`⏳ Waiting for initial indexing… (${err.message})\n`); }
|
|
73
83
|
|
|
74
84
|
// In-memory backend: the daemon is a separate process that rewrites
|
|
75
85
|
// code-index.json — without reloading, this server would answer from a stale
|
|
76
86
|
// snapshot until restart. (The SQLite store refreshes itself per query via
|
|
77
87
|
// PRAGMA data_version, so no watcher is needed there.)
|
|
78
|
-
if (
|
|
88
|
+
if (backend !== 'sqlite' && typeof db.reload === 'function') {
|
|
79
89
|
let reloadTimer = null;
|
|
80
90
|
const scheduleReload = () => {
|
|
81
91
|
if (reloadTimer) clearTimeout(reloadTimer);
|
|
@@ -126,17 +136,38 @@ server.resource(
|
|
|
126
136
|
}
|
|
127
137
|
);
|
|
128
138
|
|
|
139
|
+
// ─── Query embedder ────────────────────────────────────────────────────────────
|
|
140
|
+
// Query with the SAME provider/model the index was built with (stamped in the
|
|
141
|
+
// embeddings-bin sidecar). No stamp → an index from an older version: keep the
|
|
142
|
+
// legacy behaviour (try Ollama, fall back to lexical). The local pipeline loads
|
|
143
|
+
// lazily on first query, so an unused provider costs nothing at startup.
|
|
144
|
+
const embedMeta = readEmbedMeta(config.embeddingPath);
|
|
145
|
+
const embedder = await createEmbedder(
|
|
146
|
+
config,
|
|
147
|
+
embedMeta?.provider
|
|
148
|
+
? { provider: embedMeta.provider, model: embedMeta.model }
|
|
149
|
+
: { provider: config.embeddingsEnabled ? 'ollama' : 'off', model: config.embedModel }
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// ─── Git signals (air-gapped sidecar; blast-radius hint + opt-in rank boost) ────
|
|
153
|
+
const gitSignals = config.gitSignals ? loadGitSignals(config.gitSignalsPath) : null;
|
|
154
|
+
|
|
129
155
|
// ─── Tools ───────────────────────────────────────────────────────────────────
|
|
130
156
|
registerTools(server, db, {
|
|
131
157
|
projectRoot: PROJECT_ROOT,
|
|
132
|
-
artifactPath:
|
|
158
|
+
artifactPath: backend === 'sqlite' ? config.sqlitePath : config.indexPath,
|
|
133
159
|
pidFile: PID_FILE,
|
|
134
|
-
embeddingsEnabled: config.embeddingsEnabled,
|
|
135
|
-
|
|
136
|
-
embedModel: config.embedModel,
|
|
160
|
+
embeddingsEnabled: config.embeddingsEnabled && embedder.provider !== 'off',
|
|
161
|
+
embedder,
|
|
137
162
|
rerank: config.rerank,
|
|
163
|
+
hyde: config.hyde,
|
|
164
|
+
ollamaHost: config.ollamaHost,
|
|
165
|
+
llmProvider: config.llmProvider,
|
|
166
|
+
mlxLmHost: config.mlxLmHost,
|
|
167
|
+
gitSignals,
|
|
168
|
+
gitRankBoost: config.gitRankBoost,
|
|
138
169
|
});
|
|
139
170
|
|
|
140
171
|
const transport = new StdioServerTransport();
|
|
141
172
|
await server.connect(transport);
|
|
142
|
-
process.stderr.write(`✅ graph-indexer MCP server running (v${version}, ${
|
|
173
|
+
process.stderr.write(`✅ graph-indexer MCP server running (v${version}, ${backend} backend).\n`);
|
package/package.json
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graph-indexer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Air-gapped code-retrieval MCP server: AST chunking, hybrid RRF search and cross-language call graph, with an optional zero-dependency SQLite backend for monorepo scale and optional local-LLM semantic enrichment.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "
|
|
6
|
+
"main": "engine/memory.mjs",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./
|
|
8
|
+
".": "./engine/memory.mjs"
|
|
9
9
|
},
|
|
10
10
|
"bin": {
|
|
11
11
|
"graph-indexer": "init.mjs",
|
|
12
12
|
"idx-index": "indexer.mjs",
|
|
13
13
|
"idx-watch": "watch-daemon.mjs",
|
|
14
|
+
"idx-daemon": "daemon-ctl.mjs",
|
|
14
15
|
"idx-mcp": "mcp-server.mjs"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"*.mjs",
|
|
18
|
-
"
|
|
19
|
+
"engine/",
|
|
20
|
+
"mcp/",
|
|
21
|
+
"parse/",
|
|
22
|
+
"embedders/setup-mlx.mjs",
|
|
23
|
+
"embedders/python/mlx_embed_server.py",
|
|
24
|
+
"embedders/python/requirements-mlx.txt",
|
|
25
|
+
"!embedders/python/test_servers.mjs",
|
|
26
|
+
"prompts/",
|
|
19
27
|
"README.md",
|
|
28
|
+
"CHANGELOG.md",
|
|
29
|
+
"SECURITY.md",
|
|
30
|
+
"TRADEMARK.md",
|
|
20
31
|
"LICENSE"
|
|
21
32
|
],
|
|
22
33
|
"repository": {
|
|
@@ -31,28 +42,43 @@
|
|
|
31
42
|
"test:enrich": "node test/enrichment.mjs",
|
|
32
43
|
"test:mcp": "node test/mcp.mjs",
|
|
33
44
|
"test:scale": "node test/scale.mjs",
|
|
34
|
-
"test:
|
|
45
|
+
"test:callgraph": "node test/callgraph.mjs",
|
|
46
|
+
"test:references": "node test/references.mjs",
|
|
47
|
+
"test:routes": "node test/routes.mjs",
|
|
48
|
+
"test:jsonout": "node test/json-output.mjs",
|
|
49
|
+
"test:gitsignals": "node test/git-signals.mjs",
|
|
50
|
+
"test:security": "node test/security.mjs",
|
|
51
|
+
"test:embed": "node test/embeddings.mjs",
|
|
52
|
+
"test:languages": "node test/languages.mjs",
|
|
53
|
+
"test:all": "node test/unit.mjs && node test/sqlite.mjs && node test/enrichment.mjs && node test/mcp.mjs && node test/scale.mjs && node test/callgraph.mjs && node test/references.mjs && node test/routes.mjs && node test/json-output.mjs && node test/git-signals.mjs && node test/security.mjs && node test/embeddings.mjs && node test/languages.mjs",
|
|
35
54
|
"test:eval": "node test/evaluate.mjs",
|
|
36
|
-
"test:eval:embeddings": "OLLAMA_HOST=http://localhost:
|
|
55
|
+
"test:eval:embeddings": "OLLAMA_HOST=http://localhost:11434 node test/evaluate.mjs --embeddings",
|
|
37
56
|
"test:setup": "node test/setup.mjs",
|
|
38
57
|
"test:run": "node test/run.mjs",
|
|
39
|
-
"test:embeddings": "OLLAMA_HOST=http://localhost:
|
|
40
|
-
"test:embeddings:skip": "OLLAMA_HOST=http://localhost:
|
|
58
|
+
"test:embeddings": "OLLAMA_HOST=http://localhost:11434 node test/run-embeddings.mjs",
|
|
59
|
+
"test:embeddings:skip": "OLLAMA_HOST=http://localhost:11434 node test/run-embeddings.mjs --skip-indexing",
|
|
41
60
|
"test:suite": "node test/run.mjs --suite",
|
|
42
61
|
"test:json": "node test/run.mjs --json",
|
|
43
62
|
"test:reset": "rm -rf test/fixtures && node test/setup.mjs",
|
|
44
|
-
"
|
|
63
|
+
"embed:setup:mlx": "node embedders/setup-mlx.mjs",
|
|
64
|
+
"mcp:index": "idx-index --repo .",
|
|
45
65
|
"mcp:index:sqlite": "node indexer.mjs --repo . --use-sqlite",
|
|
46
|
-
"mcp:index:enriched": "node indexer.mjs --repo . --
|
|
66
|
+
"mcp:index:enriched": "node indexer.mjs --repo . --enrichment",
|
|
47
67
|
"mcp:watch": "node watch-daemon.mjs",
|
|
48
|
-
"mcp:start": "
|
|
68
|
+
"mcp:start": "idx-mcp",
|
|
69
|
+
"mcp:daemon": "node daemon-ctl.mjs status",
|
|
70
|
+
"mcp:daemon:start": "node daemon-ctl.mjs start",
|
|
71
|
+
"mcp:daemon:stop": "node daemon-ctl.mjs stop",
|
|
72
|
+
"mcp:daemon:restart": "node daemon-ctl.mjs restart",
|
|
73
|
+
"mcp:daemon:status": "node daemon-ctl.mjs status",
|
|
74
|
+
"mcp:daemon:logs": "node daemon-ctl.mjs logs"
|
|
49
75
|
},
|
|
50
76
|
"dependencies": {
|
|
51
77
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
52
78
|
"chokidar": "5.0.0",
|
|
53
79
|
"ignore": "5.3.2",
|
|
54
80
|
"tree-sitter": "0.21.1",
|
|
55
|
-
"zod": "3.
|
|
81
|
+
"zod": "^3.25.76"
|
|
56
82
|
},
|
|
57
83
|
"keywords": [
|
|
58
84
|
"mcp",
|
|
@@ -87,7 +113,10 @@
|
|
|
87
113
|
"access": "public"
|
|
88
114
|
},
|
|
89
115
|
"optionalDependencies": {
|
|
116
|
+
"@huggingface/transformers": "3.8.1",
|
|
90
117
|
"hnswlib-node": "3.0.0",
|
|
118
|
+
"tree-sitter-bash": "0.23.3",
|
|
119
|
+
"tree-sitter-c": "0.21.4",
|
|
91
120
|
"tree-sitter-c-sharp": "0.21.3",
|
|
92
121
|
"tree-sitter-css": "0.21.1",
|
|
93
122
|
"tree-sitter-go": "0.21.0",
|
|
@@ -98,6 +127,8 @@
|
|
|
98
127
|
"tree-sitter-python": "0.21.0",
|
|
99
128
|
"tree-sitter-ruby": "0.23.1",
|
|
100
129
|
"tree-sitter-rust": "0.21.0",
|
|
130
|
+
"tree-sitter-scss": "1.0.0",
|
|
131
|
+
"tree-sitter-swift": "0.5.0",
|
|
101
132
|
"tree-sitter-typescript": "0.21.2"
|
|
102
133
|
}
|
|
103
|
-
}
|
|
134
|
+
}
|