GitHub自动化工具

GitHub MCP是一个强大的GitHub自动化工具,通过AI助手直接操作GitHub仓库,提高开发效率。

  • by Seey215
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 Seey215/github-mcp

使用说明

🚀 Let AI Control Your GitHub

A powerful GitHub automation tool that seamlessly connects AI assistants to your GitHub repositories


💡 为什么选择GitHub MCP?

你曾经面对过这些挑战吗?

  • ❌ 反复性作业:每天手动检查、创建和更新问题和拉取请求
  • ❌ 效率低:不断在命令行和浏览器之间切换
  • ❌ 协作困难:团队成员需要一种统一的方式来运营GitHub

GitHub MCP解决了这一切!

✅ 让Claude、ChatGPT和其他人工智能助手 直接操作 GitHub
✅ 无需离开对话界面, 用一句话完成任务
✅ 基于模型上下文协议, 安全可靠
✅ 完全开源, 易于扩展 具有新功能


⚡️ 快速入门(3个步骤)

步骤1:安装

npm install github-mcp

或全局安装:

npm install -g github-mcp

第二步:获取GitHub Token

  1. 访问 GitHub设置>个人访问令牌
  2. 点击“生成新令牌(经典)”
  3. 检查 repo 权限(用于访问存储库信息)
  4. 复制生成的令牌

步骤3:启动服务器

# Set environment variable
export GITHUB_ACCESS_TOKEN="your_github_token_here"

# Start the server
npx github-mcp

🎉 完成! 现在你的AI助手可以操作GitHub了!

替代传输:流式HTTP(Hono)

需要HTTP/SSE端点而不是STDIO?启动由Hono驱动的Streamable HTTP服务器:

npx github-mcp streamableHttp

或者通过环境变量启用它:

MCP_TRANSPORT=streamableHttp STREAMABLE_HTTP_PORT=3001 npx github-mcp

Hono服务器暴露 /mcp 对于POST/GET/DELETE请求,自动处理CORS,并保持SSE流开放以进行实时消息传递。它仍然重复使用相同的东西 GitHubMCPServer STDIO的逻辑,因此您的工具和配置行为相同。

小贴士:即使没有Token也可以启动服务器,只有在调用GitHub API时才需要身份验证。


🎯 用例

场景1:快速查看问题列表

传统方式:

  1. 打开浏览器
  2. 登录GitHub
  3. 查找存储库
  4. 单击“问题”选项卡
  5. 手动过滤和查看

使用GitHub MCP:

You: Help me check what unresolved Issues are in Seey215/github-mcp repository
AI:  Querying... Found 3 unresolved Issues:
     1. #12 - Add Pull Request management feature
     2. #10 - Support GitHub Actions trigger
     3. #8 - Optimize error messages

场景2:批处理问题

You: Mark all Issues with "bug" in the title as high priority
AI:  Added high priority label to 5 Issues

场景3:自动化工作流

You: Summarize new Issues from yesterday every morning at 9 AM
AI:  Scheduled task created, will send daily report via email

🛠️ 核心功能

✅ 当前可用

功能 描述 状态
🔍 列出问题 查询任何存储库的问题列表 ✅ 可用
📊 问题详情 获取单个问题的完整信息 ✅ 可用
🔐 安全认证 基于GitHub Token的安全访问✅ 可用
⚙️ 灵活的配置 支持环境变量和代码配置 ✅ 可用
🎨 面向对象设计 类结构清晰,易于扩展 ✅ 可用

🚧 即将推出

特性 描述 预计时间
✏️ 创建问题 通过人工智能快速创建问题 2026年第一季度
🏷️ 标签管理 添加、删除、修改问题标签 2026年第1季度
💬 评论功能 对问题和PR的评论 2026年第一季度
🔀 拉取请求 完整的公关管理功能 2026年第二季度
🤖 GitHub 操作 触发和监控工作流程 2026年第2季度
📈 数据分析 问题趋势和统计分析 2026年第二季度

📚 详细使用指南

作为MCP服务器运行(推荐)

这是最常见的用法,适合与Claude Desktop、Continue等人工智能工具集成。

配置Claude桌面:

编辑配置文件 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "github-mcp"],
      "env": {
        "GITHUB_ACCESS_TOKEN": "your_token_here"
      }
    }
  }
}

重新启动Claude Desktop,您可以在对话中使用GitHub功能!

用作Node.js库

如果你想在自己的项目中使用它:

import { GitHubMCPServer } from 'github-mcp';
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

// Create server instance
const server = new GitHubMCPServer({
  token: 'your_github_token',
  serverName: 'my-custom-server',
  serverVersion: '1.0.0'
});

// Connect transport layer
const transport = new StdioServerTransport();
await server.connect(transport);

console.log('GitHub MCP Server started!');

配置选项

GitHubMCPServer 支持以下配置:

interface GitHubConfig {
  token?: string;           // GitHub Personal Access Token
  apiBase?: string;         // API base URL (default: https://api.github.com)
  apiVersion?: string;      // API version (default: 2022-11-28)
  serverName?: string;      // Server name (default: github-mcp-server)
  serverVersion?: string;   // Server version (default: 1.0.0)
}

配置优先:构造函数参数>环境变量>默认值


🔧 API 参考

工具:list_issues

列出指定存储库中的问题

输入参数:

{
  owner: string;    // Repository owner, e.g., "Seey215"
  repo: string;     // Repository name, e.g., "github-mcp"
  state?: 'open' | 'closed';  // Issue state (optional, default 'open')
}

返回数据:

{
  issues: Array<{
    number: number;        // Issue number
    title: string;         // Title
    body: string | null;   // Description content
    state: 'open' | 'closed';
    user: string;          // Creator
    created_at: string;    // Creation time
    updated_at: string;    // Update time
    html_url: string;      // GitHub page link
  }>
}

用法示例:

// In AI conversation
"Help me check all Issues in Seey215/github-mcp repository"

// Underlying call
await server.callTool('list_issues', {
  owner: 'Seey215',
  repo: 'github-mcp'
});

🏗️ 建筑设计

面向对象的体系结构

┌─────────────────────────────────────┐
│   GitHubMCPServer (Core Class)      │
├─────────────────────────────────────┤
│ - config: GitHubConfig              │
│ - server: McpServer                 │
├─────────────────────────────────────┤
│ + constructor(config?)              │
│ + connect(transport)                │
│ - registerTools()                   │
│ - githubApiRequest(endpoint)        │
└─────────────────────────────────────┘
         │
         │ uses
         ▼
┌─────────────────────────────────────┐
│   MCP SDK (Communication Protocol)  │
│   - StdioServerTransport            │
│   - Tool Registration & Invocation  │
└─────────────────────────────────────┘
         │
         │ calls
         ▼
┌─────────────────────────────────────┐
│   GitHub REST API                   │
│   - Issues                          │
│   - Pull Requests (coming soon)     │
│   - Actions (planned)               │
└─────────────────────────────────────┘

设计原则

  • 单一责任: GitHubMCPServer 专注于GitHub API集成
  • 封装:私有方法隐藏实现细节
  • 可配置性:灵活的构造函数支持多种配置方法
  • 可扩展性:清晰的结构使添加新工具变得容易
  • 延迟验证:代币仅在使用API时进行验证,改善用户体验

🤝 贡献

我们热忱欢迎社会各界的贡献!无论是:

  • 🐛 报告Bug:发现问题?提交 问题
  • 💡 建议功能:有好主意吗?告诉我们!
  • 🔨 提交代码:分叉项目,提交Pull Request
  • 📖 改进文档:帮助改进文档和示例

开发环境设置

# 1. Fork and clone repository
git clone https://github.com/your-username/github-mcp.git
cd github-mcp

# 2. Install dependencies
npm install

# 3. Build project
npm run build

# 4. Start development mode (auto-recompile)
npm run watch

# 5. Run tests
npx tsx demo.ts

项目结构

github-mcp/
├── src/
│   ├── types.ts              # TypeScript type definitions
│   ├── server.ts             # GitHubMCPServer main class
│   └── index.ts              # Entry file
├── dist/                     # Compiled output directory
├── demo.ts                   # Example and test file
├── package.json              # Project configuration
├── tsconfig.json             # TypeScript configuration
└── README.md                 # Project documentation

添加新工具

  1. 在中添加新的私有方法 src/server.ts
  2. 在中注册该工具 registerTools()
  3. 更新README文档
  4. 提交拉取请求

示例代码:

private registerCreateIssueTool(): void {
  this.server.registerTool(
    'create_issue',
    {
      title: 'Create Issue',
      description: 'Create a new issue in a GitHub repository',
      inputSchema: {
        owner: z.string(),
        repo: z.string(),
        title: z.string(),
        body: z.string().optional()
      },
      outputSchema: {
        issue: z.object({
          number: z.number(),
          html_url: z.string()
        })
      }
    },
    async ({ owner, repo, title, body }) => {
      const endpoint = `/repos/${owner}/${repo}/issues`;
      const data = await this.githubApiRequest(endpoint, {
        method: 'POST',
        body: JSON.stringify({ title, body })
      });
      
      return {
        content: [],
        structuredContent: { issue: data }
      };
    }
  );
}

❓ 常见问题解答

Q: 为什么不在启动时验证Token?

A.:为了更好的用户体验!即使没有令牌,您也可以:

  • 查看所有可用工具
  • 了解每个工具的功能
  • 令牌准备就绪时使用它们

Q: 令牌安全吗?

A.:是的!令牌仅存储在本地环境变量中,从不上传或共享。建议:

  • 使用细粒度令牌限制权限范围
  • 定期旋转令牌
  • 永远不要在公共代码中硬编码Token

Q: 它支持GitHub Enterprise吗?

A.:是的!只需配置自定义API地址:

const server = new GitHubMCPServer({
  apiBase: 'https://github.your-company.com/api/v3',
  token: 'your_token'
});

Q: 如何调试?

A.:使用演示文件进行测试:

# Set Token
export GITHUB_ACCESS_TOKEN="your_token"

# Run test
npx tsx demo.ts

Q: API速率限制如何?

A.:GitHub API有速率限制:

  • 未经身份验证:60个请求/小时
  • 已验证:5000次请求/小时

建议使用Token以获得更高的配额。


📊 路线图

v0.1.0-当前版本✅

  • [x] 基本MCP服务器框架
  • [x] GitHub问题列表查询
  • [x] 面向对象的体系结构设计
  • [x] TypeScript类型支持

v0.2.0-下一版本🚧

  • []创建和更新问题
  • []发布评论功能
  • []标签管理
  • []搜索功能优化

v0.3.0-未来计划📋

  • []完全拉取请求支持
  • []GitHub Actions集成
  • []Webhook支持
  • []批处理操作功能

v1.0.0-长期目标🎯

  • []完整的GitHub API覆盖范围
  • []图形化管理界面
  • []插件系统
  • []多账户管理

想参与发展吗? 检查 问题 对于待处理的任务!


🌟 致谢

感谢以下项目和社区:


📞 联系


📄 许可证

该项目根据 MIT许可证.

MIT License

Copyright (c) 2025 Seey215

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...

如果这个项目对你有帮助,请给它一个⭐️ Star!

由以下材料制成❤️ 通过 见215