代码上下文 MCP 服务器
一个模型上下文协议 (MCP) 服务器,用于提供来自本地 Git 代码库的代码上下文。此服务器允许您:
本地克隆 git 存储库
处理分支和文件
为代码块生成嵌入
对代码执行语义搜索
特征
使用本地 git 存储库而不是 GitHub API
将数据存储在 SQLite 数据库中
将代码拆分成语义块
使用 Ollama 为代码块生成嵌入
提供代码语义搜索
Related MCP server: Git MCP
先决条件
Node.js(v16+)
Git
带有嵌入模型的 Ollama
安装
# Clone the repository
git clone <repository-url>
cd code-context-mcp
# Install dependencies
npm install
# Build the project
npm run build配置
设置以下环境变量:
DATA_DIR:SQLite 数据库目录(默认值:'~/.codeContextMcp/data')REPO_CACHE_DIR:克隆存储库的目录(默认值:'~/.codeContextMcp/repos')
使用 Ollama
为了获得更快、更强大的嵌入,您可以使用 Ollama:
# Install Ollama from https://ollama.ai/
# Pull an embedding model (unclemusclez/jina-embeddings-v2-base-code is recommended)
ollama pull unclemusclez/jina-embeddings-v2-base-code
用法
与 Claude Desktop 一起使用
将以下配置添加到您的 Claude Desktop 配置文件( claude_desktop_config.json ):
{
"mcpServers": {
"code-context-mcp": {
"command": "/path/to/your/node",
"args": ["/path/to/code-context-mcp/dist/index.js"]
}
}
}工具
服务器提供以下工具:
查询Repo
克隆存储库、处理代码并执行语义搜索:
{
"repoUrl": "https://github.com/username/repo.git",
"branch": "main", // Optional - defaults to repository's default branch
"query": "Your search query",
"keywords": ["keyword1", "keyword2"], // Optional - filter results by keywords
"filePatterns": ["**/*.ts", "src/*.js"], // Optional - filter files by glob patterns
"excludePatterns": ["**/node_modules/**"], // Optional - exclude files by glob patterns
"limit": 10 // Optional - number of results to return, default: 10
}branch参数是可选的。如果没有提供,工具将自动使用仓库的默认分支。
keywords参数是可选的。如果提供,结果将被过滤,仅包含至少包含一个指定关键字的区块(不区分大小写匹配)。
filePatterns和excludePatterns参数是可选的。它们允许你使用 glob 模式(例如, **/*.ts表示所有 TypeScript 文件)来过滤需要处理和搜索的文件。
数据库架构
该服务器使用具有以下架构的 SQLite:
repository:存储有关存储库的信息branch:存储有关分支的信息file:存储有关文件的信息branch_file_association:将文件与分支关联file_chunk:存储代码块及其嵌入
执照
麻省理工学院
This server cannot be installed
Resources
Looking for Admin?
Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.