G

Git MCP 本地仓库管理工具

@kjozsa/git-mcp
0 Stars 644 次浏览 kjozsa 更新于 2026-08-23

用于管理本地仓库Git操作的MCP服务器,允许用户通过标准化接口列出仓库、获取和创建标签、列出提交记录、推送标签以及刷新仓库。

MCP 服务配置

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

{
  "mcpServers": {
    "git-mcp": {
      "args": [
        "git-mcp"
      ],
      "command": "uvx",
      "env": {
        "GIT_REPOS_PATH": "/path/to/your/git/repositories"
      }
    }
  }
}

该服务需要配置环境变量:GIT_REPOS_PATH

可用工具 (6 个)

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

get_last_git_tag 1 个参数 需填 1 项

Find the last git tag in the repository Args: repo_name: Name of the git repository Returns: Dictionary containing tag version and date

必填参数:repo_name

list_commits_since_last_tag 2 个参数 需填 1 项

List commit messages since main HEAD and the last git tag Args: repo_name: Name of the git repository max_count: Maximum number of commits to return Returns: List of dictionaries containing commit hash, author, date, and message

必填参数:repo_name

list_repositories

List all git repositories in the configured path Returns: List of repository names

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

create_git_tag 3 个参数 需填 2 项

Create a new git tag in the repository Args: repo_name: Name of the git repository tag_name: Name of the tag to create message: Optional message for annotated tag Returns: Dictionary containing status and tag information

必填参数:repo_name、tag_name

push_git_tag 2 个参数 需填 2 项

Push a git tag to the default remote Args: repo_name: Name of the git repository tag_name: Name of the tag to push Returns: Dictionary containing status and information about the operation

必填参数:repo_name、tag_name

refresh_repository 1 个参数 需填 1 项

Refresh repository by checking out main branch and pulling all remotes Args: repo_name: Name of the git repository Returns: Dictionary containing status and information about the operation

必填参数:repo_name

服务介绍

Git MCP

smithery badge
用于管理本地仓库Git操作的MCP服务器。

安装

通过Smithery安装

要通过Smithery自动为Claude Desktop安装Git MCP:

npx -y @smithery/cli install @kjozsa/git-mcp --client claude

手动安装

uvx install git-mcp

配置

使用以下JSON配置片段添加MCP服务器:

{
  "mcpServers": {
    "git-mcp": {
      "command": "uvx",
      "args": ["git-mcp"],
      "env": {
        "GIT_REPOS_PATH": "/path/to/your/git/repositories"
      }
    }
  }
}

功能和用法

环境变量

  • GIT_REPOS_PATH: 包含您的Git仓库的目录路径(必需)

您可以在环境中设置此变量,或者在运行服务器的目录中创建一个.env文件。

可用方法

list_repositories

列出配置路径中的所有Git仓库。

  • 参数:无
  • 返回值:仓库名称列表

get_last_git_tag

查找指定仓库中的最后一个Git标签。

  • 参数:repo_name (Git仓库名称)
  • 返回值:包含version(标签名)和date(标签创建日期)的字典

list_commits_since_last_tag

列出从最后一个Git标签到HEAD之间的提交信息。

  • 参数:
    • repo_name: Git仓库名称
    • max_count (可选): 要返回的最大提交数量
  • 返回值:包含hash, author, date, 和 message的字典列表

create_git_tag

在指定仓库中创建一个新的git标签。

  • 参数:
    • repo_name: git仓库名称
    • tag_name: 要创建的标签名称
    • message (可选): 注释标签的消息(如果不提供,则创建轻量级标签)
  • 返回值:包含status, version(标签名), date(标签创建日期), 和 type(注释或轻量级)的字典

push_git_tag

将现有的git标签推送到默认的远程仓库。

  • 参数:
    • repo_name: git仓库名称
    • tag_name: 要推送的标签名称
  • 返回值:包含status, remote(远程名称), tag(标签名称), 和 message(成功消息)的字典

refresh_repository

通过检出主分支(或作为回退的master分支)并从所有远程拉取来刷新仓库。

  • 参数:
    • repo_name: git仓库名称
  • 返回值:包含status, repository, branch, 和 pull_results(每个远程的结果)的字典

故障排除

  • 找不到仓库:确保GIT_REPOS_PATH设置正确并且仓库存在
  • 未找到任何标签:该仓库还没有任何标签

开发

# Install dependencies
uv pip install -r requirements.txt

# Run in dev mode with Inspector
mcp dev git_mcp/server.py

测试

该项目包括两个测试脚本:

  1. test_git_mcp.py - 直接测试底层Git命令功能,不使用MCP服务器。
  2. test_mcp_server.py - 通过启动服务器实例并向其发送请求来测试MCP服务器功能。

要运行测试:

# Test the Git command functionality
python test_git_mcp.py

# Test the MCP server (requires the git-mcp package to be installed)
python test_mcp_server.py

相关 MCP 服务