smart-context-mcp 0.8.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 +21 -0
- package/README.md +414 -0
- package/package.json +63 -0
- package/scripts/devctx-server.js +4 -0
- package/scripts/init-clients.js +356 -0
- package/scripts/report-metrics.js +195 -0
- package/src/index.js +976 -0
- package/src/mcp-server.js +3 -0
- package/src/metrics.js +65 -0
- package/src/server.js +143 -0
- package/src/tokenCounter.js +12 -0
- package/src/tools/smart-context.js +1192 -0
- package/src/tools/smart-read/additional-languages.js +684 -0
- package/src/tools/smart-read/code.js +216 -0
- package/src/tools/smart-read/fallback.js +23 -0
- package/src/tools/smart-read/python.js +178 -0
- package/src/tools/smart-read/shared.js +39 -0
- package/src/tools/smart-read/structured.js +72 -0
- package/src/tools/smart-read-batch.js +63 -0
- package/src/tools/smart-read.js +459 -0
- package/src/tools/smart-search.js +412 -0
- package/src/tools/smart-shell.js +213 -0
- package/src/utils/fs.js +47 -0
- package/src/utils/paths.js +1 -0
- package/src/utils/runtime-config.js +29 -0
- package/src/utils/text.js +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Francisco Caballero Portero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
# smart-context-mcp
|
|
2
|
+
|
|
3
|
+
`smart-context-mcp` is an MCP server that reduces agent token usage and improves response quality with compact file summaries, ranked code search, and curated context.
|
|
4
|
+
|
|
5
|
+
It exposes:
|
|
6
|
+
|
|
7
|
+
- `smart_read`: compact file summaries instead of full-file dumps
|
|
8
|
+
- `smart_read_batch`: read multiple files in one call — reduces round-trip latency
|
|
9
|
+
- `smart_search`: ripgrep-first code search with grouped, ranked results and intent-aware ranking
|
|
10
|
+
- `smart_context`: one-call context planner that combines search + read + graph expansion
|
|
11
|
+
- `smart_shell`: safe diagnostic shell execution with a restricted allowlist
|
|
12
|
+
- `build_index`: lightweight symbol index for faster lookups and smarter ranking
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install smart-context-mcp
|
|
18
|
+
npx smart-context-init --target .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This installs the MCP server and generates client configs for Cursor, Codex, Qwen, and Claude Code. Open the project with your IDE/agent and the server starts automatically.
|
|
22
|
+
|
|
23
|
+
## Binaries
|
|
24
|
+
|
|
25
|
+
The package exposes three binaries:
|
|
26
|
+
|
|
27
|
+
- `smart-context-server`
|
|
28
|
+
- `smart-context-init`
|
|
29
|
+
- `smart-context-report`
|
|
30
|
+
|
|
31
|
+
Start the MCP server against the current project:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
smart-context-server
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Start it against another repository:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
smart-context-server --project-root /path/to/target-repo
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Generate client configs
|
|
44
|
+
|
|
45
|
+
Generate MCP config files for a target project:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
smart-context-init --target /path/to/project
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Limit the generated clients if needed:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
smart-context-init --target /path/to/project --clients cursor,codex,qwen,claude
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Override the command used in generated configs:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
smart-context-init --target /path/to/project --command node --args '["./tools/devctx/src/mcp-server.js"]'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Metrics
|
|
64
|
+
|
|
65
|
+
Each tool call persists token metrics to the target repo by default in:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
.devctx/metrics.jsonl
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This makes per-repo usage visible without digging into `node_modules`. Running `smart-context-init` also adds `.devctx/` to the target repo's `.gitignore` idempotently.
|
|
72
|
+
|
|
73
|
+
Show a quick report:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
smart-context-report
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Show JSON output or a custom file:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
smart-context-report --json
|
|
83
|
+
smart-context-report --file ./.devctx/metrics.jsonl
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Example output:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
devctx metrics report
|
|
90
|
+
|
|
91
|
+
File: /path/to/repo/.devctx/metrics.jsonl
|
|
92
|
+
Source: default
|
|
93
|
+
Entries: 148
|
|
94
|
+
Raw tokens: 182,340
|
|
95
|
+
Final tokens: 41,920
|
|
96
|
+
Saved tokens: 140,420 (77.01%)
|
|
97
|
+
|
|
98
|
+
By tool:
|
|
99
|
+
smart_context count=42 raw=96,200 final=24,180 saved=72,020 (74.86%)
|
|
100
|
+
smart_read count=71 raw=52,810 final=9,940 saved=42,870 (81.18%)
|
|
101
|
+
smart_search count=35 raw=33,330 final=7,800 saved=25,530 (76.59%)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If you want to override the location entirely, set `DEVCTX_METRICS_FILE`.
|
|
105
|
+
|
|
106
|
+
## Usage per client
|
|
107
|
+
|
|
108
|
+
After installing and running `smart-context-init`, each client picks up the server automatically:
|
|
109
|
+
|
|
110
|
+
### Cursor
|
|
111
|
+
|
|
112
|
+
Open the project in Cursor. The MCP server starts automatically. Enable it in **Cursor Settings > MCP** if needed. All six tools are available in Agent mode.
|
|
113
|
+
|
|
114
|
+
### Codex CLI
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
cd /path/to/your-project
|
|
118
|
+
codex
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Codex reads `.codex/config.toml` and starts the MCP server on launch.
|
|
122
|
+
|
|
123
|
+
### Claude Code
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
cd /path/to/your-project
|
|
127
|
+
claude
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Claude Code reads `.mcp.json` from the project root.
|
|
131
|
+
|
|
132
|
+
### Qwen Code
|
|
133
|
+
|
|
134
|
+
Open the project in Qwen Code. The MCP server starts from `.qwen/settings.json`.
|
|
135
|
+
|
|
136
|
+
## Agent rules
|
|
137
|
+
|
|
138
|
+
`smart-context-init` generates agent rules that instruct AI agents to prefer devctx tools over their built-in equivalents. This is what makes agents use `smart_read` in outline/signatures mode instead of reading full files.
|
|
139
|
+
|
|
140
|
+
### Intent-based workflows
|
|
141
|
+
|
|
142
|
+
The `intent` parameter in `smart_search` and `smart_context` adjusts ranking and suggests optimal workflows:
|
|
143
|
+
|
|
144
|
+
| Intent | Ranking priority | Suggested workflow |
|
|
145
|
+
|--------|-----------------|-------------------|
|
|
146
|
+
| `debug` | Error messages, stack traces, logs | Search error → read signatures → inspect symbol → smart_shell |
|
|
147
|
+
| `implementation` | Source files, changed files | Read outline/signatures → focus on changed symbols |
|
|
148
|
+
| `tests` | Test files, spec files | Find tests → read symbol of function under test |
|
|
149
|
+
| `config` | Config files, env vars, YAML/JSON | Find settings → read full config files |
|
|
150
|
+
| `explore` | Entry points, main modules | Directory structure → outlines of key modules |
|
|
151
|
+
|
|
152
|
+
### Generated files per client
|
|
153
|
+
|
|
154
|
+
- **Cursor**: `.cursor/rules/devctx.mdc` (always-apply rule)
|
|
155
|
+
- **Codex**: `AGENTS.md` (devctx section with sentinel markers)
|
|
156
|
+
- **Claude Code**: `CLAUDE.md` (devctx section with sentinel markers)
|
|
157
|
+
|
|
158
|
+
The rules are idempotent — running `smart-context-init` again updates the section without duplicating it. Existing content in `AGENTS.md` and `CLAUDE.md` is preserved.
|
|
159
|
+
|
|
160
|
+
## What it is good at
|
|
161
|
+
|
|
162
|
+
| Level | Languages / Stack | Use cases |
|
|
163
|
+
|-------|------------------|-----------|
|
|
164
|
+
| **Strong** | JS/TS, React, Next.js, Node.js, Python | Modern web apps, monorepos, backend services, scripts |
|
|
165
|
+
| **Strong** | Terraform, Docker, YAML, shell, SQL | Infra/platform repos, config-heavy codebases |
|
|
166
|
+
| **Good** | Go, Rust, Java, C#/.NET, Kotlin, PHP, Swift | Services, libraries, Android/iOS, Laravel/Symfony |
|
|
167
|
+
| **Partial** | Enterprise Java/C# with heavy frameworks | Generated code, polyglot monorepos needing semantic ranking |
|
|
168
|
+
| **Limited** | Ruby, Elixir, Scala | Deep semantic understanding required, general shell needs |
|
|
169
|
+
|
|
170
|
+
## Tool behavior
|
|
171
|
+
|
|
172
|
+
### `smart_read`
|
|
173
|
+
|
|
174
|
+
Modes:
|
|
175
|
+
|
|
176
|
+
- `outline` — compact structural summary (~90% token savings)
|
|
177
|
+
- `signatures` — exported API surface only
|
|
178
|
+
- `range` — specific line range with line numbers (`startLine`, `endLine`)
|
|
179
|
+
- `symbol` — extract function/class/method by name; accepts a string or an array for batch extraction
|
|
180
|
+
- `full` — file content capped at 12k chars, with truncation marker when needed
|
|
181
|
+
|
|
182
|
+
The `symbol` mode supports nested methods (class methods, object methods), interface signatures, and multiline function signatures across all supported languages.
|
|
183
|
+
|
|
184
|
+
Cross-file symbol context:
|
|
185
|
+
|
|
186
|
+
- Pass `context: true` with `symbol` mode to include callers, tests, and referenced types from the dependency graph
|
|
187
|
+
- Callers: files that import the current file and reference the symbol (via graph + ripgrep)
|
|
188
|
+
- Tests: test files related to the current file that mention the symbol
|
|
189
|
+
- Types: type/interface names referenced in the symbol definition that exist in the index
|
|
190
|
+
- Requires `build_index` for graph data; without it, the definition is returned with an empty context and a hint
|
|
191
|
+
- Response includes `context: { callers, tests, types }` with counts, `graphCoverage: { imports, tests }` (`full|partial|none`), and `contextHints` if applicable
|
|
192
|
+
- `graphCoverage` indicates how reliable cross-file context is: `full` for JS/TS/Python/Go (imports resolved), `partial` for C#/Kotlin/PHP/Swift (imports extracted but namespace-based), `none` for other languages
|
|
193
|
+
|
|
194
|
+
Token budget mode:
|
|
195
|
+
|
|
196
|
+
- Pass `maxTokens` to let the tool auto-select the most detailed mode that fits the budget
|
|
197
|
+
- Cascade order: `full` -> `outline` -> `signatures` -> truncated
|
|
198
|
+
- If the requested mode (or default `outline`) exceeds the budget, the tool falls back to a more compact mode automatically
|
|
199
|
+
- `range` and `symbol` modes do not cascade but will truncate by tokens if needed
|
|
200
|
+
- When the mode changes, the response includes `chosenMode` (the mode actually used) and `budgetApplied: true`
|
|
201
|
+
|
|
202
|
+
Responses are cached in memory per session. If the same file+mode is requested again and the file's `mtime` has not changed, the cached result is returned without re-parsing. The response includes `cached: true` when served from cache.
|
|
203
|
+
|
|
204
|
+
Every response includes a `confidence` block:
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{ "parser": "ast|heuristic|fallback|raw", "truncated": false, "cached": false }
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Additional metadata: `indexHint` (symbol mode), `chosenMode`/`budgetApplied` (token budget), `graphCoverage` (symbol+context mode).
|
|
211
|
+
|
|
212
|
+
**Example response (outline mode):**
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"mode": "outline",
|
|
217
|
+
"parser": "ast",
|
|
218
|
+
"truncated": false,
|
|
219
|
+
"cached": false,
|
|
220
|
+
"tokens": 245,
|
|
221
|
+
"confidence": { "parser": "ast", "truncated": false, "cached": false },
|
|
222
|
+
"content": "import express from 'express';\nexport class AuthMiddleware { ... }\nexport function requireRole(role: string) { ... }"
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Current support:
|
|
227
|
+
|
|
228
|
+
- First-class (AST): JS, JSX, TS, TSX
|
|
229
|
+
- Heuristic: Python, Go, Rust, Java, C#, Kotlin, PHP, Swift, shell, Terraform, HCL, Dockerfile, SQL, JSON, TOML, YAML
|
|
230
|
+
- Fallback: plain-text structural extraction for unsupported formats
|
|
231
|
+
|
|
232
|
+
### `smart_read_batch`
|
|
233
|
+
|
|
234
|
+
Read multiple files in one MCP call. Reduces round-trip latency for common patterns like "read the outline of these 5 files".
|
|
235
|
+
|
|
236
|
+
Parameters:
|
|
237
|
+
|
|
238
|
+
- `files` (required, max 20) — array of items, each with:
|
|
239
|
+
- `path` (required) — file path
|
|
240
|
+
- `mode` (optional) — `outline`, `signatures`, `full`, `range`, `symbol`
|
|
241
|
+
- `symbol`, `startLine`, `endLine` (optional) — as in `smart_read`
|
|
242
|
+
- `maxTokens` (optional) — per-file token budget with automatic mode cascade
|
|
243
|
+
- `maxTokens` (optional) — global token budget; stops reading more files once exceeded (at least 1 file is always read)
|
|
244
|
+
|
|
245
|
+
Response:
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"results": [
|
|
250
|
+
{ "filePath": "...", "mode": "outline", "parser": "ast", "truncated": false, "content": "..." },
|
|
251
|
+
{ "filePath": "...", "mode": "signatures", "parser": "heuristic", "truncated": false, "content": "..." }
|
|
252
|
+
],
|
|
253
|
+
"metrics": { "totalTokens": 450, "filesRead": 2, "filesSkipped": 0, "totalSavingsPct": 88 }
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### `smart_search`
|
|
258
|
+
|
|
259
|
+
- Uses embedded ripgrep via `@vscode/ripgrep`
|
|
260
|
+
- Falls back to filesystem walking if rg is unavailable or fails
|
|
261
|
+
- Groups matches by file, ranks results to reduce noise
|
|
262
|
+
- Optional `intent` parameter adjusts ranking: `implementation`, `debug`, `tests`, `config`, `docs`, `explore`
|
|
263
|
+
- When a symbol index exists (via `build_index`), files with matching definitions get +50 ranking bonus, and related files (importers, tests, neighbors) get +25 graph boost
|
|
264
|
+
- Index is loaded from `projectRoot`, so subdirectory searches still benefit from the project-level index
|
|
265
|
+
- Returns `confidence` block: `{ "level": "high", "indexFreshness": "fresh" }`
|
|
266
|
+
|
|
267
|
+
**Example response:**
|
|
268
|
+
|
|
269
|
+
```json
|
|
270
|
+
{
|
|
271
|
+
"engine": "rg",
|
|
272
|
+
"retrievalConfidence": "high",
|
|
273
|
+
"indexFreshness": "fresh",
|
|
274
|
+
"confidence": { "level": "high", "indexFreshness": "fresh" },
|
|
275
|
+
"sourceBreakdown": { "textMatch": 7, "indexBoost": 2, "graphBoost": 1 },
|
|
276
|
+
"results": [
|
|
277
|
+
{ "file": "src/auth/middleware.js", "matches": 3, "rank": 150, "preview": "export class AuthMiddleware { ..." }
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### `smart_context`
|
|
283
|
+
|
|
284
|
+
One-call context planner. Instead of the manual cycle of `smart_search` → `smart_read` → `smart_read` → ..., `smart_context` receives a task description and returns curated context in a single response.
|
|
285
|
+
|
|
286
|
+
**Pipeline:**
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
task input → intent detection → search/diff → graph expansion → smart_read_batch → symbol extraction → response
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
**Parameters:**
|
|
293
|
+
- `task` (required) — natural language description (e.g., `"debug the auth flow in AuthMiddleware"`)
|
|
294
|
+
- `intent` (optional) — override auto-detected intent
|
|
295
|
+
- `detail` (optional) — `minimal` | `balanced` (default) | `deep`
|
|
296
|
+
- `maxTokens` (optional, default 8000) — token budget
|
|
297
|
+
- `entryFile` (optional) — guarantee specific file inclusion
|
|
298
|
+
- `diff` (optional) — `true` (vs HEAD) or git ref (`"main"`) to scope to changed files only
|
|
299
|
+
- `include` (optional) — `["content","graph","hints","symbolDetail"]` to control response fields
|
|
300
|
+
|
|
301
|
+
**Detail modes:**
|
|
302
|
+
|
|
303
|
+
| Mode | Behavior | Use when |
|
|
304
|
+
|------|----------|----------|
|
|
305
|
+
| `minimal` | Index-first: paths, roles, evidence, signatures, symbol previews (no file reads) | Fastest exploration, budget-constrained |
|
|
306
|
+
| `balanced` | Batch read with smart compression (outline/signatures) | Default, most tasks |
|
|
307
|
+
| `deep` | Full content reads | Deep investigation, debugging |
|
|
308
|
+
|
|
309
|
+
**How it works:**
|
|
310
|
+
|
|
311
|
+
1. **Search or diff**: Extracts queries from task and runs `smart_search`, OR runs `git diff` when `diff` parameter provided
|
|
312
|
+
2. **Graph expansion**: Expands top results via relational graph (imports, importedBy, tests, neighbors)
|
|
313
|
+
3. **Read strategy**: Index-first mode (no file reads) OR batch read mode using `smart_read_batch` with role-based compression
|
|
314
|
+
4. **Symbol extraction**: Detects identifiers in task and extracts focused symbol details
|
|
315
|
+
5. **Deduplication**: In `minimal` mode, omits redundant outline when `symbolDetail` covers same file
|
|
316
|
+
6. **Assembly**: Returns curated context with `reasonIncluded` / `evidence` per item, graph summary, hints, and confidence block
|
|
317
|
+
|
|
318
|
+
Diff mode is ideal for PR review and debugging recent changes — reads only changed files plus their tests and dependencies.
|
|
319
|
+
|
|
320
|
+
Example response:
|
|
321
|
+
|
|
322
|
+
```json
|
|
323
|
+
{
|
|
324
|
+
"task": "debug AuthMiddleware",
|
|
325
|
+
"intent": "debug",
|
|
326
|
+
"indexFreshness": "fresh",
|
|
327
|
+
"confidence": { "indexFreshness": "fresh", "graphCoverage": { "imports": "full", "tests": "full" } },
|
|
328
|
+
"context": [
|
|
329
|
+
{ "file": "src/auth/middleware.js", "role": "primary", "readMode": "outline", "reasonIncluded": "Matched task search: AuthMiddleware", "evidence": [{ "type": "searchHit", "query": "AuthMiddleware", "rank": 1 }, { "type": "symbolMatch", "symbols": ["AuthMiddleware"] }], "symbols": ["AuthMiddleware", "requireRole"], "symbolPreviews": [{ "name": "AuthMiddleware", "kind": "class", "signature": "export class AuthMiddleware", "snippet": "export class AuthMiddleware { ..." }], "content": "..." },
|
|
330
|
+
{ "file": "tests/auth.test.js", "role": "test", "readMode": "signatures", "reasonIncluded": "Test for src/auth/middleware.js", "evidence": [{ "type": "testOf", "via": "src/auth/middleware.js" }], "content": "..." },
|
|
331
|
+
{ "file": "src/utils/jwt.js", "role": "dependency", "readMode": "signatures", "reasonIncluded": "Imported by src/auth/middleware.js", "evidence": [{ "type": "dependencyOf", "via": "src/auth/middleware.js" }], "content": "..." },
|
|
332
|
+
{ "file": "src/auth/middleware.js", "role": "symbolDetail", "readMode": "symbol", "reasonIncluded": "Focused symbol detail: AuthMiddleware", "evidence": [{ "type": "symbolDetail", "symbols": ["AuthMiddleware"] }], "content": "..." }
|
|
333
|
+
],
|
|
334
|
+
"graph": {
|
|
335
|
+
"primaryImports": ["src/utils/jwt.js"],
|
|
336
|
+
"tests": ["tests/auth.test.js"],
|
|
337
|
+
"dependents": [],
|
|
338
|
+
"neighbors": ["src/utils/logger.js"]
|
|
339
|
+
},
|
|
340
|
+
"graphCoverage": { "imports": "full", "tests": "full" },
|
|
341
|
+
"metrics": { "totalTokens": 1200, "filesIncluded": 4, "filesEvaluated": 8, "savingsPct": 82 },
|
|
342
|
+
"hints": ["Inspect symbols with smart_read: verifyJwt, createJwt"]
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
`graphCoverage` indicates how complete the relational context is: `full` for JS/TS/Python/Go (imports resolved to local files), `partial` for C#/Kotlin/PHP/Swift (imports extracted but namespace-based), `none` for other languages. When files from multiple languages are included, the level reflects the weakest coverage.
|
|
347
|
+
|
|
348
|
+
File roles: `primary` (search hits or changed files), `test` (related test files), `dependency` (imports), `dependent` (importedBy), `symbolDetail` (extracted symbol bodies). Each item also includes `reasonIncluded` and structured `evidence` so the agent knows why it was selected.
|
|
349
|
+
|
|
350
|
+
When using diff mode, the response includes a `diffSummary`:
|
|
351
|
+
|
|
352
|
+
```json
|
|
353
|
+
{
|
|
354
|
+
"diffSummary": { "ref": "main", "totalChanged": 5, "included": 3, "skippedDeleted": 1 }
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### `build_index`
|
|
359
|
+
|
|
360
|
+
- Builds a lightweight symbol index for the project (functions, classes, methods, types, etc.)
|
|
361
|
+
- Supports JS/TS (via TypeScript AST), Python, Go, Rust, Java, C#, Kotlin, PHP, Swift
|
|
362
|
+
- Extracts imports/exports and builds a dependency graph with `import` and `testOf` edges
|
|
363
|
+
- Test files are linked to source files via import analysis and naming conventions
|
|
364
|
+
- Index stored per-project in `.devctx/index.json`, invalidated by file mtime
|
|
365
|
+
- Each symbol includes a condensed `signature` (one line, max 200 chars) and a short `snippet` preview so agents can inspect likely definitions without opening files
|
|
366
|
+
- Accelerates `smart_search` (symbol + graph ranking) and `smart_read` symbol mode (line hints)
|
|
367
|
+
- Pass `incremental=true` to only reindex files with changed mtime — much faster for large repos (10k+ files). Falls back to full rebuild if no prior index exists.
|
|
368
|
+
- Incremental response includes `reindexed`, `removed`, `unchanged` counts
|
|
369
|
+
- Run once after checkout or when many files changed; not required but recommended for large projects
|
|
370
|
+
|
|
371
|
+
### `smart_shell`
|
|
372
|
+
|
|
373
|
+
- Runs only allowlisted diagnostic commands
|
|
374
|
+
- Executes from the effective project root
|
|
375
|
+
- Blocks shell operators and unsafe commands by design
|
|
376
|
+
|
|
377
|
+
## Evaluations (repo development only)
|
|
378
|
+
|
|
379
|
+
The eval harness and corpora are available in the [source repository](https://github.com/Arrayo/devctx-mcp-mvp) but are **not included in the npm package**. Clone the repo to run evaluations.
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
cd tools/devctx
|
|
383
|
+
npm run eval
|
|
384
|
+
npm run eval -- --baseline
|
|
385
|
+
npm run eval:self
|
|
386
|
+
npm run eval:context
|
|
387
|
+
npm run eval:both
|
|
388
|
+
npm run eval:report
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Commands:
|
|
392
|
+
- `eval` — synthetic corpus with index + intent
|
|
393
|
+
- `eval -- --baseline` — baseline without index/intent
|
|
394
|
+
- `eval:self` — self-eval against the real devctx repo
|
|
395
|
+
- `eval:context` — evaluate smart_context alongside search
|
|
396
|
+
- `eval:both` — search + context evaluation
|
|
397
|
+
- `eval:report` — scorecard with delta vs baseline
|
|
398
|
+
|
|
399
|
+
The harness supports `--root=` and `--corpus=` for evaluating against any repo with custom task corpora. Use `--tool=search|context|both` to control which tools are evaluated. When `--tool=context`, pass/fail is determined by `smart_context` precision; when `--tool=both`, both search and context must pass.
|
|
400
|
+
|
|
401
|
+
Metrics include: P@5, P@10, Recall, wrong-file rate, retrieval honesty, follow-up reads, tokens-to-success, latency p50/p95, confidence calibration (accuracy, over-confident rate, under-confident rate), and smart_context metrics when applicable. smart_context reporting now includes precision, explanation coverage (`reasonIncluded` + `evidence`), preview coverage (`symbolPreviews`), and preview symbol recall. Token metrics (`totalTokens`) reflect the full JSON payload, not just content blocks.
|
|
402
|
+
|
|
403
|
+
## Notes
|
|
404
|
+
|
|
405
|
+
- `@vscode/ripgrep` provides a bundled `rg` binary, so a system install is not required.
|
|
406
|
+
- Metrics are written under `.devctx/metrics.jsonl` in the package root.
|
|
407
|
+
- Symbol index stored in `.devctx/index.json` when `build_index` is used.
|
|
408
|
+
- This package is a navigation and diagnostics layer, not a full semantic code intelligence system.
|
|
409
|
+
|
|
410
|
+
## Repository
|
|
411
|
+
|
|
412
|
+
Source repository and full project documentation:
|
|
413
|
+
|
|
414
|
+
- https://github.com/Arrayo/devctx-mcp-mvp
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "smart-context-mcp",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "MCP server that reduces agent token usage and improves response quality with compact file summaries, ranked code search, and curated context.",
|
|
5
|
+
"author": "Francisco Caballero Portero <fcp1978@hotmail.com>",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Arrayo/devctx-mcp-mvp.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Arrayo/devctx-mcp-mvp#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Arrayo/devctx-mcp-mvp/issues"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"smart-context-server": "scripts/devctx-server.js",
|
|
17
|
+
"smart-context-init": "scripts/init-clients.js",
|
|
18
|
+
"smart-context-report": "scripts/report-metrics.js"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./src/server.js",
|
|
22
|
+
"./server": "./src/server.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src/",
|
|
26
|
+
"scripts/devctx-server.js",
|
|
27
|
+
"scripts/init-clients.js",
|
|
28
|
+
"scripts/report-metrics.js"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"mcp",
|
|
36
|
+
"model-context-protocol",
|
|
37
|
+
"ai-tools",
|
|
38
|
+
"code-search",
|
|
39
|
+
"ripgrep",
|
|
40
|
+
"devtools"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"start": "node ./scripts/devctx-server.js",
|
|
44
|
+
"smoke": "node ./scripts/smoke-test.js",
|
|
45
|
+
"smoke:json": "node ./scripts/smoke-test.js --json",
|
|
46
|
+
"init:clients": "node ./scripts/init-clients.js",
|
|
47
|
+
"smoke:formats": "node ./scripts/format-smoke.js",
|
|
48
|
+
"test": "node --test ./tests/*.test.js",
|
|
49
|
+
"eval": "node ./evals/harness.js",
|
|
50
|
+
"eval:context": "node ./evals/harness.js --tool=context",
|
|
51
|
+
"eval:both": "node ./evals/harness.js --tool=both",
|
|
52
|
+
"eval:self": "node ./evals/harness.js --root=../.. --corpus=./evals/corpus/self-tasks.json",
|
|
53
|
+
"eval:report": "node ./evals/report.js",
|
|
54
|
+
"report:metrics": "node ./scripts/report-metrics.js"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
58
|
+
"@vscode/ripgrep": "^1.17.1",
|
|
59
|
+
"js-tiktoken": "^1.0.21",
|
|
60
|
+
"typescript": "^6.0.2",
|
|
61
|
+
"zod": "^4.1.5"
|
|
62
|
+
}
|
|
63
|
+
}
|