GitHub仓库管理服务

一个基于Model Context Protocol (MCP)的GitHub仓库管理服务,提供创建仓库等功能。

  • by Joseph19820124
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 joseph19820124/joseph-github-mcp-server

使用说明

GitHub MCP服务器

提供GitHub存储库管理功能的模型上下文协议(MCP)服务器。

特性

  • 创建存储库:使用可自定义的设置创建新的GitHub存储库

先决条件

  • Python 3.8或更高版本
  • 具有存储库创建权限的GitHub个人访问令牌

安装

  1. 克隆此存储库:
git clone https://github.com/Joseph19820124/joseph-github-mcp-server.git
cd joseph-github-mcp-server
  1. 安装依赖项:
pip install -r requirements.txt
  1. 设置您的GitHub令牌:
export GITHUB_TOKEN="your_github_personal_access_token"

用法

运行MCP服务器

python main.py

服务器将启动并通过stdin/stdout监听MCP请求。

可用工具

创建存储库

创建一个新的GitHub存储库。

参数:

  • name (必填):存储库名称
  • description (可选):存储库描述
  • private (可选):存储库是否应该是私有的(默认值:false)

请求示例:

{
  "method": "tools/call",
  "params": {
    "name": "create_repository",
    "arguments": {
      "name": "my-new-repo",
      "description": "A sample repository",
      "private": false
    }
  },
  "id": "1"
}

示例响应:

{
  "content": [
    {
      "type": "text",
      "text": "{\n  \"success\": true,\n  \"repository\": {\n    \"id\": 123456789,\n    \"name\": \"my-new-repo\",\n    \"full_name\": \"username/my-new-repo\",\n    \"html_url\": \"https://github.com/username/my-new-repo\",\n    \"clone_url\": \"https://github.com/username/my-new-repo.git\",\n    \"ssh_url\": \"git@github.com:username/my-new-repo.git\",\n    \"private\": false,\n    \"description\": \"A sample repository\"\n  }\n}"
    }
  ],
  "id": "1"
}

GitHub令牌设置

要使用此MCP服务器,您需要一个具有以下权限的GitHub个人访问令牌:

  1. 前往GitHub设置>开发者设置>个人访问令牌

  2. 生成具有以下作用域的新令牌:

    • repo (用于访问存储库)
    • user (供用户参考)
  3. 将令牌设置为环境变量:

export GITHUB_TOKEN="your_token_here"

发展

项目结构

joseph-github-mcp-server/
├── main.py              # Main MCP server implementation
├── requirements.txt     # Python dependencies
├── README.md           # This file
└── pyproject.toml      # Project configuration

测试

您可以通过发送JSON-RPC请求来测试服务器:

  1. 启动服务器:
python main.py
  1. 发送测试请求:
echo '{"method": "tools/list", "id": "1"}' | python main.py

MCP(模型上下文协议)

该服务器实现了模型上下文协议,这是一个将人工智能应用程序与外部数据源和工具连接的开放标准。该协议通过stdio使用JSON-RPC 2.0进行通信。

支持的MCP方法

  • tools/list:列出可用工具
  • tools/call:执行特定工具

工具架构

这 create_repository 工具遵循MCP工具模式:

{
  "name": "create_repository",
  "description": "Create a new GitHub repository",
  "inputSchema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "description": "Repository name"
      },
      "description": {
        "type": "string",
        "description": "Repository description",
        "default": ""
      },
      "private": {
        "type": "boolean",
        "description": "Whether the repository should be private",
        "default": false
      }
    },
    "required": ["name"]
  }
}

许可证

MIT许可证

贡献

欢迎拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。