Local Code Indexing for Cursor

Local Code Indexing for Cursor

site icon
2025.03.20 13
Python代码索引语义搜索开发效率
cursor-local-indexing 是一个实验性的基于 Python 的服务器,用于本地索引代码库,并通过 MCP(Model Context Protocol)服务器提供语义搜索工具,适用于 Cursor 等工具。
View on GitHub

Overview

基本能力

产品定位

cursor-local-indexing 是一个本地代码索引和语义搜索工具,旨在为开发者提供高效的代码搜索能力。

核心功能

  1. 本地代码索引:使用 ChromaDB 对代码库进行本地索引。
  2. 语义搜索:通过 MCP 服务器提供语义搜索功能。
  3. 集成 Cursor:与 Cursor IDE 集成,支持在 IDE 中使用本地搜索功能。

适用场景

  1. 代码搜索:在大型代码库中快速找到相关代码片段。
  2. 开发辅助:在 Cursor IDE 中通过语义搜索提高开发效率。
  3. 代码理解:通过语义搜索快速理解代码功能和结构。

工具列表

  1. ChromaDB:用于本地代码索引的数据库。
  2. MCP 服务器:提供语义搜索服务的协议服务器。

常见问题解答

  1. 如何配置索引目录?:在 .env 文件中设置 PROJECTS_ROOTFOLDERS_TO_INDEX
  2. 如何启动服务器?:使用 docker-compose up -d 命令启动。
  3. 如何集成到 Cursor?:在 ~/.cursor/mcp.json 中配置服务器 URL。

使用教程

使用依赖

  1. 确保已安装 Docker 和 Docker Compose。
  2. 确保已安装 Git。

安装教程

  1. 克隆仓库并进入目录: bash git clone <repository-url> cd cursor-local-indexing
  2. 复制 .env.example.envbash cp .env.example .env
  3. 配置 .env 文件: env PROJECTS_ROOT=~/your/projects/root FOLDERS_TO_INDEX=project1,project2
  4. 启动索引服务器: bash docker-compose up -d
  5. 配置 Cursor 使用本地搜索服务器: 创建或编辑 ~/.cursor/mcp.jsonjson { "mcpServers": { "workspace-code-search": { "url": "http://localhost:8978/sse" } } }
  6. 重启 Cursor IDE 以应用更改。
  7. 打开一个已配置为索引的项目。
  8. 创建 .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>
  9. 开始使用 Cursor Agent 模式并查看本地向量搜索功能。

调试方式

  1. 检查 Docker 容器是否正常运行: bash docker ps
  2. 查看容器日志: bash docker-compose logs
  3. 确保 Cursor IDE 已正确配置 MCP 服务器 URL。

许可证

None