Git协议服务器

一个与LLM Agent集成的Python Git功能协议服务器,提供仓库状态查询、提交管理、分支操作等完整的Git功能支持。

  • by zerogon1203
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 zerogon1203/git-mcp-server

使用说明

GIT-MCP服务器

可与LLM Agent配合使用的Model Context Protocol(MCP)Stdio服务器。

项目说明

该项目提供了基于Python的Git相关功能,使LLM Agent能够利用Git相关功能。

主要功能

  • 查看存储库状态
  • 创建和管理提交
  • 推送/推送
  • 创建/移动/合并分支
  • 查询提交历史记录
  • 变更统计
  • 标签管理
  • 远程存储管理
  • 全任务管理

安装方法

  1. 存储库克隆
git clone https://github.com/yourusername/git-mcp-server.git
cd git-mcp-server
  1. 创建和激活虚拟环境
python -m venv venv
source venv/bin/activate  # Linux/Mac
# 또는
.\venv\Scripts\activate  # Windows
  1. 依赖性安装
pip install -r requirements.txt
  1. 设置环境变量 .env 创建文件并添加以下内容:
GIT_REPO_PATH=/path/to/your/git/repository
GITHUB_TOKEN=your_github_personal_access_token  # GitHub API 사용 시 필요

MCP设置

将以下内容添加到MCP设置文件:

{
  "git-mcp-server": {
    "transport": "stdio",
    "command": "/path/to/your/venv/bin/python",
    "args": ["/path/to/your/git-mcp-server/main.py"],
    "env": {
      "GIT_REPO_PATH": "/path/to/your/git/repository",
      "GITHUB_TOKEN": "your_github_personal_access_token"
    }
  }
}

使用方法

服务器运行:

python main.py

可用命令

  1. 查看存储库状态
{
    "command": "get_repo_status"
}
  1. 提交更改
{
    "command": "commit_changes",
    "params": {
        "message": "커밋 메시지",
        "files": ["file1.txt", "file2.txt"]  // 선택사항
    }
}
  1. 推送更改
{
    "command": "push_changes",
    "params": {
        "remote": "origin",  // 선택사항
        "branch": "main"     // 선택사항
    }
}
  1. 变更池
{
    "command": "pull_changes",
    "params": {
        "remote": "origin",  // 선택사항
        "branch": "main"     // 선택사항
    }
}
  1. 创建分支
{
    "command": "create_branch",
    "params": {
        "branch_name": "feature/new-branch"
    }
}
  1. 分支切换
{
    "command": "switch_branch",
    "params": {
        "branch_name": "feature/new-branch"
    }
}
  1. 合并分支
{
    "command": "merge_branch",
    "params": {
        "source_branch": "feature/new-branch"
    }
}
  1. 查询提交历史记录
{
    "command": "get_commit_history",
    "params": {
        "limit": 10  // 선택사항
    }
}
  1. 查看分支信息
{
    "command": "get_branch_info"
}
  1. 查看更改统计信息
{
    "command": "get_diff_stats"
}
  1. 创建标记
{
    "command": "create_tag",
    "params": {
        "tag_name": "v1.0.0",
        "message": "릴리스 버전 1.0.0",  // 선택사항
        "commit_hash": "abc123"  // 선택사항
    }
}
  1. 查看标记列表
{
    "command": "list_tags"
}
  1. 删除标记
{
    "command": "delete_tag",
    "params": {
        "tag_name": "v1.0.0",
        "remote": true  // 선택사항, 원격 저장소에서도 삭제할지 여부
    }
}
  1. 查看远程存储库列表
{
    "command": "list_remotes"
}
  1. 添加远程存储
{
    "command": "add_remote",
    "params": {
        "name": "upstream",
        "url": "https://github.com/original/repo.git"
    }
}
  1. 删除远程存储
{
    "command": "remove_remote",
    "params": {
        "name": "upstream"
    }
}
  1. 更改远程存储库URL
{
    "command": "set_remote_url",
    "params": {
        "name": "origin",
        "url": "https://github.com/new/repo.git"
    }
}
  1. 创建完整请求
{
    "command": "create_pull_request",
    "params": {
        "title": "새로운 기능 추가",
        "body": "이 PR은 새로운 기능을 추가합니다.",
        "head": "feature/new-feature",
        "base": "main",  // 선택사항
        "repo_owner": "username",  // 선택사항
        "repo_name": "repo-name"  // 선택사항
    }
}
  1. 查看完整的任务列表
{
    "command": "list_pull_requests",
    "params": {
        "state": "open",  // 선택사항: open, closed, all
        "repo_owner": "username",  // 선택사항
        "repo_name": "repo-name"  // 선택사항
    }
}
  1. 完整请求详细查询
{
    "command": "get_pull_request",
    "params": {
        "pull_number": 123,
        "repo_owner": "username",  // 선택사항
        "repo_name": "repo-name"  // 선택사항
    }
}
  1. 更新完整请求
{
    "command": "update_pull_request",
    "params": {
        "pull_number": 123,
        "title": "수정된 제목",  // 선택사항
        "body": "수정된 내용",  // 선택사항
        "state": "open",  // 선택사항: open, closed
        "repo_owner": "username",  // 선택사항
        "repo_name": "repo-name"  // 선택사항
    }
}
  1. 合并完整请求
{
    "command": "merge_pull_request",
    "params": {
        "pull_number": 123,
        "merge_method": "merge",  // 선택사항: merge, squash, rebase
        "commit_title": "병합 커밋 제목",  // 선택사항
        "commit_message": "병합 커밋 메시지",  // 선택사항
        "repo_owner": "username",  // 선택사항
        "repo_name": "repo-name"  // 선택사항
    }
}

许可证

MIT许可证