Back to MCP directory
publicPublicdnsLocal runtime

github-mcp-server-in-go

一个用Go实现的GitHub模型上下文协议(MCP)服务器,支持通过GitHub API进行仓库管理、分支操作、文件处理等交互功能。

article

README

🚀 GitHub MCP 服务器的 Go 实现

这是 GitHub 模型上下文协议(MCP)服务器的 Go 语言实现方案。借助该实现,AI 助手能够与 GitHub API 进行交互,进而执行创建仓库、管理分支、文件操作等各类操作。

🚀 快速开始

要使用此服务器,你需要完成先决条件的准备、安装服务器、进行认证设置,最后启动服务器。以下是详细步骤:

  1. 确保满足先决条件。
  2. 按照安装指南完成安装。
  3. 选择合适的认证方式进行认证。
  4. 启动服务器开始使用。

✨ 主要特性

  • 支持 AI 助手与 GitHub API 交互,实现多种操作。
  • 提供两种认证方式,方便不同场景使用。
  • 支持在不同 Web 框架间无缝集成,保持一致的身份验证机制。
  • 提供丰富的可用工具,涵盖仓库搜索、创建、文件操作、问题管理等多个方面。

📦 安装指南

先决条件

  • Go 1.21 或更高版本
  • 具有适当权限的 GitHub 个人访问令牌

安装命令

go get github.com/metoro-io/github-mcp-server-go

💻 使用示例

基础用法

认证设置

环境变量认证

将你的 GitHub 个人访问令牌设置为环境变量:

export GITHUB_PERSONAL_ACCESS_TOKEN=your_github_token
HTTP 头认证

服务器还可以从 HTTP 请求中提取身份验证令牌。你可以通过 Authorization 标头传递你的 GitHub 令牌:

Authorization: Bearer your_github_token

或简单地:

Authorization: your_github_token

启动服务器

go run main.go

高级用法

上下文传递

对于 HTTP 处理器,服务器支持两种方式:

  1. 标准的 http_request 上下文值用于 HTTP 请求。
  2. 使用 Gin 框架时的 ginContext 值。 这使得在不同的 Web 框架之间无缝集成成为可能,同时保持一致的身份验证机制。

📚 详细文档

可用工具

该服务器提供以下工具: | 工具名称 | 功能描述 | | ---- | ---- | | search_repositories | 搜索 GitHub 仓库 | | create_repository | 在你的账户下创建一个新的 GitHub 仓库 | | fork_repository | 将 GitHub 仓库叉到你的账户或指定的组织 | | create_branch | 在一个 GitHub 仓库中创建新的分支 | | get_file_contents | 获取 GitHub 仓库中的文件或目录内容 | | create_or_update_file | 创建或更新单个文件 | | push_files | 一次提交多个文件到 GitHub 仓库 | | create_issue | 在 GitHub 仓库中创建新问题 | | get_issue | 获取特定问题的详细信息 | | list_issues | 列出带有筛选选项的 GitHub 仓库中的问题 | | update_issue | 更新现有的问题 | | add_issue_comment | 向现有问题添加评论 | | list_commits | 获取分支的提交列表 | | search_code | 在 GitHub 仓库中搜索代码 | | search_issues | 在 GitHub 仓库中搜索问题和拉取请求 | | search_users | 搜索 GitHub 上的用户 |

🔧 技术细节

项目结构

  • main.go:应用程序的入口点
  • common/:通用工具和错误处理
  • operations/:GitHub API 操作实现
  • tools/:MCP 工具定义和处理程序

从源代码构建

go build -o github-mcp-server

运行测试

go test ./...

📄 许可证

此项目采用 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