trace-mcp 0.1.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/LICENSE ADDED
@@ -0,0 +1,137 @@
1
+ Elastic License 2.0 + Ethical Use Addendum
2
+
3
+ Copyright 2026 Nikolai Vysotskyi
4
+
5
+ URL: https://www.elastic.co/licensing/elastic-license
6
+
7
+ ## Acceptance
8
+
9
+ By using the software, you agree to all of the terms and conditions below.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
14
+ non-sublicensable, non-transferable license to use, copy, distribute, make
15
+ available, and prepare derivative works of the software, in each case subject
16
+ to the limitations and conditions below.
17
+
18
+ ## Limitations
19
+
20
+ You may not provide the software to third parties as a hosted or managed
21
+ service, where the service provides users with access to any substantial set
22
+ of the features or functionality of the software.
23
+
24
+ You may not alter, remove, or obscure any licensing, copyright, or other
25
+ notices of the licensor in the software. Any use of the licensor's trademarks
26
+ is subject to applicable law.
27
+
28
+ ## Ethical Use Restrictions
29
+
30
+ In addition to the limitations above, you may NOT use, deploy, integrate, or
31
+ incorporate this software (in whole or in part, directly or indirectly) in any
32
+ of the following contexts:
33
+
34
+ ### 1. Military and Warfare
35
+
36
+ (a) Military operations, including but not limited to combat planning,
37
+ logistics of armed conflict, targeting, and battlefield management.
38
+ (b) Development, production, testing, maintenance, or deployment of weapons,
39
+ weapons systems, munitions, or military-grade equipment.
40
+ (c) Military intelligence gathering or military reconnaissance.
41
+
42
+ ### 2. Violence and Harm
43
+
44
+ (a) Any project, product, or service whose purpose or foreseeable effect is to
45
+ facilitate, promote, or cause physical violence against individuals or
46
+ groups.
47
+ (b) Development or operation of autonomous systems designed to cause physical
48
+ harm to persons.
49
+
50
+ ### 3. Surveillance
51
+
52
+ (a) Mass surveillance of populations, including but not limited to: collection,
53
+ aggregation, or analysis of personal data of individuals without their
54
+ informed, voluntary consent and without lawful authority.
55
+ (b) Social scoring systems that rank, classify, or restrict individuals' rights
56
+ or access to services based on aggregated behavioral data.
57
+ (c) Facial recognition or biometric identification systems used for tracking
58
+ individuals without their explicit consent.
59
+
60
+ ### 4. Discrimination and Oppression
61
+
62
+ (a) Any use that facilitates discrimination, oppression, or persecution of
63
+ individuals or groups based on race, ethnicity, national origin, religion,
64
+ gender, sexual orientation, disability, or political opinion.
65
+ (b) Any use in systems designed to suppress freedom of expression, freedom of
66
+ assembly, or freedom of the press.
67
+
68
+ ## Ethical Restrictions Apply to Derivative Works
69
+
70
+ Any derivative work based on this software, in whole or in part, must retain
71
+ and be subject to the Ethical Use Restrictions set forth above. You may not
72
+ re-license, sublicense, or otherwise distribute derivative works under terms
73
+ that remove, weaken, or circumvent these restrictions.
74
+
75
+ ## Clarifications
76
+
77
+ - Use by civilian government agencies for non-military, non-surveillance
78
+ purposes (e.g., healthcare, education, public infrastructure) is permitted.
79
+ - Use by medical or humanitarian organizations, including those operating in
80
+ conflict zones for the purpose of saving lives, is permitted.
81
+ - Security research, defensive cybersecurity, and lawful penetration testing
82
+ are permitted.
83
+ - Standard business analytics and application monitoring that process only
84
+ aggregated, anonymized data are not considered surveillance.
85
+ - Law enforcement use is permitted only where it does not conflict with the
86
+ Ethical Use Restrictions above.
87
+
88
+ ## Notices
89
+
90
+ You must ensure that anyone who gets a copy of any part of the software from
91
+ you also gets a copy of these terms.
92
+
93
+ If you modify the software, you must include in any modified copies of the
94
+ software prominent notices stating that you have modified the software.
95
+
96
+ ## No Other Rights
97
+
98
+ These terms do not imply any licenses other than those expressly granted in
99
+ these terms.
100
+
101
+ ## Termination
102
+
103
+ If you use the software in violation of these terms, such use is not licensed,
104
+ and your licenses will automatically terminate. If the licensor provides you
105
+ with a notice of your violation, and you cease all violation of these terms no
106
+ later than 30 days after you receive that notice, your licenses will be
107
+ reinstated retroactively. However, if you violate these terms after such
108
+ reinstatement, any additional violation of these terms will cause your licenses
109
+ to terminate automatically and permanently.
110
+
111
+ ## No Liability
112
+
113
+ As far as the law allows, the software comes as is, without any warranty or
114
+ condition, and the licensor will not be liable to you for any damages arising
115
+ out of these terms or the use or nature of the software, under any kind of
116
+ legal claim.
117
+
118
+ ## Definitions
119
+
120
+ The **licensor** is the entity offering these terms, and the **software** is
121
+ the software the licensor makes available under these terms, including any
122
+ portion of it.
123
+
124
+ **you** refers to the individual or entity agreeing to these terms, including
125
+ any legal entity, sole proprietorship, or other organization that you work for,
126
+ plus all organizations that have control over, are under the control of, or are
127
+ under common control with that organization. **control** means ownership of
128
+ substantially all the assets of an entity, or the power to direct its
129
+ management and policies by vote, contract, or otherwise. Control can be direct
130
+ or indirect.
131
+
132
+ **your licenses** are all the licenses granted to you for the software under
133
+ these terms.
134
+
135
+ **use** means anything you do with the software requiring one of your licenses.
136
+
137
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,298 @@
1
+ # trace-mcp
2
+
3
+ **Framework-aware code intelligence MCP server for Laravel / Vue / Inertia / Nuxt stacks.**
4
+
5
+ > Your AI agent reads `UserController.php` and sees a class.
6
+ > trace-mcp reads it and sees a route → controller → FormRequest → Eloquent model → Inertia render → Vue page → child components — **in one graph.**
7
+
8
+ ---
9
+
10
+ ## The problem
11
+
12
+ AI coding agents are language-aware but **framework-blind**.
13
+
14
+ They don't know that `Inertia::render('Users/Show', $data)` connects a Laravel controller to `resources/js/Pages/Users/Show.vue`. They don't know that `$user->posts()` means the `posts` table defined three migrations ago. They can't trace a request from URL to rendered pixel.
15
+
16
+ So they brute-read files, guess at relationships, and miss cross-language edges entirely. The bigger the project, the worse it gets.
17
+
18
+ ## The solution
19
+
20
+ trace-mcp builds a **cross-language dependency graph** from your source code — PHP, TypeScript, Vue SFCs, Blade templates — and exposes it through the [Model Context Protocol](https://modelcontextprotocol.io). Any MCP-compatible agent (Claude Code, Cursor, Windsurf, etc.) gets framework-level understanding out of the box.
21
+
22
+ | Without trace-mcp | With trace-mcp |
23
+ |---|---|
24
+ | Agent reads 15 files to understand a feature | Agent calls `get_feature_context` — gets relevant code in one shot |
25
+ | Agent doesn't know which Vue page a controller renders | Agent sees `routes_to → renders_component → uses_prop` edges |
26
+ | "What breaks if I change this model?" — agent guesses | `get_change_impact` traverses reverse dependencies across PHP + Vue |
27
+ | Schema? Agent needs a running database | Migrations are parsed — schema reconstructed from code |
28
+ | Prop mismatch between PHP and Vue? Discovered in production | Detected at index time — PHP data vs. `defineProps` |
29
+
30
+ ---
31
+
32
+ ## What you get
33
+
34
+ | Capability | How it works |
35
+ |---|---|
36
+ | **Request flow tracing** | URL → Route → Middleware → Controller → FormRequest → Model → Inertia → Vue Page → Props |
37
+ | **Component trees** | Parent → Child render hierarchy with props / emits / slots |
38
+ | **Schema from migrations** | Table structure reconstructed from migration files — no DB connection needed |
39
+ | **Event chains** | Event → Listener → Job fan-out across async boundaries |
40
+ | **Prop mismatch detection** | PHP `Inertia::render()` data vs. Vue `defineProps` — catch type drift before production |
41
+ | **Change impact analysis** | "What breaks if I touch this?" — reverse dependency traversal across languages |
42
+ | **Feature context assembly** | Describe a feature in plain English → get all relevant code within a token budget |
43
+
44
+ ---
45
+
46
+ ## Supported frameworks
47
+
48
+ | Layer | Frameworks | What's extracted |
49
+ |---|---|---|
50
+ | **Backend** | Laravel 6–13 | Routes, controllers, Eloquent relations, migrations, FormRequests, events/listeners, middleware |
51
+ | **Templates** | Blade | `@extends`, `@include`, `@component`, `<x-*>` directives, template inheritance |
52
+ | **Bridge** | Inertia.js | `Inertia::render()` calls, controller ↔ Vue page mapping, prop extraction & validation |
53
+ | **Frontend** | Vue 2 (Options API), Vue 3 (Composition API) | `defineProps`, `defineEmits`, composables, component render trees |
54
+ | **Meta-framework** | Nuxt 3 | File-based routing, auto-imports, `useFetch` / `useAsyncData`, server API routes |
55
+ | **Languages** | PHP, TypeScript, JavaScript, Vue SFC | Full symbol extraction via tree-sitter |
56
+
57
+ ---
58
+
59
+ ## MCP tools
60
+
61
+ ### Project
62
+
63
+ | Tool | What it does |
64
+ |---|---|
65
+ | `get_project_map` | Project overview — detected frameworks, directory structure, entry points |
66
+ | `get_index_health` | Index stats — file count, symbol count, edge count, errors |
67
+ | `reindex` | Trigger full or incremental re-indexing |
68
+
69
+ ### Navigation
70
+
71
+ | Tool | What it does |
72
+ |---|---|
73
+ | `search` | Full-text search (FTS5 + BM25) with kind / language / file pattern filters |
74
+ | `get_symbol` | Look up a symbol by ID or FQN — returns source code |
75
+ | `get_file_outline` | All symbols in a file — signatures only, no bodies |
76
+
77
+ ### Framework intelligence
78
+
79
+ | Tool | What it does |
80
+ |---|---|
81
+ | `get_component_tree` | Build Vue/Blade component render tree from a root file |
82
+ | `get_change_impact` | Reverse dependency graph — what depends on this file or symbol |
83
+ | `get_feature_context` | NLP-driven context assembly — describe a feature, get relevant code within a token budget |
84
+
85
+ ### Resources
86
+
87
+ | Resource | URI | Description |
88
+ |---|---|---|
89
+ | Project map | `project://map` | JSON project overview |
90
+ | Index health | `project://health` | Index status |
91
+
92
+ ---
93
+
94
+ ## When does it help?
95
+
96
+ | Scenario | Without trace-mcp | With trace-mcp |
97
+ |---|---|---|
98
+ | "Add a new field to the User model" | Agent edits model, misses migration, FormRequest, and Vue form | `get_change_impact` shows all dependents — model, migration, request validation, Vue props |
99
+ | "What components does this page use?" | Agent greps for import statements, misses dynamic components | `get_component_tree` returns full render tree with props/slots |
100
+ | "Refactor the auth flow" | Agent reads files one by one, burns tokens | `get_feature_context("authentication")` assembles relevant code in one call |
101
+ | "Does the Vue page match the controller response?" | Manual comparison, easy to miss fields | Prop mismatch detection flags drift automatically |
102
+ | "What's the DB schema?" | Need a running database or read raw SQL | Migrations parsed — `get_schema` returns reconstructed tables |
103
+
104
+ ---
105
+
106
+ ## Quick start
107
+
108
+ ### 1. Install
109
+
110
+ ```bash
111
+ npm install -g trace-mcp
112
+ ```
113
+
114
+ ### 2. Add to your MCP client
115
+
116
+ **Claude Code:**
117
+ ```bash
118
+ claude mcp add trace-mcp -- trace-mcp serve
119
+ ```
120
+
121
+ **Claude Desktop / Cursor / Windsurf** (MCP config JSON):
122
+ ```json
123
+ {
124
+ "mcpServers": {
125
+ "trace-mcp": {
126
+ "command": "trace-mcp",
127
+ "args": ["serve"],
128
+ "cwd": "/path/to/your/project"
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ ### 3. Start using it
135
+
136
+ The server auto-indexes on first tool call. No configuration needed for standard Laravel + Vue projects.
137
+
138
+ ```
139
+ > Use get_project_map to see what frameworks are detected
140
+ > Use get_feature_context to find code related to "user registration"
141
+ > Use get_change_impact on app/Models/User.php to see what depends on it
142
+ ```
143
+
144
+ ---
145
+
146
+ ## How it works
147
+
148
+ ```
149
+ Source files (PHP, TS, Vue, Blade)
150
+
151
+
152
+ ┌──────────────────────────────────────────┐
153
+ │ Pass 1 — Per-file extraction │
154
+ │ tree-sitter → symbols │
155
+ │ framework plugins → routes, components, │
156
+ │ migrations, events, Eloquent models │
157
+ └────────────────────┬─────────────────────┘
158
+
159
+
160
+ ┌──────────────────────────────────────────┐
161
+ │ Pass 2 — Cross-file resolution │
162
+ │ PSR-4 · ES modules · Vue components │
163
+ │ Inertia bridge · Blade inheritance │
164
+ │ → unified directed edge graph │
165
+ └────────────────────┬─────────────────────┘
166
+
167
+
168
+ ┌──────────────────────────────────────────┐
169
+ │ SQLite (WAL mode) + FTS5 │
170
+ │ nodes · edges · symbols · routes │
171
+ │ components · migrations │
172
+ └────────────────────┬─────────────────────┘
173
+
174
+
175
+ MCP stdio server
176
+ 9 tools · 2 resources
177
+ ```
178
+
179
+ **Incremental by default** — files are content-hashed; unchanged files are skipped on re-index.
180
+
181
+ **Plugin architecture** — language plugins (symbol extraction) and framework plugins (semantic edges) are loaded based on project detection. Adding a new framework = implementing `FrameworkPlugin` with `detect()`, `extractNodes()`, and `resolveEdges()`.
182
+
183
+ ---
184
+
185
+ ## Configuration
186
+
187
+ Optional. Works out of the box for standard Laravel + Vue projects.
188
+
189
+ Create `.trace-mcp.json` in your project root (or add a `"trace-mcp"` key to `package.json`):
190
+
191
+ ```jsonc
192
+ {
193
+ "root": ".",
194
+ "include": [
195
+ "app/**/*.php",
196
+ "routes/**/*.php",
197
+ "resources/**/*.vue",
198
+ "resources/views/**/*.blade.php",
199
+ "src/**/*.{ts,js,vue}"
200
+ ],
201
+ "exclude": [
202
+ "vendor/**",
203
+ "node_modules/**",
204
+ "storage/**"
205
+ ],
206
+ "db": {
207
+ "path": ".trace-mcp/index.db"
208
+ },
209
+ "frameworks": {
210
+ "laravel": {
211
+ "artisan": { "enabled": true, "timeout": 10000 },
212
+ "graceful_degradation": true
213
+ }
214
+ },
215
+ "security": {
216
+ "max_file_size_bytes": 524288
217
+ }
218
+ }
219
+ ```
220
+
221
+ Config is loaded via [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig) — supports `.trace-mcp.json`, `.trace-mcp.yaml`, `package.json`, and more. All values validated with [Zod](https://zod.dev). Environment variable overrides available.
222
+
223
+ ---
224
+
225
+ ## Tech stack
226
+
227
+ | Component | Technology |
228
+ |---|---|
229
+ | Parsing | [tree-sitter](https://tree-sitter.github.io/) (PHP, TypeScript), [@vue/compiler-sfc](https://github.com/vuejs/core) (Vue SFCs) |
230
+ | Database | [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) — WAL mode, FTS5 full-text search |
231
+ | Module resolution | [oxc-resolver](https://github.com/nicolo-ribaudo/oxc-resolver) (ESM/CJS), PSR-4 (PHP autoloading) |
232
+ | Validation | [Zod](https://zod.dev) — config + input validation |
233
+ | Error handling | [neverthrow](https://github.com/supermacro/neverthrow) — Rust-style `Result<T, E>` types |
234
+ | MCP | [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) |
235
+ | Build | tsup · vitest · TypeScript 5.7 |
236
+
237
+ ---
238
+
239
+ ## Security
240
+
241
+ - **Path traversal protection** — all file access validated against project root
242
+ - **Symlink detection** — prevents escape from project boundary
243
+ - **Secret pattern filtering** — configurable regex patterns
244
+ - **File size limits** — per-file byte cap
245
+ - **Artisan whitelist** — only safe artisan commands allowed (when Laravel integration is enabled)
246
+
247
+ ---
248
+
249
+ ## Development
250
+
251
+ ```bash
252
+ git clone https://github.com/nickvysotskyi/trace-mcp.git
253
+ cd trace-mcp
254
+ npm install
255
+ npm run build
256
+ npm test # 286 tests
257
+ npm run dev # watch mode (tsup)
258
+ npm run serve # start MCP server (dev)
259
+ ```
260
+
261
+ ### Project structure
262
+
263
+ ```
264
+ src/
265
+ ├── db/ # SQLite schema, store, FTS5
266
+ ├── indexer/
267
+ │ ├── plugins/
268
+ │ │ ├── language/ # PHP, TypeScript, Vue parsers
269
+ │ │ └── framework/ # Laravel, Vue, Inertia, Nuxt, Blade
270
+ │ ├── resolvers/ # PSR-4, ES module resolution
271
+ │ └── pipeline.ts # Two-pass indexing engine
272
+ ├── tools/ # MCP tool implementations
273
+ ├── scoring/ # PageRank, BM25, hybrid scoring
274
+ ├── plugin-api/ # Plugin registry + executor
275
+ ├── server.ts # MCP server setup
276
+ ├── config.ts # Cosmiconfig + Zod
277
+ └── cli.ts # Commander CLI
278
+ ```
279
+
280
+ ---
281
+
282
+ ## Best for
283
+
284
+ - Laravel + Vue / Inertia / Nuxt full-stack projects
285
+ - Teams using AI agents (Claude, Cursor, Windsurf) for day-to-day development
286
+ - Projects where PHP ↔ JavaScript boundaries create blind spots
287
+ - CI/CD environments where a running database isn't available
288
+ - Large codebases where agents waste tokens re-reading files
289
+
290
+ ---
291
+
292
+ ## License
293
+
294
+ [Elastic License 2.0](LICENSE) — free for personal and internal use. See LICENSE for full terms.
295
+
296
+ ---
297
+
298
+ Built by [Nikolai Vysotskyi](https://github.com/nickvysotskyi)
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node