fast-context-mcp 1.0.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,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,222 @@
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 │
15
+ │ (local MCP server) │
16
+ │ │
17
+ │ 1. Maps project → /codebase
18
+ │ 2. Sends query to Windsurf Devstral API
19
+ │ 3. AI generates rg/readfile/tree commands
20
+ │ 4. Executes commands locally (built-in rg)
21
+ │ 5. Returns results to AI
22
+ │ 6. Repeats for N rounds
23
+ │ 7. Returns file paths + line ranges
24
+ │ + suggested search keywords
25
+ └─────────────────────────┘
26
+
27
+
28
+ Found 3 relevant files.
29
+ [1/3] /project/src/auth/handler.py (L10-60)
30
+ [2/3] /project/src/middleware/jwt.py (L1-40)
31
+ [3/3] /project/src/models/user.py (L20-80)
32
+
33
+ Suggested search keywords:
34
+ authenticate, jwt.*verify, session.*token
35
+ ```
36
+
37
+ ## Prerequisites
38
+
39
+ - **Node.js** >= 18
40
+ - **Windsurf account** — free tier works (needed for API key)
41
+
42
+ No need to install ripgrep — it's bundled via `@vscode/ripgrep`.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ git clone https://github.com/SammySnake-d/fast-context-mcp.git
48
+ cd fast-context-mcp
49
+ npm install
50
+ ```
51
+
52
+ ## Setup
53
+
54
+ ### 1. Get Your Windsurf API Key
55
+
56
+ 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.
57
+
58
+ Key is stored in Windsurf's local SQLite database:
59
+
60
+ | Platform | Path |
61
+ |----------|------|
62
+ | macOS | `~/Library/Application Support/Windsurf/User/globalStorage/state.vscdb` |
63
+ | Windows | `%APPDATA%/Windsurf/User/globalStorage/state.vscdb` |
64
+ | Linux | `~/.config/Windsurf/User/globalStorage/state.vscdb` |
65
+
66
+ ### 2. Configure MCP Client
67
+
68
+ #### Claude Code
69
+
70
+ Add to `~/.claude.json` under `mcpServers`:
71
+
72
+ ```json
73
+ {
74
+ "fast-context": {
75
+ "command": "node",
76
+ "args": ["/absolute/path/to/fast-context-mcp/src/server.mjs"],
77
+ "env": {
78
+ "WINDSURF_API_KEY": "sk-ws-01-xxxxx"
79
+ }
80
+ }
81
+ }
82
+ ```
83
+
84
+ #### Claude Desktop
85
+
86
+ Add to `claude_desktop_config.json` under `mcpServers`:
87
+
88
+ ```json
89
+ {
90
+ "fast-context": {
91
+ "command": "node",
92
+ "args": ["/absolute/path/to/fast-context-mcp/src/server.mjs"],
93
+ "env": {
94
+ "WINDSURF_API_KEY": "sk-ws-01-xxxxx"
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ > If `WINDSURF_API_KEY` is omitted, the server auto-discovers it from your local Windsurf installation.
101
+
102
+ ## Environment Variables
103
+
104
+ | Variable | Default | Description |
105
+ |----------|---------|-------------|
106
+ | `WINDSURF_API_KEY` | *(auto-discover)* | Windsurf API key |
107
+ | `FC_MAX_TURNS` | `3` | Search rounds per query (more = deeper but slower) |
108
+ | `FC_MAX_COMMANDS` | `8` | Max parallel commands per round |
109
+ | `FC_TIMEOUT_MS` | `30000` | Connect-Timeout-Ms for streaming requests |
110
+ | `FC_RESULT_MAX_LINES` | `50` | Max lines per command output (truncation) |
111
+ | `FC_LINE_MAX_CHARS` | `250` | Max characters per output line (truncation) |
112
+ | `WS_MODEL` | `MODEL_SWE_1_6_FAST` | Windsurf model name |
113
+ | `WS_APP_VER` | `1.48.2` | Windsurf app version (protocol metadata) |
114
+ | `WS_LS_VER` | `1.9544.35` | Windsurf language server version (protocol metadata) |
115
+
116
+ ## Available Models
117
+
118
+ The model can be changed by setting `WS_MODEL` (see environment variables above).
119
+
120
+ ![Available Models](docs/models.png)
121
+
122
+ Default: `MODEL_SWE_1_6_FAST` — fastest speed, richest grep keywords, finest location granularity.
123
+
124
+ ## MCP Tools
125
+
126
+ ### `fast_context_search`
127
+
128
+ AI-driven semantic code search with tunable parameters.
129
+
130
+ | Parameter | Type | Required | Default | Description |
131
+ |-----------|------|----------|---------|-------------|
132
+ | `query` | string | Yes | — | Natural language search query |
133
+ | `project_path` | string | No | cwd | Absolute path to project root |
134
+ | `tree_depth` | integer | No | `3` | Directory tree depth for repo map (1-6). Higher = more context but larger payload. Auto falls back to lower depth if tree exceeds 250KB. Use 1-2 for huge monorepos (>5000 files), 3 for most projects, 4-6 for small projects. |
135
+ | `max_turns` | integer | No | `3` | Search rounds (1-5). More = deeper search but slower. Use 1-2 for simple lookups, 3 for most queries, 4-5 for complex analysis. |
136
+ | `max_results` | integer | No | `10` | Maximum number of files to return (1-30). Smaller = more focused, larger = broader exploration. |
137
+
138
+ Returns:
139
+ 1. **Relevant files** with line ranges
140
+ 2. **Suggested search keywords** (rg patterns used during AI search)
141
+ 3. **Diagnostic metadata** (`[config]` line showing actual tree_depth used, tree size, and whether fallback occurred)
142
+
143
+ Example output:
144
+ ```
145
+ Found 3 relevant files.
146
+
147
+ [1/3] /project/src/auth/handler.py (L10-60, L120-180)
148
+ [2/3] /project/src/middleware/jwt.py (L1-40)
149
+ [3/3] /project/src/models/user.py (L20-80)
150
+
151
+ grep keywords: authenticate, jwt.*verify, session.*token
152
+
153
+ [config] tree_depth=3, tree_size=12.5KB, max_turns=3
154
+ ```
155
+
156
+ Error output includes status-specific hints:
157
+ ```
158
+ Error: Request failed: HTTP 403
159
+
160
+ [hint] 403 Forbidden: Authentication failed. The API key may be expired or revoked.
161
+ Try re-extracting with extract_windsurf_key, or set a fresh WINDSURF_API_KEY env var.
162
+ ```
163
+
164
+ ```
165
+ Error: Request failed: HTTP 413
166
+
167
+ [diagnostic] tree_depth_used=3, tree_size=280.0KB (auto fell back from requested depth)
168
+ [hint] If the error is payload-related, try a lower tree_depth value.
169
+ ```
170
+
171
+ ### `extract_windsurf_key`
172
+
173
+ Extract Windsurf API Key from local installation. No parameters.
174
+
175
+ ## Project Structure
176
+
177
+ ```
178
+ fast-context-mcp/
179
+ ├── package.json
180
+ ├── src/
181
+ │ ├── server.mjs # MCP server entry point
182
+ │ ├── core.mjs # Auth, message building, streaming, search loop
183
+ │ ├── executor.mjs # Tool executor: rg, readfile, tree, ls, glob
184
+ │ ├── extract-key.mjs # Windsurf API Key extraction (SQLite)
185
+ │ └── protobuf.mjs # Protobuf encoder/decoder + Connect-RPC frames
186
+ ├── README.md
187
+ └── LICENSE
188
+ ```
189
+
190
+ ## How the Search Works
191
+
192
+ 1. Project directory is mapped to virtual `/codebase` path
193
+ 2. Directory tree generated at requested depth (default L=3), with **automatic fallback** to lower depth if tree exceeds 250KB
194
+ 3. Query + directory tree sent to Windsurf's Devstral model via Connect-RPC/Protobuf
195
+ 4. Devstral generates tool commands (ripgrep, file reads, tree, ls, glob)
196
+ 5. Commands executed locally in parallel (up to `FC_MAX_COMMANDS` per round)
197
+ 6. Results sent back to Devstral for the next round
198
+ 7. After `max_turns` rounds, Devstral returns file paths + line ranges
199
+ 8. All rg patterns used during search are collected as suggested keywords
200
+ 9. Diagnostic metadata appended to help the calling AI tune parameters
201
+
202
+ ## Technical Details
203
+
204
+ - **Protocol**: Connect-RPC over HTTP/1.1, Protobuf encoding, gzip compression
205
+ - **Model**: Devstral (`MODEL_SWE_1_6_FAST`, configurable)
206
+ - **Local tools**: `rg` (bundled via @vscode/ripgrep), `readfile` (Node.js fs), `tree` (tree-node-cli), `ls` (Node.js fs), `glob` (Node.js fs)
207
+ - **Auth**: API Key → JWT (auto-fetched per session)
208
+ - **Runtime**: Node.js >= 18 (ESM)
209
+
210
+ ### Dependencies
211
+
212
+ | Package | Purpose |
213
+ |---------|---------|
214
+ | `@modelcontextprotocol/sdk` | MCP server framework |
215
+ | `@vscode/ripgrep` | Bundled ripgrep binary (cross-platform) |
216
+ | `tree-node-cli` | Cross-platform directory tree (replaces system `tree`) |
217
+ | `better-sqlite3` | Read Windsurf's local SQLite DB |
218
+ | `zod` | Schema validation (MCP SDK requirement) |
219
+
220
+ ## License
221
+
222
+ MIT
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "fast-context-mcp",
3
+ "version": "1.0.0",
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
+ "dependencies": {
22
+ "@modelcontextprotocol/sdk": "^1.0.0",
23
+ "@vscode/ripgrep": "^1.15.9",
24
+ "better-sqlite3": "^11.0.0",
25
+ "tree-node-cli": "^1.6.0",
26
+ "zod": "^3.23.0"
27
+ },
28
+ "license": "MIT"
29
+ }