typegraph-mcp 0.9.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/.claude-plugin/plugin.json +17 -0
- package/.cursor-plugin/plugin.json +17 -0
- package/.mcp.json +10 -0
- package/LICENSE +21 -0
- package/README.md +451 -0
- package/benchmark.ts +735 -0
- package/check.ts +459 -0
- package/cli.ts +778 -0
- package/commands/check.md +23 -0
- package/commands/test.md +23 -0
- package/config.ts +50 -0
- package/gemini-extension.json +16 -0
- package/graph-queries.ts +462 -0
- package/hooks/hooks.json +15 -0
- package/module-graph.ts +507 -0
- package/package.json +39 -0
- package/scripts/ensure-deps.sh +34 -0
- package/server.ts +837 -0
- package/skills/code-exploration/SKILL.md +55 -0
- package/skills/dependency-audit/SKILL.md +50 -0
- package/skills/impact-analysis/SKILL.md +52 -0
- package/skills/refactor-safety/SKILL.md +50 -0
- package/skills/tool-selection/SKILL.md +79 -0
- package/smoke-test.ts +500 -0
- package/tsserver-client.ts +413 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Code Exploration Workflow
|
|
2
|
+
|
|
3
|
+
Efficiently explore unfamiliar TypeScript code using navigation tools instead of reading entire files.
|
|
4
|
+
|
|
5
|
+
## When to Activate
|
|
6
|
+
|
|
7
|
+
- User asks "how does X work?" or "walk me through the code for X"
|
|
8
|
+
- Exploring a new codebase or unfamiliar module
|
|
9
|
+
- Understanding the architecture or data flow of a feature
|
|
10
|
+
- Tracing a request from API handler to database
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
### Step 1: Find the Entry Point
|
|
15
|
+
If you know the symbol name but not the file:
|
|
16
|
+
- Call `ts_navigate_to` with the symbol name
|
|
17
|
+
|
|
18
|
+
If you know the file:
|
|
19
|
+
- Call `ts_module_exports` to see what the file provides
|
|
20
|
+
- Call `ts_find_symbol` to locate a specific symbol within it
|
|
21
|
+
|
|
22
|
+
### Step 2: Understand the Type
|
|
23
|
+
Call `ts_type_info` on the entry point symbol. This gives you the full type signature and documentation without reading the entire file.
|
|
24
|
+
|
|
25
|
+
### Step 3: Trace the Implementation
|
|
26
|
+
Call `ts_trace_chain` to follow the definition chain from the entry point to the implementation. Each hop shows the file, line, and a code preview.
|
|
27
|
+
|
|
28
|
+
### Step 4: Explore the Neighborhood
|
|
29
|
+
Call `ts_subgraph` with the key files discovered in step 3 to see the surrounding module structure. Use `direction: "both"` and `depth: 1` for immediate context.
|
|
30
|
+
|
|
31
|
+
### Step 5: Deep Dive Where Needed
|
|
32
|
+
Only now, read specific files at the lines identified by the tools. You have precise coordinates — no need to read entire files.
|
|
33
|
+
|
|
34
|
+
## Key Principle
|
|
35
|
+
|
|
36
|
+
**Never start by reading entire files.** Use navigation tools to find the exact lines that matter, then read only those lines. This saves context tokens and produces more accurate understanding.
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
User: "How does the magic link authentication flow work?"
|
|
42
|
+
|
|
43
|
+
1. ts_navigate_to({ symbol: "MagicLinkHandler" })
|
|
44
|
+
-> Found in apps/core-api/src/entrypoints/magic-link.ts
|
|
45
|
+
|
|
46
|
+
2. ts_type_info -> Shows handler signature with ClaimToken input, AuthResult output
|
|
47
|
+
|
|
48
|
+
3. ts_trace_chain -> 4 hops:
|
|
49
|
+
magic-link.ts -> ClaimService.ts -> TokenRepository.ts -> tenant-context.ts
|
|
50
|
+
|
|
51
|
+
4. ts_subgraph({ files: [those 4 files], depth: 1 })
|
|
52
|
+
-> Shows AuthService and NotificationService also connect to ClaimService
|
|
53
|
+
|
|
54
|
+
5. Read the specific lines at each hop to explain the flow
|
|
55
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Dependency Audit Workflow
|
|
2
|
+
|
|
3
|
+
Audit module dependencies to find circular imports, analyze coupling, and understand the dependency structure.
|
|
4
|
+
|
|
5
|
+
## When to Activate
|
|
6
|
+
|
|
7
|
+
- User asks about circular dependencies or import cycles
|
|
8
|
+
- User wants to understand the module structure or dependency graph
|
|
9
|
+
- User asks about coupling between packages or modules
|
|
10
|
+
- Debugging import-related issues (circular deps, missing exports)
|
|
11
|
+
- Evaluating module boundaries for extraction or reorganization
|
|
12
|
+
|
|
13
|
+
## Workflow
|
|
14
|
+
|
|
15
|
+
### Step 1: Detect Cycles
|
|
16
|
+
Call `ts_import_cycles` (no filter for project-wide, or with a file/package filter for targeted analysis).
|
|
17
|
+
|
|
18
|
+
### Step 2: Analyze Hotspots
|
|
19
|
+
For each cycle found, call `ts_dependency_tree` on the files in the cycle to understand why the cycle exists (what each file needs from the other).
|
|
20
|
+
|
|
21
|
+
### Step 3: Measure Coupling
|
|
22
|
+
Call `ts_module_boundary` on the package or directory you want to analyze. The isolation score quantifies how self-contained it is:
|
|
23
|
+
- **> 0.7**: Well isolated
|
|
24
|
+
- **0.3 - 0.7**: Moderate coupling
|
|
25
|
+
- **< 0.3**: Tightly coupled (candidate for restructuring)
|
|
26
|
+
|
|
27
|
+
### Step 4: Map Cross-Package Dependencies
|
|
28
|
+
Call `ts_dependents` on key files to see the cross-package dependency picture. The `byPackage` grouping shows which packages depend on what.
|
|
29
|
+
|
|
30
|
+
### Step 5: Report
|
|
31
|
+
Present findings as:
|
|
32
|
+
1. **Cycles found** (count + file lists)
|
|
33
|
+
2. **Coupling scores** (per module/directory)
|
|
34
|
+
3. **Cross-package dependencies** (dependency direction violations, if any)
|
|
35
|
+
4. **Recommendations** (break cycles, reduce coupling, extract modules)
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
User: "Are there any circular dependencies in the project?"
|
|
41
|
+
|
|
42
|
+
1. ts_import_cycles() -> 1 cycle: TodoService.ts <-> TodoHistoryService.ts
|
|
43
|
+
2. ts_dependency_tree({ file: "TodoService.ts" }) -> imports TodoHistoryService for history recording
|
|
44
|
+
ts_dependency_tree({ file: "TodoHistoryService.ts" }) -> imports TodoService for status lookup
|
|
45
|
+
3. ts_module_boundary({ files: [services directory files] }) -> isolation: 0.42 (moderate)
|
|
46
|
+
|
|
47
|
+
Report: 1 circular dependency found between TodoService and TodoHistoryService.
|
|
48
|
+
Root cause: mutual dependency for history recording + status lookup.
|
|
49
|
+
Recommendation: Extract shared types into a separate file to break the cycle.
|
|
50
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Impact Analysis Workflow
|
|
2
|
+
|
|
3
|
+
Analyze the impact of changing a TypeScript symbol by combining blast radius, dependents, and module boundary analysis.
|
|
4
|
+
|
|
5
|
+
## When to Activate
|
|
6
|
+
|
|
7
|
+
- User asks "what will break if I change X?"
|
|
8
|
+
- User asks about the impact or blast radius of a change
|
|
9
|
+
- Before modifying a widely-used symbol, type, or interface
|
|
10
|
+
- Assessing risk of a refactor
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
### Step 1: Blast Radius
|
|
15
|
+
Call `ts_blast_radius` with the file and symbol to get direct callers and affected files.
|
|
16
|
+
|
|
17
|
+
### Step 2: Assess Scope
|
|
18
|
+
- If **< 5 callers**: Low impact. Report the callers and you're done.
|
|
19
|
+
- If **5-20 callers**: Medium impact. Proceed to step 3 for package breakdown.
|
|
20
|
+
- If **> 20 callers**: High impact. Proceed to steps 3 and 4.
|
|
21
|
+
|
|
22
|
+
### Step 3: Package Breakdown
|
|
23
|
+
Call `ts_dependents` on the file to see the transitive impact grouped by package. This shows whether the change is contained to one package or crosses boundaries.
|
|
24
|
+
|
|
25
|
+
### Step 4: Module Boundary (for high-impact changes)
|
|
26
|
+
Call `ts_module_boundary` with the affected files to understand the coupling. A low isolation score means the change is tightly coupled to external code.
|
|
27
|
+
|
|
28
|
+
### Step 5: Report
|
|
29
|
+
Present findings as:
|
|
30
|
+
1. **Direct callers** (count + file list)
|
|
31
|
+
2. **Packages affected** (from dependents breakdown)
|
|
32
|
+
3. **Risk assessment** (low/medium/high based on caller count and cross-package spread)
|
|
33
|
+
4. **Suggested approach** (safe migration steps if high impact)
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
User: "What happens if I change the TenantId schema?"
|
|
39
|
+
|
|
40
|
+
1. ts_blast_radius({ file: "packages/core/src/schemas/ids.ts", symbol: "TenantId" })
|
|
41
|
+
-> 45 direct callers across 28 files
|
|
42
|
+
|
|
43
|
+
2. ts_dependents({ file: "packages/core/src/schemas/ids.ts" })
|
|
44
|
+
-> 158 transitive dependents across 4 packages
|
|
45
|
+
|
|
46
|
+
3. ts_module_boundary({ files: ["packages/core/src/schemas/ids.ts"] })
|
|
47
|
+
-> isolation score: 0.058 (highly coupled)
|
|
48
|
+
|
|
49
|
+
Report: HIGH IMPACT. 45 direct usages across 28 files in 4 packages.
|
|
50
|
+
The schemas module has very low isolation (0.058).
|
|
51
|
+
Recommend: add new schema alongside old, migrate callers incrementally, then remove old.
|
|
52
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Refactor Safety Check Workflow
|
|
2
|
+
|
|
3
|
+
Verify a refactor is safe before making changes by checking call chains, circular dependencies, and module boundaries.
|
|
4
|
+
|
|
5
|
+
## When to Activate
|
|
6
|
+
|
|
7
|
+
- User is about to rename, move, or restructure TypeScript modules
|
|
8
|
+
- User asks "is it safe to refactor X?"
|
|
9
|
+
- Before extracting code into a new module or package
|
|
10
|
+
- Before changing an interface or service definition
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
### Step 1: Trace the Chain
|
|
15
|
+
Call `ts_trace_chain` on the symbol being refactored to understand its full definition chain. This reveals all the layers of indirection the refactor needs to preserve.
|
|
16
|
+
|
|
17
|
+
### Step 2: Check for Cycles
|
|
18
|
+
Call `ts_import_cycles` filtered to the file being refactored. If the file participates in a cycle, the refactor must not break or worsen it.
|
|
19
|
+
|
|
20
|
+
### Step 3: Assess Boundaries
|
|
21
|
+
Call `ts_module_boundary` with the files involved in the refactor (source + destination). Check:
|
|
22
|
+
- **Incoming edges**: Other code that imports from these files (must be preserved)
|
|
23
|
+
- **Outgoing edges**: Dependencies these files need (must be available at new location)
|
|
24
|
+
- **Isolation score**: How self-contained the module is
|
|
25
|
+
|
|
26
|
+
### Step 4: Verify References
|
|
27
|
+
Call `ts_references` on the key symbol to get the complete list of call sites that need updating.
|
|
28
|
+
|
|
29
|
+
### Step 5: Report
|
|
30
|
+
Present a safety assessment:
|
|
31
|
+
1. **Definition chain** (what indirection exists)
|
|
32
|
+
2. **Cycle involvement** (any circular dependencies to be aware of)
|
|
33
|
+
3. **Boundary analysis** (incoming/outgoing edges, isolation)
|
|
34
|
+
4. **Call sites to update** (complete list from references)
|
|
35
|
+
5. **GO / CAUTION / STOP** recommendation
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
User: "I want to move AuthService from packages/core to apps/gateway"
|
|
41
|
+
|
|
42
|
+
1. ts_trace_chain -> AuthService defined in core, consumed via Layer in gateway
|
|
43
|
+
2. ts_import_cycles -> No cycles involving AuthService.ts
|
|
44
|
+
3. ts_module_boundary -> 12 incoming edges (other core modules import it), 3 outgoing
|
|
45
|
+
4. ts_references -> 23 references across 15 files
|
|
46
|
+
|
|
47
|
+
CAUTION: AuthService has 12 incoming edges within packages/core.
|
|
48
|
+
Moving it to apps/gateway would break the core -> gateway dependency direction.
|
|
49
|
+
Consider: keep the interface in core, move only the Live implementation.
|
|
50
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# TypeGraph Tool Selection Guide
|
|
2
|
+
|
|
3
|
+
Select the right typegraph-mcp tool for the task at hand. These tools provide type-aware TypeScript navigation — use them instead of grep/glob for any TypeScript codebase navigation.
|
|
4
|
+
|
|
5
|
+
## When to Activate
|
|
6
|
+
|
|
7
|
+
- Navigating TypeScript code (finding definitions, references, types)
|
|
8
|
+
- Exploring unfamiliar code or understanding how modules connect
|
|
9
|
+
- Preparing to refactor or modify TypeScript symbols
|
|
10
|
+
- Answering questions about code structure, dependencies, or impact
|
|
11
|
+
- Any task where you would otherwise use grep/glob to find TypeScript symbols
|
|
12
|
+
|
|
13
|
+
## Tool Selection Decision Tree
|
|
14
|
+
|
|
15
|
+
### "Where is X defined?"
|
|
16
|
+
Use **ts_definition** with the file + symbol name (or line+column). Resolves through barrel files, re-exports, and project references.
|
|
17
|
+
|
|
18
|
+
### "I don't know which file X is in"
|
|
19
|
+
Use **ts_navigate_to** with just the symbol name. Searches the entire project. For object literal keys (like RPC handlers), also pass a `file` hint.
|
|
20
|
+
|
|
21
|
+
### "What is the type of X?"
|
|
22
|
+
Use **ts_type_info** — returns the same info as hovering in VS Code. Includes documentation.
|
|
23
|
+
|
|
24
|
+
### "What are all the exports of this file?"
|
|
25
|
+
Use **ts_module_exports** — lists all exported symbols with their resolved types.
|
|
26
|
+
|
|
27
|
+
### "Where is X used?"
|
|
28
|
+
Use **ts_references** for all semantic references. Unlike grep, this returns only real code references, not string matches in comments or unrelated variables.
|
|
29
|
+
|
|
30
|
+
### "What breaks if I change X?"
|
|
31
|
+
Use **ts_blast_radius** — finds all usage sites and groups them by file. This is the starting point for impact analysis.
|
|
32
|
+
|
|
33
|
+
### "How does the code get from A to B?"
|
|
34
|
+
Use **ts_trace_chain** — follows go-to-definition hops automatically, building a call chain. Stops at the bottom of the chain or at node_modules boundaries.
|
|
35
|
+
|
|
36
|
+
### "What does this file import?"
|
|
37
|
+
Use **ts_dependency_tree** for the transitive import tree. Set `depth` to limit traversal.
|
|
38
|
+
|
|
39
|
+
### "What imports this file?"
|
|
40
|
+
Use **ts_dependents** — all files that depend on a given file, grouped by package. Shows both direct and transitive dependents.
|
|
41
|
+
|
|
42
|
+
### "Are there circular imports?"
|
|
43
|
+
Use **ts_import_cycles** — detects strongly connected components. Filter by file or package.
|
|
44
|
+
|
|
45
|
+
### "How does module A reach module B?"
|
|
46
|
+
Use **ts_shortest_path** — finds the shortest import path between two files in the module graph.
|
|
47
|
+
|
|
48
|
+
### "What's the neighborhood around these files?"
|
|
49
|
+
Use **ts_subgraph** — extracts nodes and edges around seed files, expanding by depth in any direction (imports, dependents, or both).
|
|
50
|
+
|
|
51
|
+
### "How coupled is this module?"
|
|
52
|
+
Use **ts_module_boundary** — analyzes incoming/outgoing edges, shared dependencies, and computes an isolation score.
|
|
53
|
+
|
|
54
|
+
## Key Principles
|
|
55
|
+
|
|
56
|
+
1. **Always prefer ts_* tools over grep/glob** for TypeScript navigation. They resolve through barrel files, re-exports, and project references.
|
|
57
|
+
2. **Start narrow, expand if needed.** Use ts_definition or ts_find_symbol first. Only use ts_navigate_to (project-wide search) when you don't know the file.
|
|
58
|
+
3. **Combine tools for workflows.** Impact analysis = ts_blast_radius + ts_dependents. Refactor safety = ts_trace_chain + ts_import_cycles.
|
|
59
|
+
4. **Graph queries are instant** (~0.1ms). Point queries are fast (~2-50ms). Don't hesitate to use them liberally.
|
|
60
|
+
5. **First query may be slow** (~2s) as tsserver warms up. All subsequent queries are fast.
|
|
61
|
+
|
|
62
|
+
## Tool Reference
|
|
63
|
+
|
|
64
|
+
| Tool | Input | Best For |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `ts_find_symbol` | file + symbol name | Locating a symbol when you know the file |
|
|
67
|
+
| `ts_definition` | file + symbol (or line+col) | Go-to-definition through any indirection |
|
|
68
|
+
| `ts_references` | file + symbol (or line+col) | All semantic references to a symbol |
|
|
69
|
+
| `ts_type_info` | file + symbol (or line+col) | Type signature and documentation |
|
|
70
|
+
| `ts_navigate_to` | symbol name (+ optional file) | Project-wide symbol search |
|
|
71
|
+
| `ts_trace_chain` | file + symbol + maxHops | Following a call chain to implementation |
|
|
72
|
+
| `ts_blast_radius` | file + symbol | Impact analysis for changes |
|
|
73
|
+
| `ts_module_exports` | file | Listing a module's public API |
|
|
74
|
+
| `ts_dependency_tree` | file (+ depth) | What a file depends on |
|
|
75
|
+
| `ts_dependents` | file (+ depth) | What depends on a file |
|
|
76
|
+
| `ts_import_cycles` | optional file/package filter | Circular dependency detection |
|
|
77
|
+
| `ts_shortest_path` | from file + to file | Import path between two files |
|
|
78
|
+
| `ts_subgraph` | seed files + depth + direction | Neighborhood extraction |
|
|
79
|
+
| `ts_module_boundary` | file list | Module coupling analysis |
|