@sdsrs/code-graph 0.1.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/README.md +131 -0
- package/bin/cli.js +81 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# code-graph-mcp
|
|
2
|
+
|
|
3
|
+
A high-performance code knowledge graph server implementing the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/). Indexes codebases into a structured AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing — designed to give AI coding assistants deep, structured understanding of your code.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Multi-language parsing** — Tree-sitter based AST extraction for TypeScript, JavaScript, Go, Python, Rust, Java, C, C++, HTML, CSS
|
|
8
|
+
- **Semantic code search** — Hybrid BM25 full-text + vector semantic search with Reciprocal Rank Fusion (RRF), powered by sqlite-vec
|
|
9
|
+
- **Call graph traversal** — Recursive CTE queries to trace callers/callees with cycle detection
|
|
10
|
+
- **HTTP route tracing** — Map route paths to backend handler functions (Express, Flask/FastAPI, Go)
|
|
11
|
+
- **Incremental indexing** — Merkle tree change detection with file system watcher for real-time updates
|
|
12
|
+
- **Context compression** — Token-aware snippet extraction for LLM context windows
|
|
13
|
+
- **Embedding model** — Optional local embedding via Candle (feature-gated `embed-model`)
|
|
14
|
+
- **MCP protocol** — JSON-RPC 2.0 over stdio, plug-and-play with Claude Code, Cursor, and other MCP clients
|
|
15
|
+
|
|
16
|
+
## Architecture
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
src/
|
|
20
|
+
├── mcp/ # MCP protocol layer (JSON-RPC, tool registry, server)
|
|
21
|
+
├── parser/ # Tree-sitter parsing, relation extraction, language support
|
|
22
|
+
├── indexer/ # 3-phase pipeline, Merkle tree, file watcher
|
|
23
|
+
├── storage/ # SQLite schema, CRUD, FTS5 full-text search
|
|
24
|
+
├── graph/ # Recursive CTE call graph queries
|
|
25
|
+
├── search/ # RRF fusion search combining BM25 + vector
|
|
26
|
+
├── embedding/ # Candle embedding model (optional)
|
|
27
|
+
├── sandbox/ # Context compressor with token estimation
|
|
28
|
+
└── utils/ # Language detection, config
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
### Option 1: Claude Code (Recommended)
|
|
34
|
+
|
|
35
|
+
One-command setup — registers as an MCP server directly in Claude Code:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
claude mcp add code-graph-mcp npx @sdsrs/code-graph
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Option 2: npx (No Install)
|
|
42
|
+
|
|
43
|
+
Run directly without installing:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx @sdsrs/code-graph
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Option 3: npm (Global Install)
|
|
50
|
+
|
|
51
|
+
Install globally, then run anywhere:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install -g @sdsrs/code-graph
|
|
55
|
+
code-graph-mcp
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Build from Source
|
|
59
|
+
|
|
60
|
+
### Prerequisites
|
|
61
|
+
|
|
62
|
+
- Rust 1.75+ (2021 edition)
|
|
63
|
+
- A C compiler (for bundled SQLite / sqlite-vec)
|
|
64
|
+
|
|
65
|
+
### Build
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Default build (with local embedding model)
|
|
69
|
+
cargo build --release
|
|
70
|
+
|
|
71
|
+
# Without embedding model (lighter build)
|
|
72
|
+
cargo build --release --no-default-features
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Configure with Claude Code (Manual)
|
|
76
|
+
|
|
77
|
+
If you built from source, add to your MCP settings:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"mcpServers": {
|
|
82
|
+
"code-graph": {
|
|
83
|
+
"command": "/path/to/code-graph-mcp",
|
|
84
|
+
"cwd": "/path/to/your/project"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## MCP Tools
|
|
91
|
+
|
|
92
|
+
| Tool | Description |
|
|
93
|
+
|------|-------------|
|
|
94
|
+
| `semantic_code_search` | Hybrid BM25 + vector + graph search for AST nodes |
|
|
95
|
+
| `get_call_graph` | Trace upstream/downstream call chains for a function |
|
|
96
|
+
| `find_http_route` | Map route path to backend handler function |
|
|
97
|
+
| `get_ast_node` | Extract a specific code symbol from a file |
|
|
98
|
+
| `read_snippet` | Read original code snippet by node ID with context |
|
|
99
|
+
| `start_watch` / `stop_watch` | Start/stop file system watcher for incremental indexing |
|
|
100
|
+
| `get_index_status` | Query index status and health |
|
|
101
|
+
| `rebuild_index` | Force full index rebuild |
|
|
102
|
+
|
|
103
|
+
## Supported Languages
|
|
104
|
+
|
|
105
|
+
TypeScript, JavaScript, Go, Python, Rust, Java, C, C++, HTML, CSS
|
|
106
|
+
|
|
107
|
+
## Storage
|
|
108
|
+
|
|
109
|
+
Uses SQLite with:
|
|
110
|
+
- FTS5 for full-text search
|
|
111
|
+
- sqlite-vec extension for vector similarity search
|
|
112
|
+
- Merkle tree hashes for incremental change detection
|
|
113
|
+
|
|
114
|
+
Data is stored in `.code-graph/index.db` under the project root (auto-created, gitignored).
|
|
115
|
+
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Run tests
|
|
120
|
+
cargo test
|
|
121
|
+
|
|
122
|
+
# Run tests without embedding model
|
|
123
|
+
cargo test --no-default-features
|
|
124
|
+
|
|
125
|
+
# Check compilation
|
|
126
|
+
cargo check
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
See [LICENSE](LICENSE) for details.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync, spawn } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
|
|
8
|
+
function getBinaryName() {
|
|
9
|
+
return os.platform() === "win32" ? "code-graph-mcp.exe" : "code-graph-mcp";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function findBinary() {
|
|
13
|
+
const binaryName = getBinaryName();
|
|
14
|
+
|
|
15
|
+
// 1. Check platform-specific npm package (code-graph-<os>-<arch>)
|
|
16
|
+
const platformPkg = `@sdsrs/code-graph-${os.platform()}-${os.arch()}`;
|
|
17
|
+
try {
|
|
18
|
+
const pkgPath = require.resolve(`${platformPkg}/package.json`);
|
|
19
|
+
const pkgDir = path.dirname(pkgPath);
|
|
20
|
+
const platBinary = path.join(pkgDir, binaryName);
|
|
21
|
+
if (fs.existsSync(platBinary)) {
|
|
22
|
+
return platBinary;
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
// Platform package not installed
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 2. Check bundled binary in the same directory
|
|
29
|
+
const bundled = path.join(__dirname, binaryName);
|
|
30
|
+
if (fs.existsSync(bundled)) {
|
|
31
|
+
return bundled;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 3. Check cargo build output (for development)
|
|
35
|
+
const cargoRelease = path.join(__dirname, "..", "target", "release", binaryName);
|
|
36
|
+
if (fs.existsSync(cargoRelease)) {
|
|
37
|
+
return cargoRelease;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 4. Check if available in PATH
|
|
41
|
+
try {
|
|
42
|
+
const which = os.platform() === "win32" ? "where" : "which";
|
|
43
|
+
const result = execFileSync(which, [binaryName], { encoding: "utf8" }).trim();
|
|
44
|
+
if (result) return result;
|
|
45
|
+
} catch {
|
|
46
|
+
// not in PATH
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const binary = findBinary();
|
|
53
|
+
|
|
54
|
+
if (!binary) {
|
|
55
|
+
console.error(
|
|
56
|
+
"Error: code-graph-mcp binary not found.\n\n" +
|
|
57
|
+
"To build from source:\n" +
|
|
58
|
+
" cargo build --release --no-default-features\n\n" +
|
|
59
|
+
"Or install the platform-specific binary."
|
|
60
|
+
);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Spawn the binary, forwarding stdio for MCP JSON-RPC communication
|
|
65
|
+
const child = spawn(binary, process.argv.slice(2), {
|
|
66
|
+
stdio: "inherit",
|
|
67
|
+
env: process.env,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
child.on("error", (err) => {
|
|
71
|
+
console.error(`Failed to start code-graph-mcp: ${err.message}`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
child.on("exit", (code, signal) => {
|
|
76
|
+
if (signal) {
|
|
77
|
+
process.kill(process.pid, signal);
|
|
78
|
+
} else {
|
|
79
|
+
process.exit(code ?? 1);
|
|
80
|
+
}
|
|
81
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sdsrs/code-graph",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server that indexes codebases into an AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/sdsrss/code-graph-mcp"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"mcp",
|
|
12
|
+
"code-graph",
|
|
13
|
+
"ast",
|
|
14
|
+
"knowledge-graph",
|
|
15
|
+
"semantic-search",
|
|
16
|
+
"tree-sitter",
|
|
17
|
+
"code-analysis",
|
|
18
|
+
"call-graph"
|
|
19
|
+
],
|
|
20
|
+
"bin": {
|
|
21
|
+
"code-graph": "./bin/cli.js",
|
|
22
|
+
"code-graph-mcp": "./bin/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"bin/cli.js",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "cargo build --release --no-default-features && node scripts/copy-binary.js"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=16"
|
|
33
|
+
},
|
|
34
|
+
"optionalDependencies": {
|
|
35
|
+
"@sdsrs/code-graph-linux-x64": "0.1.0",
|
|
36
|
+
"@sdsrs/code-graph-linux-arm64": "0.1.0",
|
|
37
|
+
"@sdsrs/code-graph-darwin-x64": "0.1.0",
|
|
38
|
+
"@sdsrs/code-graph-darwin-arm64": "0.1.0",
|
|
39
|
+
"@sdsrs/code-graph-win32-x64": "0.1.0"
|
|
40
|
+
}
|
|
41
|
+
}
|