@sdsrs/code-graph 0.2.1 → 0.4.0-rc1

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 CHANGED
@@ -13,6 +13,34 @@ A high-performance code knowledge graph server implementing the [Model Context P
13
13
  - **Embedding model** — Optional local embedding via Candle (feature-gated `embed-model`)
14
14
  - **MCP protocol** — JSON-RPC 2.0 over stdio, plug-and-play with Claude Code, Cursor, and other MCP clients
15
15
 
16
+ ## Why code-graph-mcp?
17
+
18
+ Unlike naive full-text search or simple AST dumps, code-graph-mcp builds a **structured knowledge graph** that understands the relationships between symbols across your entire codebase.
19
+
20
+ ### Incremental by Design
21
+
22
+ BLAKE3 Merkle tree tracks every file's content hash. On re-index, only changed files are re-parsed — unchanged directory subtrees are skipped entirely via mtime cache. When a function signature changes, **dirty propagation** automatically regenerates context for all downstream callers across files.
23
+
24
+ ### Hybrid Search, Not Just Grep
25
+
26
+ Combines BM25 full-text ranking (FTS5) with vector semantic similarity (sqlite-vec) via **Reciprocal Rank Fusion (RRF)** — so searching "handle user login" finds the right function even if it's named `authenticate_session`. Results are auto-compressed to fit LLM context windows (L0→full code, L1→summaries, L2→file groups, L3→directory overview).
27
+
28
+ ### Scope-Aware Relation Extraction
29
+
30
+ The parser doesn't just find function calls — it tracks them within their proper scope context. Extracts calls, imports, inheritance, interface implementations, exports, and HTTP route bindings. Same-file targets are preferred over cross-file matches to minimize false-positive edges.
31
+
32
+ ### HTTP Request Flow Tracing
33
+
34
+ Unique to code-graph-mcp: trace from `GET /api/users` → route handler → service layer → database call in a single query. Supports Express, Flask/FastAPI, and Go HTTP frameworks.
35
+
36
+ ### Zero External Dependencies at Runtime
37
+
38
+ Single binary, embedded SQLite, bundled sqlite-vec extension, optional local embedding model via Candle — no database server, no cloud API, no Docker required. Runs entirely on your machine.
39
+
40
+ ### Built for AI Assistants
41
+
42
+ Every design decision — from token-aware compression to node_id-based snippet expansion — is optimized for LLM context windows. Works out of the box with Claude Code, Cursor, Windsurf, and any MCP-compatible client.
43
+
16
44
  ## Architecture
17
45
 
18
46
  ```
@@ -35,18 +63,33 @@ src/
35
63
  One-command setup — registers as an MCP server directly in Claude Code:
36
64
 
37
65
  ```bash
38
- claude mcp add code-graph-mcp npx @sdsrs/code-graph
66
+ claude mcp add code-graph-mcp -- npx -y @sdsrs/code-graph
67
+ ```
68
+
69
+ ### Option 2: Cursor / Windsurf / Other MCP Clients
70
+
71
+ Add to your MCP settings file (e.g. `~/.cursor/mcp.json`):
72
+
73
+ ```json
74
+ {
75
+ "mcpServers": {
76
+ "code-graph": {
77
+ "command": "npx",
78
+ "args": ["-y", "@sdsrs/code-graph"]
79
+ }
80
+ }
81
+ }
39
82
  ```
40
83
 
41
- ### Option 2: npx (No Install)
84
+ ### Option 3: npx (No Install)
42
85
 
43
86
  Run directly without installing:
44
87
 
45
88
  ```bash
46
- npx @sdsrs/code-graph
89
+ npx -y @sdsrs/code-graph
47
90
  ```
48
91
 
49
- ### Option 3: npm (Global Install)
92
+ ### Option 4: npm (Global Install)
50
93
 
51
94
  Install globally, then run anywhere:
52
95
 
@@ -55,6 +98,24 @@ npm install -g @sdsrs/code-graph
55
98
  code-graph-mcp
56
99
  ```
57
100
 
101
+ ## Uninstallation
102
+
103
+ ### Claude Code
104
+
105
+ ```bash
106
+ claude mcp remove code-graph-mcp
107
+ ```
108
+
109
+ ### Cursor / Windsurf / Other MCP Clients
110
+
111
+ Remove the `code-graph` entry from your MCP settings file (e.g. `~/.cursor/mcp.json`).
112
+
113
+ ### npm (Global)
114
+
115
+ ```bash
116
+ npm uninstall -g @sdsrs/code-graph
117
+ ```
118
+
58
119
  ## Build from Source
59
120
 
60
121
  ### Prerequisites
@@ -72,16 +133,15 @@ cargo build --release
72
133
  cargo build --release --no-default-features
73
134
  ```
74
135
 
75
- ### Configure with Claude Code (Manual)
136
+ ### Configure (from source)
76
137
 
77
- If you built from source, add to your MCP settings:
138
+ Add the compiled binary to your MCP settings:
78
139
 
79
140
  ```json
80
141
  {
81
142
  "mcpServers": {
82
143
  "code-graph": {
83
- "command": "/path/to/code-graph-mcp",
84
- "cwd": "/path/to/your/project"
144
+ "command": "/path/to/target/release/code-graph-mcp"
85
145
  }
86
146
  }
87
147
  }
@@ -94,6 +154,7 @@ If you built from source, add to your MCP settings:
94
154
  | `semantic_code_search` | Hybrid BM25 + vector + graph search for AST nodes |
95
155
  | `get_call_graph` | Trace upstream/downstream call chains for a function |
96
156
  | `find_http_route` | Map route path to backend handler function |
157
+ | `trace_http_chain` | Full request flow: route → handler → downstream call chain |
97
158
  | `get_ast_node` | Extract a specific code symbol from a file |
98
159
  | `read_snippet` | Read original code snippet by node ID with context |
99
160
  | `start_watch` / `stop_watch` | Start/stop file system watcher for incremental indexing |
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "code-graph",
3
+ "description": "AST knowledge graph for intelligent code navigation — auto-indexes your codebase and provides semantic search, call graph traversal, HTTP route tracing, and impact analysis via MCP tools",
4
+ "author": {
5
+ "name": "sdsrs"
6
+ },
7
+ "version": "0.3.0",
8
+ "keywords": ["code-graph", "ast", "navigation", "mcp", "knowledge-graph"]
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "mcpServers": {
3
+ "code-graph": {
4
+ "command": "code-graph-mcp",
5
+ "args": ["serve"],
6
+ "env": {}
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: code-explorer
3
+ description: Deep code understanding expert using AST knowledge graph. Use when exploring unfamiliar code, tracing complex relationships, or understanding module architecture.
4
+ tools: ["Read", "Grep", "Glob", "Bash", "mcp__code-graph__semantic_code_search", "mcp__code-graph__get_call_graph", "mcp__code-graph__get_ast_node", "mcp__code-graph__read_snippet", "mcp__code-graph__trace_http_chain"]
5
+ model: sonnet
6
+ ---
7
+
8
+ You are a code exploration specialist with access to an AST knowledge graph.
9
+
10
+ ## Strategy
11
+
12
+ 1. **Start with semantic_code_search** to locate relevant code by meaning
13
+ 2. **Use get_call_graph** to understand function relationships and call chains
14
+ 3. **Use get_ast_node** to get symbol metadata (signature, type, doc comment)
15
+ 4. **Use read_snippet** to examine specific code implementations
16
+ 5. **Use trace_http_chain** for HTTP request flow analysis
17
+ 6. **Fall back to Grep/Read** only when code-graph tools lack coverage (e.g., config files, non-code assets)
18
+
19
+ ## Rules
20
+
21
+ - Always prefer structured graph queries over raw text search
22
+ - Return structured findings: name, file, line, relationships
23
+ - When reporting call chains, include depth and direction
24
+ - Estimate token cost: if Read would require >3 files, prefer code-graph tools
@@ -0,0 +1,19 @@
1
+ ---
2
+ description: Analyze the impact scope of changing a symbol before modifying it
3
+ argument-hint: <symbol_name>
4
+ ---
5
+
6
+ # Impact Analysis
7
+
8
+ Analyze what will be affected if you change the given symbol.
9
+
10
+ ## Steps
11
+
12
+ 1. Call `get_call_graph(symbol, "callers", depth=3)` to find all upstream callers
13
+ 2. Call `get_call_graph(symbol, "callees", depth=2)` to find downstream dependencies
14
+ 3. Check if any callers are HTTP route handlers (look for route-related nodes)
15
+ 4. Summarize findings:
16
+ - **Affected files**: list all unique files containing callers/callees
17
+ - **Affected routes**: list any HTTP routes that flow through this symbol
18
+ - **Risk level**: LOW (≤3 callers, no routes), MEDIUM (4-10 callers OR 1-2 routes), HIGH (>10 callers OR ≥3 routes)
19
+ 5. Present the analysis before making any modifications
@@ -0,0 +1,15 @@
1
+ ---
2
+ description: Trace a full HTTP request flow from route to data layer
3
+ argument-hint: <route_path>
4
+ ---
5
+
6
+ # HTTP Request Flow Tracing
7
+
8
+ Trace the complete execution path of an HTTP request.
9
+
10
+ ## Steps
11
+
12
+ 1. Call `trace_http_chain(route, depth=5)` to get the full chain
13
+ 2. For each key node in the chain, call `read_snippet` to show the implementation
14
+ 3. Map the flow: route → middleware → validation → business logic → data access → response
15
+ 4. Highlight any error handling, authentication checks, or database operations
@@ -0,0 +1,21 @@
1
+ ---
2
+ description: Deep dive into a module or file's architecture and relationships
3
+ argument-hint: <file_or_dir_path>
4
+ ---
5
+
6
+ # Module Deep Dive
7
+
8
+ Understand what a module does, its public API, and how it connects to the rest of the codebase.
9
+
10
+ ## Steps
11
+
12
+ 1. Call `get_index_status` to verify the code graph index is current
13
+ 2. Call `semantic_code_search` with the module name to find its key symbols
14
+ 3. For each important export, call `get_call_graph` to map caller/callee relationships
15
+ 4. Summarize:
16
+ - **Purpose**: what this module does
17
+ - **Public API**: exported functions/classes with signatures
18
+ - **Internal structure**: key internal helpers
19
+ - **Dependencies**: what it imports
20
+ - **Dependents**: who imports it
21
+ - **Hot paths**: most-called functions (by caller count)
@@ -0,0 +1,29 @@
1
+ {
2
+ "hooks": {
3
+ "PostToolUse": [
4
+ {
5
+ "matcher": "tool == \"Write\" || tool == \"Edit\"",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "code-graph-mcp incremental-index --quiet",
10
+ "timeout": 10
11
+ }
12
+ ],
13
+ "description": "Auto-update code graph index after file edits"
14
+ }
15
+ ],
16
+ "SessionStart": [
17
+ {
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "code-graph-mcp health-check --format oneline",
22
+ "timeout": 5
23
+ }
24
+ ],
25
+ "description": "Verify code graph index freshness at session start"
26
+ }
27
+ ]
28
+ }
29
+ }
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require('child_process');
3
+ try {
4
+ const out = execSync('code-graph-mcp health-check --format json', {
5
+ timeout: 3000,
6
+ stdio: ['pipe', 'pipe', 'pipe']
7
+ }).toString().trim();
8
+ const s = JSON.parse(out);
9
+ const icon = s.healthy ? '\u2713' : '\u2717';
10
+ process.stdout.write(
11
+ `code-graph: ${icon} ${s.nodes} nodes | ${s.files} files` +
12
+ (s.watching ? ' | watching' : '')
13
+ );
14
+ } catch {
15
+ process.stdout.write('code-graph: offline');
16
+ }
@@ -0,0 +1,29 @@
1
+ ---
2
+ name: code-navigation
3
+ description: Smart code navigation decision tree for code-graph MCP tools. Use when exploring, understanding, or navigating code in a project indexed by code-graph.
4
+ ---
5
+
6
+ # Code Navigation with Code Graph
7
+
8
+ This project has a code-graph MCP server providing AST-level code intelligence.
9
+ These tools return structured, token-efficient results. Use them as your
10
+ PRIMARY navigation method for code understanding tasks.
11
+
12
+ | You want to... | Use this | NOT this |
13
+ |---|---|---|
14
+ | Find code by concept/meaning | `semantic_code_search` | Grep multiple patterns |
15
+ | Understand who calls what | `get_call_graph` | Grep function name + Read files |
16
+ | Trace HTTP request flow | `trace_http_chain` | Read router -> handler -> service |
17
+ | Find route handler | `find_http_route` | Grep route string |
18
+ | Get symbol signature + relations | `get_ast_node` | Read entire file |
19
+ | Read specific code after search | `read_snippet` (by node_id) | Read entire file |
20
+ | Analyze change impact | `impact_analysis` | Manual call graph tracing |
21
+ | Understand a module | `module_overview` | Read all files in directory |
22
+ | Map dependencies | `dependency_graph` | Grep import statements |
23
+ | Find similar code | `find_similar_code` | Grep partial function names |
24
+
25
+ ## Still use native tools for
26
+ - Exact string match → Grep
27
+ - File path lookup → Glob
28
+ - Reading a specific known file → Read
29
+ - Creating/editing files → Write/Edit
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdsrs/code-graph",
3
- "version": "0.2.1",
3
+ "version": "0.4.0-rc1",
4
4
  "description": "MCP server that indexes codebases into an AST knowledge graph with semantic search, call graph traversal, and HTTP route tracing",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -23,7 +23,8 @@
23
23
  },
24
24
  "files": [
25
25
  "bin/cli.js",
26
- "README.md"
26
+ "README.md",
27
+ "claude-plugin"
27
28
  ],
28
29
  "scripts": {
29
30
  "build": "cargo build --release --no-default-features && node scripts/copy-binary.js"
@@ -32,10 +33,10 @@
32
33
  "node": ">=16"
33
34
  },
34
35
  "optionalDependencies": {
35
- "@sdsrs/code-graph-linux-x64": "0.2.1",
36
- "@sdsrs/code-graph-linux-arm64": "0.2.1",
37
- "@sdsrs/code-graph-darwin-x64": "0.2.1",
38
- "@sdsrs/code-graph-darwin-arm64": "0.2.1",
39
- "@sdsrs/code-graph-win32-x64": "0.2.1"
36
+ "@sdsrs/code-graph-linux-x64": "0.4.0-rc1",
37
+ "@sdsrs/code-graph-linux-arm64": "0.4.0-rc1",
38
+ "@sdsrs/code-graph-darwin-x64": "0.4.0-rc1",
39
+ "@sdsrs/code-graph-darwin-arm64": "0.4.0-rc1",
40
+ "@sdsrs/code-graph-win32-x64": "0.4.0-rc1"
40
41
  }
41
42
  }