G

Git MCP 服务器

@Sheshiyer/git-mcp-v2
0 Stars 396 次浏览 Sheshiyer 更新于 2026-08-23

Git MCP服务器通过模型上下文协议(Model Context Protocol)允许AI助手执行增强的Git操作,支持核心Git功能、分支和标签管理、GitHub集成等更多功能。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "git-v2": {
      "args": [
        "path/to/git-mcp-v2/build/index.js"
      ],
      "command": "node",
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your-github-pat",
        "GIT_DEFAULT_PATH": "/path/to/default/git/directory"
      }
    }
  }
}

该服务需要配置环境变量:GITHUB_PERSONAL_ACCESS_TOKEN、GIT_DEFAULT_PATH

可用工具 (21 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

init 1 个参数

Initialize a new Git repository

该工具无需必填参数,直接调用即可

clone 2 个参数 需填 1 项

Clone a repository

必填参数:url

status 1 个参数

Get repository status

该工具无需必填参数,直接调用即可

add 2 个参数 需填 1 项

Stage files

必填参数:files

commit 2 个参数 需填 1 项

Create a commit

必填参数:message

push 6 个参数 需填 1 项

Push commits to remote

必填参数:branch

pull 3 个参数 需填 1 项

Pull changes from remote

必填参数:branch

branch_list 1 个参数

List all branches

该工具无需必填参数,直接调用即可

branch_create 5 个参数 需填 1 项

Create a new branch

必填参数:name

branch_delete 2 个参数 需填 1 项

Delete a branch

必填参数:name

checkout 2 个参数 需填 1 项

Switch branches or restore working tree files

必填参数:target

tag_list 1 个参数

List tags

该工具无需必填参数,直接调用即可

tag_create 6 个参数 需填 1 项

Create a tag

必填参数:name

tag_delete 2 个参数 需填 1 项

Delete a tag

必填参数:name

remote_list 1 个参数

List remotes

该工具无需必填参数,直接调用即可

remote_add 3 个参数 需填 2 项

Add a remote

必填参数:name、url

remote_remove 2 个参数 需填 1 项

Remove a remote

必填参数:name

stash_list 1 个参数

List stashes

该工具无需必填参数,直接调用即可

stash_save 5 个参数

Save changes to stash

该工具无需必填参数,直接调用即可

stash_pop 2 个参数

Apply and remove a stash

该工具无需必填参数,直接调用即可

bulk_action 2 个参数 需填 1 项

Execute multiple Git operations in sequence. This is the preferred way to execute multiple operations.

必填参数:actions

服务介绍

Git MCP 服务器

一个通过标准化接口提供增强的 Git 操作的模型上下文协议(MCP)服务器。该服务器与 MCP 生态系统集成,为 AI 助手提供 Git 功能。

特性

  • 核心 Git 操作:初始化、克隆、状态、添加、提交、推送、拉取
  • 分支管理:列出、创建、删除、切换
  • 标签操作:列出、创建、删除
  • 远程管理:列出、添加、移除
  • 储藏操作:列出、保存、弹出
  • 批量操作:按顺序执行多个 Git 操作
  • GitHub 集成:通过个人访问令牌内置支持 GitHub
  • 路径解析:智能路径处理,并可选配置默认路径
  • 错误处理:全面的错误处理及自定义错误类型
  • 仓库缓存:高效的仓库状态管理
  • 性能监控:内置性能跟踪

安装

  1. 克隆仓库:
git clone https://github.com/yourusername/git-mcp-v2.git
cd git-mcp-v2
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build

配置

在您的 MCP 设置文件中添加:

{
  "mcpServers": {
    "git-v2": {
      "command": "node",
      "args": ["path/to/git-mcp-v2/build/index.js"],
      "env": {
        "GIT_DEFAULT_PATH": "/path/to/default/git/directory",
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your-github-pat"
      }
    }
  }
}

环境变量

  • GIT_DEFAULT_PATH:(可选)Git 操作的默认路径
  • GITHUB_PERSONAL_ACCESS_TOKEN:(可选)用于 GitHub 操作的个人访问令牌

可用工具

基本操作

  • init:初始化一个新的 Git 仓库
  • clone:克隆仓库
  • status:获取仓库状态
  • add:暂存文件
  • commit:创建提交
  • push:将提交推送到远程
  • pull:从远程拉取更改

分支操作

  • branch_list:列出所有分支
  • branch_create:创建新分支
  • branch_delete:删除分支
  • checkout:切换分支或恢复工作树文件

标签操作

  • tag_list:列出标签
  • tag_create:创建标签
  • tag_delete:删除标签

远程操作

  • remote_list:列出远程
  • remote_add:添加远程
  • remote_remove:移除远程

储藏操作

  • stash_list:列出储藏
  • stash_save:保存变更到储藏
  • stash_pop:应用并移除储藏

批量操作

  • bulk_action:按顺序执行多个 Git 操作

开发

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Run linter
npm run lint

# Format code
npm run format

许可证

MIT

贡献

  1. 分叉仓库
  2. 创建你的功能分支 (git checkout -b feature/amazing-feature)
  3. 提交你的更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开一个 Pull Request

相关 MCP 服务