Token导航 LogoToken导航TokenDH.com
Codebase Index MCP logo
搜索检索stdio官方级别未说明来源级核验

Codebase Index MCP

MCP Server

基于向量相似度的代码库索引MCP服务,支持OpenAI兼容的embeddings和Torch本地向量存储,适用于代码搜索和索引管理。

工具数

4

提示词数

0

GitHub Stars

0

资源数

0
代码索引向量搜索PythonOpenAI

安装说明

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

作者 / 组织

yuemingruoan

提供方

yuemingruoan

最后核验

2026/5/17 20:21

运行时

Python

快速接入

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

命令预览

python3 -m pip install -e .

详细介绍

代码库索引mcp

英语 | 中文

英语

基于向量相似性的代码库索引MCP服务器。使用OpenAI兼容的嵌入和基于Torch的本地向量存储,并具有CUDA/MPS加速功能。

特性

  • MCP工具: init, search, status, update
  • 与OpenAI API兼容的嵌入(base_url, api_key, model)
  • 基于Torch的本地存储(CUDA/MPS可用时,CPU回退)
  • Git只跟踪文件;已筛选二进制文件
  • 基于行的重叠组块
  • 增量刷新打开 search (可选)
  • 可配置的设备、搜索模式和最大VRAM预算

需求

  • Python>=3.12
  • Git
  • OpenAI兼容的嵌入端点
  • Torch(CPU或GPU构建)

安装

python3 -m pip install -e .

CLI使用情况

初始化回购索引:

code-index init /abs/path/to/repo \
  --persist-dir /abs/path/to/persist \
  --base-url https://api.openai.com \
  --api-key $OPENAI_API_KEY \
  --model text-embedding-3-small \
  --device auto \
  --search-mode exact \
  --metric ip \
  --approx-sample-rate 0.2 \
  --max-vram-mb 2048

搜索(默认增量刷新):

code-index search /abs/path/to/repo "query text" --persist-dir /abs/path/to/persist

跳过刷新:

code-index search /abs/path/to/repo "query text" --persist-dir /abs/path/to/persist --no-refresh

覆盖一个查询的设备/搜索设置:

code-index search /abs/path/to/repo "query text" \
  --persist-dir /abs/path/to/persist \
  --device mps \
  --search-mode approx \
  --approx-sample-rate 0.3 \
  --max-vram-mb 1024

状态:

code-index status /abs/path/to/repo --persist-dir /abs/path/to/persist

更新嵌入配置(完全重建):

code-index update /abs/path/to/repo \
  --persist-dir /abs/path/to/persist \
  --base-url https://api.openai.com \
  --api-key $OPENAI_API_KEY \
  --model text-embedding-3-small \
  --device auto \
  --search-mode exact \
  --metric ip \
  --approx-sample-rate 0.2 \
  --max-vram-mb 2048

您还可以设置 CODE_INDEX_PERSIST_DIR 避免超车 --persist-dir 每次。 集 CODE_INDEX_MAX_VRAM_MB 定义搜索/索引的默认VRAM预算。

笔记:

  • --device auto 首先选择CUDA,然后选择MPS,然后选择CPU;如果不可用,显式CUDA/MPS将回退到CPU。
  • --search-mode approx 基于以下内容对候选对象进行采样 --approx-sample-rate (越低越快,召回率越低)。
  • --metric 支持 ip (默认)或 l2.

MCP服务器

启动MCP服务器:

code-index serve --persist-dir /abs/path/to/persist

工具:

  • init:创建新索引
  • search:语义搜索(返回相对路径+行范围)
  • status:当前索引信息
  • update:更新配置并重建索引

持久性布局

/persist
  server.json
  /
    config.json
    vectors/
      embeddings.pt
      meta.json

测试

python3 -m pytest -q

故障排除

  • NOT_GIT_REPO:确保 repo_path 位于git存储库中
  • NOT_INITIALIZED:run code-index init 第一
  • EMBEDDING_ERROR:检查 base_url, api_key,以及网络访问
  • STORAGE_ERROR:确保 torch 已安装,矢量目录可写

中文

使用向量相似度驱动的代码库索引 MCP 服务,基于 OpenAI 兼容的 embedding,并提供支持 CUDA/MPS 加速的 Torch 本地向量存储。

功能

  • MCP 工具:initsearchstatusupdate
  • OpenAI API兼容 嵌入(base_urlapi_keymodel
  • Torch 本地存储(可用时启用 CUDA/MPS,加速不可用时回退到 CPU)
  • 仅索引 Git 跟踪文件,过滤二进制
  • 按行切分并支持重叠
  • search 可选增量刷新
  • 支持设备、检索模式与显存预算配置

环境要求

  • Python>=3.12
  • Git
  • OpenAI 兼容的 embedding 接口
  • Torch(CPU 或 GPU 版本)

安装

python3 -m pip install -e .

CLI 用法

初始化仓库索引:

code-index init /abs/path/to/repo \
  --persist-dir /abs/path/to/persist \
  --base-url https://api.openai.com \
  --api-key $OPENAI_API_KEY \
  --model text-embedding-3-small \
  --device auto \
  --search-mode exact \
  --metric ip \
  --approx-sample-rate 0.2 \
  --max-vram-mb 2048

搜索(默认会做增量刷新):

code-index search /abs/path/to/repo "query text" --persist-dir /abs/path/to/persist

跳过刷新:

code-index search /abs/path/to/repo "query text" --persist-dir /abs/path/to/persist --no-refresh

单次查询覆盖设备/检索参数:

code-index search /abs/path/to/repo "query text" \
  --persist-dir /abs/path/to/persist \
  --device mps \
  --search-mode approx \
  --approx-sample-rate 0.3 \
  --max-vram-mb 1024

状态查看:

code-index status /abs/path/to/repo --persist-dir /abs/path/to/persist

更新 embedding 配置(全量重建):

code-index update /abs/path/to/repo \
  --persist-dir /abs/path/to/persist \
  --base-url https://api.openai.com \
  --api-key $OPENAI_API_KEY \
  --model text-embedding-3-small \
  --device auto \
  --search-mode exact \
  --metric ip \
  --approx-sample-rate 0.2 \
  --max-vram-mb 2048

可通过 CODE_INDEX_PERSIST_DIR 避免每次传入 --persist-dir。 通过 CODE_INDEX_MAX_VRAM_MB 设置默认显存预算。

说明:

  • --device auto 优先选 CUDA,其次 MPS,再回退 CPU;显式 CUDA/MPS 不可用时会回退 CPU。
  • --search-mode approx 通过 --approx-sample-rate 采样候选(值越小越快但召回更低)。
  • --metric 支持 ip(默认)或 l2

MCP服务器

启动 MCP 服务:

code-index serve --persist-dir /abs/path/to/persist

工具:

  • init:创建新索引
  • search:语义检索(返回相对路径与行号范围)
  • status:索引状态
  • update:更新配置并重建索引

持久化目录结构

/persist
  server.json
  /
    config.json
    vectors/
      embeddings.pt
      meta.json

测试

python3 -m pytest -q

故障排查

  • NOT_GIT_REPO:确保 repo_path 在 git 仓库内
  • NOT_INITIALIZED:先执行 code-index init
  • EMBEDDING_ERROR:检查 base_urlapi_key 与网络访问
  • STORAGE_ERROR:确认已安装 torch 且向量目录可写

目录标签

目录标签

代码索引向量搜索PythonOpenAI本地部署TorchCUDA加速

接入字段

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

stdio

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

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

4

资源数量(resourceCount,资源数)

0

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

0

权限和风险

stdionone部署方式未说明

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

安装前确认

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

来源信息

继续浏览同类 MCP