关于 Local Code Indexing for Cursor
Local Code Indexing for Cursor 是一个实验性的 Python 服务,使用 ChromaDB 在本地为代码库建立索引,并通过 MCP 服务提供语义搜索工具。它面向在 Cursor 中处理多个项目的开发者,所有索引数据保存在本地。
主要功能
- 01基于 ChromaDB 的本地索引
- 02通过 MCP 暴露 search_code 语义搜索工具
- 03可通过 .env 配置索引的项目目录
- 04使用 Docker Compose 启动服务
适用场景
- 01在 Cursor Agent 模式中按语义检索已索引项目的代码
- 02在编码时替代部分 grep 类命令行搜索
MCP 相关
该项目是一个 MCP 服务,通过 SSE 端点(http://localhost:8978/sse)向 Cursor 等客户端提供 @search_code 工具。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
服务地址
http://localhost:8978/sse一键复制安装命令
Claude CodeTerminal
claude mcp add --transport http cursor-local-indexing http://localhost:8978/sseCursor.cursor/mcp.json
{"mcpServers":{"cursor-local-indexing":{"type":"http","url":"http://localhost:8978/sse"}}}在 Cursor 中打开VS Code.vscode/mcp.json
{"servers":{"cursor-local-indexing":{"type":"http","url":"http://localhost:8978/sse"}}}在 VS Code 中打开Claude Desktopclaude_desktop_config.json
{"mcpServers":{"cursor-local-indexing":{"type":"http","url":"http://localhost:8978/sse"}}}Windsurf~/.codeium/windsurf/mcp_config.json
{"mcpServers":{"cursor-local-indexing":{"serverUrl":"http://localhost:8978/sse"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
详细介绍
Cursor 的本地代码索引
一个基于 Python 的实验性服务,使用 ChromaDB 在本地为代码库建立索引,并通过 MCP(Model Context Protocol)服务为 Cursor 等工具提供语义搜索工具。
设置
-
克隆并进入仓库:
git clone <repository-url> cd cursor-local-indexing -
复制
.env.example,创建.env文件:cp .env.example .env -
配置
.env文件:PROJECTS_ROOT=~/your/projects/root # Path to your projects directory FOLDERS_TO_INDEX=project1,project2 # Comma-separated list of folders to index示例:
PROJECTS_ROOT=~/projects FOLDERS_TO_INDEX=project1,project2 -
启动索引服务:
docker-compose up -d -
配置 Cursor 以使用本地搜索服务: 创建或编辑
~/.cursor/mcp.json:{ "mcpServers": { "workspace-code-search": { "url": "http://localhost:8978/sse" } } } -
重启 Cursor IDE 以应用更改。
服务将开始为你指定的项目建立索引;当这些项目处于活动状态时,你便可以在 Cursor 中使用代码语义搜索。
- 打开一个你配置为已建立索引的项目。
创建 .cursorrules 文件并添加以下内容:
<instructions>
For any request, use the @search_code tool to check what the code does.
Prefer that first before resorting to command line grepping etc.
</instructions>
- 开始使用 Cursor Agent 模式,看看它如何执行本地向量搜索!
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。