Git提交自动化服务器

一个自动化Git提交、更新变更日志并可选择推送的MCP服务器,适用于需要AI辅助生成规范提交消息和管理CHANGELOG的开发场景。

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

使用说明

Git提交MCP服务器

一个小型MCP(模型上下文协议)服务器,可以自动执行常规Git提交、更改日志更新和可选推送。当您希望AI助手创建格式良好的常规提交消息并自动管理CHANGELOG时,请使用此存储库。

请参阅 docs/ 文件夹:

  • docs/architecture.md --高级架构、组件和数据流。
  • docs/usage.md --设置、配置和常见工作流(包括PowerShell示例)。

快速开始

先决条件

  • Python 3.10+
  • Git已安装并配置
  • uv 包管理器(用于开发)
  • pipx (适用于全球安装)

安装

选项1:使用pipx进行全局安装(推荐)

全局安装,以便服务器可以从任何目录访问:

# Install pipx if you don't have it
uv tool install pipx

# Install from PyPI (production)
pipx install git-commit-mcp-server

# Or install from TestPyPI (testing)
pipx install git-commit-mcp-server --index-url https://test.pypi.org/simple/ --pip-args="--extra-index-url https://pypi.org/simple/"

选项2:使用uvx运行(无需安装)

无需安装即可直接运行:

uvx git-commit-mcp-server

选项3:开发模式

对于当地发展:

# Clone the repository
git clone https://github.com/surajfale/git-mcp-server.git
cd git-mcp-server

# Install with development dependencies
uv pip install -e ".[dev]"

# Run the server
python -m git_commit_mcp.__main__

配置

MCP客户端设置

该服务器可与各种MCP兼容的客户端配合使用,包括:

  • 开发 IDE — .kiro/settings/mcp.json 或 ~/.kiro/settings/mcp.json
  • 光标IDE --请参阅 光标配置 在......下面
  • 克劳德桌面 — claude_desktop_config.json
  • 弯曲 --MCP配置文件
  • VSCode --带MCP扩展

示例配置(Kiro IDE):

{
  "mcpServers": {
    "git-commit": {
      "command": "git-commit-mcp",
      "args": [],
      "disabled": false,
      "env": {
        "OPENAI_API_KEY": "sk-your-key-here",
        "ENABLE_AI": "true",
        "AI_MODEL": "gpt-4o-mini",
        "FORCE_SSH_ONLY": "true"
      },
      "autoApprove": []
    }
  }
}

环境变量

关键环境变量:

  • OPENAI_API_KEY --需要时 ENABLE_AI=true 用于AI驱动的提交消息
  • ENABLE_AI --设置为 true 使用AI生成(默认: true)
  • AI_MODEL --要使用的OpenAI模型(默认值: gpt-4o-mini)
  • FORCE_SSH_ONLY --Git操作需要SSH(默认值: true)
  • LOG_LEVEL --日志记录级别:调试、信息、警告、错误(默认值: INFO)

在PowerShell中设置:

# Current session
$env:OPENAI_API_KEY = 'sk-your-key-here'

# Persistent (user-level)
setx OPENAI_API_KEY "sk-your-key-here"

光标IDE配置

重要提示: Cursor IDE有特定的要求。请参阅 详细的光标设置指南 在 docs/usage.md.

光标的快速设置:

  1. 配置文件位置(Windows):

    %APPDATA%\Cursor\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
    
  2. 基本配置:

    {
      "mcpServers": {
        "git-commit-mcp": {
          "command": "git-commit-mcp",
          "args": [],
          "env": {
            "OPENAI_API_KEY": "sk-your-key-here",
            "ENABLE_AI": "true"
          }
        }
      }
    }
    
  3. 对于当地发展:

    {
      "mcpServers": {
        "git-commit-mcp": {
          "command": "python",
          "args": ["-m", "git_commit_mcp.__main__"],
          "cwd": "C:\\path\\to\\git_commit_message",
          "env": {
            "OPENAI_API_KEY": "sk-your-key-here"
          }
        }
      }
    }
    

故障排除: 如果在Cursor中遇到问题,请参阅 光标特定故障排除部分 在 docs/usage.md.

用法

配置后,与您的AI助手一起使用自然语言:

User: "Commit my changes"
AI: [Analyzes your git diff and generates a conventional commit message]
AI: "Created commit abc1234: feat(auth): Add user authentication module"

User: "Commit and push"
AI: [Commits and pushes to remote]
AI: "Successfully pushed to origin/main"

服务器提供两个主要工具:

  • generate_commit_message --在不提交的情况下生成提交消息
  • git_commit_and_push --完整的工作流程:分析、提交和可选推送

特性

  • AI驱动的消息:分析实际的git差异以生成准确的提交消息
  • 常规承诺:遵循常规承诺规范
  • 智能类型检测:自动确定提交类型(feat、fix、docs等)
  • 变更日志管理:使用提交历史记录维护CHANGELOG.md
  • 推送确认:在推动之前需要明确批准
  • 多存储库:适用于任何Git存储库,本地或远程

测试

运行测试套件:

# Run all tests
pytest

# Run with coverage
pytest --cov=git_commit_mcp

# Run specific tests
pytest tests/test_integration.py -v

更新中

更新到最新版本:

# Update global installation
pipx upgrade git-commit-mcp-server

# Or from TestPyPI
pipx upgrade git-commit-mcp-server --index-url https://test.pypi.org/simple/ --pip-args="--extra-index-url https://pypi.org/simple/"

文档

  • docs/usage.md --详细的设置、配置、故障排除和最佳实践
  • docs/architecture.md --系统架构、组件和设计决策

贡献

欢迎投稿!拜托:

  1. 分叉存储库
  2. 创建要素分支
  3. 通过测试进行更改
  4. 提交拉取请求

许可证

MIT许可证-有关详细信息,请参阅许可证文件

链接

  • 仓库: https://github.com/surajfale/git-mcp-server
  • 问题: https://github.com/surajfale/git-mcp-server/issues
  • PyPI: https://pypi.org/project/git-commit-mcp-server/
  • TestPyPI: https://test.pypi.org/project/git-commit-mcp-server/