代码上下文 MCP 服务器
一个模型上下文协议 (MCP) 服务器,用于提供来自本地 Git 代码库的代码上下文。此服务器允许您:
- 本地克隆 git 存储库
- 处理分支和文件
- 为代码块生成嵌入
- 对代码执行语义搜索
特征
- 使用本地 git 存储库而不是 GitHub API
- 将数据存储在 SQLite 数据库中
- 将代码拆分成语义块
- 使用 Ollama 为代码块生成嵌入
- 提供代码语义搜索
先决条件
- Node.js(v16+)
- Git
- 带有嵌入模型的 Ollama
安装
配置
设置以下环境变量:
DATA_DIR
:SQLite 数据库目录(默认值:'~/.codeContextMcp/data')REPO_CACHE_DIR
:克隆存储库的目录(默认值:'~/.codeContextMcp/repos')
使用 Ollama
为了获得更快、更强大的嵌入,您可以使用 Ollama:
用法
与 Claude Desktop 一起使用
将以下配置添加到您的 Claude Desktop 配置文件( claude_desktop_config.json
):
工具
服务器提供以下工具:
查询Repo
克隆存储库、处理代码并执行语义搜索:
branch
参数是可选的。如果没有提供,工具将自动使用仓库的默认分支。
keywords
参数是可选的。如果提供,结果将被过滤,仅包含至少包含一个指定关键字的区块(不区分大小写匹配)。
filePatterns
和excludePatterns
参数是可选的。它们允许你使用 glob 模式(例如, **/*.ts
表示所有 TypeScript 文件)来过滤需要处理和搜索的文件。
数据库架构
该服务器使用具有以下架构的 SQLite:
repository
:存储有关存储库的信息branch
:存储有关分支的信息file
:存储有关文件的信息branch_file_association
:将文件与分支关联file_chunk
:存储代码块及其嵌入
执照
麻省理工学院
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
MCP 服务器提供对本地 git 存储库的语义搜索,使用户能够克隆存储库、处理分支以及通过矢量化代码块搜索代码。
Related MCP Servers
- AsecurityFlicenseAqualityMCP Server for the GitHub API, providing features for file operations, repository management, and advanced search, with automatic branch creation and comprehensive error handling.Last updated -1843TypeScript
- -securityAlicense-qualityA specialized MCP server for in-depth analysis of git repositories, offering tools for branch overview, time period analysis, file changes, and merge recommendations.Last updated -41JavaScriptApache 2.0
- AsecurityFlicenseAqualityMCP server for managing Git operations on local repositories, allowing users to list repositories, get and create tags, list commits, push tags, and refresh repositories through a standardized interface.Last updated -6Python
- -securityAlicense-qualityA MCP server that transforms code repositories from GitHub, GitLab, or local directories into LLM-friendly formats, preserving context and structure for better AI processing.Last updated -1PythonApache 2.0