GitHub GraphQL MCP 服务器是一个基于 Model Context Protocol (MCP) 的工具,它提供了对 GitHub GraphQL API 的便捷访问。借助该服务器,用户能够针对 GitHub 的 API 执行任意的 GraphQL 查询和变异操作。
本服务器允许你对 GitHub 的 API 执行任意的 GraphQL 查询和变异。要使用它,你需要完成安装并配置相关环境。
# 在 macOS/Linux 上
python3 -m venv .venv
source .venv/bin/activate
# 在 Windows 上
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
# 如果使用虚拟环境,请确保已激活
source .venv/bin/activate # 在 Windows 上:.venv\Scripts\activate
# 使用你的 GitHub 令牌运行服务器
GITHUB_TOKEN=your_github_token_here python github_graphql_mcp_server.py
将以下内容添加到你的 Claude Desktop 配置文件中:
{
"github-graphql": {
"command": "/absolute/path/to/your/.venv/bin/python",
"args": [
"/absolute/path/to/github_graphql_mcp_server.py"
],
"options": {
"cwd": "/absolute/path/to/repository"
},
"env": {
"GITHUB_TOKEN": "your_github_token_here"
}
}
}
请替换 /absolute/path/to/ 为你的服务器文件的实际路径,并添加你的 GitHub 令牌。
query GetRepo($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
name
description
stargazerCount
url
createdAt
owner {
login
avatarUrl
}
}
}
变量:
{
"owner": "octocat",
"name": "Hello-World"
}
query SearchRepos($query: String!, $first: Int!) {
search(query: $query, type: REPOSITORY, first: $first) {
repositoryCount
edges {
node {
... on Repository {
name
owner { login }
description
stargazerCount
url
}
}
}
}
}
变量:
{
"query": "language:python stars:1000",
"first": 5
}
query GetUserInfo($login: String!) {
user(login: $login) {
name
login
bio
avatarUrl
followers {
totalCount
}
repositories(first: 5, orderBy: {field: STARGAZERS, direction: DESC}) {
nodes {
name
description
stargazerCount
}
}
}
}
变量:
{
"login": "octocat"
}
注意 GitHub 的 API 速率限制:
如果你遇到问题,请按以下步骤排查:
spawn python ENOENT
/path/to/your/.venv/bin/python)。ModuleNotFoundError: No module named 'httpx' (或其他包)
pip install -r requirements.txt 来安装缺失的依赖项。GITHUB_TOKEN 不可为空 或类似错误