Git代理MCP

一个安全的MCP服务器,允许基于云的AI助手(如Claude.ai、ChatGPT、Gemini等)使用您的现有Git凭证与私有Git仓库进行交互,而无需这些凭证离开您的机器。

  • by MatejGomboc
  • Rust
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 MatejGomboc/git-proxy-mcp

使用说明

git代理mcp

您的Git凭据将保留在您的计算机上。你的仓库位于人工智能的工作空间中。

一个安全的MCP服务器,允许基于云的AI助手(Claude.AI、ChatGPT、Gemini等) 使用现有的Git凭据使用私有Git存储库,而无需这些凭据 证书永远不会离开你的机器。


问题

基于云的AI编码助手面临着一个根本的困境:

方法 问题
GitHub MCP服务器 逐文件API调用。50个文件=50个电话。无法运行测试。缓慢得令人痛苦。
向AI提供您的凭据 安全噩梦。您的PAT/SSH密钥位于其他人的云中。
仅使用公共仓库 大多数实际工作都是在私有存储库上进行的。

结果: AI助手可以编写代码,但实际上不能像真正的开发人员那样在你的项目上工作。

解决方案

git代理mcp充当 经过身份验证的流媒体代理 Git提供者和AI工作区之间:

┌─────────────────┐      ┌─────────────────┐      ┌─────────────────┐
│  Git Providers  │      │    YOUR PC      │      │    AI's VM      │
│                 │      │                 │      │                 │
│  GitHub         │◄────►│  git-proxy-mcp  │◄────►│  Claude.ai      │
│  GitLab         │      │                 │      │                 │
│  Bitbucket      │      │  (credentials   │      │  /home/claude/  │
│  Azure DevOps   │      │   stay here)    │      │    repo/        │
│  Self-hosted    │      │                 │      │  (files live    │
│                 │      │                 │      │   here)         │
└─────────────────┘      └─────────────────┘      └─────────────────┘

关键见解: AI有自己的VM,具有完整的Linux功能。它只是无法对您的私人存储库进行身份验证。我们解决 仅 这个问题。

运作原理

  1. 克隆: AI请求回购→ MCP服务器进行身份验证→ 将文件直接流式传输到AI的VM
  2. 工作: AI有一个完整的本地git仓库。分支、编辑、测试、提交——都是原生的。
  3. 推: AI发送提交→ MCP服务器进行身份验证→ 推到远程

凭证永远不会离开你的机器。文件永远不会碰你的机器。


这是给谁的?

|环境|本地Git?需要这个吗?|为什么| |-------------|------------|-------------|-----| | Claude.ai | ❌ 云虚拟机|✅ 是 |有计算能力,缺乏凭据| | ChatGPT+代码解释器 | ❌ 沙盒|✅ 是 |同样的情况| | Gemini+代码执行 | ❌ 沙盒|✅ 是 |同样的情况| | 任何带有VM的云AI | ❌ | ✅ 是 |通用解决方案| |克劳德代码|✅ 本地|❌ 否|已经可以直接访问| |光标|✅ 本地|❌ 否|在您的机器上运行| |GitHub副本|✅ 本地|❌ 无|IDE扩展|


比较:GitHub MCP与git代理MCP

操作 GitHub MCP服务器 git代理MCP
克隆100个文件 100个API调用,分钟 1个流式调用,秒
快跑 cargo test ❌ 不可能 ✅ 原生于AI的虚拟机中
交互式重基 ❌ 不可能 ✅ git rebase -i
分支+编辑+提交+推送 4+neneneba API调用 本地工作,1推送
查看git log/diff API调用 即时本地命令
大型存储库 超时地狱 浅克隆,稀疏结账
速率限制 持续命中 仅授权,API使用最少

建筑

安全模型

┌─────────────────────────────────────────────────────────────────┐
│  YOUR PC (credentials stay here, files don't)                   │
│                                                                 │
│  ┌──────────────────┐      ┌─────────────────────────────────┐  │
│  │ git-proxy-mcp    │      │ Your Git Configuration          │  │
│  │                  │◄────►│                                 │  │
│  │ • Auth callbacks │      │ • ~/.gitconfig                  │
│  │ • Object stream  │      │ • SSH keys (ssh-agent)          │  │
│  │ • No file storage│      │ • Credential helpers            │  │
│  └────────┬─────────┘      └─────────────────────────────────┘  │
│           │                                                     │
└───────────┼─────────────────────────────────────────────────────┘
            │
            │ Streaming: files/patches (NOT credentials)
            ▼
┌─────────────────────────────────────────────────────────────────┐
│  AI's VM (files live here, credentials don't)                   │
│                                                                 │
│  ┌──────────────────┐                                           │
│  │ /home/claude/    │  AI workflow (all local, no network):     │
│  │   repo/          │  • git checkout -b feature                │
│  │     .git/        │  • vim src/main.rs                        │
│  │     src/         │  • cargo test                             │
│  │     Cargo.toml   │  • git commit -m "fix bug"                │
│  └──────────────────┘                                           │
└─────────────────────────────────────────────────────────────────┘

什么流向哪里

数据 你的电脑 网络 人工智能的虚拟机
凭据(PAT、SSH密钥) ✅ 停留 ❌ 从不 ❌ 从来没有
存储库文件 ❌ 从未存储 流式传输 ✅ 住在这里
Git对象/历史记录 ❌ 从未存储 流式传输 ✅ 住在这里
提交/补丁 ❌ 仅限临时 已流式传输 ✅ 在这里创建

MCP工具

第1层:单一响应工具

repo_clone

将存储库流式传输到AI的工作区(中小型存储库)。

{
    "name": "repo_clone",
    "arguments": {
        "url": "https://github.com/user/private-repo",
        "branch": "main",
        "depth": 1,
        "sparse": ["src/", "Cargo.toml"]
    }
}

上面未显示的可选参数:

  • exclude_binary (bool)--跳过二进制文件
  • max_file_size (数量,字节)--跳过超过大小限制的文件
  • resolve_lfs (bool)-获取LFS指针文件并用其实际内容替换
  • include_submodules (bool)--递归获取子模块
  • submodule_depth (number)——子模块递归深度。省略为无限(镜像 git clone --recurse-submodules). 1 =仅顶层子模块; 0 =跳过子模块 完全(覆盖 include_submodules: true).
  • submodule_include (glob模式数组)--仅获取与至少一个模式匹配的子模块
  • submodule_exclude (glob模式数组)--跳过匹配任何模式的子模块(优先于include)

答复: Base64编码tar.gz archive, commit 沙, branch, file_count, archive_size (字节,base64之前),以及a hint 字符串指向 helper_script 用于提取。 可选计数器仅在非零时显示: skipped_by_filter, skipped_binary, skipped_too_large, skipped_path_too_long, lfs_resolved, lfs_failed, submodules_included, submodules_failed.

repo_push

将git包从AI的工作区推送到远程。

{
    "name": "repo_push",
    "arguments": {
        "url": "https://github.com/user/private-repo",
        "branch": "feature/fix-bug",
        "bundle": "<base64-encoded git bundle>",
        "force": false
    }
}

答复: branch,推 commit 沙, force 消毒过的旗帜(回声) remote_url, 和一个 hint 解释如何为后续推送创建包的字符串。

第2层:分块流媒体工具(大型仓库)

对于太大而无法在单个响应中传输的存储库。

repo_clone_start

启动分块克隆会话。

{
    "name": "repo_clone_start",
    "arguments": {
        "url": "https://gitlab.com/org/large-repo",
        "branch": "main",
        "depth": 1,
        "chunk_size": 1048576
    }
}

上面未显示的可选参数 --与对应的语义相同 repo_clone 上面记录的论点:

  • sparse (路径/球体阵列)
  • exclude_binary (布尔)
  • max_file_size (数字,字节)
  • resolve_lfs (布尔)
  • include_submodules (布尔)
  • submodule_depth (编号)
  • submodule_include (球状图案阵列)
  • submodule_exclude (球状图案阵列)

答复: session_id, total_chunks, total_size (字节,base64之前的总存档大小), chunk_size (字节,夹紧后协商的每个块大小), commit, branch, file_count, 和一个 hint 弦。与跳过/LFS/子模块计数器相同的可选计数器 repo_clone 当非零时出现。

repo_clone_chunk

从流媒体会话中获取数据块。

{
    "name": "repo_clone_chunk",
    "arguments": {
        "session_id": "stream_abc123",
        "chunk_index": 0
    }
}

答复: Base64编码 data,the chunk_index (回应), chunk_size (这一块 base64之前的字节大小), is_last 旗,以及 next_missing_chunk (当没有块时省略 resident——用于在传输中断后恢复)。

repo_clone_status

检查分块克隆会话的进度和恢复状态。

{
    "name": "repo_clone_status",
    "arguments": {
        "session_id": "stream_abc123"
    }
}

答复: session_id (回应), total_chunks, delivered_chunks, next_missing_chunk (当检索到所有块时为空), progress_percent (0.0–100.0),以及 is_complete 旗帜。

repo_clone_cancel

取消流媒体会话(可选,在配置的超时后自动过期)。

{
    "name": "repo_clone_cancel",
    "arguments": {
        "session_id": "stream_abc123"
    }
}

答复: { "cancelled": <bool> } — true 如果找到并删除了会话, false 如果不存在这样的会话(不是错误)。

其他工具

repo_pull

将远程的新更改同步到AI的工作区。

{
    "name": "repo_pull",
    "arguments": {
        "url": "https://github.com/user/private-repo",
        "branch": "main",
        "since_commit": "abc123"
    }
}

答复: 统一 diff,base64 tar.gz更改/添加的文件(files_archive), changed_files 列出每个文件的更改类型, deleted_files 列表, base_commit 和 new_commit SHA,更改 stats, up_to_date 旗,和a hint 字符串指向 helper_script 用于提取 files_archive.

repo_diff

获取两次提交之间的差异。

{
    "name": "repo_diff",
    "arguments": {
        "url": "https://github.com/user/private-repo",
        "base_commit": "abc123",
        "head_commit": "def456"
    }
}

答复: 统一 diff 文本, stats (添加/删除/文件更改计数),以及 完全解决 base_commit 和 head_commit SHA(这样AI就可以缓存比较结果,而无需 重新解析原始参考文献)。

repo_refs

列出远程分支和标签。

{
    "name": "repo_refs",
    "arguments": {
        "url": "https://github.com/user/private-repo"
    }
}

答复: branches 和 tags 列表(每个条目都有引用名称和提交SHA), default_branch (例如。 main 或 master,从远程HEAD获取),以及 total_refs 计数。

公用事业

helper_script

获取一个Python辅助脚本来处理结果(解码base64,提取tar.gz)。

{
    "name": "helper_script",
    "arguments": {}
}

答复: Python脚本源代码,加上建议 filename,简短 usage 指令和脚本 version.


安装

先决条件

Git命令行界面

服务器的大多数Git操作(克隆、推送、拉取、差异、引用)都在进程内进行身份验证 通过libgit2的凭据回调,从不向 git (参见 src/git2_ops/auth.rs). 这 git 尽管如此,CLI仍然是必需的,因为服务器调用它是为了两个更窄的任务: git credential fill (通过操作系统凭据助手读取您存储的凭据,用于 Git LFS对象下载)和 git fetch 从捆绑包文件(应用 repo_push 有效载荷 在经过身份验证的推送之前——请参阅 src/git2_ops/push.rs).任何合理的现代git(2.x) 上 PATH 作品;git≥2.53(含 # v3 git bundle 标题)也 认可的。

Git身份验证

将Git配置为在不提示的情况下进行身份验证:

# macOS
git config --global credential.helper osxkeychain

# Windows
git config --global credential.helper manager

# Linux
git config --global credential.helper libsecret

对于SSH,请确保您的密钥在SSH代理中:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# macOS: also cache the key's passphrase in the Keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

使用Claude Desktop

添加到您的Claude Desktop MCP配置中:

{
    "mcpServers": {
        "git-proxy": {
            "command": "git-proxy-mcp",
            "args": []
        }
    }
}

配置

配置文件位置:

  • Linux/macOS: ~/.git-proxy-mcp/config.json
  • 窗户: %USERPROFILE%\.git-proxy-mcp\config.json
{
    "git_identity": {
        "name": "Claude AI",
        "email": "ai-assistant@your-domain.com"
    },
    "security": {
        "allow_force_push": false,
        "protected_branches": ["main", "master"]
    },
    "logging": {
        "level": "warn",
        "audit_log_path": "~/.git-proxy-mcp/audit.log"
    },
    "timeouts": {
        "request_timeout_secs": 300
    },
    "limits": {
        "max_output_bytes": 10485760
    },
    "rate_limits": {
        "max_burst": 20,
        "refill_rate_per_sec": 5.0
    },
    "proxy": {
        "url": "http://proxy.example.com:8080",
        "no_proxy": "*.internal.com,localhost"
    },
    "sessions": {
        "timeout_secs": 3600,
        "max_streaming_sessions": 10,
        "max_repo_sessions": 100
    },
    "lfs": {
        "retry_max_attempts": 3,
        "max_object_size": 104857600
    },
    "submodules": {
        "exclude_patterns": ["vendor/*"]
    }
}

有关显示每个部分和选项的完整填充示例,请参阅 config/example-config.json.

配置选项

章节 选项 描述
git_identity name AI辅助提交的名称,例如“Claude AI”(默认值:null——AI设置自己的身份)
git_identity email AI辅助提交的电子邮件(默认值:null)
security allow_force_push 允许强制推动(默认值:false)
security protected_branches 阻止强制推送和删除的分支。默认值:空列表,服务器将其视为“使用内置安全集”(main, master, develop);设置为任何非空列表以覆盖回退。
security repo_allowlist 只允许这些仓库模式(默认值:null--禁用allowlist模式)
security repo_blocklist 阻止这些回购模式(默认值:null--无阻止列表)
logging level 日志级别:跟踪、调试、信息、警告、错误(默认值: warn)
logging audit_log_path 审核日志文件的路径(默认值:null--禁用审核日志记录)
timeouts request_timeout_secs Git操作超时(默认值:300)
limits max_output_bytes 每个命令的最大组合stdout+stderr(默认值:10 MiB)
rate_limits max_burst 最大突发操作数(默认值:20)
rate_limits refill_rate_per_sec 持续速率限制(默认值:5.0)
proxy url 代理URL——HTTP、HTTPS或SOCKS5(默认值:null——无代理,回退到git http.proxy)
proxy no_proxy 逗号分隔的主机绕过代理(默认值:null)
sessions timeout_secs 会话不活动超时(默认值:3600)
sessions max_streaming_sessions 最大第2层流会话数(默认值:10)
sessions max_repo_sessions 最大回购跟踪会话数(默认值:100)
lfs retry_max_attempts 最大LFS下载重试次数(默认值:3)
lfs retry_initial_backoff_ms 初始重试回退(毫秒)(默认值:500)
lfs retry_max_backoff_ms 最大重试回退(毫秒)(默认值:30000)
lfs retry_backoff_multiplier 指数退避倍数(默认值:2.0)
lfs max_object_size 最大单个LFS对象大小(以字节为单位)(默认值:null--无限制;超大对象保留为指针文件)
lfs request_timeout_secs 批量API POST的HTTP请求超时(以秒为单位)(默认值:300)
lfs connect_timeout_secs HTTP连接超时(秒)(默认值:30)
lfs download_timeout_secs HTTP每个对象下载超时(秒)——通常大于 request_timeout_secs 对于多GiB blob(默认值:600)
submodules max_concurrent 并行子模块取数(默认值:4)
submodules max_failures 停止前最大子模块故障数(默认值:3)
submodules include_patterns 要包含的全局模式(默认值:null——允许所有子模块)
submodules exclude_patterns 要排除的全局模式(默认值:null--不排除任何内容)

验证

加载时验证配置;无效值会中止启动 带着一个 configuration validation failed: … 命名违规字段的消息。 这些检查只拒绝会使子系统不可用的值:零 timeouts.request_timeout_secs 或任何 lfs.*_timeout_secs (每一个请求 会立即超时),零 limits.max_output_bytes (每个命令 组合的stdout+stderr将被截断为无), rate_limits.max_burst 的 0 (每个操作都被永久阻止),非有限或负数 rate_limits.refill_rate_per_sec (0.0 是允许的,意思是“爆裂一次,从不重新填充”),零 sessions.timeout_secs / sessions.max_streaming_sessions / sessions.max_repo_sessions和a logging.level 外面 trace/debug/info/warn/error.


贡献

欢迎投稿!看 贡献.md 作为指导方针。


许可证

版权所有(C)2026 Matej Gomboc https://github.com/MatejGomboc/git-proxy-mcp.

GNU通用公共许可证v3.0或更高版本——请参阅 许可证.


链接