GitHub API工具集

提供专注于GraphQL和REST API的工具集,用于与GitHub交互,包括用户信息获取、仓库搜索、问题管理等功能。

  • by michaelneale
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 michaelneale/mcp-github-cli

使用说明

mcp github客户端

MCP服务器,提供重点GraphQL和RESTneneneba API工具,用于与GitHub交互。该服务器提供了一套精简的强大工具,利用GitHub的API提供丰富的数据和功能。

用法

uvx mcp-github-cli

将从PyPI运行。这可用于 goose 或 claude.

先决条件

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

    • macOS: brew install gh
    • Linux: sudo apt install gh
    • 窗户: 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):创建pull请求
  • gh_rest_branches(owner_repo):列出存储库分支
  • gh_rest_commits(owner_repo, branch, limit):列出存储库提交
  • gh_rest_api(endpoint, method, data, query_params):执行自定义REST API请求

例子

以下是使用这些工具的示例:

用户信息

# Get authenticated user information
gh_get_me()

GraphQL示例

# Get repository information
gh_graphql_repo_info("block/goose")

# Get user profile
gh_graphql_user_profile("octocat")

# Get open pull requests
gh_graphql_pull_requests("block/goose", 5, "OPEN")

# Get issues with specific labels
gh_graphql_issues("block/goose", 10, "OPEN", ["bug", "help wanted"])

# Custom GraphQL query
gh_custom_graphql("""
query {
  viewer {
    login
    name
  }
}
""")

REST API示例

# Search for repositories
gh_rest_search_repos("language:python stars:>1000", 5)

# Get file contents
gh_rest_repo_contents("block/goose", "README.md")

# Create an issue
gh_rest_create_issue("your-username/your-repo", "Bug report", "There's a bug", ["bug"])

# List branches
gh_rest_branches("block/goose")

# Custom REST API request
gh_rest_api("repos/block/goose", "GET", query_params={"sort": "updated"})

建筑与出版

  1. 更新版本 pyproject.toml:
[project]
version = "x.y.z"  # Update this
  1. 构建包:
# Clean previous builds
rm -rf dist/*

# Or build in a clean environment using uv
uv venv .venv
source .venv/bin/activate
uv pip install build
python -m build
  1. 发布到PyPI:
# Install twine if needed
uv pip install twine

# Upload to PyPI
python -m twine upload dist/*

许可证

麻省理工学院