Token导航 LogoToken导航TokenDH.com
Codeindex MCP logo
开发工具未说明官方级别未说明来源级核验

Codeindex MCP

MCP Server

一个基于内存的MCP服务器,用于源代码索引,提供快速全文搜索和文件搜索功能,适用于大型代码库和MCP兼容客户端。

工具数

5

提示词数

0

GitHub Stars

3

资源数

0
开发工具GoClaude全文搜索Claude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

lexandro

提供方

lexandro

最后核验

2026/5/17 20:23

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

代码索引mcp

![CI](https://github.com/lexandro/codeindex-mcp/actions/workflows/ci.yml) ![Go Report Card](https://goreportcard.com/report/github.com/lexandro/codeindex-mcp) ![Go Reference](https://pkg.go.dev/github.com/lexandro/codeindex-mcp) ![License: MIT](LICENSE) ![MCP](https://modelcontextprotocol.io/) ![Claude Code](https://docs.anthropic.com/en/docs/claude-code)

内存中 主控程序 用于源代码索引的服务器。一个快速、索引化的替代品 grepfind,专为 克劳德代码 以及任何MCP兼容客户端。

为什么?

  • 数量级更快grep/find 在大型代码库上--使用预构建的内存索引
  • 全文搜索 由Bleve提供支持(单词、精确短语和正则表达式查询)
  • 基于Glob的文件搜索 随着 ** 双星支持
  • 自动更新 --后台文件监视器使索引与磁盘保持同步
  • 可配置的过滤 --尊重 .gitignore, .claudeignore,并自定义排除模式
  • 零运行时依赖关系 --单个静态Go二进制文件(~17 MB)

快速开始

# Register for a project (creates .mcp.json)
./codeindex-mcp register project /path/to/your/project

# Or register globally for all projects (updates ~/.claude.json)
./codeindex-mcp register user

就是这样——Claude Code将自动发现并使用索引搜索工具。

安装

先决条件

从源代码构建

git clone https://github.com/lexandro/codeindex-mcp.git
cd codeindex-mcp
go build -o codeindex-mcp .

在Windows上,这会产生 codeindex-mcp.exe.

在克劳德代码中注册

构建后,注册服务器,以便Claude Code可以找到它:

# Project-specific (writes .mcp.json in the target directory)
./codeindex-mcp register project /path/to/your/project

# Global (writes ~/.claude.json — available in all projects)
./codeindex-mcp register user

# With extra server flags
./codeindex-mcp register project . -- --max-file-size 5242880 --exclude "vendor/"

register 命令自动检测二进制路径并创建正确的配置条目,包括 cmd /C Windows上的包装器。

运行测试

go test ./...

用法

独立式(用于测试)

./codeindex-mcp --root /path/to/project

服务器使用MCP协议通过stdio(stdin/stdout)进行通信,因此它本身不是交互式的——从MCP客户端使用它。

Claude代码集成

注册服务器最简单的方法是内置 register 子命令:

# Register for a specific project (writes .mcp.json in the project directory)
./codeindex-mcp register project /path/to/project

# Register globally for all projects (writes ~/.claude.json)
./codeindex-mcp register user

# Forward extra flags to the server
./codeindex-mcp register project . -- --max-file-size 5242880 --exclude "vendor/"

或者,手动添加到您的Claude Code MCP设置中。对于特定于项目的配置,请创建 .mcp.json 在项目根目录中:

{
  "mcpServers": {
    "codeindex": {
      "command": "/path/to/codeindex-mcp",
      "args": ["--root", "."]
    }
  }
}

对于全局配置,请添加到 ~/.claude.json:

{
  "mcpServers": {
    "codeindex": {
      "command": "/path/to/codeindex-mcp",
      "args": ["--root", "/path/to/project"]
    }
  }
}

Claude Code将自动使用 codeindex_search, codeindex_files, codeindex_read, codeindex_status,以及 codeindex_reindex 工具。

CLI标志

标志默认值描述
--root DIR当前目录要索引的项目根目录
--exclude PATTERN_(无)_额外的忽略模式,可重复(例如。 --exclude "*.generated.go" --exclude "vendor/")
--force-include PATTERN_(无)_强制包含模式覆盖所有排除,可重复(例如。 --force-include "*.log")
--max-file-size N1048576 (1 MB)最大文件大小(字节);跳过较大的文件
--max-results N50默认最大搜索结果数
--log-enabledtrue启用日志记录(false 禁用所有日志输出,不创建日志文件)
--log-level LEVELinfo日志级别: debug, info, warn, error
--log-file PATH/codeindex-mcp.log日志文件路径
--sync-interval N0 (禁用)周期性索引同步验证间隔(秒)(0=禁用)

例子

# Index the current directory
./codeindex-mcp

# Specify project root with extra exclusions
./codeindex-mcp --root ~/myproject \
  --exclude "*.generated.go" \
  --exclude "testdata/"

# Force-include log files (overrides the default *.log exclusion)
./codeindex-mcp --root . --force-include "*.log"

# Multiple force-include patterns (additive)
./codeindex-mcp --root . --force-include "*.log" --force-include "vendor/*.go"

# Combine exclude and force-include
./codeindex-mcp --root ~/myproject \
  --exclude "*.generated.go" \
  --force-include "*.log"

# Disable logging entirely (no log file created)
./codeindex-mcp --root . --log-enabled=false

# Debug logging to a specific file
./codeindex-mcp --root . --log-level debug --log-file /tmp/codeindex.log

# Enable periodic sync verification every 5 minutes
./codeindex-mcp --root . --sync-interval 300

# Allow larger files (5 MB)
./codeindex-mcp --root . --max-file-size 5242880

MCP工具

服务器注册了5个工具:

1. codeindex_search --内容搜索

对所有索引文件内容进行全文搜索。

参数:

名称类型必填描述
querystringyes搜索查询(见下面的格式)
filePathstringno在单个文件中搜索的精确相对路径(覆盖 fileGlob)
fileGlobstringno用于过滤文件的Glob模式(例如。 **/*.go)
maxResultsintno文件结果的最大数量(默认值:50)
contextLinesintno每次匹配前后的上下文行(默认值:2)

查询格式:

格式示例行为
纯文本handleRequest字级匹配(Bleve MatchQuery)
"quoted""func main"精确短语匹配(PhraseQuery)
/regex//func\s+\w+Handler/正则表达式(RegexpQuery)

输出示例:

3 matches in 2 files:
main.go
  4: import "fmt"
  5:
  6: func main() {
  7:     fmt.Println("hello world")
  8: }

server/server.go
  14: func main() {
  15:     startServer()
  16: }

2. codeindex_files --文件搜索

在索引中进行基于全局的文件搜索。

参数:

名称类型必填描述
patternstringyes球状模式(例如。 **/*.ts, src/**/*.go)
nameOnlybool如果 true,仅返回不带元数据的文件路径
maxResultsintno最大结果数(默认值:50)

输出示例:

src/main.go (Go, 2.1 KB, 85L)
src/utils/helper.go (Go, 1.3 KB, 42L)
src/server/handler.go (Go, 4.7 KB, 156L)
src/config/config.go (Go, 892 B, 31L)

3. codeindex_read --从索引读取文件

直接从内存索引中读取文件内容。零磁盘I/O——比内置的读取工具更快。

参数:

名称类型必填描述
filePathstringyes要读取的相对文件路径(例如。 src/main.go)

输出示例:

1: package main
2:
3: import "fmt"
4:
5: func main() {
6:     fmt.Println("hello")
7: }

4. codeindex_status --指标状态

显示当前索引统计信息。

参数:

输出示例:

root: /home/user/myproject
uptime: 45s
files: 1234 (8.5 MB)
memory: 95.2 MB
languages: TypeScript:456, Go:312, JavaScript:189, Python:98

5. codeindex_reindex --强制重新索引

清除索引并从头开始重建。也重新加载 .gitignore.claudeignore 规则。

参数:

输出示例:

reindexed: 1234 files (8.5 MB) in 1.234s

忽略系统

服务器使用多层过滤系统来确定要索引哪些文件:

1.内置默认模式

自动跳过,无需任何配置:

类别图案
版本控制.git, .svn, .hg
依赖关系node_modules, vendor, bower_components, .yarn
构建输出dist, build, out, target, bin, obj
IDE文件.idea, .vscode, .vs
二进制文件*.exe, *.dll, *.so, *.dylib, *.class, *.jar
图片*.png, *.jpg, *.gif, *.webp, *.ico
字体*.woff, *.woff2, *.ttf, *.eot
媒体中心*.mp3, *.mp4, *.avi, *.mov
文件*.pdf, *.doc, *.xlsx, *.pptx
锁定文件package-lock.json, yarn.lock, go.sum, Cargo.lock
档案*.zip, *.tar, *.tar.gz, *.rar, *.7z
缩小*.min.js, *.min.css
源地图*.map
缓存.cache, .next, .nuxt, .parcel-cache
日志*.log
数据库*.sqlite, *.sqlite3, *.db

2. .gitignore 支持

完全尊重 .gitignore 项目根中的模式,包括globs、negation(!important.log),以及特定于目录的模式。

3. .claudeignore 支持

A. .claudeignore 项目根目录中的文件使用与相同的语法 .gitignore。使用它从git中的索引中排除与AI代码搜索无关的文件。

示例 .claudeignore:

# Generated files
*.generated.go
*.pb.go

# Large test fixtures
testdata/large/

# Archived migrations
migrations/archive/

4.CLI --exclude 模式

通过运行时排除 --exclude 标志:

./codeindex-mcp --exclude "*.generated.go" --exclude "vendor/"

5.CLI --force-include 模式

强制包括模式覆盖 全部 排除规则(内置默认值, .gitignore, .claudeignore,以及 --exclude).多个 --force-include 标志是累加的。二进制检测和文件大小限制仍然适用。

# Index *.log files even though they are excluded by default
./codeindex-mcp --force-include "*.log"

# Force-include vendor Go files while still excluding the rest of vendor/
./codeindex-mcp --force-include "vendor/*.go"

当强制包含模式处于活动状态时,可能包含匹配文件的目录在遍历过程中不会被修剪。这 .git 无论强制包含模式如何,目录都会被跳过。

6.二进制文件检测

扫描每个文件的前512个字节以查找空字节。如果找到,该文件将被视为二进制文件并跳过。这独立于 .gitignore.

7.文件大小限制

可通过以下方式配置 --max-file-size (默认值:1 MB)。大于此值的文件将被跳过。

优先级

过滤器按顺序应用:

  1. --force-include 模式 (最高优先级——如果匹配,则无论规则2-5如何,文件都会被包含在内)
  2. 内置默认模式
  3. .gitignore 规则
  4. .claudeignore 规则
  5. 命令行界面 --exclude 模式
  6. 二进制检测(始终适用,即使是强制包含的文件)
  7. 文件大小限制(始终适用,即使是强制包含的文件)

如果强制包含模式匹配,则文件将绕过所有排除规则(2-5)。二进制检测和文件大小限制是始终适用的安全检查。

建筑

MCP Client (stdio)  MCP Server  Index Engine
                                            │
                                    ┌───────┼────────┐
                                    │       │        │
                                  Bleve   FileMap   Watcher
                               (full-text) (path)  (fsnotify)

双指标设计

索引技术目的
内容索引留下 NewMemOnly()对文件内容进行全文搜索(倒排索引)
文件路径索引去吧 map +排序切片使用glob模式搜索文件名/路径

文件监视器

  • 用途 Fsnotify (在Windows上: ReadDirectoryChangesW API
  • 递归:在启动时监视所有未被忽略的子目录
  • 100ms去抖动窗口:编辑器在保存时生成多个事件——这些事件被合并为一个
  • 自动监视新创建的目录
  • 自动重新加载忽略规则 .gitignore.claudeignore 变化

启动顺序

  1. 解析CLI标志
  2. 创建忽略匹配器(内置+.gitignore+.claudeignore+CLI模式)
  3. 初始化Bleve内存索引和文件路径索引
  4. 使用8个worker goroutines进行并行索引
  5. 启动文件监视器
  6. 在stdio传输上启动MCP服务器

项目结构

codeindex-mcp/
├── main.go                  # Entry point, CLI flags, component wiring
├── indexing.go              # Directory walking, parallel indexing, watcher events
├── sync.go                  # Periodic background index sync verification
├── server/
│   └── server.go            # MCP server setup, tool registration
├── index/
│   ├── content.go           # Bleve content index (CRUD operations)
│   ├── content_search.go    # Full-text search logic, query parsing
│   ├── content_test.go
│   ├── files.go             # File path index (glob search) + IndexedFile type
│   └── files_test.go
├── watcher/
│   ├── watcher.go           # Recursive fsnotify wrapper
│   └── debouncer.go         # 100ms event collapsing
├── ignore/
│   ├── ignore.go            # .gitignore + .claudeignore + custom patterns
│   ├── ignore_test.go
│   └── defaults.go          # Built-in ignore patterns
├── register/
│   ├── register.go          # Auto-register subcommand for Claude Code config
│   └── register_test.go
├── tools/
│   ├── search.go            # codeindex_search handler
│   ├── files.go             # codeindex_files handler
│   ├── read.go              # codeindex_read handler
│   ├── status.go            # codeindex_status handler
│   ├── reindex.go           # codeindex_reindex handler
│   └── format.go            # Output formatting
└── language/
    ├── detect.go            # Extension → language mapping (70+)
    ├── detect_test.go
    ├── binary.go            # Binary file detection
    └── binary_test.go

依赖项

版本目的
modelcontextprotocol/go-sdkv1.3.0MCP服务器(stdio传输)
保持搜索/保持/v2v2.5.7内存全文搜索
Fsnotify/Fsnotifyv1.9.0文件系统监视
bmatcuk/双星/v4v4.10.0版本** glob支持
异常/go-gitignore最新.gitignore/.claudeignore解析

演出

度量约5k个文件约10k个文件
初始索引~1-2s~2-3s
内存使用量~75-100 MB~180-230 MB
文本搜索\<5ms\<10ms
正则表达式搜索\<50ms\<50ms
全球搜索\<2ms\<5ms
增量更新\<10ms/文件\<10ms/文件

支持的语言

语言检测可识别70多个文件扩展名,包括:

Go、TypeScript、JavaScript、Python、Rust、Java、Kotlin、C、C++、C#、Swift、Dart、Ruby、PHP、Shell、PowerShell、HTML、CSS、SCSS、Sass、Less、JSON、YAML、TOML、XML、SQL、GraphQL、Protobuf、Terraform、Lua、R、Scala、Elixir、Erlang、Haskell、Zig、Vue、Svelte、Markdown、Dockerfile、Makefile、CMake、Batch等等。

许可证

麻省理工学院

目录标签

目录标签

开发工具GoClaude全文搜索源代码索引本地部署文件搜索MCP兼容

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

5

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP