这是一个提供访问 GitHub GraphQL API 的 Model Context Protocol (MCP) 服务器。此服务器公开了一个工具,允许执行任意的 GraphQL 查询和突变操作针对 GitHub 的 API。
# 在 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.txtError: GitHub token not found in environment variables
服务器无法找到你的 GitHub 令牌
解决方案:确保你已设置了 GITHUB_TOKEN 环境变量