Skip to main content
Glama
ViperJuice
by ViperJuice

Code-Index-MCP (本地优先代码索引器)

模块化、可扩展的本地优先代码索引器,旨在增强 Claude Code 和其他 LLM 的深度代码理解能力。基于模型上下文协议 (MCP) 构建,可与 AI 助手无缝集成。

实现状态

版本: 1.0.0 (MVP 发布版) 核心功能: 稳定 - 本地索引、符号/文本搜索、48 种语言支持 可选功能: 语义搜索 (需要 Voyage AI)、索引同步 (测试版) 性能: 查询延迟低于 100ms,缓存仓库索引时间小于 10s(基于此代码库进行基准测试;结果因仓库大小和语言组合而异)

Code-Index-MCP 新手? 查看我们的 入门指南 获取快速上手教程。

🎯 核心功能

  • 🚀 本地优先架构: 所有索引均在本地完成,确保速度和隐私

  • 📂 本地索引存储: 所有索引存储在 .indexes/ (相对于 MCP 服务器)

  • 🔌 基于插件的设计: 可通过特定语言插件轻松扩展

  • 🔍 48 种语言支持: 完整的 tree-sitter 集成及语义搜索

  • ⚡ 实时更新: 文件系统监控,实现即时索引更新

  • 🧠 语义搜索: 基于 Voyage AI 嵌入的 AI 驱动代码搜索

  • 📊 丰富的代码智能: 符号解析、类型推断、依赖跟踪

  • 🚀 增强性能: 低于 100ms 的查询响应,具备超时保护和 BM25 绕过机制

  • 🔄 Git 同步: 自动跟踪仓库变更的索引更新

  • 📦 便携式索引管理: 通过 GitHub Artifacts 实现零成本索引共享

  • 🔄 自动索引同步: 克隆时拉取索引,变更时推送

  • 🎯 智能结果重排序: 多策略重排序以提高相关性

  • 🎯 查询意图路由: 符号模式查询 (class Foo, def bar, CamelCase) 可绕过 BM25 直接命中符号表,实现 5ms 以内的查找

  • 🔒 安全感知导出: 自动从共享索引中过滤敏感文件

  • 🔍 混合搜索: BM25 + 语义搜索,支持可配置融合

  • 🔐 本地索引一切: 搜索机器上的 .env 文件和密钥

  • 🚫 共享时的智能过滤: .gitignore 和 .mcp-index-ignore 模式仅在导出时应用

  • 🌐 多语言索引: 索引包含混合语言的整个仓库

🏗️ 架构

Code-Index-MCP 遵循模块化、基于插件的架构,旨在实现可扩展性和高性能:

系统层级

  1. 🌐 系统上下文 (Level 1)

    • 开发者与 Claude Code 或其他 LLM 交互

    • MCP 协议提供标准化的工具接口

    • 本地优先处理,支持可选的云功能

    • 性能 SLA: 符号查找 <100ms,搜索 <500ms

  2. 📦 容器架构 (Level 2)

    ┌─────────────────┐     ┌──────────────┐     ┌─────────────┐
    │   API Gateway   │────▶│  Dispatcher  │────▶│   Plugins   │
    │   (FastAPI)     │     │              │     │ (Language)  │
    └─────────────────┘     └──────────────┘     └─────────────┘
           │                        │                     │
           ▼                        ▼                     ▼
    ┌─────────────────┐     ┌──────────────┐     ┌─────────────┐
    │  Local Index    │     │ File Watcher │     │  Embedding  │
    │  (SQLite+FTS5)  │     │  (Watchdog)  │     │   Service   │
    └─────────────────┘     └──────────────┘     └─────────────┘
  3. 🔧 组件详情 (Level 3)

    • 网关控制器: RESTful API 端点

    • 调度核心: 插件路由和生命周期

    • 插件基类: 所有插件的标准接口

    • 语言插件: 专门的解析器和分析器

    • 索引管理器: 使用 FTS5 的 SQLite,实现快速搜索

    • 监控服务: 实时文件监控

📁 项目结构

项目遵循清晰、有组织的结构。详细布局请参阅 docs/PROJECT_STRUCTURE.md

关键目录:

  • mcp_server/ - 核心 MCP 服务器实现

  • scripts/ - 开发和实用脚本

  • tests/ - 包含测试夹具的综合测试套件

  • docs/ - 文档和指南

  • architecture/ - 系统设计和图表

  • docker/ - Docker 配置和 compose 文件

  • data/ - 数据库文件和索引

  • logs/ - 应用程序和测试日志

  • reports/ - 生成的性能报告和分析

  • analysis_archive/ - 历史分析和归档研究

🛠️ 语言支持

✅ 完全支持的语言 (总计 46+)

生产就绪功能:

  • 动态插件加载: 按需加载语言以获得最佳性能

  • Tree-sitter 解析: 基于 AST 的精确符号提取,支持特定语言查询

  • 查询缓存: 通过缓存 tree-sitter 查询提高性能

  • 语义搜索: 可选的 AI 驱动代码搜索 (当 Qdrant 可用时)

  • 跨语言搜索: 在所有支持的语言中查找符号和模式

语言类别:

类别

语言

功能

专用插件

Python, JavaScript, TypeScript, C, C++, Dart, HTML/CSS

增强分析,框架支持

系统语言

Go, Rust, C, C++, Zig, Nim, D, V

内存安全,性能分析

JVM 语言

Java, Kotlin, Scala, Clojure

包分析,构建工具集成

Web 技术

JavaScript, TypeScript, HTML, CSS, SCSS, PHP

框架检测,打包工具支持

脚本语言

Python, Ruby, Perl, Lua, R, Julia

动态类型,REPL 集成

函数式语言

Haskell, Elixir, Erlang, F#, OCaml

模式匹配,类型推断

移动开发

Swift, Kotlin, Dart, Objective-C

平台特定 API

基础设施

Dockerfile, Bash, PowerShell, Makefile, CMake

构建自动化,CI/CD

数据格式

JSON, YAML, TOML, XML, GraphQL, SQL

模式验证,查询优化

文档

Markdown, LaTeX, reStructuredText

交叉引用,格式化

实现状态: 生产就绪 - 所有语言均通过增强型调度程序支持,具备:

  • ✅ 动态插件加载 (延迟初始化)

  • ✅ 强大的错误处理和回退机制

  • ✅ 复杂项目结构的路径解析

  • ✅ 外部服务不可用时的优雅降级

🚀 快速开始

🎯 Claude Code/Desktop 自动设置 (推荐)

# Auto-configures MCP for your environment
./scripts/setup-mcp-json.sh

# Or interactive mode
./scripts/setup-mcp-json.sh --interactive

这将自动检测您的环境并创建相应的 .mcp.json 配置。

🐳 按环境进行 Docker 设置

选项 1: 基础搜索 (无需 API 密钥) - 2 分钟

# Install MCP Index with Docker
curl -sSL https://raw.githubusercontent.com/ViperJuice/Code-Index-MCP/main/scripts/install-mcp-docker.sh | bash

# Index your current directory
docker run -it -v $(pwd):/workspace ghcr.io/code-index-mcp/mcp-index:minimal

选项 2: AI 驱动的搜索

# Set your API key (get one at https://www.voyageai.com — free tier available)
export VOYAGE_API_KEY=your-key

# Run with semantic search
docker run -it -v $(pwd):/workspace -e VOYAGE_API_KEY ghcr.io/code-index-mcp/mcp-index:standard

💻 环境特定设置

🪟 Windows (原生)

# PowerShell
.\scripts\setup-mcp-json.ps1

# Or manually with Docker Desktop
docker run -it -v ${PWD}:/workspace ghcr.io/code-index-mcp/mcp-index:minimal

🍎 macOS

# Install Docker Desktop or use Homebrew
brew install --cask docker

# Run setup
./scripts/setup-mcp-json.sh

🐧 Linux

# Install Docker (no Desktop needed)
curl -fsSL https://get.docker.com | sh

# Run setup
./scripts/setup-mcp-json.sh

🔄 WSL2 (Windows Linux 子系统)

# With Docker Desktop integration
./scripts/setup-mcp-json.sh  # Auto-detects WSL+Docker

# Without Docker Desktop
cp .mcp.json.templates/native.json .mcp.json
pip install -e .

📦 嵌套容器 (Dev Containers)

# For VS Code/Cursor dev containers
# Option 1: Use native Python (already in container)
cp .mcp.json.templates/native.json .mcp.json

# Option 2: Use Docker sidecar (avoids dependency conflicts)
docker-compose -f docker/compose/development/docker-compose.mcp-sidecar.yml up -d
cp .mcp.json.templates/docker-sidecar.json .mcp.json

📋 MCP.json 配置示例

设置脚本会为您的环境创建相应的 .mcp.json。手动示例:

原生 Python (Dev Container/本地)

{
  "mcpServers": {
    "code-index-native": {
      "command": "python",
      "args": ["scripts/cli/mcp_server_cli.py"],
      "cwd": "${workspace}"
    }
  }
}

Docker (Windows/Mac/Linux)

{
  "mcpServers": {
    "code-index-docker": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-v", "${workspace}:/workspace",
        "ghcr.io/code-index-mcp/mcp-index:minimal"
      ]
    }
  }
}

🌍 在其他仓库中使用

要索引不同的仓库,请在您的 Claude Code MCP 配置 (~/.claude/settings.json.mcp.json) 中将服务器的 cwd 指向该仓库:

{
  "mcpServers": {
    "code-index-mcp": {
      "command": "/abs/path/to/Code-Index-MCP/.venv/bin/python",
      "args": ["/abs/path/to/Code-Index-MCP/scripts/cli/mcp_server_cli.py"],
      "cwd": "/abs/path/to/your-repo"
    }
  }
}

cwd 字段控制索引哪个仓库。首次使用时,服务器会在后台线程中自动构建索引 — 服务器在索引进行时会立即响应,并且 search_code 响应会包含 "indexing_in_progress": true,直到初始构建完成。

选项:

  • 在服务器环境中设置 MCP_AUTO_INDEX=false 以跳过后台自动索引,并手动调用 reindex MCP 工具(推荐用于超大型仓库)。

  • 在目标仓库的 .mcp-index.json 中添加 {"enabled": false} 以完全禁用该仓库的索引。

  • 在完全重新索引或代码更改后,调用 reindex MCP 工具按需重建索引。

语义配置文件: BM25 搜索无需额外配置。对于语义(向量)搜索,服务器会自动从其安装目录加载 code-index-mcp.profiles.yaml — 无需将其复制到每个仓库。要使用自定义配置文件覆盖,请在服务器环境中设置 MCP_PROFILES_PATH=/abs/path/to/your-profiles.yaml。要覆盖单个端点 URL 而无需编辑 YAML,请使用文件中引用的环境变量(例如 VLLM_EMBEDDING_BASE_URL, VLLM_SUMMARIZATION_BASE_URL)。

⚡ 启用语义搜索

BM25 关键字搜索无需配置即可工作。要添加向量(语义)搜索,请选择一种路径:

选项 A — Voyage AI (推荐):

export VOYAGE_API_KEY=your-key   # free tier available at voyageai.com

commercial_high 配置文件会自动激活。重启 MCP 服务器 — 启动日志将确认语义搜索已激活。

选项 B — 本地 OSS (通过 vLLM 的 Qwen3-Embedding-8B,无需 API 密钥):

export VLLM_EMBEDDING_BASE_URL=http://localhost:8000/v1
# Start vLLM (requires ~20GB VRAM or shared CPU with --dtype float32):
docker run -p 8000:8000 vllm/vllm-openai --model Qwen/Qwen3-Embedding-8B

配置文件及其集合名称均定义在 code-index-mcp.profiles.yaml 中,可以自定义。

💰 成本与功能

功能

最小化

标准

完整

成本

代码搜索

免费

48 种语言

免费

语义搜索

~$0.05/1M tokens

GitHub 同步

免费

监控

免费

🚀 快速开始 (Python)

先决条件

  • Python 3.12+

  • Git

安装

选项 1: 通过 pip 安装 (推荐)

# Install the package
pip install index-it-mcp

# Or install with dev tools for testing
pip install index-it-mcp[dev]

选项 2: 从源码安装

# Clone the repository
git clone https://github.com/ViperJuice/Code-Index-MCP.git
cd Code-Index-MCP

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in editable mode
pip install -e .

安装后的快速开始

# Authenticate GitHub artifact access once
gh auth login

# Check repo/artifact readiness before starting work
mcp-index preflight

# Pull the latest published index baseline for this repo
mcp-index artifact pull --latest

# Reconcile only your local drift after restore
mcp-index artifact sync

# The restored files live locally for MCP runtime use:
# - code_index.db
# - .index_metadata.json
# - vector_index.qdrant/

# Check index status
mcp-index index status

# Start the API server
mcp-index serve

# Or choose a custom port explicitly
mcp-index serve --port 9123

# Test the API
curl http://localhost:8000/status
curl -X POST http://localhost:8000/search \
  -H "Content-Type: application/json" \
  -d '{"query": "def parse"}'

🔧 配置

创建一个 .env 文件进行配置:

# Semantic profile setup — set VOYAGE_API_KEY (free tier at voyageai.com) to enable vector search
VOYAGE_API_KEY=your_api_key_here
# Use 127.0.0.1 for local inference, or a Tailscale/SSH tunnel IP for remote GPUs
OPENAI_API_BASE=http://127.0.0.1:8001/v1
QDRANT_PATH=vector_index.qdrant

# Server settings
MCP_SERVER_HOST=0.0.0.0
MCP_SERVER_PORT=8000
MCP_LOG_LEVEL=INFO

# Workspace settings
MCP_WORKSPACE_ROOT=.
MCP_MAX_FILE_SIZE=10485760  # 10MB

# GitHub Artifact Sync (privacy settings)
MCP_ARTIFACT_SYNC=false  # Set to true to enable
AUTO_UPLOAD=false        # Auto-upload on changes
AUTO_DOWNLOAD=true       # Auto-download on clone

已发布的制品现在携带完整的词法基准线和两个语义配置文件:

  • commercial_high 使用 voyage-code-3

  • oss_high 使用 Qwen/Qwen3-Embedding-8B

这些配置文件存储在制品内的独立 Qdrant 集合中,因此消费者可以拉取一个基准线并在本地使用任一配置文件。

专家提示:开源配置文件的远程推理 如果您的本地机器缺乏运行 oss_high 嵌入模型的 GPU 能力(例如通过 vLLM 或 Ollama),您可以在远程机器上运行推理并将 MCP 服务器指向它:

  • Tailscale/VPN: 设置 OPENAI_API_BASE=http://<tailnet-ip>:8001/v1

  • SSH 隧道: 运行 ssh -L 8001:localhost:8001 user@remote-gpu-machine,默认的 127.0.0.1:8001 配置将直接隧道连接到您的推理服务器。

生成的索引文件不应存在于 git 历史记录中。仓库跟踪构建/发布它们所需的代码、工作流和配置;GitHub 制品分发 MCP 在本地恢复的实际运行时基准线。

同机多仓库工作流

对于开源用户,推荐的多仓库模型是在一台机器上本地优先:

# Register each local repository once
mcp-index repository register /path/to/repo-a
mcp-index repository register /path/to/repo-b

# Inspect repository-level readiness details
mcp-index repository list -v

# Inspect all registered repositories and their local artifact/runtime readiness
mcp-index artifact workspace-status

# Refresh readiness after restoring or rebuilding local indexes
mcp-index artifact reconcile-workspace

# Prepare per-repo local artifact payloads without requiring remote publication
mcp-index artifact publish-workspace

推荐模式:

  1. 使用 mcp-index repository register <path> 注册每个仓库检出

  2. 保持每个仓库检出独立

  3. 根据需要为每个仓库恢复或重建本地运行时文件

  4. 使用 mcp-index repository list -v 和工作区状态/协调来查看哪些仓库已就绪或已过期

  5. 仅在确实想要共享仓库基准线时使用 GitHub 制品发布

🔐 隐私与 GitHub 制品同步

控制代码索引的共享方式:

// .mcp-index.json
{
  "github_artifacts": {
    "enabled": false,        // Disable sync entirely
    "auto_upload": false,    // Manual upload only
    "auto_download": true,   // Still get team indexes
    "exclude_patterns": [    // Additional exclusions
      "internal/*",
      "proprietary/*"
    ]
  }
}

隐私功能:

  • 索引自动通过 .gitignore 过滤

  • 通过 .mcp-index-ignore 支持额外模式

  • 审计日志显示被排除的内容

  • Docker 最小化版本中默认禁用同步

🆕 高级功能

搜索结果重排序

提供三种重排序器,通过 RERANKER_TYPE 环境变量配置:

重排序器

说明

flashrank

FlashRank

OSS,本地,快速 (~1–5 ms 开销)

cross-encoder

Cross-Encoder

OSS,本地,质量最高

voyage

Voyage Reranker

云 API,需要 VOYAGE_API_KEY

none

禁用

默认

export RERANKER_TYPE=flashrank   # or cross-encoder, voyage, none

重排序仅应用于语义检索路径。BM25/FTS 结果不会被重排序。 实现: mcp_server/dispatcher/reranker.py

LLM 分块摘要

语义分块可以在嵌入前使用 LLM 生成的摘要进行增强,从而提高基于意图查询的检索效果。在 code-index-mcp.profiles.yaml 中按配置文件配置:

summarization:
  enabled: true
  mode: lazy           # lazy (on first query) | comprehensive (at index time)
  provider: openai_compatible
  model_name: gpt-4o-mini
  base_url: "https://api.openai.com/v1"
  api_key_env: OPENAI_API_KEY
  prompt_template: "Describe this code chunk's inputs, outputs, and purpose in 2 concise sentences."

⚠️ 安全: 不要使用云端 LLM 总结不受信任的代码。注释中的隐藏指令可能会被摘要器执行。请参阅 安全说明 部分。

实现: mcp_server/indexing/summarization.py

安全感知索引共享

防止意外共享敏感文件:

# Analyze current index for security issues
python scripts/utilities/analyze_gitignore_security.py

# Create secure index export (filters gitignored files)
python scripts/utilities/secure_index_export.py

# The secure export will:
# - Exclude all gitignored files
# - Remove sensitive patterns (*.env, *.key, etc.)
# - Create audit logs of excluded files

BM25 混合搜索

结合传统全文搜索与语义搜索:

# The system automatically uses hybrid search when available
# Configure weights in settings:
HYBRID_SEARCH_BM25_WEIGHT=0.3
HYBRID_SEARCH_SEMANTIC_WEIGHT=0.5
HYBRID_SEARCH_FUZZY_WEIGHT=0.2

🔧 调度程序配置

增强型调度程序 (默认)

增强型调度程序包括超时保护和自动回退:

from mcp_server.dispatcher.dispatcher_enhanced import EnhancedDispatcher
from mcp_server.storage.sqlite_store import SQLiteStore

store = SQLiteStore(".indexes/YOUR_REPO_ID/current.db")
dispatcher = EnhancedDispatcher(
    sqlite_store=store,
    semantic_search_enabled=True,  # Enable if Qdrant available
    lazy_load=True,               # Load plugins on-demand
    use_plugin_factory=True       # Use dynamic plugin loading
)

# Search with automatic optimization
results = list(dispatcher.search("your query", limit=10))

简单调度程序 (轻量级替代方案)

为了获得仅 BM25 搜索的最佳性能:

from mcp_server.dispatcher.simple_dispatcher import create_simple_dispatcher

# Ultra-fast BM25 search without plugin overhead
dispatcher = create_simple_dispatcher(".indexes/YOUR_REPO_ID/current.db")
results = list(dispatcher.search("your query", limit=10))

配置选项

通过环境变量配置调度程序行为:

# Dispatcher settings
MCP_DISPATCHER_TIMEOUT=5          # Plugin loading timeout (seconds)
MCP_USE_SIMPLE_DISPATCHER=false   # Use simple dispatcher
MCP_PLUGIN_LAZY_LOAD=true        # Load plugins on-demand

# Performance tuning
MCP_BM25_BYPASS_ENABLED=true     # Enable direct BM25 bypass
MCP_MAX_PLUGIN_MEMORY=1024       # Max memory for plugins (MB)

# Auto-indexing (cross-repo use)
MCP_AUTO_INDEX=true               # Set false to skip background auto-index on first run
MCP_AUTO_INDEX_MAX_FILES=100000   # Skip auto-index if repo exceeds this file count
MCP_PROFILES_PATH=                # Absolute path to a custom profiles YAML (overrides built-in)

# Endpoint overrides (no need to edit profiles.yaml)
VLLM_EMBEDDING_BASE_URL=          # Override vLLM embedding endpoint (default: http://ai:8001/v1)
VLLM_SUMMARIZATION_BASE_URL=      # Override summarization endpoint (default: http://win:8002/v1)

🗂️ 索引管理

集中式索引存储

所有索引现在都集中存储在 .indexes/ (相对于 MCP 项目),以便更好地组织并防止意外提交:

.indexes/
├── {repo_hash}/              # Unique hash for each repository
│   ├── main_abc123.db        # Index for main branch at commit abc123
│   ├── main_abc123.metadata.json
│   └── current.db -> main_abc123.db  # Symlink to active index
├── qdrant/                   # Semantic search embeddings
│   └── main.qdrant/          # Centralized Qdrant database

优点:

  • 索引永远不会意外提交到 git

  • 可在同一仓库的多个克隆之间重用

  • 代码与索引之间有清晰的分离

  • 基于 git 远程的自动发现

迁移: 对于具有本地索引的现有仓库:

python scripts/move_indexes_to_central.py

对于此仓库

本项目使用 GitHub Actions Artifacts 进行高效的索引共享,因此大多数用户从已发布的索引基准线开始,而不是在本地重建。

# First time setup - pull latest indexes
mcp-index artifact pull --latest

# After pull, reconcile only your branch/worktree drift
mcp-index artifact sync

# Share your indexes with the team
mcp-index artifact push

# Check sync status
mcp-index artifact sync

# Optional: Install git hooks for automatic sync
mcp-index hooks install
# Now indexes upload automatically on git push
# and download automatically on git pull

对于任何仓库 (MCP Index Kit)

在任何仓库中启用便携式索引管理,且无需 GitHub 计算成本:

快速安装

# One-line install
curl -sSL https://raw.githubusercontent.com/ViperJuice/Code-Index-MCP/main/scripts/install-mcp.sh | bash

# Or via npm
npm install -g mcp-index-kit
mcp-index init

工作原理

  1. 零成本架构

    • 所有索引均在开发者机器上完成

    • 索引存储为 GitHub Artifacts (公共仓库免费)

    • 克隆时自动下载,推送时自动上传

    • 无需 GitHub

-
security - not tested
A
license - permissive license
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ViperJuice/Code-Index-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server