Git仓库管理服务

用于本地Git仓库管理的MCP服务器,提供仓库列表、标签操作、提交查询等功能。

  • by kjozsa
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 kjozsa/git-mcp

使用说明

Git MCP

MCP服务器,用于管理本地存储库上的Git操作。

安装

通过Smithery安装

通过以下方式自动安装Git MCP for Claude Desktop 史密瑟里:

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

通过签出主分支(或主分支作为回退)并从所有远程拉取来刷新存储库。

  • 参数:
    • 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