Code Context MCP Server

Code Context MCP Server

site icon
2025.04.09 4
TypeScript代码管理语义搜索开发效率
Code Context MCP Server 是一个基于 Model Context Protocol (MCP) 的服务器,用于从本地 git 仓库中提取代码上下文。该服务器允许用户克隆 git 仓库、处理分支和文件、为代码块生成嵌入向量,并执行语义搜索。主要特性包括使用本地 git 仓库而非 GitHub API、将数据存储在 SQLite 数据库中、将代码分割成语义块、使用 Ollama 为代码块生成嵌入向量,以及提供代码的语义搜索功能。适用于需要快速查找和理解代码上下文的开发场景。
View on GitHub

Overview

基本能力

产品定位

Code Context MCP Server 是一个为开发者提供的代码上下文管理工具,旨在通过语义搜索帮助开发者快速理解和定位代码。

核心功能

  • 克隆 git 仓库到本地
  • 处理分支和文件
  • 为代码块生成嵌入向量
  • 执行语义搜索
  • 使用 SQLite 存储数据
  • 支持 Ollama 嵌入模型

适用场景

  • 代码审查
  • 代码理解
  • 快速查找代码片段
  • 代码库探索

工具列表

  • queryRepo: 克隆仓库、处理代码并执行语义搜索。支持参数包括仓库 URL、分支、查询字符串、关键词过滤、文件模式过滤和结果数量限制。

常见问题解答

  • 如何配置 Ollama? 安装 Ollama 并拉取推荐的嵌入模型 unclemusclez/jina-embeddings-v2-base-code
  • 如何调试? 使用 curl 命令测试 Ollama 的嵌入生成功能。

使用教程

使用依赖

  • Node.js (v16+)
  • Git
  • Ollama 及嵌入模型

安装命令:

# 安装 Ollama
# 从 https://ollama.ai/ 下载并安装

# 拉取嵌入模型
ollama pull unclemusclez/jina-embeddings-v2-base-code

安装教程

# 克隆仓库
git clone <repository-url>
cd code-context-mcp

# 安装依赖
npm install

# 构建项目
npm run build

配置

设置以下环境变量: - DATA_DIR: SQLite 数据库目录(默认:'~/.codeContextMcp/data') - REPO_CACHE_DIR: 克隆仓库的目录(默认:'~/.codeContextMcp/repos')

调试方式

curl http://localhost:11434/api/embed -d '{"model":"unclemusclez/jina-embeddings-v2-base-code","input":"Llamas are members of the camelid family"}'
curl http://127.0.01:11434/api/embed -d '{"model":"unclemusclez/jina-embeddings-v2-base-code","input":"Llamas are members of the camelid family"}'
curl http://[::1]:11434/api/embed -d '{"model":"unclemusclez/jina-embeddings-v2-base-code","input":"Llamas are members of the camelid family"}'

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。