Skip to main content
Glama

codeindex

一个结构化的代码智能引擎,以 MCP 服务器 的形式为 AI 编码代理提供服务。

它使用 tree-sitter(40+ 种语言)为你的代码库建立索引,构建三元组全文索引、倒排词索引和依赖图——然后通过 16 个 MCP 工具 暴露这些能力。

 ┌─────────────┐      MCP (stdio)       ┌──────────────┐
 │  AI Agent   │ ◄─────────────────────► │   codeindex  │
 │ (Claude,    │   16 tools, JSON-RPC    │  (Zig binary) │
 │  Cursor…)   │                         │              │
 └─────────────┘                         └──────┬───────┘
                                                │
                                   tree-sitter parse (40+ langs)
                                         trigram + word index
                                         dependency graph
                                         snapshot persistence

为什么

AI 编码代理会花费大量令牌来读取整个文件。codeindex 回答结构化问题——符号大纲、定义、调用者、爆炸半径、依赖链——只需几百个令牌,而不是数千个。

一次 plan_change 调用即可返回:符号定义的位置、所有调用点、文件的架构角色(上帝模块 / 稳定核心 / 孤岛 / 驱动模块)、需要检查的硬编码字面量,以及文件变更时的完整传递性爆炸半径。

Related MCP server: OpenCodeHub MCP Server

快速开始

# Install (prebuilt binary or build from source)
curl -fsSL https://raw.githubusercontent.com/munhq/codeindex/main/install.sh | bash

# Or build manually:
cd zig && ./fetch-vendor.sh && zig build -Doptimize=ReleaseFast

向你的 AI 代理注册:

# Claude Code — the plugin is the one-step path. It ships the skill, the hook
# and the MCP server together, and its launcher finds or fetches the binary.
claude plugin marketplace add munhq/codeindex
claude plugin install codeindex@codeindex

# Without the plugin (or for a different MCP client), register the binary
# directly. Do not do both: two registrations mean two servers, two copies of
# every tool schema, and two writers on one snapshot. install.sh detects the
# plugin and skips this step when it is present.
claude mcp add -s user codeindex -- ~/.local/bin/codeindex --mcp

# Cursor / other MCP clients: add to your config
{
  "mcpServers": {
    "codeindex": {
      "command": "~/.local/bin/codeindex",
      "args": ["--mcp"]
    }
  }
}

下次代理启动时,codeindex 会在后台为你的项目建立索引,并服务结构化查询。

MCP 工具

工具

功能

status

索引统计:文件数、符号数、索引状态、令牌节省百分比

search

跨所有已索引文件的三元组加速全文搜索

find_symbol

按名称查找符号定义(函数、结构体、类等)

find_word

在倒排词索引中精确查找单词/标识符

find_callers

近似查找符号的调用者(启发式,不进行完整名称解析)

get_outline

文件的结构大纲(符号、行数)

get_tree

带文件元数据的目录树

get_imports

给定文件导入/依赖了哪些文件

get_imported_by

反向依赖——谁导入了此文件

get_change_impact

传递性爆炸半径:文件变更会破坏什么

plan_change

符号或文件的完整重构计划——定义、调用者、文件角色、字面量、爆炸半径

get_hot_files

按最近修改时间排序的文件

read_file

读取文件内容,可指定行范围

read_symbol

仅读取符号的源代码(可带上下文行)

index_workspace

索引或重新索引工作区目录

analyze

运行 16 种代码分析之一(见下文)

分析(analyze 工具)

分析

发现内容

security

硬编码密钥、SQL 注入模式、不安全块、eval 使用

dead_code

未被引用的文件和符号

unwrap_audit

.unwrap() / 易引发 panic 的错误处理(Rust)

test_coverage

没有测试覆盖的文件

architecture

架构坏味道——上帝模块、循环依赖、孤岛

crossref

跨文件符号引用

type_drift

跨模块的类型签名不匹配

db_schema

迁移与代码之间的数据库模式漂移

migration_parity

模式变更缺失的迁移

manifest_compliance

package.json / Cargo.toml / go.mod 合规问题

literal_scan

硬编码的 URL、IP、端口、绝对路径、TODO

coupling

模块耦合度量

cycles

循环依赖检测

duplication

重复造轮子的自由函数——同一工作写了两次

clones

复制粘贴的函数体,忽略名称和空白

health

将上述分析汇总为一份索引健康报告

支持的语言

40+ 种语言,通过 tree-sitter:Rust、Python、TypeScript/TSX、Go、Zig、C、C++、Java、Ruby、Bash、C#、Kotlin、Lua、Scala、Elixir、R、Swift、Dart、Haskell、TOML、JSON、YAML、HTML、CSS、SCSS、SQL、HCL、Dockerfile、Markdown、Nix、Make 等。

配置

codeindex --mcp                          # Run as MCP server (stdio)
codeindex --workspace ./my-project       # Index a specific directory
codeindex --project-id my-project        # Project identifier
codeindex -v                             # Print version
codeindex -h                             # Print help

# Environment variables
CODEINDEX_WORKSPACE=/path/to/project     # Same as --workspace
CODEINDEX_PROJECT_ID=my-project          # Same as --project-id

codeindex 通过从工作目录向上遍历查找 .gitpackage.jsonCargo.tomlgo.modbuild.zigpyproject.toml 等文件来自动检测项目根目录。

它拒绝索引你的整个主目录或文件系统根目录——请显式传递 --workspace

架构

  • 解析器:tree-sitter,40+ 语法,编译为单个二进制文件

  • 索引:用于模糊文本搜索的三元组索引 + 用于精确标识符查找的倒排词索引

  • 依赖图:文件级导入解析,包含正向和反向边

  • 版本存储:使用序列号跟踪文件变更,支持增量更新

  • 实时监视器:在文件创建/修改/删除时重新索引(MCP 模式下为后台线程)。Linux 上使用 inotify;macOS 和 Windows 上使用轮询遍历,每隔几秒比较修改时间和大小。status 会报告当前生效的后端为 watcher_backend

  • 快照:将完整索引持久化到 .codeindex.json,因此重启时加载快照而不是重新索引

  • MCP 服务器:基于 stdio 的 JSON-RPC,实现 MCP 2024-11-05 协议

平台支持

每一行都由 CI 构建,并在该平台上运行测试,除非另有说明。status 会报告当前生效的监视器后端,因此无需猜测。

二进制

CI 中运行测试

监视器

install.sh

插件

Linux x86_64

inotify

Linux aarch64

交叉编译

inotify

macOS aarch64

轮询

macOS x86_64

交叉编译

轮询

Windows x86_64

轮询

需要 shell

见下文

Windows aarch64

交叉编译

轮询

需要 shell

见下文

在 Windows 上,install.sh 和插件的启动器是 shell 脚本,因此它们需要 Git Bash、MSYS2 或 Cygwin——它们会检测到并解析正确的 .exe 资源。插件通过该启动器注册其服务器,因此没有 shell 的原生 Windows Claude Code 应直接注册二进制文件:

claude mcp add -s user codeindex -- C:\path\to\codeindex.exe --mcp

这里没有任何内容经过签名或公证。在 macOS 上,使用 curl 获取的二进制文件运行时不会出现 Gatekeeper 提示;通过浏览器下载的会被隔离,使用 xattr -d com.apple.quarantine codeindex 可清除隔离。

从源码构建

需要 Zig 0.16.0

cd zig
./fetch-vendor.sh    # Clone tree-sitter + 40 grammar repos
zig build -Doptimize=ReleaseFast
# Binary: zig/zig-out/bin/codeindex

运行测试:

cd zig && zig build test-bin && ./zig-out/bin/test

zig build test 通过构建运行器的 IPC 协议在 stdout 上传递结果,而链接的 tree-sitter C 源码会通过其调试 printf 路径破坏该协议。直接构建测试二进制文件并运行,是相同的测试,但不受该协议干扰。

对比

codeindex

ast-grep

ctags

LSIF

Sourcegraph

MCP 原生

令牌高效

是(大纲,而非完整文件)

部分

单一二进制

否(服务器)

实时监视器

是(inotify / 轮询)

依赖图

爆炸半径

是(传递性)

部分

重构规划器

是(plan_change

语言

40+

20+

50+

视情况而定

视情况而定

与 chat-recall 搭配使用

codeindex 回答关于你面前代码的问题。chat-recall 回答关于你已完成工作的问题——它将你的 Claude Code、Gemini CLI、Codex、OpenCode 和 Antigravity 会话索引到一个可搜索的历史记录中,并通过 MCP 暴露这些数据。

它们共同覆盖了代理遗忘的两个方面:codeindex 阻止它重新阅读本可以概述的文件,chat-recall 阻止它重复已完成的工作。chat-recall 会检测你 PATH 中的 codeindex 二进制文件,并在找到时注册四个额外的代码智能工具——两者互不依赖。

许可证

MIT。参见 LICENSE

Maintenance

ActivityActive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to search code by meaning, explore codebase structure, store and query knowledge with temporal facts, and read source code through a set of MCP tools.
    481
    7
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Provides code intelligence for AI coding agents by indexing repositories into a hybrid knowledge graph, enabling agents to query dependencies, impact, and context through 28 MCP tools.
    3
    Apache 2.0
  • F
    license
    Not graded
    quality
    C
    maintenance
    Provides structural code intelligence via 26 MCP tools, enabling AI assistants to query code symbols, dependencies, and call graphs accurately without file-pasting.
  • A
    license
    A
    quality
    A
    maintenance
    Enables AI coding agents to efficiently explore codebases by providing structural outlines, module digests, symbol bodies, and AST-aware grep via MCP.
    4
    17
    1
    MIT

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/munhq/codeindex'

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