返回市场
MCP-GitHub客户端

MCP-GitHub客户端

作者:michaelneale2 星标更新:2025-05-01

项目介绍

mcp-github-cli

用于与GitHub交互的MCP服务器,提供专注于GraphQL和REST API工具。此服务器提供了一套强大的工具,利用GitHub的API来提供丰富的数据和功能。

使用方法

uvx mcp-github-cli

可以从PyPI运行。这可以在gooseclaude中使用。

预备条件

  1. 如果尚未安装,请安装GitHub CLI (gh):

    • macOS: brew install gh
    • Linux: sudo apt install gh
    • Windows: winget install GitHub.cli
  2. 使用GitHub进行身份验证:

    gh auth login
    

测试

uv run python main.py --test

这将运行一个全面的测试套件,验证以下内容:

  • 与GitHub的身份验证状态
  • 用户信息检索(gh_get_me)
  • GraphQL查询功能(查看器信息)
  • REST API仓库搜索
  • GraphQL仓库信息检索
  • REST API分支列表

测试输出很好地展示了不同工具的能力。

从源码使用

从CLI运行(Goose,或尝试使用)

uv --directory /path/to/mcp-github-cli run python main.py

功能

此MCP服务器专注于提供强大的、集中的工具,利用GitHub的GraphQL和REST API:

用户信息

  • gh_get_me(): 获取已认证用户的详细信息

GraphQL工具

GraphQL工具在单个请求中提供丰富、嵌套的数据:

  • gh_graphql_repo_info(owner_repo): 获取综合仓库信息
  • gh_graphql_user_profile(username): 获取详细的用户资料数据
  • gh_graphql_pull_requests(owner_repo, limit, state): 获取带有审阅者和状态的拉取请求
  • gh_graphql_issues(owner_repo, limit, state, labels): 获取带有评论和标签的问题
  • gh_graphql_repo_contributors(owner_repo, limit): 获取仓库贡献者及其提交记录
  • gh_custom_graphql(query, variables): 执行自定义GraphQL查询

REST API工具

REST工具为常见的操作提供特定的功能:

  • gh_rest_search_repos(query, limit): 搜索仓库
  • gh_rest_repo_contents(owner_repo, path, ref): 获取仓库内容
  • gh_rest_create_issue(owner_repo, title, body, labels): 创建问题
  • gh_rest_create_pr(owner_repo, title, body, head, base, draft): 创建拉取请求
  • gh_rest_branches(owner_repo): 列出仓库分支
  • gh_rest_commits(owner_repo, branch, limit): 列出仓库提交
  • gh_rest_api(endpoint, method, data, query_params): 执行自定义REST API请求

示例

这里是一些使用这些工具的例子:

用户信息

# 获取已认证用户的信息
gh_get_me()

GraphQL示例

# 获取仓库信息
gh_graphql_repo_info("block/goose")

# 获取用户资料
gh_graphql_user_profile("octocat")

# 获取打开的拉取请求
gh_graphql_pull_requests("block/goose", 5, "OPEN")

# 获取具有特定标签的问题
gh_graphql_issues("block/goose", 10, "OPEN", ["bug", "help wanted"])

# 自定义GraphQL查询
gh_custom_graphql("""
query {
  viewer {
    login
    name
  }
}
""")

REST API示例

# 搜索仓库
gh_rest_search_repos("language:python stars:>1000", 5)

# 获取文件内容
gh_rest_repo_contents("block/goose", "README.md")

# 创建一个问题
gh_rest_create_issue("your-username/your-repo", "Bug report", "There's a bug", ["bug"])

# 列出分支
gh_rest_branches("block/goose")

# 自定义REST API请求
gh_rest_api("repos/block/goose", "GET", query_params={"sort": "updated"})

构建和发布

  1. 更新pyproject.toml中的版本:
[project]
version = "x.y.z"  # 更新此版本
  1. 构建包:
# 清除之前的构建
rm -rf dist/*

# 或在干净环境中使用uv构建
uv venv .venv
source .venv/bin/activate
uv pip install build
python -m build
  1. 发布到PyPI:
# 如果需要,安装twine
uv pip install twine

# 上传到PyPI
python -m twine upload dist/*

许可证

MIT