代码上下文MCP服务器是一个提供来自本地Git仓库代码上下文的模型上下文协议(MCP)服务器。它能让您在本地克隆Git仓库、处理分支和文件、为代码片段生成嵌入,还能在代码上执行语义搜索,极大提升代码处理和搜索效率。
本服务器允许您完成以下操作:
# 克隆仓库
git clone
cd code-context-mcp
# 安装依赖项
npm install
# 构建项目
npm run build
设置以下环境变量:
DATA_DIR:SQLite数据库目录(默认:~/.codeContextMcp/data)REPO_CACHE_DIR:克隆的仓库目录(默认:~/.codeContextMcp/repos)为了更快且更强大的嵌入,您可以使用Ollama:
# 从https://ollama.ai/安装Ollama
# 拉取一个嵌入模型(unclemusclez/jina-embeddings-v2-base-code推荐)
ollama pull unclemusclez/jina-embeddings-v2-base-code
将以下配置添加到您的Claude Desktop配置文件(claude_desktop_config.json)中:
{
"mcpServers": {
"code-context-mcp": {
"command": "/path/to/your/node",
"args": ["/path/to/code-context-mcp/dist/index.js"]
}
}
}
服务器提供以下工具:
克隆仓库,处理代码,并执行语义搜索:
{
"repoUrl": "https://github.com/username/repo.git",
"branch": "main", // 可选 - 默认为仓库的默认分支
"query": "您的搜索查询",
"keywords": ["keyword1", "keyword2"], // 可选 - 按关键字过滤结果
"filePatterns": ["**/*.ts", "src/*.js"], // 可选 - 使用glob模式过滤文件
"excludePatterns": ["**/node_modules/**"], // 可选 - 排除文件的glob模式
"limit": 10 // 可选 - 结果数量,默认为10
}
针对Mac M系列芯片的ARM架构问题:
# 尝试以下命令:
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.0.1: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许可证。