项目简介: GitHub Integration Hub 是一个基于 Model Context Protocol (MCP) 的服务器,专门用于处理 GitHub 认证(OAuth)和执行 GitHub 仓库相关的操作。它提供了一个统一的接口,使 AI 代理能够通过标准化的 JSON-RPC 协议与 GitHub 交互,进行授权、列出仓库和创建议题等任务。该项目还展示了如何通过 HTTP API、TypeScript SDK 和命令行工具 (CLI) 暴露相同的业务逻辑。

主要功能点:

  • GitHub OAuth 认证: 引导用户完成 GitHub OAuth 授权流程,安全存储访问令牌。
  • 仓库管理: 列出指定用户已授权的 GitHub 仓库。
  • 议题创建: 在指定的 GitHub 仓库中创建新的议题。
  • 多接口支持: 除了 MCP 服务器,还提供 HTTP API、TypeScript SDK 和命令行工具 (CLI) 来访问相同的功能。
  • SQLite 数据存储: 使用 SQLite 数据库持久化用户连接信息和授权令牌。

安装步骤:

  1. 克隆仓库:
    git clone https://github.com/CrBatista/mcp-cli-github-integration.git
    cd mcp-cli-github-integration
  2. 安装依赖:
    npm install
  3. 配置环境: 复制 '.env.example' 文件为 '.env',并根据您的 GitHub OAuth 应用信息进行配置。
    cp .env.example .env
    编辑 '.env' 文件,填入您的 GitHub OAuth 凭据。请确保在 GitHub OAuth 应用设置中,回调 URL 与 'GITHUB_REDIRECT_URI' (例如 'http://localhost:3000/auth/github/callback') 完全匹配。
    PORT=3000
    DATABASE_FILE=./github-integration-hub.db
    GITHUB_CLIENT_ID=your-client-id
    GITHUB_CLIENT_SECRET=your-client-secret
    GITHUB_OAUTH_AUTHORIZE_URL=https://github.com/login/oauth/authorize
    GITHUB_OAUTH_TOKEN_URL=https://api.github.com/login/oauth/access_token
    GITHUB_API_BASE_URL=https://api.github.com
    GITHUB_REDIRECT_URI=http://localhost:3000/auth/github/callback
    GITHUB_INTEGRATION_HUB_BASE_URL=http://localhost:3000

MCP 服务器配置 (供MCP客户端使用): MCP客户端需要以下配置信息来连接到此服务器并调用其工具。

{
  "name": "github-integration-hub",
  "command": "node",
  "args": ["dist/mcp/server.js"],
  "description": "连接到GitHub并执行授权、仓库列表和议题创建操作。",
  "capabilities": {
    "tools": {
      "github_start_auth": {
        "description": "启动GitHub OAuth流程并返回授权URL。",
        "inputSchema": {
          "type": "object",
          "properties": {
            "userId": { "type": "string", "description": "用户的唯一标识符。" }
          },
          "required": ["userId"]
        }
      },
      "github_list_repos": {
        "description": "列出具有现有GitHub连接的用户的GitHub仓库。",
        "inputSchema": {
          "type": "object",
          "properties": {
            "userId": { "type": "string", "description": "用户的唯一标识符。" }
          },
          "required": ["userId"]
        }
      },
      "github_create_issue": {
        "description": "使用存储的连接创建GitHub议题。",
        "inputSchema": {
          "type": "object",
          "properties": {
            "userId": { "type": "string", "description": "用户的唯一标识符。" },
            "owner": { "type": "string", "description": "仓库所有者(组织或用户名)。" },
            "repo": { "type": "string", "description": "仓库名称。" },
            "title": { "type": "string", "description": "议题标题。" },
            "body": { "type": "string", "description": "议题正文(可选)。" }
          },
          "required": ["userId", "owner", "repo", "title"]
        }
      }
    }
  },
  "instructions": "使用这些工具来启动GitHub OAuth并对现有连接运行仓库/议题操作。"
}

注意: 在运行服务器之前,请先执行 'npm run build' 进行编译。

基本使用方法:

  1. 编译项目:

    npm run build
  2. 启动 MCP 服务器:

    npm run start:mcp

    服务器将以标准输入/输出 (stdio) 模式运行,等待 MCP 客户端连接。

  3. 通过 MCP 客户端调用工具: 例如,如果您使用支持 MCP 的 IDE 或 CLI (如 Codex),可以连接到此服务器进程并调用以下工具:

    • 'github_start_auth': 获取 GitHub 授权 URL,用户访问此 URL 完成授权。 参数:'userId' (用户的唯一标识)
    • 'github_list_repos': 列出已授权用户的所有 GitHub 仓库。 参数:'userId'
    • 'github_create_issue': 在指定仓库中创建议题。 参数:'userId', 'owner', 'repo', 'title', 'body' (可选)

    授权流程示例:

    • 通过 MCP 客户端调用 'github_start_auth' 工具,提供一个 'userId'。
    • 获取返回的 'authUrl',并在浏览器中访问此 URL 以完成 GitHub 授权。
    • 授权成功后,GitHub 将重定向到 'GITHUB_REDIRECT_URI',服务器会自动存储用户的连接信息。
    • 之后,MCP 客户端即可使用 'github_list_repos' 或 'github_create_issue' 工具对该用户执行 GitHub 操作。

信息

分类

开发者工具