typegraph-mcp 0.9.19 → 0.9.21
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 +117 -338
- package/benchmark.ts +4 -2
- package/cli.ts +18 -2
- package/commands/bench.md +24 -0
- package/dist/benchmark.js +1284 -0
- package/dist/cli.js +761 -229
- package/package.json +1 -1
- package/tsup.config.ts +1 -0
package/README.md
CHANGED
|
@@ -4,9 +4,16 @@
|
|
|
4
4
|
<img src="./assets/hero.jpg" alt="typegraph-mcp — Semantic TypeScript understanding for AI agents" width="800">
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Supercharge your AI coding agent with TypeScript superintelligence.
|
|
8
8
|
|
|
9
|
-
14 semantic navigation tools
|
|
9
|
+
14 semantic navigation tools delivered via the [Model Context Protocol](https://modelcontextprotocol.io/) so any MCP-compatible agent can use them.
|
|
10
|
+
|
|
11
|
+
- **Instant type resolution** — hover info, generics, inferred types without reading files
|
|
12
|
+
- **Instant call tracing** — follow a symbol from handler to implementation in one call
|
|
13
|
+
- **Instant impact analysis** — "what breaks if I change this?" across the entire codebase
|
|
14
|
+
- **Instant dependency mapping** — what imports what, direct and transitive, by package
|
|
15
|
+
- **Instant cycle detection** — circular imports found in <1ms
|
|
16
|
+
- **Zero false positives** — semantic references, not string matches
|
|
10
17
|
|
|
11
18
|
## The problem
|
|
12
19
|
|
|
@@ -16,15 +23,20 @@ Every wrong turn burns context tokens and degrades the agent's output.
|
|
|
16
23
|
|
|
17
24
|
## The difference
|
|
18
25
|
|
|
19
|
-
Measured on a real
|
|
26
|
+
Measured on a real 440-file TypeScript monorepo:
|
|
20
27
|
|
|
21
28
|
| | grep | typegraph-mcp |
|
|
22
29
|
|---|---|---|
|
|
23
|
-
| **
|
|
30
|
+
| **Context tokens** | ~113,000 | 1,006 |
|
|
24
31
|
| **Files touched** | 47 | 3 |
|
|
25
|
-
| **False positives** | dozens
|
|
32
|
+
| **False positives** | dozens | 0 |
|
|
33
|
+
| **Barrel file resolution** | reads 6 files, still guessing | 1 tool call, exact source |
|
|
34
|
+
| **Cross-package impact** | 1,038 string matches | 31 direct + 158 transitive, by package |
|
|
35
|
+
| **Circular dependency detection** | impossible | instant |
|
|
36
|
+
| **Avg latency (semantic)** | n/a | 16.9ms |
|
|
37
|
+
| **Avg latency (graph)** | n/a | 0.1ms |
|
|
26
38
|
|
|
27
|
-
**99% context reduction
|
|
39
|
+
**99% context reduction. 100% accuracy. [Full benchmarks](./BENCHMARKS.md).**
|
|
28
40
|
|
|
29
41
|
### Before: grep-based navigation
|
|
30
42
|
|
|
@@ -47,253 +59,113 @@ Agent: ts_trace_chain({ file: "src/handlers.ts", symbol: "createUser" })
|
|
|
47
59
|
|
|
48
60
|
## Quick start
|
|
49
61
|
|
|
50
|
-
###
|
|
62
|
+
### Step 1: Install
|
|
51
63
|
|
|
52
64
|
```bash
|
|
53
65
|
cd /path/to/your-ts-project
|
|
54
66
|
npx typegraph-mcp setup
|
|
55
67
|
```
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
# Clone and install
|
|
61
|
-
git clone https://github.com/guyowen/typegraph-mcp.git ~/typegraph-mcp
|
|
62
|
-
cd ~/typegraph-mcp && npm install
|
|
63
|
-
|
|
64
|
-
# Load the plugin
|
|
65
|
-
claude --plugin-dir ~/typegraph-mcp
|
|
66
|
-
```
|
|
69
|
+
The interactive setup auto-detects your AI agents, installs the plugin into `./plugins/typegraph-mcp/`, registers the MCP server, copies workflow skills, appends agent instructions, and runs verification. Use `--yes` to skip prompts.
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
- MCP server starts automatically with the correct environment
|
|
70
|
-
- 5 workflow skills teach Claude *when* and *how* to chain tools (impact analysis, refactor safety, dependency audit, code exploration, tool selection)
|
|
71
|
-
- `/typegraph:check` and `/typegraph:test` commands available in-session
|
|
72
|
-
- SessionStart hook verifies dependencies are installed
|
|
71
|
+
### Step 2: Launch your agent
|
|
73
72
|
|
|
74
|
-
|
|
73
|
+
**Claude Code** — load the plugin for the full experience:
|
|
75
74
|
|
|
76
75
|
```bash
|
|
77
|
-
|
|
78
|
-
git clone https://github.com/guyowen/typegraph-mcp.git ~/typegraph-mcp
|
|
79
|
-
cd ~/typegraph-mcp && npm install
|
|
80
|
-
|
|
81
|
-
# Run setup from your project root
|
|
82
|
-
cd /path/to/your-ts-project
|
|
83
|
-
npx tsx ~/typegraph-mcp/cli.ts setup
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
The interactive `setup` command (Options A and C):
|
|
87
|
-
1. Auto-detects which AI agents you use (Claude Code, Cursor, Codex CLI, Gemini CLI, GitHub Copilot)
|
|
88
|
-
2. Copies the plugin into `./plugins/typegraph-mcp/` and installs dependencies
|
|
89
|
-
3. Registers the MCP server in each agent's config file (`.mcp.json`, `.cursor/mcp.json`, `.codex/config.toml`, `.vscode/mcp.json`)
|
|
90
|
-
4. Copies workflow skills to `.agents/skills/` for agents that discover them there
|
|
91
|
-
5. Appends agent instructions to `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, or `.github/copilot-instructions.md`
|
|
92
|
-
6. Runs health checks and smoke tests to verify everything works
|
|
93
|
-
|
|
94
|
-
Use `--yes` to skip prompts and auto-select detected agents.
|
|
95
|
-
|
|
96
|
-
### Option D: Manual setup
|
|
97
|
-
|
|
98
|
-
If you prefer to configure things yourself:
|
|
99
|
-
|
|
100
|
-
1. Add to `.claude/mcp.json` in your project (or `~/.claude/mcp.json` for global):
|
|
101
|
-
|
|
102
|
-
```json
|
|
103
|
-
{
|
|
104
|
-
"mcpServers": {
|
|
105
|
-
"typegraph": {
|
|
106
|
-
"command": "npx",
|
|
107
|
-
"args": ["tsx", "/absolute/path/to/typegraph-mcp/server.ts"],
|
|
108
|
-
"env": {
|
|
109
|
-
"TYPEGRAPH_PROJECT_ROOT": ".",
|
|
110
|
-
"TYPEGRAPH_TSCONFIG": "./tsconfig.json"
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
76
|
+
claude --plugin-dir ./plugins/typegraph-mcp
|
|
115
77
|
```
|
|
116
78
|
|
|
117
|
-
|
|
79
|
+
This gives you 14 MCP tools, 5 workflow skills that teach Claude *when* and *how* to chain tools, `/typegraph:check`, `/typegraph:test`, and `/typegraph:bench` slash commands, and a SessionStart hook for dependency verification.
|
|
118
80
|
|
|
119
|
-
|
|
81
|
+
**Other agents** (Cursor, Codex CLI, Gemini CLI, GitHub Copilot) — restart your agent session. The MCP server and skills are already configured.
|
|
120
82
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
First query takes ~2s (tsserver warmup). Subsequent queries: 1–60ms.
|
|
83
|
+
First query takes ~2s (tsserver warmup). Subsequent queries: 1-60ms.
|
|
124
84
|
|
|
125
85
|
## Requirements
|
|
126
86
|
|
|
127
87
|
- **Node.js** >= 18
|
|
128
|
-
- **TypeScript** >= 5.0 in the target project
|
|
129
|
-
- **npm** for
|
|
130
|
-
|
|
131
|
-
## CLI
|
|
132
|
-
|
|
133
|
-
```
|
|
134
|
-
Usage: typegraph-mcp <command> [options]
|
|
135
|
-
|
|
136
|
-
Commands:
|
|
137
|
-
setup Install typegraph-mcp plugin into the current project
|
|
138
|
-
remove Uninstall typegraph-mcp from the current project
|
|
139
|
-
check Run health checks (12 checks)
|
|
140
|
-
test Run smoke tests (all 14 tools)
|
|
141
|
-
start Start the MCP server (stdin/stdout)
|
|
142
|
-
|
|
143
|
-
Options:
|
|
144
|
-
--yes Skip confirmation prompts (accept all defaults)
|
|
145
|
-
--help Show help
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Run any command with:
|
|
149
|
-
|
|
150
|
-
```bash
|
|
151
|
-
npx tsx ~/typegraph-mcp/cli.ts <command>
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### `setup`
|
|
155
|
-
|
|
156
|
-
Interactive project setup. Detects which AI agents you use, copies the plugin into `./plugins/typegraph-mcp/`, registers the MCP server in each agent's config, installs dependencies, and runs verification. If an existing installation is detected, offers Update/Remove/Exit.
|
|
157
|
-
|
|
158
|
-
### `remove`
|
|
159
|
-
|
|
160
|
-
Cleanly uninstalls typegraph-mcp from the project: removes the plugin directory, deregisters the MCP server from all agent configs (`.cursor/mcp.json`, `.codex/config.toml`, `.vscode/mcp.json`), strips agent instruction snippets, and cleans up `.agents/skills/`.
|
|
161
|
-
|
|
162
|
-
### `check`
|
|
163
|
-
|
|
164
|
-
Runs 12 health checks: Node.js version, TypeScript installation, tsconfig validity, MCP registration, dependency versions, etc. Every failing check shows a `Fix:` instruction.
|
|
165
|
-
|
|
166
|
-
### `test`
|
|
167
|
-
|
|
168
|
-
Exercises all 14 tools against the target project — graph build, dependency tree, cycle detection, go-to-definition, references, type info, and more. Dynamically discovers a file in the project to test against.
|
|
169
|
-
|
|
170
|
-
### `start`
|
|
171
|
-
|
|
172
|
-
Starts the MCP server on stdin/stdout. This is what the MCP client calls — you typically don't run this directly.
|
|
88
|
+
- **TypeScript** >= 5.0 in the target project
|
|
89
|
+
- **npm** for dependency installation
|
|
173
90
|
|
|
174
91
|
## Tools
|
|
175
92
|
|
|
176
|
-
### Semantic
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
93
|
+
### Semantic queries (tsserver)
|
|
94
|
+
|
|
95
|
+
| Tool | Description |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `ts_find_symbol` | Find a symbol's location in a file by name |
|
|
98
|
+
| `ts_definition` | Go to definition — resolves through imports, re-exports, barrel files, generics |
|
|
99
|
+
| `ts_references` | Find all semantic references (not string matches) |
|
|
100
|
+
| `ts_type_info` | Get type and documentation — same as VS Code hover |
|
|
101
|
+
| `ts_navigate_to` | Search for a symbol across the entire project |
|
|
102
|
+
| `ts_trace_chain` | Follow definition hops automatically, building a call chain |
|
|
103
|
+
| `ts_blast_radius` | Analyze impact of changing a symbol — all usage sites and affected files |
|
|
104
|
+
| `ts_module_exports` | List all exports from a module with resolved types |
|
|
105
|
+
|
|
106
|
+
### Import graph queries (oxc-parser + oxc-resolver)
|
|
107
|
+
|
|
108
|
+
| Tool | Description |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `ts_dependency_tree` | Transitive dependency tree of a file |
|
|
111
|
+
| `ts_dependents` | All files that depend on a given file, grouped by package |
|
|
112
|
+
| `ts_import_cycles` | Detect circular import dependencies |
|
|
113
|
+
| `ts_shortest_path` | Shortest import path between two files |
|
|
114
|
+
| `ts_subgraph` | Extract the neighborhood around seed files |
|
|
115
|
+
| `ts_module_boundary` | Analyze module coupling: incoming/outgoing edges, isolation score |
|
|
198
116
|
|
|
199
|
-
|
|
200
|
-
{ file: "src/services/Auth.ts", symbol: "validateToken" }
|
|
201
|
-
→ { references: [{ file, line, column, preview, isDefinition }], count }
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
#### `ts_type_info`
|
|
205
|
-
Get the TypeScript type and documentation — the same info you see hovering in VS Code.
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
{ file: "src/handlers.ts", symbol: "userService" }
|
|
209
|
-
→ { type: "const userService: { readonly getUser: ...", documentation: "..." }
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
#### `ts_navigate_to`
|
|
213
|
-
Search for a symbol across the entire project without knowing which file it's in.
|
|
214
|
-
|
|
215
|
-
```
|
|
216
|
-
{ symbol: "validateToken", maxResults: 10 }
|
|
217
|
-
→ { results: [{ file, line, column, kind, containerName }], count }
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
#### `ts_trace_chain`
|
|
221
|
-
Follow go-to-definition hops automatically, building a call chain from entry point to implementation.
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
{ file: "src/handlers.ts", symbol: "createUser", maxHops: 5 }
|
|
225
|
-
→ { chain: [{ file, line, column, preview }, ...], hops: 3 }
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
#### `ts_blast_radius`
|
|
229
|
-
Analyze the impact of changing a symbol — all usage sites and affected files.
|
|
117
|
+
## CLI
|
|
230
118
|
|
|
231
119
|
```
|
|
232
|
-
|
|
233
|
-
→ { directCallers: 12, filesAffected: ["src/handlers.ts", ...], callers: [...] }
|
|
234
|
-
```
|
|
120
|
+
typegraph-mcp <command> [options]
|
|
235
121
|
|
|
236
|
-
|
|
237
|
-
|
|
122
|
+
setup Install plugin into the current project
|
|
123
|
+
remove Uninstall from the current project
|
|
124
|
+
check Run 12 health checks
|
|
125
|
+
test Smoke test all 14 tools
|
|
126
|
+
bench Run benchmarks (token, latency, accuracy)
|
|
127
|
+
start Start the MCP server (stdin/stdout)
|
|
238
128
|
|
|
239
|
-
|
|
240
|
-
{ file: "src/services/Auth.ts" }
|
|
241
|
-
→ { exports: [{ symbol, kind, line, type }], count }
|
|
129
|
+
--yes Skip prompts --help Show help
|
|
242
130
|
```
|
|
243
131
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
These tools operate on the full import graph, built in ~100ms and kept current via `fs.watch`.
|
|
247
|
-
|
|
248
|
-
#### `ts_dependency_tree`
|
|
249
|
-
Transitive dependency tree of a file — what it depends on.
|
|
250
|
-
|
|
251
|
-
```
|
|
252
|
-
{ file: "src/handlers.ts", depth: 3, includeTypeOnly: false }
|
|
253
|
-
→ { root, nodes: 42, files: [...] }
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
#### `ts_dependents`
|
|
257
|
-
All files that depend on a given file, grouped by package.
|
|
258
|
-
|
|
259
|
-
```
|
|
260
|
-
{ file: "src/schemas/ids.ts" }
|
|
261
|
-
→ { nodes: 155, directCount: 31, byPackage: { "@my/core": [...] } }
|
|
262
|
-
```
|
|
132
|
+
## Troubleshooting
|
|
263
133
|
|
|
264
|
-
|
|
265
|
-
Detect circular import dependencies (strongly connected components).
|
|
134
|
+
Run the health check first — it catches most issues:
|
|
266
135
|
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
→ { count: 1, cycles: [["src/a.ts", "src/b.ts"]] }
|
|
136
|
+
```bash
|
|
137
|
+
npx typegraph-mcp check
|
|
270
138
|
```
|
|
271
139
|
|
|
272
|
-
|
|
273
|
-
|
|
140
|
+
| Symptom | Fix |
|
|
141
|
+
|---|---|
|
|
142
|
+
| Server won't start | `cd plugins/typegraph-mcp && npm install` |
|
|
143
|
+
| "TypeScript not found" | Add `typescript` to devDependencies |
|
|
144
|
+
| Tools return empty results | Check `TYPEGRAPH_TSCONFIG` points to the right tsconfig |
|
|
145
|
+
| Build errors from plugins/ | Add `"plugins/**"` to tsconfig.json `exclude` array |
|
|
274
146
|
|
|
275
|
-
|
|
276
|
-
{ from: "src/handlers.ts", to: "src/schemas/ids.ts" }
|
|
277
|
-
→ { path: ["handlers.ts", "schemas/index.ts", "schemas/ids.ts"], hops: 2 }
|
|
278
|
-
```
|
|
147
|
+
## Manual MCP configuration
|
|
279
148
|
|
|
280
|
-
|
|
281
|
-
Extract the neighborhood around seed files — imports, dependents, or both.
|
|
149
|
+
Add to `.claude/mcp.json` (or `~/.claude/mcp.json` for global):
|
|
282
150
|
|
|
283
|
-
```
|
|
284
|
-
{
|
|
285
|
-
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"mcpServers": {
|
|
154
|
+
"typegraph": {
|
|
155
|
+
"command": "npx",
|
|
156
|
+
"args": ["tsx", "/absolute/path/to/typegraph-mcp/server.ts"],
|
|
157
|
+
"env": {
|
|
158
|
+
"TYPEGRAPH_PROJECT_ROOT": ".",
|
|
159
|
+
"TYPEGRAPH_TSCONFIG": "./tsconfig.json"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
286
164
|
```
|
|
287
165
|
|
|
288
|
-
|
|
289
|
-
Analyze coupling of a module: incoming/outgoing edges, shared dependencies, isolation score.
|
|
166
|
+
`TYPEGRAPH_PROJECT_ROOT` resolves relative to the agent's working directory. The `args` path to `server.ts` must be absolute.
|
|
290
167
|
|
|
291
|
-
|
|
292
|
-
{ files: ["src/schemas/ids.ts", "src/schemas/queue.ts"] }
|
|
293
|
-
→ { internalEdges: 8, incomingEdges: [...], outgoingEdges: [...], isolationScore: 0.058 }
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Architecture
|
|
168
|
+
## How it works
|
|
297
169
|
|
|
298
170
|
```
|
|
299
171
|
AI Agent ─── stdin/stdout ─── MCP Server ─┬── tsserver (child process)
|
|
@@ -303,156 +175,63 @@ AI Agent ─── stdin/stdout ─── MCP Server ─┬── tsserver (chil
|
|
|
303
175
|
structural graph queries
|
|
304
176
|
```
|
|
305
177
|
|
|
306
|
-
### Plugin structure (Claude Code)
|
|
307
|
-
|
|
308
|
-
```
|
|
309
|
-
typegraph-mcp/
|
|
310
|
-
├── .claude-plugin/plugin.json # Plugin manifest
|
|
311
|
-
├── .mcp.json # Auto-configured MCP server
|
|
312
|
-
├── hooks/hooks.json # SessionStart dependency check
|
|
313
|
-
├── scripts/ensure-deps.sh # Installs node_modules if missing
|
|
314
|
-
├── commands/
|
|
315
|
-
│ ├── check.md # /typegraph:check
|
|
316
|
-
│ └── test.md # /typegraph:test
|
|
317
|
-
├── skills/
|
|
318
|
-
│ ├── tool-selection/ # Which of the 14 tools to use when
|
|
319
|
-
│ ├── impact-analysis/ # blast_radius + dependents + boundary
|
|
320
|
-
│ ├── refactor-safety/ # trace_chain + cycles + references
|
|
321
|
-
│ ├── dependency-audit/ # cycles + dependency_tree + boundary
|
|
322
|
-
│ └── code-exploration/ # navigate_to + trace_chain + subgraph
|
|
323
|
-
├── server.ts # MCP server entry point
|
|
324
|
-
├── cli.ts # CLI (setup, check, test, start)
|
|
325
|
-
└── ...
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### Server internals
|
|
329
|
-
|
|
330
178
|
Two subsystems start concurrently:
|
|
331
179
|
|
|
332
|
-
1. **tsserver** — child process for semantic queries. Communicates via pipes using tsserver's JSON protocol. Auto-restarts on crash (up to 3 times)
|
|
333
|
-
|
|
334
|
-
2. **Module graph** — in-process import graph built with [oxc-parser](https://github.com/nicolo-ribaudo/oxc-parser) (fast NAPI parser, no AST walking) and [oxc-resolver](https://github.com/nicolo-ribaudo/oxc-resolver) (tsconfig-aware resolution). Incrementally updated via `fs.watch`.
|
|
180
|
+
1. **tsserver** — child process for semantic queries. Communicates via pipes using tsserver's JSON protocol. Auto-restarts on crash (up to 3 times).
|
|
335
181
|
|
|
336
|
-
|
|
182
|
+
2. **Module graph** — in-process import graph built with [oxc-parser](https://github.com/nicolo-ribaudo/oxc-parser) and [oxc-resolver](https://github.com/nicolo-ribaudo/oxc-resolver). Incrementally updated via `fs.watch`.
|
|
337
183
|
|
|
338
|
-
|
|
184
|
+
**Monorepo support** — resolves through `composite` project references, maps `dist/` back to source, handles `extensionAlias` for `.js` → `.ts` mapping, and follows cross-package barrel re-exports.
|
|
339
185
|
|
|
340
|
-
|
|
341
|
-
- Maps `dist/` paths back to source (handles `outDir: "dist"` / `rootDir: "src"`)
|
|
342
|
-
- `extensionAlias` for NodeNext `.js` → `.ts` import mapping
|
|
343
|
-
- Cross-package barrel re-export resolution
|
|
186
|
+
## Contributing
|
|
344
187
|
|
|
345
|
-
|
|
188
|
+
### Setup from source
|
|
346
189
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
```javascript
|
|
352
|
-
ignores: [
|
|
353
|
-
"plugins/**",
|
|
354
|
-
]
|
|
190
|
+
```bash
|
|
191
|
+
git clone https://github.com/guyowen/typegraph-mcp.git
|
|
192
|
+
cd typegraph-mcp
|
|
193
|
+
npm install
|
|
355
194
|
```
|
|
356
195
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
### Agent instructions snippet
|
|
360
|
-
|
|
361
|
-
Add this to your agent instructions file (`CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, etc.) so the agent uses TypeGraph instead of grep:
|
|
196
|
+
### Run locally against a project
|
|
362
197
|
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
Use the `ts_*` MCP tools instead of grep/glob for navigating TypeScript code. They resolve through barrel files, re-exports, and project references — returning precise results, not string matches.
|
|
367
|
-
|
|
368
|
-
- **Point queries** (tsserver): `ts_find_symbol`, `ts_definition`, `ts_references`, `ts_type_info`, `ts_navigate_to`, `ts_trace_chain`, `ts_blast_radius`, `ts_module_exports`
|
|
369
|
-
- **Graph queries** (import graph): `ts_dependency_tree`, `ts_dependents`, `ts_import_cycles`, `ts_shortest_path`, `ts_subgraph`, `ts_module_boundary`
|
|
198
|
+
```bash
|
|
199
|
+
cd /path/to/your-ts-project
|
|
200
|
+
npx tsx ~/typegraph-mcp/cli.ts setup
|
|
370
201
|
```
|
|
371
202
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
Measured on a 440-file TypeScript monorepo (4 apps, 4 packages, 972 import edges). All scenarios were discovered dynamically from the module graph — no hardcoded symbols.
|
|
375
|
-
|
|
376
|
-
Run the benchmark on your own codebase:
|
|
203
|
+
Or start the MCP server directly:
|
|
377
204
|
|
|
378
205
|
```bash
|
|
379
|
-
TYPEGRAPH_PROJECT_ROOT=/path/to/project npx tsx ~/typegraph-mcp/
|
|
206
|
+
TYPEGRAPH_PROJECT_ROOT=/path/to/project TYPEGRAPH_TSCONFIG=/path/to/project/tsconfig.json npx tsx ~/typegraph-mcp/server.ts
|
|
380
207
|
```
|
|
381
208
|
|
|
382
|
-
###
|
|
383
|
-
|
|
384
|
-
How many context tokens the agent consumes to answer a query. grep requires reading entire matching files; typegraph returns structured JSON.
|
|
385
|
-
|
|
386
|
-
| Scenario | Symbol | grep tokens | typegraph tokens | Calls | Reduction |
|
|
387
|
-
|---|---|---|---|---|---|
|
|
388
|
-
| Barrel re-export resolution | `AwsSesConfig` | 9,880 | 6 | 2 | 99.9% |
|
|
389
|
-
| High-fanout symbol lookup | `TenantId` | 125,000 | 7 | 2 | 99.9% |
|
|
390
|
-
| Call chain tracing | `AccessMaterializationService` | 53,355 | 4 | 1 | 99.9% |
|
|
391
|
-
| Impact analysis | `ids` | 125,000 | 3,373 | 1 | 97.3% |
|
|
392
|
-
|
|
393
|
-
**Average: 99% token reduction.**
|
|
394
|
-
|
|
395
|
-
### Latency
|
|
396
|
-
|
|
397
|
-
Per-tool timing across 5 runs. Test file: `AddressServiceLive.ts` (auto-discovered).
|
|
398
|
-
|
|
399
|
-
| Tool | p50 | p95 | avg |
|
|
400
|
-
|---|---|---|---|
|
|
401
|
-
| `ts_find_symbol` | 1.8ms | 3.0ms | 2.0ms |
|
|
402
|
-
| `ts_definition` | 0.3ms | 4.5ms | 1.1ms |
|
|
403
|
-
| `ts_references` | 13.3ms | 227.3ms | 56.4ms |
|
|
404
|
-
| `ts_type_info` | 1.0ms | 4.2ms | 1.7ms |
|
|
405
|
-
| `ts_navigate_to` | 32.4ms | 61.9ms | 38.3ms |
|
|
406
|
-
| `ts_module_exports` | 1.6ms | 2.2ms | 1.7ms |
|
|
407
|
-
| `ts_dependency_tree` | 0.0ms | 0.2ms | 0.1ms |
|
|
408
|
-
| `ts_dependents` | 0.0ms | 0.0ms | 0.0ms |
|
|
409
|
-
| `ts_import_cycles` | 0.3ms | 0.6ms | 0.3ms |
|
|
410
|
-
| `ts_shortest_path` | 0.0ms | 0.1ms | 0.0ms |
|
|
411
|
-
| `ts_subgraph` | 0.1ms | 0.3ms | 0.2ms |
|
|
412
|
-
| `ts_module_boundary` | 0.2ms | 0.3ms | 0.2ms |
|
|
413
|
-
|
|
414
|
-
**tsserver queries: 16.9ms avg. Graph queries: 0.1ms avg.**
|
|
415
|
-
|
|
416
|
-
### Accuracy
|
|
417
|
-
|
|
418
|
-
| Scenario | grep | typegraph |
|
|
419
|
-
|---|---|---|
|
|
420
|
-
| **Barrel resolution** — find where `AwsSesConfig` is defined, not re-exported | 13 matches across 6 files. Agent must read each to distinguish definition from re-exports. | Resolves directly to source definition in 1 tool call. |
|
|
421
|
-
| **Same-name disambiguation** — distinguish `CoreApiClient` from `CoreApiClientRpcLive`, `CoreApiClientTest`, etc. | 278 matches, 90 of which are variant names sharing the prefix. | 2 exact matches: `CoreApiClient.ts:103` [class], `index.ts:82` [alias]. |
|
|
422
|
-
| **Type-only vs runtime imports** — classify imports in a file with both kinds | `grep "import"` shows all imports. Agent must parse each line to check for `import type`. | 1 type-only, 13 runtime — classified automatically by the module graph. |
|
|
423
|
-
| **Cross-package impact** — find everything that depends on `ids.ts` | 1,038 matches for "ids". Cannot distinguish direct vs transitive or follow re-exports. | 31 direct, 158 transitive. Broken down by package. |
|
|
424
|
-
| **Circular dependency detection** | Impossible with grep. | 1 cycle: `TodoService.ts` <-> `TodoHistoryService.ts`. |
|
|
425
|
-
|
|
426
|
-
**5/5 typegraph wins.**
|
|
427
|
-
|
|
428
|
-
### Run your own benchmark
|
|
429
|
-
|
|
430
|
-
The benchmark is fully dynamic — it discovers scenarios from the module graph, so it works on any TypeScript project:
|
|
209
|
+
### Load as a Claude Code plugin (from source)
|
|
431
210
|
|
|
432
211
|
```bash
|
|
433
|
-
|
|
434
|
-
TYPEGRAPH_PROJECT_ROOT=/path/to/project npx tsx benchmark.ts
|
|
212
|
+
claude --plugin-dir ~/typegraph-mcp
|
|
435
213
|
```
|
|
436
214
|
|
|
437
|
-
|
|
215
|
+
### Verify your changes
|
|
438
216
|
|
|
439
|
-
|
|
217
|
+
```bash
|
|
218
|
+
npx tsx ~/typegraph-mcp/cli.ts check # 12 health checks
|
|
219
|
+
npx tsx ~/typegraph-mcp/cli.ts test # smoke test all 14 tools
|
|
220
|
+
```
|
|
440
221
|
|
|
441
|
-
|
|
222
|
+
### Build compiled output
|
|
442
223
|
|
|
443
224
|
```bash
|
|
444
|
-
|
|
225
|
+
npm run build # compiles to dist/ via tsup
|
|
445
226
|
```
|
|
446
227
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
| Tools return empty results | tsconfig misconfigured | Check `TYPEGRAPH_TSCONFIG` points to the right file |
|
|
452
|
-
| MCP registration not found | Wrong path in config | Verify the `args` path to `server.ts` is absolute |
|
|
228
|
+
### Branch workflow
|
|
229
|
+
|
|
230
|
+
- **`dev`** — all work happens here
|
|
231
|
+
- **`main`** — merge to main triggers CI: auto-bumps patch version, publishes to npm via OIDC trusted publishers
|
|
453
232
|
|
|
454
233
|
## Known limitations
|
|
455
234
|
|
|
456
235
|
- **Object literal property keys** (e.g., RPC handler names) are not indexed by tsserver's `navto`. Use `ts_find_symbol` with a specific file, or pass the `file` hint to `ts_navigate_to`.
|
|
457
|
-
- **First query latency** — ~2s as tsserver loads the project. Subsequent queries
|
|
458
|
-
- **Memory** — tsserver holds the project in memory. For very large monorepos (1000+ files), expect ~200
|
|
236
|
+
- **First query latency** — ~2s as tsserver loads the project. Subsequent queries: 1-60ms.
|
|
237
|
+
- **Memory** — tsserver holds the project in memory. For very large monorepos (1000+ files), expect ~200-500MB RSS.
|
package/benchmark.ts
CHANGED
|
@@ -27,7 +27,8 @@ import { resolveConfig } from "./config.js";
|
|
|
27
27
|
|
|
28
28
|
// ─── Configuration ───────────────────────────────────────────────────────────
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
let projectRoot!: string;
|
|
31
|
+
let tsconfigPath!: string;
|
|
31
32
|
|
|
32
33
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
33
34
|
|
|
@@ -665,7 +666,8 @@ async function benchmarkAccuracy(
|
|
|
665
666
|
|
|
666
667
|
// ─── Main ────────────────────────────────────────────────────────────────────
|
|
667
668
|
|
|
668
|
-
async function main() {
|
|
669
|
+
export async function main(config?: { projectRoot: string; tsconfigPath: string }) {
|
|
670
|
+
({ projectRoot, tsconfigPath } = config ?? resolveConfig(import.meta.dirname));
|
|
669
671
|
console.log("");
|
|
670
672
|
console.log("typegraph-mcp Benchmark");
|
|
671
673
|
console.log("=======================");
|
package/cli.ts
CHANGED
|
@@ -141,6 +141,7 @@ Commands:
|
|
|
141
141
|
remove Uninstall typegraph-mcp from the current project
|
|
142
142
|
check Run health checks (12 checks)
|
|
143
143
|
test Run smoke tests (all 14 tools)
|
|
144
|
+
bench Run benchmarks (token, latency, accuracy)
|
|
144
145
|
start Start the MCP server (stdin/stdout)
|
|
145
146
|
|
|
146
147
|
Options:
|
|
@@ -723,9 +724,9 @@ async function runVerification(pluginDir: string, selectedAgents: AgentId[]): Pr
|
|
|
723
724
|
|
|
724
725
|
if (checkResult.failed === 0 && testResult.failed === 0) {
|
|
725
726
|
if (selectedAgents.includes("claude-code")) {
|
|
726
|
-
p.outro("Setup complete! Run: claude --plugin-dir ./plugins/typegraph-mcp");
|
|
727
|
+
p.outro("Setup complete! Run: claude --plugin-dir ./plugins/typegraph-mcp\n Slash commands: /typegraph:check, /typegraph:test, /typegraph:bench");
|
|
727
728
|
} else {
|
|
728
|
-
p.outro("Setup complete! typegraph-mcp tools are now available to your agents
|
|
729
|
+
p.outro("Setup complete! typegraph-mcp tools are now available to your agents.\n CLI: npx typegraph-mcp check | test | bench");
|
|
729
730
|
}
|
|
730
731
|
} else {
|
|
731
732
|
p.cancel("Setup completed with issues. Fix the failures above and re-run.");
|
|
@@ -786,6 +787,14 @@ async function test(): Promise<void> {
|
|
|
786
787
|
process.exit(result.failed > 0 ? 1 : 0);
|
|
787
788
|
}
|
|
788
789
|
|
|
790
|
+
// ─── Benchmark Command ───────────────────────────────────────────────────────
|
|
791
|
+
|
|
792
|
+
async function benchmark(): Promise<void> {
|
|
793
|
+
const config = resolveConfig(resolvePluginDir());
|
|
794
|
+
const { main: benchMain } = await import("./benchmark.js");
|
|
795
|
+
await benchMain(config);
|
|
796
|
+
}
|
|
797
|
+
|
|
789
798
|
// ─── Start Command ───────────────────────────────────────────────────────────
|
|
790
799
|
|
|
791
800
|
async function start(): Promise<void> {
|
|
@@ -829,6 +838,13 @@ switch (command) {
|
|
|
829
838
|
process.exit(1);
|
|
830
839
|
});
|
|
831
840
|
break;
|
|
841
|
+
case "bench":
|
|
842
|
+
case "benchmark":
|
|
843
|
+
benchmark().catch((err) => {
|
|
844
|
+
console.error("Fatal:", err);
|
|
845
|
+
process.exit(1);
|
|
846
|
+
});
|
|
847
|
+
break;
|
|
832
848
|
case "start":
|
|
833
849
|
start().catch((err) => {
|
|
834
850
|
console.error("Fatal:", err);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Run typegraph-mcp benchmarks (token, latency, accuracy)
|
|
3
|
+
argument-hint: []
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TypeGraph Benchmark
|
|
7
|
+
|
|
8
|
+
Run benchmarks to measure typegraph-mcp performance on this project.
|
|
9
|
+
|
|
10
|
+
## Instructions
|
|
11
|
+
|
|
12
|
+
1. Run the benchmark command:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx tsx ${CLAUDE_PLUGIN_ROOT}/cli.ts bench
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. Parse the output and report results:
|
|
19
|
+
- **Token comparison**: grep tokens vs typegraph tokens per scenario, with reduction percentage
|
|
20
|
+
- **Latency**: p50, p95, and average per tool
|
|
21
|
+
- **Accuracy**: grep vs typegraph for each scenario, with verdict
|
|
22
|
+
- **Summary**: average token reduction, average query latency, accuracy score
|
|
23
|
+
|
|
24
|
+
3. The benchmark dynamically discovers symbols and scenarios from the project's module graph. Scenarios that don't apply to this codebase are skipped.
|