callgraph-mcp 1.0.3 → 1.2.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 +70 -208
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,30 +8,25 @@ Powered by [`@codeflow-map/core`](https://www.npmjs.com/package/@codeflow-map/co
|
|
|
8
8
|
|
|
9
9
|
**Supports:** TypeScript · JavaScript · TSX · JSX · Python · Go
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
> **Bundled grammars:** TypeScript, JavaScript, TSX, JSX, Python, and Go grammars are included. After install, they are available in `callgraph-mcp/grammars`.
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Why Deterministic Analysis Matters
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Most AI coding tools answer structural questions about your codebase by reading source files as text and reasoning over them. This causes three compounding failure modes:
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"flowmap": {
|
|
23
|
-
"type": "stdio",
|
|
24
|
-
"command": "npx",
|
|
25
|
-
"args": ["-y", "callgraph-mcp"]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
```
|
|
19
|
+
**Hallucination.** When asked "what calls `processPayment`?", a model without structural grounding will guess based on naming patterns and training priors. It will confidently name callers that don't exist and miss ones that do. The larger the codebase, the worse this gets.
|
|
20
|
+
|
|
21
|
+
**Lost in the middle.** Research shows that LLMs systematically fail to recall information from the middle of long contexts. Paste a 200-file codebase into context and the model will answer based on whatever happened to land near the top or bottom. Functions buried in the middle of that context window are effectively invisible.
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
**Attention dilution.** Even when information is present, spreading the model's attention across tens of thousands of lines means each individual fact gets less weight. A critical edge in the call graph mentioned once in one file competes for attention with everything else. The model's confidence in its answer has no relationship to whether the answer is correct.
|
|
24
|
+
|
|
25
|
+
**callgraph-mcp eliminates all three.** It never reads your code as prose. It parses every file into an AST using Tree-sitter, builds an exact directed call graph, and answers structural queries against that graph. Every caller, every callee, every reachable function, every cycle — returned as a precise index. The answer is always the same regardless of how large your codebase is, which files happen to be in context, or how deeply buried a function is. **There is no probability involved. There is no attention to dilute.**
|
|
32
26
|
|
|
33
27
|
---
|
|
34
28
|
|
|
29
|
+
|
|
35
30
|
## Setup
|
|
36
31
|
|
|
37
32
|
### Option 1 — VS Code Copilot via `npx` (no install required)
|
|
@@ -53,85 +48,11 @@ Add to your project's `.vscode/mcp.json`:
|
|
|
53
48
|
}
|
|
54
49
|
```
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
> **Tip:** Create `.vscode/mcp.json` via the Command Palette → **MCP: Add Server** → **stdio**.
|
|
51
|
+
Start the server in your editor. WASM grammars are bundled — no environment variables needed.
|
|
59
52
|
|
|
60
|
-
|
|
53
|
+
> **Tip:** Create `.vscode/mcp.json` via the Command Palette -> **MCP: Add Server** -> **stdio**.
|
|
61
54
|
|
|
62
|
-
|
|
63
|
-
npm install -g callgraph-mcp
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
```json
|
|
67
|
-
{
|
|
68
|
-
"servers": {
|
|
69
|
-
"flowmap": {
|
|
70
|
-
"type": "stdio",
|
|
71
|
-
"command": "callgraph-mcp",
|
|
72
|
-
"env": {
|
|
73
|
-
"FLOWMAP_TRANSPORT": "stdio"
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Option 3 — Claude Desktop
|
|
81
|
-
|
|
82
|
-
Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
83
|
-
|
|
84
|
-
```json
|
|
85
|
-
{
|
|
86
|
-
"mcpServers": {
|
|
87
|
-
"flowmap": {
|
|
88
|
-
"command": "npx",
|
|
89
|
-
"args": ["-y", "callgraph-mcp"],
|
|
90
|
-
"env": {
|
|
91
|
-
"FLOWMAP_TRANSPORT": "stdio"
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Option 4 — Cursor
|
|
99
|
-
|
|
100
|
-
Add to your project's `.cursor/mcp.json`:
|
|
101
|
-
|
|
102
|
-
```json
|
|
103
|
-
{
|
|
104
|
-
"mcpServers": {
|
|
105
|
-
"flowmap": {
|
|
106
|
-
"command": "npx",
|
|
107
|
-
"args": ["-y", "callgraph-mcp"],
|
|
108
|
-
"env": {
|
|
109
|
-
"FLOWMAP_TRANSPORT": "stdio"
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Option 5 — Cline
|
|
117
|
-
|
|
118
|
-
Add to your Cline MCP settings (commonly `cline_mcp_settings.json`):
|
|
119
|
-
|
|
120
|
-
```json
|
|
121
|
-
{
|
|
122
|
-
"mcpServers": {
|
|
123
|
-
"flowmap": {
|
|
124
|
-
"command": "npx",
|
|
125
|
-
"args": ["-y", "callgraph-mcp"],
|
|
126
|
-
"env": {
|
|
127
|
-
"FLOWMAP_TRANSPORT": "stdio"
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Option 6 — HTTP-SSE (shared or remote server)
|
|
55
|
+
### Option 2 — HTTP-SSE (shared or remote server)
|
|
135
56
|
|
|
136
57
|
Use `FLOWMAP_TRANSPORT=http` for HTTP-SSE compatible clients.
|
|
137
58
|
|
|
@@ -156,100 +77,6 @@ Then point your client at it:
|
|
|
156
77
|
}
|
|
157
78
|
```
|
|
158
79
|
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
## Configure Environment Variables
|
|
162
|
-
|
|
163
|
-
Use one of the following approaches depending on your client.
|
|
164
|
-
|
|
165
|
-
### In VS Code `.vscode/mcp.json`
|
|
166
|
-
|
|
167
|
-
```json
|
|
168
|
-
{
|
|
169
|
-
"servers": {
|
|
170
|
-
"flowmap": {
|
|
171
|
-
"type": "stdio",
|
|
172
|
-
"command": "npx",
|
|
173
|
-
"args": ["-y", "callgraph-mcp"],
|
|
174
|
-
"env": {
|
|
175
|
-
"FLOWMAP_TRANSPORT": "http",
|
|
176
|
-
"FLOWMAP_PORT": "3100",
|
|
177
|
-
"FLOWMAP_GRAMMARS": "/absolute/path/to/grammars"
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### In Claude Desktop config
|
|
185
|
-
|
|
186
|
-
```json
|
|
187
|
-
{
|
|
188
|
-
"mcpServers": {
|
|
189
|
-
"flowmap": {
|
|
190
|
-
"command": "npx",
|
|
191
|
-
"args": ["-y", "callgraph-mcp"],
|
|
192
|
-
"env": {
|
|
193
|
-
"FLOWMAP_TRANSPORT": "stdio",
|
|
194
|
-
"FLOWMAP_GRAMMARS": "/absolute/path/to/grammars"
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### In Cursor `.cursor/mcp.json`
|
|
202
|
-
|
|
203
|
-
```json
|
|
204
|
-
{
|
|
205
|
-
"mcpServers": {
|
|
206
|
-
"flowmap": {
|
|
207
|
-
"command": "npx",
|
|
208
|
-
"args": ["-y", "callgraph-mcp"],
|
|
209
|
-
"env": {
|
|
210
|
-
"FLOWMAP_TRANSPORT": "stdio",
|
|
211
|
-
"FLOWMAP_GRAMMARS": "/absolute/path/to/grammars"
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
### In Cline MCP settings
|
|
219
|
-
|
|
220
|
-
```json
|
|
221
|
-
{
|
|
222
|
-
"mcpServers": {
|
|
223
|
-
"flowmap": {
|
|
224
|
-
"command": "npx",
|
|
225
|
-
"args": ["-y", "callgraph-mcp"],
|
|
226
|
-
"env": {
|
|
227
|
-
"FLOWMAP_TRANSPORT": "stdio",
|
|
228
|
-
"FLOWMAP_GRAMMARS": "/absolute/path/to/grammars"
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
### In your shell for one-off runs
|
|
236
|
-
|
|
237
|
-
macOS / Linux:
|
|
238
|
-
|
|
239
|
-
```bash
|
|
240
|
-
FLOWMAP_TRANSPORT=http FLOWMAP_PORT=3100 npx callgraph-mcp
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
Windows PowerShell:
|
|
244
|
-
|
|
245
|
-
```powershell
|
|
246
|
-
$env:FLOWMAP_TRANSPORT="http"
|
|
247
|
-
$env:FLOWMAP_PORT="3100"
|
|
248
|
-
npx callgraph-mcp
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
80
|
## Tools Reference
|
|
254
81
|
|
|
255
82
|
| Tool | Required params | Optional | What it returns |
|
|
@@ -278,43 +105,67 @@ npx callgraph-mcp
|
|
|
278
105
|
|
|
279
106
|
## Example Use Cases
|
|
280
107
|
|
|
281
|
-
|
|
108
|
+
These prompts work because the answers come from the call graph index — not from the model's memory of what your code might look like. Every result is exact, reproducible, and complete regardless of codebase size.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### PR review and change safety
|
|
113
|
+
|
|
114
|
+
> *"I just modified `processPayment`. Without reading any code, tell me every function that could break and rank them by how many hops away they are from the change."*
|
|
115
|
+
|
|
116
|
+
The agent calls `flowmap_get_callers("processPayment", workspacePath)` for the direct impact radius (1 hop), then recursively traverses callers-of-callers to build a ranked list by distance. The output is a tiered risk report: direct callers first, then second-order, then third-order. No file needs to be read. No attention dilution across 300 files. Just the graph.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
> *"We're about to merge a PR that touches `validateCart`. Give me an impact report — what's the worst case if this function throws."*
|
|
282
121
|
|
|
283
|
-
|
|
122
|
+
The agent calls `flowmap_get_flow("validateCart", workspacePath)` to map every function reachable downstream, then `flowmap_get_callers("validateCart", workspacePath)` to map every upstream caller. Together these define the complete risk surface: everything that feeds into it and everything that depends on it. Worst-case impact is the union of both subgraphs — stated precisely, not estimated.
|
|
284
123
|
|
|
285
|
-
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### Architecture problems
|
|
127
|
+
|
|
128
|
+
> *"Which functions in this codebase are architectural nasty-surprises — called by everything but calling a lot themselves. I want names, file paths, and exact counts."*
|
|
129
|
+
|
|
130
|
+
The agent calls `flowmap_analyze_workspace(workspacePath)` to get the full graph, then filters for nodes with high in-degree (many callers) and high out-degree (many callees). These are the structural chokepoints — functions where a bug propagates in both directions. Returned with exact counts. No approximation.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
> *"Find every cycle in the call graph. For each one tell me which file I should break the dependency in to resolve it cleanly."*
|
|
135
|
+
|
|
136
|
+
The agent calls `flowmap_analyze_workspace(workspacePath)` to retrieve the full edge list, then runs cycle detection over it. Each cycle is reported as an ordered list of functions and files. Because the graph is exact, the cycle membership is exact — not a guess about which modules "seem" circular.
|
|
286
137
|
|
|
287
138
|
---
|
|
288
139
|
|
|
289
|
-
###
|
|
140
|
+
### Dead code and cleanup
|
|
290
141
|
|
|
291
|
-
> *"I
|
|
142
|
+
> *"I want to delete code safely. Give me every function that is provably unreachable — not called by anything, not an entry point. Include file and line number."*
|
|
292
143
|
|
|
293
|
-
The agent calls `
|
|
144
|
+
The agent calls `flowmap_find_orphans(workspacePath)`. This returns every function not reachable from any entry point in the call graph — with file path and line number for each one. These are not "probably unused" — they are graph-theoretically unreachable. Safe to delete. No cross-checking required.
|
|
294
145
|
|
|
295
146
|
---
|
|
296
147
|
|
|
297
|
-
###
|
|
148
|
+
### Onboarding
|
|
298
149
|
|
|
299
|
-
> *"
|
|
150
|
+
> *"I just joined this team. Walk me through this codebase starting from the entry points — explain each major flow in plain English without me having to read a single file."*
|
|
300
151
|
|
|
301
|
-
The agent calls `
|
|
152
|
+
The agent calls `flowmap_list_entry_points(workspacePath)` to find every main, route handler, CLI command, and React root. Then it calls `flowmap_get_flow` on each one to trace the execution. It can then narrate each flow top-to-bottom — what each function does in the chain, where the boundaries are, and how the pieces connect. A new engineer can understand the architecture in minutes, not days. And because the graph is built from actual parse results, nothing is invented.
|
|
302
153
|
|
|
303
154
|
---
|
|
304
155
|
|
|
305
|
-
###
|
|
156
|
+
### Refactoring
|
|
306
157
|
|
|
307
|
-
> *"
|
|
158
|
+
> *"I want to extract the payment logic into its own module. Based purely on call relationships, which functions naturally belong together and which ones would need to stay behind."*
|
|
308
159
|
|
|
309
|
-
The agent calls `
|
|
160
|
+
The agent calls `flowmap_analyze_workspace(workspacePath)` and uses the graph to find the connected component of functions reachable from payment-related entry points. Functions that are exclusively reachable through payment flows are natural candidates to extract. Functions that are shared with other flows are the cut points — they stay, or need to be duplicated. This is module boundary detection from the graph structure, not from naming conventions or folder layout.
|
|
310
161
|
|
|
311
162
|
---
|
|
312
163
|
|
|
313
|
-
###
|
|
164
|
+
### AI agent review
|
|
314
165
|
|
|
315
|
-
> *"
|
|
166
|
+
> *"Cursor just made changes across 14 files. Based on what it touched, what else in the codebase should I be nervous about that it didn't touch."*
|
|
316
167
|
|
|
317
|
-
The agent calls `flowmap_get_callers
|
|
168
|
+
The agent calls `flowmap_get_callers` for each modified function and `flowmap_get_flow` for each modified function. The union of those results — minus the files already touched — is the set of functions that depend on the changes but weren't updated. These are the places where silent breakage is most likely. Returned as a precise list, not a guess about what "might be related".
|
|
318
169
|
|
|
319
170
|
---
|
|
320
171
|
|
|
@@ -338,25 +189,36 @@ When an agent is generating new code, it can call `flowmap_analyze_workspace` be
|
|
|
338
189
|
## Example Prompts for VS Code Copilot
|
|
339
190
|
|
|
340
191
|
```
|
|
341
|
-
|
|
192
|
+
I just modified processPayment. Without reading any code, tell me every function
|
|
193
|
+
that could break and rank them by how many hops away they are from the change.
|
|
194
|
+
```
|
|
195
|
+
```
|
|
196
|
+
We're about to merge a PR that touches validateCart. Give me an impact report —
|
|
197
|
+
what's the worst case if this function throws.
|
|
342
198
|
```
|
|
343
199
|
```
|
|
344
|
-
|
|
200
|
+
Which functions in this codebase are architectural nasty-surprises — called by everything
|
|
201
|
+
but calling a lot themselves. I want names, file paths, and exact counts.
|
|
345
202
|
```
|
|
346
203
|
```
|
|
347
|
-
|
|
204
|
+
Find every cycle in the call graph. For each one tell me which file I should break
|
|
205
|
+
the dependency in to resolve it cleanly.
|
|
348
206
|
```
|
|
349
207
|
```
|
|
350
|
-
|
|
208
|
+
I want to delete code safely. Give me every function that is provably unreachable —
|
|
209
|
+
not called by anything, not an entry point. Include file and line number.
|
|
351
210
|
```
|
|
352
211
|
```
|
|
353
|
-
|
|
212
|
+
I just joined this team. Walk me through this codebase starting from the entry points —
|
|
213
|
+
explain each major flow in plain English without me having to read a single file.
|
|
354
214
|
```
|
|
355
215
|
```
|
|
356
|
-
I
|
|
216
|
+
I want to extract the payment logic into its own module. Based purely on call
|
|
217
|
+
relationships, which functions naturally belong together and which ones would need to stay behind.
|
|
357
218
|
```
|
|
358
219
|
```
|
|
359
|
-
|
|
220
|
+
Cursor just made changes across 14 files. Based on what it touched, what else in the
|
|
221
|
+
codebase should I be nervous about that it didn't touch.
|
|
360
222
|
```
|
|
361
223
|
|
|
362
224
|
---
|