{"id":46135863,"url":"https://github.com/pengcunfu/go-mcp-git","last_synced_at":"2026-03-02T05:01:25.716Z","repository":{"id":324065115,"uuid":"1095809222","full_name":"pengcunfu/go-mcp-git","owner":"pengcunfu","description":"一个使用 Go 语言实现的模型上下文协议（MCP）服务器，为大型语言模型提供 Git 仓库交互和自动化功能。支持状态查询、差异对比、提交管理、分支操作等完整的 Git 工作流，可与 Claude Desktop 等 AI 工具无缝集成。","archived":false,"fork":false,"pushed_at":"2025-11-13T15:52:27.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-13T17:21:53.256Z","etag":null,"topics":["ai-tools","cursor","git-automation","golang","mcp-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pengcunfu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-13T14:49:17.000Z","updated_at":"2025-11-13T15:52:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pengcunfu/go-mcp-git","commit_stats":null,"previous_names":["pengcunfu/go-mcp-git"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pengcunfu/go-mcp-git","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengcunfu%2Fgo-mcp-git","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengcunfu%2Fgo-mcp-git/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengcunfu%2Fgo-mcp-git/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengcunfu%2Fgo-mcp-git/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pengcunfu","download_url":"https://codeload.github.com/pengcunfu/go-mcp-git/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengcunfu%2Fgo-mcp-git/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29993023,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T01:47:34.672Z","status":"online","status_checked_at":"2026-03-02T02:00:07.342Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-tools","cursor","git-automation","golang","mcp-server"],"created_at":"2026-03-02T05:01:24.945Z","updated_at":"2026-03-02T05:01:25.708Z","avatar_url":"https://github.com/pengcunfu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-mcp-git: Go 语言实现的 Git MCP 服务器\n\n[English](README_EN.md) | 中文\n\n## 概述\n\n一个使用 Go 语言实现的模型上下文协议（Model Context Protocol）服务器，用于 Git 仓库交互和自动化。该服务器提供工具，让大型语言模型能够读取、搜索和操作 Git 仓库。\n\n这是原始 Python mcp-server-git 的 Go 语言移植版本，提供了更好的性能和更简单的部署。\n\n### 工具列表\n\n#### 基础操作\n1. `git_status` - 显示工作树状态\n2. `git_init` - **新增** 初始化新的Git仓库\n3. `git_add` - 将文件内容添加到暂存区\n4. `git_commit` - 将更改记录到仓库\n5. `git_reset` - 取消暂存所有已暂存的更改\n\n#### 分支管理\n6. `git_branch` - 列出 Git 分支\n7. `git_create_branch` - 创建新分支\n8. `git_checkout` - 切换分支\n\n#### 差异和日志\n9. `git_diff_unstaged` - 显示工作目录中尚未暂存的更改\n10. `git_diff_staged` - 显示已暂存待提交的更改\n11. `git_diff` - 显示分支或提交之间的差异\n12. `git_log` - 显示提交日志，支持可选的日期过滤\n13. `git_show` - 显示提交的内容\n\n#### 远程操作\n14. `git_push` - **新增** 推送更改到远程仓库\n15. `git_list_repositories` - **新增** 列出目录中的Git仓库\n\n#### 标签管理\n16. `git_create_tag` - **新增** 创建Git标签（支持轻量级和注释标签）\n17. `git_delete_tag` - **新增** 删除Git标签\n18. `git_list_tags` - **新增** 列出Git标签（支持模式过滤）\n19. `git_push_tags` - **新增** 推送标签到远程仓库\n\n#### 高级功能\n20. `git_raw_command` - **新增** 直接执行原始Git命令（绕过shell包装问题）\n\n## 安装\n\n### 使用 Go 安装\n\n```bash\ngo install github.com/pengcunfu/go-mcp-git@latest\n```\n\n### 从源码构建\n\n```bash\ngit clone https://github.com/pengcunfu/go-mcp-git.git\ncd go-mcp-git\ngo build -o go-mcp-git ./cmd/server\n```\n\n## 使用方法\n\n### 基本用法\n```bash\ngo-mcp-git --repository /path/to/git/repo\n```\n\n### 配置用户信息\n```bash\ngo-mcp-git --user-name \"pengcunfu\" --user-email \"3173484026@qq.com\"\n```\n\n### 完整参数\n```bash\ngo-mcp-git --repository /path/to/git/repo --user-name \"pengcunfu\" --user-email \"3173484026@qq.com\" --verbose\n```\n\n### 命令行参数说明\n- `--repository, -r`: 指定Git仓库路径（可选，支持自动检测）\n- `--user-name, -u`: 设置Git提交时使用的用户名\n- `--user-email, -e`: 设置Git提交时使用的邮箱地址\n- `--verbose, -v`: 启用详细日志输出（可重复使用增加详细程度）\n\n### 智能路径解析\n\n**repo_path参数现在是可选的！** MCP服务器会智能地解析仓库路径：\n\n#### 路径解析优先级\n1. **提供的路径** - 如果指定了`repo_path`参数\n2. **服务器配置** - 启动时通过`--repository`参数配置的默认路径\n3. **自动检测** - 从当前工作目录向上查找Git仓库\n4. **当前目录** - 最后回退到当前工作目录\n\n#### 支持的路径格式\n```json\n// 绝对路径\n{\"repo_path\": \"/absolute/path/to/repository\"}\n\n// 相对路径\n{\"repo_path\": \"../parent-repo\"}\n{\"repo_path\": \"./current-dir\"}\n\n// 特殊符号\n{\"repo_path\": \".\"}     // 当前目录\n{\"repo_path\": \"..\"}    // 父目录\n\n// 省略参数（自动检测）\n{}  // 自动查找Git仓库\n```\n\n#### 使用示例\n```json\n// 最简单的用法 - 自动检测当前Git仓库\n{\n  \"command\": \"git status\"\n}\n\n// 指定相对路径\n{\n  \"repo_path\": \"../other-project\"\n}\n\n// 使用服务器配置的默认路径\n// 启动: go-mcp-git --repository /path/to/main/repo\n{}  // 将使用 /path/to/main/repo\n```\n\n### git_raw_command 工具特别说明\n\n`git_raw_command` 工具是专门为解决在某些环境（如Windsurf IDE）中Git命令被shell包装导致的引号转义问题而设计的。\n\n**问题场景：**\n当执行包含引号的Git命令时，例如：\n```bash\ngit tag -a v0.0.1 -m \"发布v0.0.1版本 - 初始MCP Git服务器实现\"\n```\n\n在PowerShell环境中可能被错误包装为：\n```powershell\nInvoke-Expression \"git tag -a v0.0.1 -m \"发布v0.0.1版本 - 初始MCP Git服务器实现\"\"\n```\n\n这会导致引号转义错误和命令执行失败。\n\n**解决方案：**\n使用 `git_raw_command` 工具可以直接执行原始Git命令，绕过shell包装：\n\n```json\n{\n  \"repo_path\": \"/path/to/repository\",\n  \"command\": \"git tag -a v0.0.1 -m \\\"发布v0.0.1版本 - 初始MCP Git服务器实现\\\"\"\n}\n```\n\n**支持的命令示例：**\n- `git tag -a v1.0.0 -m \"Release version 1.0.0\"`\n- `git commit --amend -m \"Updated commit message\"`\n- `git push origin --tags`\n- `git config user.name \"Your Name\"`\n\n### 新增工具使用示例\n\n#### 标签管理\n```json\n// 创建注释标签\n{\n  \"repo_path\": \"/path/to/repository\",\n  \"tag_name\": \"v1.0.0\",\n  \"message\": \"Release version 1.0.0\",\n  \"annotated\": true\n}\n\n// 列出所有标签\n{\n  \"repo_path\": \"/path/to/repository\"\n}\n\n// 推送特定标签\n{\n  \"repo_path\": \"/path/to/repository\",\n  \"remote\": \"origin\",\n  \"tag_name\": \"v1.0.0\"\n}\n\n// 推送所有标签\n{\n  \"repo_path\": \"/path/to/repository\",\n  \"remote\": \"origin\"\n}\n```\n\n#### 仓库初始化和推送\n```json\n// 初始化新仓库\n{\n  \"repo_path\": \"/path/to/new/repository\",\n  \"bare\": false\n}\n\n// 推送到远程仓库\n{\n  \"repo_path\": \"/path/to/repository\",\n  \"remote\": \"origin\",\n  \"tags\": true\n}\n```\n\n#### 仓库发现\n```json\n// 递归搜索Git仓库\n{\n  \"search_path\": \"/path/to/search\",\n  \"recursive\": true\n}\n```\n\n## 配置\n\n### 与 Claude Desktop 一起使用\n\n#### 方式1：自动检测（推荐）\n```json\n{\n  \"mcpServers\": {\n    \"go-mcp-git\": {\n      \"command\": \"D:\\\\Tools\\\\MCP\\\\go-mcp-git\\\\go-mcp-git.exe\"\n    }\n  }\n}\n```\n*服务器将自动检测当前工作目录中的Git仓库*\n\n#### 方式2：指定默认仓库\n```json\n{\n  \"mcpServers\": {\n    \"go-mcp-git\": {\n      \"command\": \"D:\\\\Tools\\\\MCP\\\\go-mcp-git\\\\go-mcp-git.exe\",\n      \"args\": [\n        \"--repository\",\n        \"D:\\\\Projects\\\\my-main-project\"\n      ]\n    }\n  }\n}\n```\n*所有操作默认使用指定的仓库路径*\n\n#### 方式3：配置用户信息（推荐）\n```json\n{\n  \"mcpServers\": {\n    \"go-mcp-git\": {\n      \"command\": \"D:\\\\Tools\\\\MCP\\\\go-mcp-git\\\\go-mcp-git.exe\",\n      \"args\": [\n        \"--user-name\", \"pengcunfu\",\n        \"--user-email\", \"3173484026@qq.com\"\n      ]\n    }\n  }\n}\n```\n*配置Git提交时使用的用户名和邮箱*\n\n#### 方式4：完整配置\n```json\n{\n  \"mcpServers\": {\n    \"go-mcp-git\": {\n      \"command\": \"D:\\\\Tools\\\\MCP\\\\go-mcp-git\\\\go-mcp-git.exe\",\n      \"args\": [\n        \"--repository\", \"D:\\\\Projects\\\\main-repo\",\n        \"--user-name\", \"pengcunfu\",\n        \"--user-email\", \"3173484026@qq.com\",\n        \"--verbose\"\n      ]\n    }\n  }\n}\n```\n*完整配置：指定仓库路径、用户信息和详细日志*\n\n## 许可证\n\n本 MCP 服务器采用 Apache 2.0 许可证。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpengcunfu%2Fgo-mcp-git","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpengcunfu%2Fgo-mcp-git","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpengcunfu%2Fgo-mcp-git/lists"}