@sammysnake/fast-context-mcp 1.3.0-beta.1

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
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,274 @@
1
+ # Fast Context MCP
2
+
3
+ AI-driven semantic code search as an MCP tool — powered by Windsurf's reverse-engineered SWE-grep protocol.
4
+
5
+ Any MCP-compatible client (Claude Code, Claude Desktop, Cursor, etc.) can use this to search codebases with natural language queries. All tools are bundled via npm — **no system-level dependencies** needed (ripgrep via `@vscode/ripgrep`, tree via `tree-node-cli`). Works on macOS, Windows, and Linux.
6
+
7
+ ## How It Works
8
+
9
+ ```
10
+ You: "where is the authentication logic?"
11
+
12
+
13
+ ┌──────────────────────────────────────────────────────┐
14
+ │ Fast Context MCP (local MCP server) │
15
+ │ │
16
+ │ Phase 1: Bootstrap (optional) │
17
+ │ 1. Mini-tree scan → Devstral API │
18
+ │ 2. Returns hot directories + rg patterns │
19
+ │ │
20
+ │ Phase 2: Directory Scoring │
21
+ │ 3. BM25F + Probe grep + Git RFM + File Agg │
22
+ │ 4. RRF fusion → adaptive topK selection │
23
+ │ (Kneedle gap + entropy + tail threshold) │
24
+ │ 5. Path spine extraction (scored file hints) │
25
+ │ │
26
+ │ Phase 3: Main Search (N rounds) │
27
+ │ 6. Query + optimized repo map → Devstral API │
28
+ │ (tree + hotspot subtrees + path spines) │
29
+ │ 7. AI generates rg/readfile/tree/ls commands │
30
+ │ 8. Execute locally (built-in rg) → return results │
31
+ │ 9. Repeat for N rounds │
32
+ │ 10. Final answer: file paths + line ranges │
33
+ │ + suggested search keywords │
34
+ └──────────────────────────────────────────────────────┘
35
+
36
+
37
+ Found 5 relevant files.
38
+ [1/5] /project/src/auth/handler.py (L10-60)
39
+ [2/5] /project/src/middleware/jwt.py (L1-40)
40
+ [3/5] /project/src/models/user.py (L20-80)
41
+ [4/5] /project/src/routes/login.py (L5-35)
42
+ [5/5] /project/src/utils/token.py (L1-25)
43
+
44
+ Suggested search keywords:
45
+ authenticate, jwt.*verify, session.*token
46
+ ```
47
+
48
+ ## Prerequisites
49
+
50
+ - **Node.js** >= 18
51
+ - **Windsurf account** — free tier works (needed for API key)
52
+
53
+ No need to install ripgrep — it's bundled via `@vscode/ripgrep`.
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ git clone https://github.com/SammySnake-d/fast-context-mcp.git
59
+ cd fast-context-mcp
60
+ npm install
61
+ ```
62
+
63
+ ## Setup
64
+
65
+ ### 1. Get Your Windsurf API Key
66
+
67
+ The server auto-extracts the API key from your local Windsurf installation. You can also use the `extract_windsurf_key` MCP tool after setup, or set `WINDSURF_API_KEY` manually.
68
+
69
+ Key is stored in Windsurf's local SQLite database:
70
+
71
+ | Platform | Path |
72
+ |----------|------|
73
+ | macOS | `~/Library/Application Support/Windsurf/User/globalStorage/state.vscdb` |
74
+ | Windows | `%APPDATA%/Windsurf/User/globalStorage/state.vscdb` |
75
+ | Linux | `~/.config/Windsurf/User/globalStorage/state.vscdb` |
76
+
77
+ ### 2. Configure MCP Client
78
+
79
+ #### Claude Code
80
+
81
+ Add to `~/.claude.json` under `mcpServers`:
82
+
83
+ ```json
84
+ {
85
+ "fast-context": {
86
+ "command": "node",
87
+ "args": ["/absolute/path/to/fast-context-mcp/src/server.mjs"],
88
+ "env": {
89
+ "WINDSURF_API_KEY": "sk-ws-01-xxxxx"
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ #### Claude Desktop
96
+
97
+ Add to `claude_desktop_config.json` under `mcpServers`:
98
+
99
+ ```json
100
+ {
101
+ "fast-context": {
102
+ "command": "node",
103
+ "args": ["/absolute/path/to/fast-context-mcp/src/server.mjs"],
104
+ "env": {
105
+ "WINDSURF_API_KEY": "sk-ws-01-xxxxx"
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ > If `WINDSURF_API_KEY` is omitted, the server auto-discovers it from your local Windsurf installation.
112
+
113
+ ## Environment Variables
114
+
115
+ | Variable | Default | Description |
116
+ |----------|---------|-------------|
117
+ | `WINDSURF_API_KEY` | *(auto-discover)* | Windsurf API key |
118
+ | `FC_MAX_TURNS` | `3` | Search rounds per query (more = deeper but slower) |
119
+ | `FC_MAX_COMMANDS` | `8` | Max parallel commands per round |
120
+ | `FC_TIMEOUT_MS` | `30000` | Connect-Timeout-Ms for streaming requests |
121
+ | `FC_REPO_MAP_MODE` | `bootstrap_hotspot` | Repo map strategy (`classic` or `bootstrap_hotspot`) |
122
+ | `FC_BOOTSTRAP_TREE_DEPTH` | `1` | Bootstrap mini-tree depth |
123
+ | `FC_HOTSPOT_TOP_K` | `4` | Base hotspot dirs (adaptive topK overrides via Kneedle + entropy) |
124
+ | `FC_HOTSPOT_TREE_DEPTH` | `2` | Tree depth for each hotspot subtree |
125
+ | `FC_HOTSPOT_MAX_BYTES` | `122880` | Max bytes budget for optimized repo map |
126
+ | `FC_BOOTSTRAP_ENABLED` | `true` | Enable standalone bootstrap phase |
127
+ | `FC_BOOTSTRAP_MAX_TURNS` | `2` | Bootstrap phase turns |
128
+ | `FC_BOOTSTRAP_MAX_COMMANDS` | `6` | Bootstrap commands per turn |
129
+ | `FC_RESULT_MAX_LINES` | `50` | Max lines per command output (truncation) |
130
+ | `FC_LINE_MAX_CHARS` | `250` | Max characters per output line (truncation) |
131
+ | `FC_PROFILE_CACHE_TTL` | `120` | Directory profile cache TTL in seconds |
132
+ | `FC_GIT_CACHE_TTL` | `300` | Git RFM analysis cache TTL in seconds |
133
+ | `WS_MODEL` | `MODEL_SWE_1_6_FAST` | Windsurf model name |
134
+ | `WS_APP_VER` | `1.48.2` | Windsurf app version (protocol metadata) |
135
+ | `WS_LS_VER` | `1.9544.35` | Windsurf language server version (protocol metadata) |
136
+
137
+ ## Available Models
138
+
139
+ The model can be changed by setting `WS_MODEL` (see environment variables above).
140
+
141
+ ![Available Models](docs/models.png)
142
+
143
+ Default: `MODEL_SWE_1_6_FAST` — fastest speed, richest grep keywords, finest location granularity.
144
+
145
+ ## MCP Tools
146
+
147
+ ### `fast_context_search`
148
+
149
+ AI-driven semantic code search with tunable parameters.
150
+
151
+ | Parameter | Type | Required | Default | Description |
152
+ |-----------|------|----------|---------|-------------|
153
+ | `query` | string | Yes | — | Natural language search query |
154
+ | `project_path` | string | No | cwd | Absolute path to project root |
155
+ | `tree_depth` | integer | No | `3` | Main-phase repo map depth (`0-6`, `0=auto`). Higher = more structure context but larger payload. |
156
+ | `max_turns` | integer | No | `3` | Main-phase search rounds (`1-5`). More = deeper search but slower. |
157
+ | `max_results` | integer | No | `10` | Maximum number of files to return (`1-30`). |
158
+ | `exclude_paths` | string[] | No | `[]` | Extra exclude patterns merged with built-in default excludes (`node_modules`, `.git`, `dist`, `build`, `coverage`, `.venv`, ...). |
159
+ | `repo_map_mode` | enum | No | `bootstrap_hotspot` | Repo map strategy: `classic` or `bootstrap_hotspot`. |
160
+ | `bootstrap_tree_depth` | integer | No | `1` | Bootstrap phase mini-tree depth (`1-3`). |
161
+ | `hotspot_top_k` | integer | No | `4` | Base hotspot dirs (`0-8`). Adaptive topK may expand this based on score distribution. |
162
+ | `hotspot_tree_depth` | integer | No | `2` | Tree depth per hotspot subtree (`1-4`). |
163
+ | `hotspot_max_bytes` | integer | No | `122880` | Max byte budget for optimized repo map (`16384-262144`). |
164
+ | `bootstrap_enabled` | boolean | No | `true` | Enable standalone bootstrap phase before main search. |
165
+ | `bootstrap_max_turns` | integer | No | `2` | Bootstrap turns (`1-3`). Independent from `max_turns`. |
166
+ | `bootstrap_max_commands` | integer | No | `6` | Bootstrap commands per turn (`1-8`). Independent from main commands. |
167
+
168
+ Returns:
169
+ 1. **Relevant files** with line ranges
170
+ 2. **Suggested search keywords** (rg patterns used during AI search)
171
+ 3. **Diagnostic metadata** (`[config]` line showing actual tree_depth used, tree size, and whether fallback occurred)
172
+
173
+ Example output:
174
+ ```
175
+ Found 3 relevant files.
176
+
177
+ [1/3] /project/src/auth/handler.py (L10-60, L120-180)
178
+ [2/3] /project/src/middleware/jwt.py (L1-40)
179
+ [3/3] /project/src/models/user.py (L20-80)
180
+
181
+ grep keywords: authenticate, jwt.*verify, session.*token
182
+
183
+ [config] tree_depth=3, tree_size=12.5KB, max_turns=3
184
+ ```
185
+
186
+ Error output includes status-specific hints:
187
+ ```
188
+ Error: Request failed: HTTP 403
189
+
190
+ [hint] 403 Forbidden: Authentication failed. The API key may be expired or revoked.
191
+ Try re-extracting with extract_windsurf_key, or set a fresh WINDSURF_API_KEY env var.
192
+ ```
193
+
194
+ ```
195
+ Error: Request failed: HTTP 413
196
+
197
+ [diagnostic] tree_depth_used=3, tree_size=280.0KB (auto fell back from requested depth)
198
+ [hint] If the error is payload-related, try a lower tree_depth value.
199
+ ```
200
+
201
+ ### `extract_windsurf_key`
202
+
203
+ Extract Windsurf API Key from local installation. No parameters.
204
+
205
+ ## Project Structure
206
+
207
+ ```
208
+ fast-context-mcp/
209
+ ├── package.json
210
+ ├── src/
211
+ │ ├── server.mjs # MCP server entry point
212
+ │ ├── core.mjs # Auth, message building, streaming, search loop
213
+ │ ├── executor.mjs # Tool executor: rg, readfile, tree, ls, glob
214
+ │ ├── directory-scorer.mjs # BM25F + Probe + Git RFM directory scoring
215
+ │ ├── extract-key.mjs # Windsurf API Key extraction (SQLite)
216
+ │ └── protobuf.mjs # Protobuf encoder/decoder + Connect-RPC frames
217
+ ├── README.md
218
+ └── LICENSE
219
+ ```
220
+
221
+ ## How the Search Works
222
+
223
+ 1. Project directory is mapped to virtual `/codebase` path
224
+ 2. **Directory scoring** via 5-signal RRF fusion:
225
+ - **BM25F**: multi-field scoring (dir name, file paths, metadata, headers)
226
+ - **Probe grep**: single ripgrep call with regex alternation for content matching
227
+ - **Bootstrap keywords**: terms from optional bootstrap pre-scan
228
+ - **Git RFM**: Recency-Frequency-Modification model from git history
229
+ - **File aggregation**: file-level Log-Sum scoring per directory
230
+ 3. **Adaptive hotspot selection** based on IR literature:
231
+ - **Kneedle gap detection** (Taguchi 2025 Adaptive-k): finds the largest score drop as a natural cutoff
232
+ - **Entropy scaling** (CMU Selective Search): flat score distributions auto-expand K; peaked distributions keep K tight
233
+ - **Adaptive tail threshold**: includes strong dirs beyond cutoff based on score decay rate (replaces fixed 0.6 ratio)
234
+ 4. **Path spine extraction**: scored file paths as navigation hints, with source-code path boost and noise path penalty
235
+ 5. Query + optimized repo map (tree + hotspot subtrees + path spines) sent to Windsurf Devstral via Connect-RPC/Protobuf
236
+ 6. Devstral generates tool commands (ripgrep, file reads, tree, ls, glob)
237
+ 7. Commands executed locally in parallel (up to `FC_MAX_COMMANDS` per round)
238
+ 8. Results sent back to Devstral for the next round
239
+ 9. After `max_turns` rounds, Devstral returns file paths + line ranges
240
+ 10. All rg patterns used during search are collected as suggested keywords
241
+ 11. Diagnostic metadata appended to help the calling AI tune parameters
242
+
243
+ ### Caching
244
+
245
+ Directory profiles and Git history analysis are cached at the process level to avoid redundant filesystem walks across repeated queries:
246
+
247
+ | Cache | TTL | Configurable via |
248
+ |-------|-----|------------------|
249
+ | Directory profiles | 120s | `FC_PROFILE_CACHE_TTL` |
250
+ | Git RFM analysis | 300s | `FC_GIT_CACHE_TTL` |
251
+
252
+ Caches are scoped to the MCP server process lifetime and automatically expire. No manual invalidation needed for normal development workflows.
253
+
254
+ ## Technical Details
255
+
256
+ - **Protocol**: Connect-RPC over HTTP/1.1, Protobuf encoding, gzip compression
257
+ - **Model**: Devstral (`MODEL_SWE_1_6_FAST`, configurable)
258
+ - **Local tools**: `rg` (bundled via @vscode/ripgrep), `readfile` (Node.js fs), `tree` (tree-node-cli), `ls` (Node.js fs), `glob` (Node.js fs)
259
+ - **Auth**: API Key → JWT (auto-fetched per session)
260
+ - **Runtime**: Node.js >= 18 (ESM)
261
+
262
+ ### Dependencies
263
+
264
+ | Package | Purpose |
265
+ |---------|---------|
266
+ | `@modelcontextprotocol/sdk` | MCP server framework |
267
+ | `@vscode/ripgrep` | Bundled ripgrep binary (cross-platform) |
268
+ | `tree-node-cli` | Cross-platform directory tree (replaces system `tree`) |
269
+ | `sql.js` | Read Windsurf's local SQLite DB (WASM, no native deps) |
270
+ | `zod` | Schema validation (MCP SDK requirement) |
271
+
272
+ ## License
273
+
274
+ MIT
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@sammysnake/fast-context-mcp",
3
+ "version": "1.3.0-beta.1",
4
+ "description": "AI-driven semantic code search via reverse-engineered Windsurf protocol (Node.js)",
5
+ "type": "module",
6
+ "main": "src/server.mjs",
7
+ "bin": {
8
+ "fast-context-mcp": "src/server.mjs"
9
+ },
10
+ "files": [
11
+ "src/",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "start": "node src/server.mjs"
17
+ },
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/SammySnake-d/fast-context-mcp.git"
24
+ },
25
+ "homepage": "https://github.com/SammySnake-d/fast-context-mcp#readme",
26
+ "bugs": {
27
+ "url": "https://github.com/SammySnake-d/fast-context-mcp/issues"
28
+ },
29
+ "keywords": [
30
+ "mcp",
31
+ "code-search",
32
+ "semantic-search",
33
+ "windsurf",
34
+ "devstral",
35
+ "ripgrep",
36
+ "claude",
37
+ "ai"
38
+ ],
39
+ "dependencies": {
40
+ "@modelcontextprotocol/sdk": "^1.0.0",
41
+ "@vscode/ripgrep": "^1.15.9",
42
+ "sql.js": "^1.14.0",
43
+ "tree-node-cli": "^1.6.0",
44
+ "zod": "^3.23.0"
45
+ },
46
+ "license": "MIT"
47
+ }