G

Git

一个用于Git仓库交互和自动化的模型上下文协议服务器。该服务器提供工具,可通过大型语言模型读取、搜索和操作Git仓库。

version-control

1.3w 查看 · 2026-07-07 更新

简介

一个用于Git仓库交互和自动化的模型上下文协议服务器。该服务器提供工具,可通过大型语言模型读取、搜索和操作Git仓库。

简介

一个用于Git仓库交互和自动化的模型上下文协议服务器。该服务器提供工具,可通过大型语言模型读取、搜索和操作Git仓库。

mcp-server-git: 一个用于 Git 的 MCP 服务器

概述

这是一个用于与 Git 仓库进行交互和自动化的模型上下文协议(Model Context Protocol, MCP)服务器。该服务器提供了通过大型语言模型来读取、搜索和操作 Git 仓库的工具。

请注意,mcp-server-git 目前处于早期开发阶段。随着我们继续开发和完善服务器,功能和可用工具可能会发生变化和扩展。

工具

  1. git_status

    • 显示工作树的状态
    • 输入:
      • repo_path (字符串): Git 仓库路径
    • 返回: 当前工作目录的状态作为文本输出
  2. git_diff_unstaged

    • 显示尚未暂存的工作目录中的更改
    • 输入:
      • repo_path (字符串): Git 仓库路径
    • 返回: 未暂存更改的差异输出
  3. git_diff_staged

    • 显示已为提交而暂存的更改
    • 输入:
      • repo_path (字符串): Git 仓库路径
    • 返回: 已暂存更改的差异输出
  4. git_diff

    • 显示分支或提交之间的差异
    • 输入:
      • repo_path (字符串): Git 仓库路径
      • target (字符串): 要比较的目标分支或提交
    • 返回: 比较当前状态与目标的差异输出
  5. git_commit

    • 记录对仓库的更改
    • 输入:
      • repo_path (字符串): Git 仓库路径
      • message (字符串): 提交信息
    • 返回: 包含新提交哈希值的确认信息
  6. git_add

    • 将文件内容添加到暂存区
    • 输入:
      • repo_path (字符串): Git 仓库路径
      • files (字符串数组): 要暂存的文件路径数组
    • 返回: 暂存文件的确认信息
  7. git_reset

    • 取消所有已暂存的更改
    • 输入:
      • repo_path (字符串): Git 仓库路径
    • 返回: 重置操作的确认信息
  8. git_log

    • 显示提交日志
    • 输入:
      • repo_path (字符串): Git 仓库路径
      • max_count (数字, 可选): 要显示的最大提交数量 (默认: 10)
    • 返回: 包含哈希、作者、日期和信息的提交条目数组
  9. git_create_branch

    • 创建新分支
    • 输入:
      • repo_path (字符串): Git 仓库路径
      • branch_name (字符串): 新分支名称
      • start_point (字符串, 可选): 新分支的起始点
    • 返回: 分支创建的确认信息
  10. git_checkout

  • 切换分支
  • 输入:
    • repo_path (字符串): Git 仓库路径
    • branch_name (字符串): 要切换到的分支名称
  • 返回: 分支切换的确认信息
  1. git_show
  • 显示特定提交的内容
  • 输入:
    • repo_path (字符串): Git 仓库路径
    • revision (字符串): 要显示的修订版本(提交哈希、分支名、标签)
  • 返回: 指定提交的内容
  1. git_init
  • 初始化一个 Git 仓库
  • 输入:
    • repo_path (字符串): 要初始化 Git 仓库的目录路径
  • 返回:仓库初始化确认

安装

使用 uv(推荐)

使用 uv 时不需要特定的安装步骤。我们将使用 uvx 直接运行 mcp-server-git

使用 PIP

或者,你可以通过 pip 安装 mcp-server-git

pip install mcp-server-git

安装完成后,你可以使用以下命令作为脚本运行它:

python -m mcp_server_git

配置

与 Claude Desktop 一起使用

将以下内容添加到你的 claude_desktop_config.json 文件中:

使用 uvx
"mcpServers": { "git": { "command": "uvx", "args": ["mcp-server-git", "--repository", "path/to/git/repo"] } }
使用 Docker
  • 注意:请将 '/Users/username' 替换为你希望此工具可访问的路径
"mcpServers": { "git": { "command": "docker", "args": ["run", "--rm", "-i", "--mount", "type=bind,src=/Users/username,dst=/Users/username", "mcp/git"] } }
使用 pip 安装
"mcpServers": { "git": { "command": "python", "args": ["-m", "mcp_server_git", "--repository", "path/to/git/repo"] } }

Zed 一起使用

在你的 Zed settings.json 中添加以下内容:

使用 uvx
"context_servers": [ "mcp-server-git": { "command": { "path": "uvx", "args": ["mcp-server-git"] } } ],
使用 pip 安装
"context_servers": { "mcp-server-git": { "command": { "path": "python", "args": ["-m", "mcp_server_git"] } } },

调试

你可以使用 MCP 检查器来调试服务器。对于 uvx 安装:

npx @modelcontextprotocol/inspector uvx mcp-server-git

或者如果你已在特定目录中安装了该包或正在开发中:

cd path/to/servers/src/git npx @modelcontextprotocol/inspector uv run mcp-server-git

运行 tail -n 20 -f ~/Library/Logs/Claude/mcp*.log 将显示来自服务器的日志,并可能帮助你调试任何问题。

开发

如果你正在进行本地开发,有两种方法可以测试你的更改:

  1. 运行 MCP 检查器以测试你的更改。有关运行说明,请参阅调试部分。

  2. 使用 Claude 桌面应用程序进行测试。向你的 claude_desktop_config.json 添加以下内容:

Docker

{ "mcpServers": { "git": { "command": "docker", "args": [ "run", "--rm", "-i", "--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop", "--mount", "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro", "--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt", "mcp/git" ] } } }

UVX

{ "mcpServers": { "git": { "command": "uv", "args": [ "--directory", "/<path to mcp-servers>/mcp-servers/src/git", "run", "mcp-server-git" ] } }

构建

Docker 构建:

cd src/git docker build -t mcp/git .

许可证

此 MCP 服务器根据 MIT 许可证许可。这意味着你可以自由地使用、修改和分发软件,但需遵守 MIT 许可证的条款和条件。更多详情,请参见项目仓库中的 LICENSE 文件。

工具列表

  • git_status: Shows the working tree status

  • git_diff_unstaged: Shows changes in the working directory that are not yet staged

  • git_diff_staged: Shows changes that are staged for commit

  • git_diff: Shows differences between branches or commits

  • git_commit: Records changes to the repository

  • git_add: Adds file contents to the staging area

  • git_reset: Unstages all staged changes

  • git_log: Shows the commit logs

  • git_create_branch: Creates a new branch from an optional base branch

  • git_checkout: Switches branches

  • git_show: Shows the contents of a commit

  • git_init: Initialize a new Git repository

来源