callgraph-mcp 1.1.0 → 1.3.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 +55 -43
- 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
|
-
|
|
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."*
|
|
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."*
|
|
93
129
|
|
|
94
|
-
|
|
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.
|
|
95
131
|
|
|
96
|
-
|
|
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.
|
|
97
137
|
|
|
98
138
|
---
|
|
99
139
|
|
|
100
|
-
###
|
|
140
|
+
### Dead code and cleanup
|
|
101
141
|
|
|
102
|
-
> *"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."*
|
|
103
143
|
|
|
104
|
-
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.
|
|
105
145
|
|
|
106
146
|
---
|
|
107
147
|
|
|
108
|
-
###
|
|
148
|
+
### Onboarding
|
|
109
149
|
|
|
110
|
-
> *"
|
|
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 `
|
|
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
|
-
###
|
|
156
|
+
### Refactoring
|
|
117
157
|
|
|
118
|
-
> *"
|
|
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 `
|
|
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
|
-
###
|
|
164
|
+
### AI agent review
|
|
125
165
|
|
|
126
|
-
> *"
|
|
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
|
|
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
|
|
|
@@ -144,34 +184,6 @@ When an agent is generating new code, it can call `flowmap_analyze_workspace` be
|
|
|
144
184
|
- No existing entry points were broken
|
|
145
185
|
- The intended call relationships were actually created
|
|
146
186
|
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
## Example Prompts for VS Code Copilot
|
|
150
|
-
|
|
151
|
-
```
|
|
152
|
-
List all entry points in this workspace
|
|
153
|
-
```
|
|
154
|
-
```
|
|
155
|
-
What functions call `buildCallGraph` anywhere in the codebase?
|
|
156
|
-
```
|
|
157
|
-
```
|
|
158
|
-
Show me the full execution path starting from `startServer`, up to 6 levels deep
|
|
159
|
-
```
|
|
160
|
-
```
|
|
161
|
-
Find all dead code — functions that are never reached from any entry point
|
|
162
|
-
```
|
|
163
|
-
```
|
|
164
|
-
What does `parseFile` directly depend on?
|
|
165
|
-
```
|
|
166
|
-
```
|
|
167
|
-
I'm changing `connectDb`. Who calls it? Give me file paths and line numbers.
|
|
168
|
-
```
|
|
169
|
-
```
|
|
170
|
-
Analyze just src/api/routes.ts and tell me what it exports and what it calls
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
187
|
## How It Works
|
|
176
188
|
|
|
177
189
|
1. Tree-sitter WASM grammars parse each source file into an AST — no runtime execution, no imports
|