Git操作服务

GitHub MCP Server是一个提供29种Git操作和11种工作流组合的MCP服务器,通过标准化接口为AI助手和开发者提供全面的Git仓库管理功能。

  • by jungchihoon
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 jungchihoon/github-mcp-server

使用说明

GitHub MCP服务器

🔗 MCP市场展望
🔗 MCP注册表视图

A. 模型上下文协议(MCP)服务器 这提供了 29个Git操作+11个工作流组合 AI助手和开发人员。该服务器通过标准化的界面提供全面的Git存储库管理,使AI模型和开发人员能够安全地管理复杂的版本控制工作流。

🎯 关于

GitHub MCP服务器 将AI助手与Git存储库连接起来,并提供强大的开发人员生产力工具。它提供:

  • 安全的Git操作 通过标准化的MCP接口(29次操作)
  • 完整的版本控制 功能包括高级操作(标记、合并、重基、选择性选择、责备、平分)
  • 31种工作流程组合 提高开发人员的工作效率
  • 高级开发工具 (备份、清理、工作流自动化)
  • 错误处理和验证 防止常见的Git错误
  • 直接积分法 使用VS Code和GitHub Copilot等人工智能助手
  • CLI包装器 用于终端接入和自动化

🚀 功能概述

此服务器通过两个主要类别提供全面的Git存储库管理:

📁 Git基本操作 (17次操作)

基本的日常Git命令组织在 bin/basic/ -看 基本操作指南 详细文档。

  • 文件管理:从暂存区添加、删除文件
  • 存储库信息:现状、历史、差异
  • 提交操作:创建提交、推送、拉取
  • 分行管理:创建、切换分支
  • 远程管理:添加、删除、配置遥控器
  • 停滞操作:临时保存更改
  • 重置操作:存储库状态管理

🚀 高级Git操作 (12项操作)

复杂的工作流程和自动化 bin/advanced/ -看 高级工作流指南 以获取全面的文档。

  • 工作流组合:完成流程(添加→提交→推送)、快速提交、同步操作
  • 开发工具:智能开发工作流程、备份系统
  • Git高级功能:标签,合并,重设基线,樱桃采摘,责备,平分
  • 维护与安全:存储库清理、优化、备份管理
  • 专业工作流程:发布管理、修补程序、团队协作

🛠️ 安装

🚀 npx快速入门(推荐)

使用GitHub MCP服务器的最快方法是 新巴拿马型船舶 -无需安装!

# Basic Git operations
npx github-mcp-server gstatus
npx github-mcp-server gadd
npx github-mcp-server gcommit "your commit message"
npx github-mcp-server gpush

# Advanced workflows
npx github-mcp-server gflow "implement new feature"
npx github-mcp-server gsync
npx github-mcp-server gbackup

# Or use the short alias
npx gms gstatus
npx gms gflow "quick fix"

📦 全球安装

对于频繁使用,请全局安装:

# Using npm
npm install -g github-mcp-server

# Using pnpm (recommended)
pnpm add -g github-mcp-server

# Then use directly
gstatus
gflow "your message"
gsync

🔧 本地开发安装

看 标记/安装.md 有关Windows、macOS、WSL和所有平台的详细安装指南。

🤖 MCP服务器集成(Cursor、Claude等)

🎯 在Cursor IDE中使用MCP服务器

要在Cursor中使用GitHub MCP Server,请添加以下设置:

文件: ~/.cursor/mcp_config.json

🔑 GitHub令牌设置(建议)

通过设置GitHub令牌,您可以在没有身份验证错误的情况下执行Git操作:

  1. GitHub个人访问令牌생성:

    • GitHub.com→ 设置→ 开发人员设置→ 个人访问令牌→ 代币(经典)
    • “生成新令牌”→ “生成新令牌(经典)”
    • 权限设置: repo, workflow, write:packages 等选择所需权限
    • 创建令牌后将其保存在安全的地方
  2. 设置环境变量:

    • GITHUB_TOKEN:GitHub个人访问令牌
    • GITHUB_USERNAME:GitHub用户名(可选,默认为“git”)
{
  "mcpServers": {
    "github-mcp-server": {
      "command": "npx",
      "args": ["github-mcp-server-mcp"],
      "env": {
        "GITHUB_TOKEN": "your_github_personal_access_token",
        "GITHUB_USERNAME": "your_github_username"
      },
      "capabilities": ["tools", "resources", "prompts"]
    }
  }
}

🔧 设置其他MCP客户端

克劳德桌面

文件: ~/.config/claude/claude_desktop_config.json

{
  "mcpServers": {
    "github-mcp-server": {
      "command": "npx",
      "args": ["github-mcp-server", "mcp"],
      "env": {}
    }
  }
}

继续(VS代码扩展)

文件: ~/.continue/config.json

{
  "models": [
    {
      "title": "GitHub MCP Assistant",
      "provider": "anthropic",
      "model": "claude-3-5-sonnet-20241022",
      "contextLength": 200000,
      "mcpServers": [
        {
          "name": "github-mcp-server",
          "command": "npx",
          "args": ["github-mcp-server", "mcp"],
          "env": {}
        }
      ]
    }
  ]
}

🚀 直接运行MCP服务器

也可以直接运行npm软件包安装的MCP服务器:

# 글로벌 설치 후
npm install -g github-mcp-server
github-mcp-server mcp

# 또는 npx로 직접 실행
npx github-mcp-server mcp

📋 可用的MCP工具

MCP服务器提供29个Git任务:

  • 基本任务git-status,git-add,git-commit,git-push,git-pull
  • 分支管理git-branch,git-checkout,git-merge,git-rebase
  • 高级任务git-tag,git-cherry-pick,git-blame,git-bisect
  • 工作流git-flow,git-sync,git-backup,git-clean

**详细设置包括: markdown/MCP_UNIVERSAL_CONFIG.md请参阅**。

🚀 快速使用指南

📁 Git基本操作

# Check repository status
npx github-mcp-server gstatus

# Add all files and commit
npx github-mcp-server gadd
npx github-mcp-server gcommit "your commit message"

# Push to remote
npx github-mcp-server gpush

# Pull from remote
npx github-mcp-server gpull

# Branch operations
npx github-mcp-server gbranch feature-auth
npx github-mcp-server gcheckout feature-auth

# View history and differences
npx github-mcp-server glog 5
npx github-mcp-server gdiff main

🚀 高级工作流

# Complete workflow (add → commit → push)
npx github-mcp-server gflow "implement new feature"

# Quick commit without push
npx github-mcp-server gquick "fix typo"

# Sync with remote (pull → push)
npx github-mcp-server gsync

# Development session management
npx github-mcp-server gdev feature-auth

# Backup and safety
npx github-mcp-server gbackup --emergency

# Repository cleanup
npx github-mcp-server gclean --optimize

🔧 专业Git操作

# Tag management
npx github-mcp-server gtag create v1.0.0 "Release version"

# Merge operations
npx github-mcp-server gmerge feature-branch

# Rebase operations
npx github-mcp-server grebase main

# Cherry-pick specific commit
npx github-mcp-server gcherry abc1234

# Line-by-line authorship
npx github-mcp-server gblame src/app.js

📚 帮助和发现

# List all available operations
npx github-mcp-server list

# Get help for specific operation
npx github-mcp-server help

# Show basic operations
npx github-mcp-server glist basic

# Show advanced workflows
npx github-mcp-server glist advanced

🏗️ 项目结构和架构

GitHub MCP服务器 为了清晰和渐进式学习而组织:

github-mcp-server/
├── src/
│   ├── index.ts              # MCP server (29 tool registrations, schema definitions)
│   └── github.ts             # Git operations engine (all 29 implementations)
├── bin/
│   ├── basic/                # 📁 17 Essential Git Operations
│   │   ├── README.md         # Comprehensive basic operations guide
│   │   ├── gadd.js           # Add files (git add)
│   │   ├── gcommit.js        # Create commits (git commit)
│   │   ├── gpush.js          # Push changes (git push)
│   │   ├── gpull.js          # Pull changes (git pull)
│   │   ├── gstatus.js        # Repository status (git status)
│   │   ├── gbranch.js        # Branch management (git branch)
│   │   ├── gcheckout.js      # Branch switching (git checkout)
│   │   ├── glog.js           # Commit history (git log)
│   │   ├── gdiff.js          # Show differences (git diff)
│   │   ├── gstash.js         # Stash operations (git stash)
│   │   ├── gpop.js           # Apply stash (git stash pop)
│   │   ├── greset.js         # Reset operations (git reset)
│   │   ├── gclone.js         # Clone repositories (git clone)
│   │   ├── gremote.js        # Remote management (git remote)
│   │   └── ginit.js          # Initialize repository (git init)
│   └── advanced/             # 🚀 13 Advanced Workflows & Automation
│       ├── README.md         # Comprehensive advanced workflows guide
│       ├── gflow.js          # Complete workflow (add→commit→push)
│       ├── gquick.js         # Quick commit workflow
│       ├── gsync.js          # Sync workflow (pull→push)
│       ├── gdev.js           # Development session management
│       ├── gworkflow.js      # Professional workflow combinations
│       ├── gfix.js           # Smart fix and patch workflows
│       ├── gfresh.js         # Fresh start workflows
│       ├── gbackup.js        # Backup and safety operations
│       ├── gclean.js         # Repository cleanup and optimization
│       ├── gsave.js          # Save and preserve workflows
│       ├── glist.js          # Tool discovery and help system
│       ├── grelease.js       # Release management workflows
│       └── common.js         # Shared utilities and helpers
├── markdown/
│   ├── INSTALLATION.md      # Detailed installation guide
│   ├── DEPLOY.md            # Production deployment guide
│   ├── DOCKER.md            # Docker setup and deployment guide
│   └── QUICK_REFERENCES.md  # Copy-paste command reference
├── mcp-cli.js               # Enhanced CLI wrapper (organized by structure)
├── package.json             # Project configuration & npm scripts
├── tsconfig.json            # TypeScript configuration
└── README.md                # This comprehensive guide

📖 文档结构

🔧 技术架构

📡 MCP服务器核心 (来源/索引.ts)

  • 29工具注册 具有完整的JSON模式
  • 增强元数据 具有操作跟踪和性能监控功能
  • 输入验证 使用Zod模式实现类型安全
  • 错误处理管道 具有超时保护和有意义的消息
  • 跨平台兼容性 环境正常化

⚙️ Git操作引擎 (src/github.ts)

  • 全面实施 在所有29个Git操作中
  • 安全功能 -命令注入预防和输入消毒
  • 增强的错误处理 为常见场景提供上下文感知消息
  • 性能监控 -运行持续时间跟踪和记录
  • 安全检查 -存储库验证和文件存在性验证

🖥️ 增强的CLI系统

  • 智能组织 -按基本操作与高级操作分类的工具
  • 目录感知帮助 -参考特定的README文件以获取详细指导
  • 进步学习 -从基础操作到高级操作的清晰路径
  • 工具发现 -增强型 glist 带类别筛选的命令

🛡️ 错误处理和安全

  • 🔍 存储库验证:确保目录是有效的Git存储库
  • 📁 文件存在性检查:在Git操作之前验证文件是否存在
  • ⏱️ 超时保护:操作超时30秒
  • 🚫 输入消毒:防止命令注入
  • 📝 详细错误消息:清晰、可操作的错误描述

许可证

ISC许可证

作者

创建用于支持模型上下文协议的AI助手。