codeindex
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 工具
工具 | 功能 |
| 索引统计:文件数、符号数、索引状态、令牌节省百分比 |
| 跨所有已索引文件的三元组加速全文搜索 |
| 按名称查找符号定义(函数、结构体、类等) |
| 在倒排词索引中精确查找单词/标识符 |
| 近似查找符号的调用者(启发式,不进行完整名称解析) |
| 文件的结构大纲(符号、行数) |
| 带文件元数据的目录树 |
| 给定文件导入/依赖了哪些文件 |
| 反向依赖——谁导入了此文件 |
| 传递性爆炸半径:文件变更会破坏什么 |
| 符号或文件的完整重构计划——定义、调用者、文件角色、字面量、爆炸半径 |
| 按最近修改时间排序的文件 |
| 读取文件内容,可指定行范围 |
| 仅读取符号的源代码(可带上下文行) |
| 索引或重新索引工作区目录 |
| 运行 16 种代码分析之一(见下文) |
分析(analyze 工具)
分析 | 发现内容 |
| 硬编码密钥、SQL 注入模式、不安全块、eval 使用 |
| 未被引用的文件和符号 |
|
|
| 没有测试覆盖的文件 |
| 架构坏味道——上帝模块、循环依赖、孤岛 |
| 跨文件符号引用 |
| 跨模块的类型签名不匹配 |
| 迁移与代码之间的数据库模式漂移 |
| 模式变更缺失的迁移 |
| package.json / Cargo.toml / go.mod 合规问题 |
| 硬编码的 URL、IP、端口、绝对路径、TODO |
| 模块耦合度量 |
| 循环依赖检测 |
| 重复造轮子的自由函数——同一工作写了两次 |
| 复制粘贴的函数体,忽略名称和空白 |
| 将上述分析汇总为一份索引健康报告 |
支持的语言
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-idcodeindex 通过从工作目录向上遍历查找 .git、package.json、Cargo.toml、go.mod、build.zig、pyproject.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/testzig build test 通过构建运行器的 IPC 协议在 stdout 上传递结果,而链接的 tree-sitter C 源码会通过其调试 printf 路径破坏该协议。直接构建测试二进制文件并运行,是相同的测试,但不受该协议干扰。
对比
codeindex | ast-grep | ctags | LSIF | Sourcegraph | |
MCP 原生 | 是 | 否 | 否 | 否 | 否 |
令牌高效 | 是(大纲,而非完整文件) | 否 | 部分 | 是 | 是 |
单一二进制 | 是 | 是 | 是 | 否 | 否(服务器) |
实时监视器 | 是(inotify / 轮询) | 否 | 否 | 否 | 否 |
依赖图 | 是 | 否 | 否 | 是 | 是 |
爆炸半径 | 是(传递性) | 否 | 否 | 否 | 部分 |
重构规划器 | 是( | 否 | 否 | 否 | 否 |
语言 | 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。
This server cannot be installed
Maintenance
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
Codebase intelligence for agents: 152 structured artifacts across 21 programs, one call.
Hosted code graph over MCP: exact callers, dependencies, and cross-repo blast radius for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables 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.4817MIT
- AlicenseNot gradedqualityAmaintenanceProvides 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.3Apache 2.0
- FlicenseNot gradedqualityCmaintenanceProvides structural code intelligence via 26 MCP tools, enabling AI assistants to query code symbols, dependencies, and call graphs accurately without file-pasting.
- AlicenseAqualityAmaintenanceEnables AI coding agents to efficiently explore codebases by providing structural outlines, module digests, symbol bodies, and AST-aware grep via MCP.4171MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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