callgraph-mcp 1.1.0 → 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.
Files changed (2) hide show
  1. package/README.md +73 -22
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -10,6 +10,22 @@ Powered by [`@codeflow-map/core`](https://www.npmjs.com/package/@codeflow-map/co
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
+ ---
14
+
15
+ ## Why Deterministic Analysis Matters
16
+
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
+
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.
22
+
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.**
26
+
27
+ ---
28
+
13
29
 
14
30
  ## Setup
15
31
 
@@ -89,43 +105,67 @@ Then point your client at it:
89
105
 
90
106
  ## Example Use Cases
91
107
 
92
- ### Explore an unfamiliar codebase
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."*
93
115
 
94
- > *"I just cloned this repo. Walk me through where execution starts and what the main flows are."*
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.
95
117
 
96
- The agent calls `flowmap_list_entry_points` to find where code begins, then `flowmap_get_flow` on each entry point to trace the full execution paths. It can describe the architecture without reading every file.
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."*
121
+
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.
123
+
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.
97
131
 
98
132
  ---
99
133
 
100
- ### Understand the impact of a change before making it
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.
137
+
138
+ ---
101
139
 
102
- > *"I need to change the signature of `processPayment`. What will break?"*
140
+ ### Dead code and cleanup
103
141
 
104
- The agent calls `flowmap_get_callers("processPayment", workspacePath)` to get every call site across the entire codebase with file paths and line numbers so it knows exactly what needs updating before touching anything.
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."*
143
+
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.
105
145
 
106
146
  ---
107
147
 
108
- ### Safe refactoring — find what to clean up
148
+ ### Onboarding
109
149
 
110
- > *"We're doing a big cleanup. What functions are safe to delete?"*
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."*
111
151
 
112
- The agent calls `flowmap_find_orphans(workspacePath)`. Functions with zero reachability from entry points and not exported are strong deletion candidates. Combined with `flowmap_get_callers` for verification, this gives a confident dead-code list.
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.
113
153
 
114
154
  ---
115
155
 
116
- ### Trace a bug through the call chain
156
+ ### Refactoring
117
157
 
118
- > *"The `submitOrder` function is failing. What does it call, and what does each of those call?"*
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."*
119
159
 
120
- The agent calls `flowmap_get_flow("submitOrder", workspacePath, maxDepth: 5)` to get the full downstream call tree showing exactly which functions are in the execution path and which files they live in.
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.
121
161
 
122
162
  ---
123
163
 
124
- ### PR review — understand what changed
164
+ ### AI agent review
125
165
 
126
- > *"This PR modifies `validateUser`. What's the blast radius?"*
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."*
127
167
 
128
- The agent calls `flowmap_get_callers("validateUser", workspacePath)` to enumerate every caller, then `flowmap_get_flow("validateUser", workspacePath)` to show all downstream dependency. It can summarise the risk surface of the change deterministically.
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".
129
169
 
130
170
  ---
131
171
 
@@ -149,25 +189,36 @@ When an agent is generating new code, it can call `flowmap_analyze_workspace` be
149
189
  ## Example Prompts for VS Code Copilot
150
190
 
151
191
  ```
152
- List all entry points in this workspace
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.
153
198
  ```
154
199
  ```
155
- What functions call `buildCallGraph` anywhere in the codebase?
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.
156
202
  ```
157
203
  ```
158
- Show me the full execution path starting from `startServer`, up to 6 levels deep
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.
159
206
  ```
160
207
  ```
161
- Find all dead code functions that are never reached from any entry point
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.
162
210
  ```
163
211
  ```
164
- What does `parseFile` directly depend on?
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.
165
214
  ```
166
215
  ```
167
- I'm changing `connectDb`. Who calls it? Give me file paths and line numbers.
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.
168
218
  ```
169
219
  ```
170
- Analyze just src/api/routes.ts and tell me what it exports and what it calls
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.
171
222
  ```
172
223
 
173
224
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "callgraph-mcp",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "MCP server for codebase call-flow analysis. Local, deterministic, language-agnostic. Powered by @codeflow-map/core.",
5
5
  "keywords": [
6
6
  "mcp",