Back to MCP directory
publicPublicdnsLocal runtime

github-mcp-server

GitHub MCP服务器是一个提供GitHub集成功能的模型上下文协议服务,支持仓库管理、文件操作和提交处理等功能。

article

README

🚀 GitHub MCP 服务器

GitHub MCP 服务器是一个提供 GitHub 集成功能的模型上下文协议(MCP)服务器。它借助 MCP 工具实现与 GitHub 仓库的交互,支持仓库管理、文件操作和提交处理等功能,极大地提升了开发者在 GitHub 上的操作效率。

✨ 主要特性

  • 🔑 账户管理和身份验证:确保用户账户的安全和操作的合法性。
  • 📂 仓库创建和管理:方便用户快速创建和管理自己的 GitHub 仓库。
  • 📄 文件操作(读取、写入、推送、拉取):支持对仓库内文件的各种操作,满足不同的开发需求。
  • 📝 提交操作:轻松完成代码提交,记录项目的开发过程。
  • 🔄 目录同步:保证本地与远程仓库目录的一致性。
  • 🔍 仓库比较和差异分析:帮助用户快速了解不同仓库之间的差异。

📦 安装指南

使用以下命令安装服务器:

npm install @modelcontextprotocol/server-github

🛠️ 配置说明

将服务器添加到您的 MCP 设置文件(cline_mcp_settings.json)中:

{
  "mcpServers": {
    "github": {
      "command": "node",
      "args": ["/path/to/github-mcp-server/dist/index.js"],
      "env": {
        "GITHUB_TOKEN_1": "your-github-token",
        "GITHUB_OWNER_1": "your-github-username"
      },
      "disabled": false,
      "alwaysAllow": []
    }
  }
}

💻 使用示例

可用工具

账户管理

  • list_accounts:列出服务器中配置的 GitHub 账户。
  • select_account:选择用于后续操作的 GitHub 账户。

仓库管理

  • create_repository:创建新的 GitHub 仓库。
{
  owner?: string;        // 仓库所有者(可选,若已选账户)
  name: string;          // 仓库名称
  description: string;   // 仓库描述
  private?: boolean;     // 是否为私有仓库
}
  • clone_repository:将 GitHub 仓库克隆到本地目录。
{
  owner?: string;    // 仓库所有者
  repo: string;      // 仓库名称
  branch?: string;   // 分支名称(默认:main)
  outputDir: string; // 克隆到的本地目录
}
  • rename_repository:重命名现有 GitHub 仓库。
{
  owner?: string;    // 仓库所有者
  repo: string;      // 当前仓库名称
  new_name: string;  // 新仓库名称
}

文件操作

  • push_file:将文件推送到 GitHub 仓库。
{
  owner?: string;     // 仓库所有者
  repo: string;       // 仓库名称
  path: string;       // 仓库中的目标路径
  message: string;    // 提交信息
  sourcePath: string; // 待推送的本地文件路径
}
  • pull_file:从 GitHub 仓库拉取文件。
{
  owner?: string;     // 仓库所有者
  repo: string;       // 仓库名称
  path: string;       // 仓库中的文件路径
  outputDir: string;  // 拉取到的本地目录
}
  • delete_file:从 GitHub 仓库删除文件。
{
  owner?: string;     // 仓库所有者
  repo: string;       // 仓库名称
  path: string;       // 仓库中的文件路径
}

提交操作

  • create_commit:向 GitHub 仓库创建提交。
{
  owner?: string;         // 仓库所有者
  repo: string;           // 仓库名称
  branch: string;         // 分支名称
  changes: {              // 待提交的更改列表
    path: string;        // 文件路径
    content: string;      // 文件内容
    mode?: string;       // 文件模式(可选)
  }[]
}

🛠️ 开发指南

依赖项安装

使用以下命令安装开发依赖项:

npm install

构建

构建项目以生成发行版本:

npm run build

🔧 技术细节

环境变量

  • GITHUB_TOKEN_<N>:用于身份验证的 GitHub 个人访问令牌。
  • GITHUB_OWNER_<N>:GitHub 用户名或组织名称。

📄 许可证

本项目采用 MIT 许可证。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client