Git MCP

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Supports configuration through environment variables that can be set directly or through a .env file, particularly for specifying the path to Git repositories.

  • Provides tools for managing local Git repositories, including listing repositories, retrieving and creating tags, listing commits, pushing tags to remote repositories, and refreshing repositories by pulling from remotes.

Git MCP

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

安装

通过 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文件。

可用方法

列出存储库

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

  • 参数:无
  • 返回:存储库名称列表

获取最后一个 git 标签

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

  • 参数: repo_name (Git 存储库的名称)
  • 返回:带有version (标签名称)和date (标签创建日期)的字典

list_commits_since_last_tag

列出最后一个 Git 标签和 HEAD 之间的提交消息。

  • 参数:
    • repo_name :Git 存储库的名称
    • max_count (可选):返回的最大提交数
  • 返回:包含hashauthordatemessage字典列表

创建 git 标签

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

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

推送_git_标签

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

  • 参数:
    • repo_name :git 存储库的名称
    • tag_name :要推送的标签名称
  • 返回:包含statusremote (远程名称)、 tag (标签名称)和message (成功消息)的字典

刷新存储库

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

  • 参数:
    • repo_name :git 存储库的名称
  • 返回:包含statusrepositorybranchpull_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

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

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

  1. Installation
    1. Installing via Smithery
    2. Installing Manually
  2. Configuration
    1. Features and Usage
      1. Environment Variables
      2. Available Methods
      3. Troubleshooting
    2. Development
      1. Testing
        ID: s9v9iezy1u