使用说明
GitHub MCP服务器
提供GitHub Pull Request审查工具的模型上下文协议(MCP)服务器。
✅ 服务器状态:工作
您的MCP服务器现在运行正常!“挂起”行为是正常的——它正在等待MCP客户端连接。
🚀 如何使用
1.设置GitHub Token(可选但推荐)
创建一个 .env 项目目录中的文件:
GITHUB_TOKEN=your_github_token_here
要获取GitHub令牌,请执行以下操作:
- 首选https://github.com/settings/tokens
- 点击“生成新令牌(经典)”
- 选择范围:
repo(适用于私人回购)或public_repo(公共回购) - 复制令牌并将其添加到您的
.env文件
2.可用工具
您的服务器提供两个主要工具:
fetch_pr_data(owner, repo, pr_number)
- 目的:从GitHub检索PR差异和元数据
- 参数:
owner:GitHub用户名或组织repo:存储库名称pr_number:拉取请求号
- 退货:PR标题和差异内容
post_review_comment(owner, repo, pr_number, comment_body)
- 目的:向PR发布评论
- 参数:
owner:GitHub用户名或组织repo:存储库名称pr_number:拉取请求号comment_body:待发布的审查意见
- 退货:成功/错误状态
3.如何连接客户
选项A:克劳德桌面(推荐)
- 安装克劳德桌面
- 将您的服务器添加到Claude的MCP配置中
- 服务器将在Claude的界面中提供GitHub工具
选项B:自定义MCP客户端
# Example of how to use the server programmatically
import subprocess
import json
# Start the server as a subprocess
server_process = subprocess.Popen(
['python', 'server.py'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
# Send MCP requests to the server
# (This is a simplified example - real MCP clients are more complex)
选项C:直接测试功能
# Import and test the functions
import server
# Test fetching PR data
result = server.fetch_pr_data("microsoft", "vscode", 1)
print(result)
# Test posting a comment
result = server.post_review_comment("microsoft", "vscode", 1, "Great work!")
print(result)
🔧 故障排除
服务器无法启动
- 确保你在正确的目录中
- 激活虚拟环境:
.\venv\Scripts\Activate.ps1 - 运行:
python server.py
“未找到GITHUB_TOKEN”警告
- 如果您没有设置令牌,这是正常的
- 服务器仍将工作,但GitHub API调用将失败
- 创建一个
.env使用您的令牌文件来修复此问题
服务器“挂起”或“冻结”
- 这是 正常行为 对于MCP服务器
- 服务器正在等待客户端连接
- 按
Ctrl+C完成后停止服务器
📋 示例用法
- 启动服务器:
python server.py - 连接客户端 (如克劳德桌面)
- 使用工具:
- “获取microsoft/vcode PR#12345的PR数据”
- “在microsoft/vcode PR#12345上发表评论,说‘干得好!’”
🎯 什么在起作用
✅ 服务器启动时没有错误
✅ 丢失令牌的正确错误处理
✅ 两个GitHub工具可用
✅ 已准备好进行MCP客户端连接
✅ 稳健的错误消息
您的MCP服务器功能齐全,随时可用!
