
Local Code Indexing for Cursor

2025.03.20
13
Python代码索引语义搜索开发效率
cursor-local-indexing 是一个实验性的基于 Python 的服务器,用于本地索引代码库,并通过 MCP(Model Context Protocol)服务器提供语义搜索工具,适用于 Cursor 等工具。
View on GitHub
Overview
基本能力
产品定位
cursor-local-indexing 是一个本地代码索引和语义搜索工具,旨在为开发者提供高效的代码搜索能力。
核心功能
- 本地代码索引:使用 ChromaDB 对代码库进行本地索引。
- 语义搜索:通过 MCP 服务器提供语义搜索功能。
- 集成 Cursor:与 Cursor IDE 集成,支持在 IDE 中使用本地搜索功能。
适用场景
- 代码搜索:在大型代码库中快速找到相关代码片段。
- 开发辅助:在 Cursor IDE 中通过语义搜索提高开发效率。
- 代码理解:通过语义搜索快速理解代码功能和结构。
工具列表
- ChromaDB:用于本地代码索引的数据库。
- MCP 服务器:提供语义搜索服务的协议服务器。
常见问题解答
- 如何配置索引目录?:在
.env
文件中设置PROJECTS_ROOT
和FOLDERS_TO_INDEX
。 - 如何启动服务器?:使用
docker-compose up -d
命令启动。 - 如何集成到 Cursor?:在
~/.cursor/mcp.json
中配置服务器 URL。
使用教程
使用依赖
- 确保已安装 Docker 和 Docker Compose。
- 确保已安装 Git。
安装教程
- 克隆仓库并进入目录:
bash git clone <repository-url> cd cursor-local-indexing
- 复制
.env.example
为.env
:bash cp .env.example .env
- 配置
.env
文件:env PROJECTS_ROOT=~/your/projects/root FOLDERS_TO_INDEX=project1,project2
- 启动索引服务器:
bash docker-compose up -d
- 配置 Cursor 使用本地搜索服务器:
创建或编辑
~/.cursor/mcp.json
:json { "mcpServers": { "workspace-code-search": { "url": "http://localhost:8978/sse" } } }
- 重启 Cursor IDE 以应用更改。
- 打开一个已配置为索引的项目。
- 创建
.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 模式并查看本地向量搜索功能。
调试方式
- 检查 Docker 容器是否正常运行:
bash docker ps
- 查看容器日志:
bash docker-compose logs
- 确保 Cursor IDE 已正确配置 MCP 服务器 URL。
许可证
None