快速上下文MCP
人工智能驱动的语义代码搜索作为MCP工具,由Windsurf的逆向工程SWE grep协议提供支持。
任何兼容MCP的客户端(Claude Code、Claude Desktop、Cursor等)都可以使用此功能通过自然语言查询搜索代码库。所有工具都通过npm捆绑-- 无系统级依赖关系 需要(ripgrep通过 @vscode/ripgrep,树通过 tree-node-cli).适用于macOS、Windows和Linux。
运作原理
You: "where is the authentication logic?"
│
▼
┌─────────────────────────┐
│ Fast Context MCP │
│ (local MCP server) │
│ │
│ 1. Maps project → /codebase
│ 2. Sends query to Windsurf Devstral API
│ 3. AI generates rg/readfile/tree commands
│ 4. Executes commands locally (built-in rg)
│ 5. Returns results to AI
│ 6. Repeats for N rounds
│ 7. Returns file paths + line ranges
│ + suggested search keywords
└─────────────────────────┘
│
▼
Found 3 relevant files.
[1/3] /project/src/auth/handler.py (L10-60)
[2/3] /project/src/middleware/jwt.py (L1-40)
[3/3] /project/src/models/user.py (L20-80)
Suggested search keywords:
authenticate, jwt.*verify, session.*token先决条件
- Node.js >= 18
- Windsurf帐户 -自由层工作(API密钥需要)
无需安装ripgrep——它通过以下方式捆绑在一起 @vscode/ripgrep.
安装
选项1:npm(推荐)
# Latest stable release
npm install @sammysnake/fast-context-mcp
# Or beta/next release
npm install @sammysnake/fast-context-mcp@next选项2:来源
git clone https://github.com/SammySnake-d/fast-context-mcp.git
cd fast-context-mcp
npm install设置
1.获取Windsurf API密钥
服务器自动从本地安装的Windsurf导出API密钥。您还可以使用 extract_windsurf_key 设置后的MCP工具,或设置 WINDSURF_API_KEY 手动。
密钥存储在Windsurf的本地SQLite数据库中:
| 平台 | 路径 |
|---|---|
| macOS | ~/Library/Application Support/Windsurf/User/globalStorage/state.vscdb |
| 窗户 | %APPDATA%/Windsurf/User/globalStorage/state.vscdb |
| Linux | ~/.config/Windsurf/User/globalStorage/state.vscdb |
2.配置MCP客户端
克劳德代码
增添 ~/.claude.json 在...之下 mcpServers:
{
"fast-context": {
"command": "npx",
"args": ["-y", "--prefer-online", "@sammysnake/fast-context-mcp"],
"env": {
"WINDSURF_API_KEY": "sk-ws-01-xxxxx"
}
}
}对于测试版/下一版本:
{
"fast-context": {
"command": "npx",
"args": ["-y", "--prefer-online", "@sammysnake/fast-context-mcp@next"],
"env": {
"WINDSURF_API_KEY": "sk-ws-01-xxxxx"
}
}
}克劳德桌面版
增添 claude_desktop_config.json 在...之下 mcpServers:
{
"fast-context": {
"command": "npx",
"args": ["-y", "--prefer-online", "@sammysnake/fast-context-mcp"],
"env": {
"WINDSURF_API_KEY": "sk-ws-01-xxxxx"
}
}
}对于测试版/下一版本:
{
"fast-context": {
"command": "npx",
"args": ["-y", "--prefer-online", "@sammysnake/fast-context-mcp@next"],
"env": {
"WINDSURF_API_KEY": "sk-ws-01-xxxxx"
}
}
}如果 WINDSURF_API_KEY 如果省略,服务器会自动从您的本地Windsurf安装中发现它。环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
WINDSURF_API_KEY | *(自动发现)* | 风帆API键 |
FC_MAX_TURNS | 3 | 每个查询的搜索轮次(更多=更深但更慢) |
FC_MAX_COMMANDS | 8 | 每轮最大并行命令数 |
FC_TIMEOUT_MS | 30000 | 流媒体请求的连接超时Ms |
FC_RESULT_MAX_LINES | 50 | 每个命令输出的最大行数(截断) |
FC_LINE_MAX_CHARS | 250 | 每行输出的最大字符数(截断) |
WS_MODEL | MODEL_SWE_1_6_FAST | Windsurf型号名称 |
WS_APP_VER | 1.48.2 | Windsurf应用程序版本(协议元数据) |
WS_LS_VER | 1.9544.35 | Windsurf语言服务器版本(协议元数据) |
可用型号
可以通过设置更改模型 WS_MODEL (见上文环境变量)。
违约: MODEL_SWE_1_6_FAST --速度最快,grep关键字最丰富,位置粒度最精细。
MCP工具
fast_context_search
人工智能驱动的语义代码搜索,参数可调。
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
query | string | 是 | -- | 自然语言搜索查询 |
project_path | string | 否 | cwd | 项目根的绝对路径 |
tree_depth | 整数 | 否 | 3 | 仓库映射的目录树深度(1-6)。更高=上下文更多,但有效载荷更大。如果树超过250KB,则自动回退到较低深度。对于大型monorepos(>5000个文件)使用1-2,对于大多数项目使用3,对于小型项目使用4-6。 |
max_turns | 整数 | 否 | 3 | 搜索轮次(1-5)。更多=搜索更深入,但速度较慢。1-2用于简单查找,3用于大多数查询,4-5用于复杂分析。 |
max_results | 整数 | 否 | 10 | 要返回的最大文件数(1-30)。更小=更专注,更大=更广泛的探索。 |
退货:
- 相关文件 带线条范围
- 建议搜索关键字 (AI搜索过程中使用的rg模式)
- 诊断元数据 (
[config]显示实际使用的树深度、树大小以及是否发生回退的行)
输出示例:
Found 3 relevant files.
[1/3] /project/src/auth/handler.py (L10-60, L120-180)
[2/3] /project/src/middleware/jwt.py (L1-40)
[3/3] /project/src/models/user.py (L20-80)
grep keywords: authenticate, jwt.*verify, session.*token
[config] tree_depth=3, tree_size=12.5KB, max_turns=3错误输出包括特定于状态的提示:
Error: Request failed: HTTP 403
[hint] 403 Forbidden: Authentication failed. The API key may be expired or revoked.
Try re-extracting with extract_windsurf_key, or set a fresh WINDSURF_API_KEY env var.Error: Request failed: HTTP 413
[diagnostic] tree_depth_used=3, tree_size=280.0KB (auto fell back from requested depth)
[hint] If the error is payload-related, try a lower tree_depth value.extract_windsurf_key
从本地安装中提取Windsurf API密钥。没有参数。
项目结构
fast-context-mcp/
├── package.json
├── src/
│ ├── server.mjs # MCP server entry point
│ ├── core.mjs # Auth, message building, streaming, search loop
│ ├── executor.mjs # Tool executor: rg, readfile, tree, ls, glob
│ ├── extract-key.mjs # Windsurf API Key extraction (SQLite)
│ └── protobuf.mjs # Protobuf encoder/decoder + Connect-RPC frames
├── README.md
└── LICENSE搜索是如何工作的
- 项目目录映射到虚拟
/codebase路径 - 在请求的深度生成目录树(默认L=3),其中 自动回退 如果树超过250KB,则降低深度
- 通过Connect-RPC/Protobuf将查询+目录树发送到Windsurf的Devstral模型
- Devstral生成工具命令(ripgrep、文件读取、树、ls、glob)
- 在本地并行执行的命令(最多
FC_MAX_COMMANDS每轮) - 结果发回Devstral进行下一轮测试
- 之后
max_turnsrounds,Devstral返回文件路径+行范围 - 搜索过程中使用的所有rg模式都被收集为建议关键字
- 附加诊断元数据以帮助调用AI调整参数
技术细节
- 协议:通过HTTP/1.1连接RPC,Protobuf编码,gzip压缩
- 模型:Devstral(
MODEL_SWE_1_6_FAST,可配置) - 本地工具:
rg(通过@vscode/ripgrep捆绑),readfile(Node.js fs),tree(树节点cli),ls(Node.js fs),glob(Node.js fs) - 认证:API密钥→ JWT(每次会话自动获取)
- 运行时:Node.js>=18(ESM)
依赖项
| 包装 | 用途 |
|---|---|
@modelcontextprotocol/sdk | MCP服务器框架 |
@vscode/ripgrep | 捆绑的ripgrep二进制文件(跨平台) |
tree-node-cli | 跨平台目录树(替换系统 tree) |
better-sqlite3 | 阅读Windsurf的本地SQLite数据库 |
zod | 模式验证(MCP SDK要求) |
许可证
麻省理工学院
