PR AI-MCP服务器
基于人工智能的GitHub公关创建 光标, 克劳德桌面, 帆板运动,以及其他MCP兼容编辑器。
为什么选择MCP?
与手动运行命令的CLI版本不同,MCP服务器允许您的AI IDE 直接 创建PR:
You: "Create a PR for my changes"
Cursor: [analyzes diff, generates description, creates PR]
✅ PR created: https://github.com/you/repo/pull/42禁止复制/粘贴。禁止切换窗口。问吧。
快速安装
# Clone and install
git clone https://github.com/USER/pr-ai-mcp.git
cd pr-ai-mcp
npm install
# Or install globally
npm install -g pr-ai-mcp光标设置
添加到光标MCP配置(~/.cursor/mcp.json 或项目 .cursor/mcp.json):
{
"mcpServers": {
"pr-ai": {
"command": "node",
"args": ["/path/to/pr-ai-mcp/src/index.js"]
}
}
}或者通过npm全局安装:
{
"mcpServers": {
"pr-ai": {
"command": "npx",
"args": ["pr-ai-mcp"]
}
}
}重新启动游标 添加配置后。
Claude桌面设置
添加到Claude桌面配置:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 窗户: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"pr-ai": {
"command": "node",
"args": ["/path/to/pr-ai-mcp/src/index.js"]
}
}
}Windsurf设置/继续/其他
大多数MCP兼容编辑器使用类似的配置。使用以下命令添加服务器:
- 命令:
node(或npx) - Args:路径
src/index.js(或pr-ai-mcp如果通过npm安装)
可用工具
| 工具 | 说明 |
|---|---|
analyze_changes | 分析git diff、提交、更改的文件 |
generate_pr_description | 获取AI生成PR描述的上下文 |
create_pr | 创建GitHub PR |
preview_pr | 预览PR而不创建 |
get_repo_config | 显示.pr-ai.json设置 |
使用示例
基础公关创建
You: Create a PR for my changes
AI: I'll analyze your changes and create a PR.
[calls analyze_changes]
[calls create_pr with generated description]
✅ PR Created!
Title: [TK-1234] add user authentication
URL: https://github.com/you/repo/pull/42具有特定选项
You: Create a draft PR targeting main, add @alice as reviewer
AI: [calls create_pr with draft=true, target=main, reviewers=alice]
✅ Draft PR created...先预览
You: Show me what the PR would look like
AI: [calls preview_pr]
## PR Preview
Title: [TK-1234] add user auth
Branch: feature/tk-1234-auth → develop
...分析变化
You: What changes am I about to PR?
AI: [calls analyze_changes]
## Git Analysis
Commits: 3
- abc123 add login endpoint
- def456 add auth middleware
- ghi789 add tests
...每回购配置(可选)
创建 .pr-ai.json 在您的repo根目录中:
{
"reviewers": ["alice", "bob"],
"targetBranch": "main",
"draft": false,
"customPrompt": "Focus on security implications",
"excludeFiles": ["package-lock.json"]
}MCP服务器会自动读取并应用:
- 默认审阅者
- 默认目标分支
- 自定义AI指令
- 默认情况下起草PR
需求
- Node.js>=18
- GitHub命令行界面(
gh)已安装并验证 - 使用GitHub远程的Git存储库
运作原理
┌─────────────────┐
│ Your IDE │
│ (Cursor/Claude) │
└────────┬────────┘
│ MCP Protocol
▼
┌─────────────────┐
│ PR AI Server │
│ (this tool) │
└────────┬────────┘
│ Git + GitHub CLI
▼
┌─────────────────┐
│ GitHub │
└─────────────────┘- 你让你的人工智能创建一个PR
- AI调用MCP工具分析变化
- AI基于差异生成描述
- AI呼叫
create_pr工具 - 服务器使用
ghCLI创建PR - 您将获得PR URL
比较:CLI与MCP
| 特性 | CLI(pr-ai) | MCP服务器 |
|---|---|---|
| 用法 | 在终端中运行命令 | 在IDE中询问AI |
| AI提供商 | Claude/Gemini/OpenAI API | 您的IDE的AI |
| API密钥 | 必需 | 不需要(使用IDE) |
| 集成 | 手动 | 无缝 |
| 最适合 | 终端用户 | IDE用户 |
故障排除
光标中“找不到工具”
- 检查MCP配置路径是否正确
- 完全重新启动游标
- 检查Cursor的MCP日志
“不在git存储库中”
确保您从git存储库打开了一个文件,或指定 working_directory.
“gh:找不到命令”
安装GitHub命令行界面:https://cli.github.com/
然后进行身份验证: gh auth login
PR创建失败
检查:
# Is gh authenticated?
gh auth status
# Can you create PR manually?
gh pr create --help许可证
麻省理工学院
