code-index-mcp

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Provides access to git repositories, allowing users to clone projects for code indexing and analysis.

代码索引 MCP

代码索引 MCP 是一个模型上下文协议服务器,它使大型语言模型 (LLM) 能够索引、搜索和分析项目目录中的代码。

特征

  • 索引和导航项目文件结构
  • 在代码中搜索特定模式
  • 获取详细文件摘要
  • 分析代码结构和复杂性
  • 支持多种编程语言
  • 项目设置的持久存储

安装

本项目使用uv进行环境管理和依赖项安装。

  1. 确保安装了 Python 3.10 或更高版本
  2. 安装 uv(推荐):
    # Windows powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | sh
  3. 获取代码:
    # Clone the repository git clone https://github.com/your-username/code-index-mcp.git

用法

直接运行服务器

# Run directly with uv - no additional dependency installation needed uv run run.py

UV 将根据项目的配置自动处理所有依赖项的安装。

与 Claude Desktop 集成

您可以轻松地将 Code Index MCP 与 Claude Desktop 集成:

  1. 确保已安装 UV(请参阅上面的安装部分)
  2. 查找或创建 Claude Desktop 配置文件:
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • macOS/Linux: ~/Library/Application Support/Claude/claude_desktop_config.json
  3. 添加以下配置(替换为你的实际路径):对于 Windows
    { "mcpServers": { "code-indexer": { "command": "uv", "args": [ "--directory", "C:\\Users\\username\\path\\to\\code-index-mcp", "run", "run.py" ] } } }
    对于 macOS/Linux
    { "mcpServers": { "code-indexer": { "command": "uv", "args": [ "--directory", "/home/username/path/to/code-index-mcp", "run", "run.py" ] } } }
    注意--directory选项很重要,因为它可以确保 uv 在正确的项目目录中运行并且可以正确加载所有依赖项。
  4. 重新启动 Claude Desktop 以使用 Code Indexer 分析代码项目

无需手动安装依赖项 - UV 将在运行服务器时自动处理所有依赖项。

基本工作流程

  1. 设置项目路径(必需的第一步):
    • 首次使用时,必须设置要分析的项目路径
    • 通过Claude命令:“我需要分析一个项目,帮我设置一下项目路径”
    • 提供完整的项目目录路径
  2. 代码搜索
    • 搜索特定的关键字或模式:“在项目中搜索‘函数名称’”
    • 按文件类型过滤:“在所有 .py 文件中搜索‘import’”
  3. 文件分析
    • 分析特定文件:“分析文件src/main.py”
    • 获取文件摘要:“给我 utils/helpers.js 中的函数列表”
  4. 项目导航
    • 查看项目结构:“显示这个项目的结构”
    • 查找符合特定模式的文件:“查找所有 test_*.py 文件”

技术细节

持久存储

所有索引和设置数据都存储在项目目录内的.code_indexer文件夹中:

  • config.json :项目配置信息
  • file_index.pickle :文件索引数据
  • content_cache.pickle :文件内容缓存

这确保了整个项目不需要在每次使用时重新建立索引。

使用 UV 进行依赖管理

Code Index MCP 使用 UV 进行依赖管理,这有几个优点:

  • 根据项目需求自动解决依赖关系
  • 更快的软件包安装和环境设置
  • 通过锁文件保持一致的依赖版本

支持的文件类型

目前支持以下文件类型的索引和分析:

  • Python(.py)
  • JavaScript/TypeScript(.js、.ts、.jsx、.tsx)
  • Java(.java)
  • C/C++(.c、.cpp、.h、.hpp)
  • C#(.cs)
  • 前往(.go)
  • Ruby(.rb)
  • PHP(.php)
  • Swift(.swift)
  • Kotlin (.kt)
  • Rust(.rs)
  • Scala(.scala)
  • Shell(.sh、.bash)
  • HTML/CSS(.html、.css、.scss)
  • Markdown(.md)
  • JSON(.json)
  • XML(.xml)
  • YAML(.yml,.yaml)

安全注意事项

  • 文件路径验证可防止目录遍历攻击
  • 不允许绝对路径访问
  • 必须明确设置项目路径,没有默认值
  • .code_indexer文件夹包含一个.gitignore文件,用于防止提交索引数据

贡献

欢迎通过问题或拉取请求做出贡献来添加新功能或修复错误。


有关中文文档,请参阅README_zh.md

-
security - not tested
F
license - not found
-
quality - not tested

模型上下文协议 (MCP) 服务器,可帮助大型语言模型以最少的设置索引、搜索和分析代码存储库

  1. Features
    1. Installation
      1. Usage
        1. Running the Server Directly
        2. Integrating with Claude Desktop
        3. Basic Workflow
      2. Technical Details
        1. Persistent Storage
        2. Dependency Management with UV
        3. Supported File Types
      3. Security Considerations
        1. Contributing
          ID: wmjk9p3tv9