一个MCP服务器,它在本地git仓库上提供语义搜索功能,使用户能够克隆仓库、处理分支并通过矢量化代码块搜索代码。
version-controlsearchdeveloper-tools
1.3k 查看 · 2026-07-07 更新
简介
一个MCP服务器,它在本地git仓库上提供语义搜索功能,使用户能够克隆仓库、处理分支并通过矢量化代码块搜索代码。
简介
一个MCP服务器,它在本地git仓库上提供语义搜索功能,使用户能够克隆仓库、处理分支并通过矢量化代码块搜索代码。
Code Context MCP 服务器
Model Context Protocol (MCP) 服务器,用于从本地 git 仓库提供代码上下文。该服务器允许您:
- 在本地克隆 git 仓库
- 处理分支和文件
- 为代码块生成嵌入
- 对代码进行语义搜索
特性
- 使用本地 git 仓库而不是 GitHub API
- 数据存储在 SQLite 数据库中
- 将代码分割成语义块
- 使用 Ollama 为代码块生成嵌入
- 提供对代码的语义搜索
前提条件
- 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"] } } }
工具
服务器提供了以下工具:
queryRepo
克隆仓库,处理代码,并执行语义搜索:
{ "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:存储代码块及其嵌入
许可证
MIT
服务配置
[{'mcpServers': {'code-context-mcp': {'args': ['/path/to/code-context-mcp/dist/index.js'], 'command': '/path/to/your/node'}}}]
来源
- 来源:github
- 链接:https://github.com/fkesheh/code-context-mcp