GitHub模型交互协议服务

一个用Go实现的GitHub模型上下文协议(MCP)服务器,允许LLM通过标准化接口与GitHub仓库、问题、拉取请求等进行交互。

  • by geropl
  • Go
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 geropl/github-mcp-go

使用说明

GitHub MCP服务器

GitHub的模型上下文协议(MCP)服务器,用Go实现。此服务器允许LLM通过标准化接口与GitHub存储库、问题、拉取请求等进行交互。

特性

  • 全面的GitHub API访问:参见 工具 在......下面
  • 设置命令:易于自动设置AI助手
    • --auto-approve 允许预先填写自动审批复选框
    • --write-access 启用远程操作的写访问
    • 将二进制文件复制到稳定位置
    • 更新工具MCP服务器配置(支持cline和claude桌面)
  • 安全控制:
    • 出于安全考虑,默认情况下禁用写入访问
    • 细粒度自动审批选项

计划的功能

  • []“get_diff”
    • 两次提交之间的差异
    • ?这应该在输出中吗 compare_commits?

安装

先决条件

  • 具有适当权限的GitHub个人访问令牌

使用预构建的二进制文件

您可以从以下网址下载适用于您平台的预构建二进制文件 GitHub发布 页面。

# Download the latest release - for "linux_amd64" in this case
RELEASE="$(curl -s https://api.github.com/repos/geropl/github-mcp-go/releases/latest)"
DOWNLOAD_URL="$(echo $RELEASE | jq -r '.assets[] | select(.name | contains("linux_amd64")) | .browser_download_url')"
curl -L -o ./github-mcp-go $DOWNLOAD_URL
chmod +x ./github-mcp-go

# Setup the mcp server (can be called in .gitpod.yml, dotfiles repo, etc.)
./github-mcp-go setup --write-access="${GITHUB_MCP_WRITE_ACCESS:-false}" --auto-approve=allow-read-only || true
rm -f ./github-mcp-go

从源头构建

如果您更喜欢从源代码构建:

# Prerequisites: Go 1.23 or later

# Clone the repository
git clone https://github.com/geropl/github-mcp-go.git
cd github-mcp-go

# Build the server
go build -o github-mcp-go .

用法

环境变量

服务器需要GitHub个人访问令牌才能通过GitHub API进行身份验证:

export GITHUB_PERSONAL_ACCESS_TOKEN=your_token_here

设置

该服务器包括一个方便的设置命令,用于安装和配置MCP服务器,以便与AI助手一起使用:

# Set up for Cline with auto-approval for read-only tools
./github-mcp-go setup --auto-approve allow-read-only --tool cline

# Set up for Claude Desktop with auto-approval for specific tools
./github-mcp-go setup --auto-approve search_repositories,get_file_contents --tool claude-desktop

# Set up with write access enabled
./github-mcp-go setup --write-access --tool cline

# Show setup help
./github-mcp-go setup --help

运行服务器

# Run the server directly (read-only mode)
./github-mcp-go serve

# Run the server with write access enabled
./github-mcp-go serve --write-access

# Show help
./github-mcp-go --help

自动审批选项

这 --auto-approve 标志可用于指定哪些工具应作为逗号分隔的列表自动批准。 allow-read-only 是一个特殊值,用于将所有只读工具添加到自动批准列表中(安全,无状态更改)。

这 --write-access 标志允许远程操作的写访问。这允许使用修改远程存储库的工具。默认情况下,为了安全起见,禁用写访问。

可用工具

存储库工具

  • search_repositories:搜索GitHub存储库
  • create_repository:创建新的GitHub存储库
  • fork_repository:分叉GitHub存储库

拉取请求工具

  • create_pull_request:创建新的pull请求
  • get_pull_request:获取有关拉取请求的详细信息
  • get_pull_request_diff:获取pull请求的差异

文件工具

  • get_file_contents:获取文件或目录的内容
  • create_or_update_file:创建或更新文件
  • push_files:在一次提交中推送多个文件

问题工具

  • create_issue:创建新问题
  • list_issues:列出筛选选项的问题
  • update_issue:更新现有问题
  • add_issue_comment:向问题添加评论
  • get_issue:获取特定问题的详细信息
  • list_issue_comments:列出对某个问题的评论

分支工具

  • list_branches:列出存储库中的分支
  • get_branch:获取特定分支的详细信息
  • create_branch:创建新分支
  • merge_branches:将一个分支合并到另一个分支
  • delete_branch:删除分支

提交工具

  • get_commit:获取特定提交的详细信息
  • list_commits:列出存储库中的提交
  • compare_commits:比较两个提交或分支
  • get_commit_status:获取特定提交的合并状态
  • create_commit_comment:向特定提交添加注释
  • list_commit_comments:列出特定提交的评论
  • create_commit:直接创建新提交

搜索工具

  • search_code:跨存储库搜索代码
  • search_issues:搜索问题并提取请求
  • search_commits:跨存储库搜索提交

GitHub操作工具

  • list_workflows:列出存储库中的所有工作流
  • get_workflow:获取特定工作流的详细信息
  • list_workflow_runs:列出存储库或特定工作流运行的工作流
  • get_workflow_run:获取特定工作流运行的详细信息
  • download_workflow_run_logs:下载并处理工作流运行日志
  • list_workflow_jobs:列出工作流运行的作业
  • get_workflow_job:获取特定工作的详细信息

发布

项目如下 语义版本控制。当新标签被推送到存储库时,新版本会自动构建并发布到GitHub Release。

有关创建新版本的详细说明,请参阅 发布.md.

可用平台

预构建的二进制文件可用于:

  • Linux(amd64、arm64)
  • macOS(amd64、arm64)
  • Windows(amd64)

发展

测试

该项目使用go-vcr的表驱动测试来记录HTTP交互:

go test ./...

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。