MCP Gitee Pull Request 服务器
一个支持多实例的 Gitee Pull Request 创建 MCP 服务器,支持自动审查、测试和合并工作流。
功能特性
- ✅ 通过 API 在 Gitee 上创建 Pull Request
- ✅ 支持多实例,通过仓库名称隔离
- ✅ 可配置审查人员(assignees 和 testers)
- ✅ 支持标签并验证格式
- ✅ 支持草稿 PR
- ✅ 自动审查、测试和合并工作流
- ✅ 操作日志记录
- ✅ 错误处理和恢复
安装
全局安装(推荐)
npm install -g @liangshanli/mcp-server-gitee-pull-request
本地安装
npm install @liangshanli/mcp-server-gitee-pull-request
从源码安装
git clone https://github.com/liliangshan/mcp-server-gitee-pull-request.git
cd mcp-server-gitee-pull-request
npm install
配置
设置环境变量:
# 必需:Gitee 账号凭证(使用 scope_ 前缀避免与系统环境变量冲突)
export scope_username="your-email@example.com"
export scope_password="your-password"
# 必需:OAuth 应用凭证
# 在以下地址创建 OAuth 应用:https://gitee.com/oauth/applications
export scope_client_id="your_client_id"
export scope_client_secret="your_client_secret"
# 注意:OAuth 权限范围已硬编码为 "user_info pull_requests enterprises"
# 必需:仓库所属空间地址(企业、组织或个人的地址path)
export owner="your-username-or-org"
# 必需:仓库路径(path)
export repo="your-repo-name"
# 必需:Pull Request 提交的源分支(要合并的分支)
export head="dev"
# 必需:Pull Request 提交目标分支的名称(合并到的分支)
export base="main"
# 可选:审查人员username,可多个,半角逗号分隔
export assignees="username1,username2"
# 可选:测试人员username,可多个,半角逗号分隔
export testers="tester1,tester2"
# 可选:默认标签(用逗号分开的标签)
export labels="bug,performance"
# 可选:项目名称(用于多实例支持)
export PROJECT_NAME="custom-mgit"
# 可选:自动化工作流开关
export AUTO_REVIEW="false"
export AUTO_TEST="false"
export AUTO_MERGE="false"
获取 OAuth 应用凭证
- 访问 Gitee OAuth 应用 创建您的应用
- 点击"创建应用"
- 填写应用信息并创建
- 获取
client_id和client_secret
注意:访问令牌会在需要时通过 OAuth 自动获取。
使用方法
1. 直接运行(全局安装)
mcp-server-gitee-pull-request
2. 使用 npx(推荐)
npx @liangshanli/mcp-server-gitee-pull-request
3. 直接启动(源码安装)
npm start
4. 托管启动(生产环境推荐)
npm run start-managed
编辑器集成
Cursor 编辑器配置
在项目根目录创建 .cursor/mcp.json 文件:
{
"mcpServers": {
"gitee-pr": {
"command": "npx",
"args": ["-y", "@liangshanli/mcp-server-gitee-pull-request"],
"env": {
"scope_username": "your-email@example.com",
"scope_password": "your-password",
"scope_client_id": "your_client_id",
"scope_client_secret": "your_client_secret",
"owner": "your-username-or-org",
"repo": "your-repo-name",
"head": "dev",
"base": "main",
"assignees": "username1,username2",
"testers": "tester1,tester2",
"labels": "bug,performance",
"PROJECT_NAME": "custom-mgit",
"AUTO_REVIEW": "false",
"AUTO_TEST": "false",
"AUTO_MERGE": "false"
}
}
}
}
VS Code 编辑器配置
创建 .vscode/mcp.json 文件:
{
"servers": {
"gitee-pr": {
"command": "npx",
"args": ["-y", "@liangshanli/mcp-server-gitee-pull-request"],
"env": {
"scope_username": "your-email@example.com",
"scope_password": "your-password",
"scope_client_id": "your_client_id",
"scope_client_secret": "your_client_secret",
"owner": "your-username-or-org",
"repo": "your-repo-name",
"head": "dev",
"base": "main",
"assignees": "username1,username2",
"testers": "tester1,tester2",
"labels": "bug,performance",
"PROJECT_NAME": "custom-mgit",
"AUTO_REVIEW": "false",
"AUTO_TEST": "false",
"AUTO_MERGE": "false"
}
}
}
}
多实例配置
您可以为不同的仓库运行多个实例。工具名称会以仓库名称作为前缀,避免冲突。
Cursor 编辑器配置
{
"mcpServers": {
"gitee-pr-repo1": {
"command": "npx",
"args": ["-y", "@liangshanli/mcp-server-gitee-pull-request"],
"env": {
"scope_username": "your-email@example.com",
"scope_password": "your-password",
"scope_client_id": "your_client_id",
"scope_client_secret": "your_client_secret",
"owner": "org1",
"repo": "repo1",
"head": "dev",
"base": "main",
"PROJECT_NAME": "custom-mgit",
"AUTO_REVIEW": "true",
"AUTO_TEST": "true",
"AUTO_MERGE": "true"
}
},
"gitee-pr-repo2": {
"command": "npx",
"args": ["-y", "@liangshanli/mcp-server-gitee-pull-request"],
"env": {
"scope_username": "your-email@example.com",
"scope_password": "your-password",
"scope_client_id": "your_client_id",
"scope_client_secret": "your_client_secret",
"owner": "org2",
"repo": "repo2",
"head": "dev",
"base": "master",
"PROJECT_NAME": "custom-mgit"
}
}
}
}
VS Code 编辑器配置
{
"servers": {
"gitee-pr-repo1": {
"command": "npx",
"args": ["-y", "@liangshanli/mcp-server-gitee-pull-request"],
"env": {
"scope_username": "your-email@example.com",
"scope_password": "your-password",
"scope_client_id": "your_client_id",
"scope_client_secret": "your_client_secret",
"owner": "org1",
"repo": "repo1",
"head": "dev",
"base": "main",
"PROJECT_NAME": "custom-mgit",
"AUTO_REVIEW": "true",
"AUTO_TEST": "true",
"AUTO_MERGE": "true"
}
},
"gitee-pr-repo2": {
"command": "npx",
"args": ["-y", "@liangshanli/mcp-server-gitee-pull-request"],
"env": {
"scope_username": "your-email@example.com",
"scope_password": "your-password",
"scope_client_id": "your_client_id",
"scope_client_secret": "your_client_secret",
"owner": "org2",
"repo": "repo2",
"head": "dev",
"base": "master",
"PROJECT_NAME": "custom-mgit"
}
}
}
}
可用工具
pr
在 Gitee 上创建 Pull Request。
参数:
title(必需):Pull Request 标题body(可选):Pull Request 描述/正文draft(可选):是否为草稿 PR(默认:false)labels(可选):标签(会覆盖环境变量设置)
自动化工作流:
- 如果
AUTO_REVIEW=true,PR 创建后将自动审查 - 如果
AUTO_TEST=true,审查后将自动测试 - 如果
AUTO_MERGE=true,测试成功后自动合并
logs
获取操作日志用于调试和监控。
参数:
limit(可选):限制数量,默认 50,最大 1000offset(可选):偏移量,默认 0
日志记录
所有操作都会记录到文件中:
- 日志目录:
.setting/或.setting.<REPO_NAME>/ - 日志文件:
mcp-gitee-pr.log
API 参考
此服务器使用 Gitee API v5:
- 端点:
POST https://gitee.com/api/v5/repos/{owner}/{repo}/pulls - Content-Type:
application/json;charset=UTF-8 - 认证:通过查询参数传递访问令牌
更多信息,请参阅 Gitee API 文档
故障排除
常见问题
- 401 未授权:检查您的访问令牌是否有效且具有所需权限
- 404 未找到:验证
owner和repo是否正确 - 422 无法处理的实体:检查分支名称(
head和base)是否存在且有效 - 无效标签:确保标签为 2-20 个字符且仅包含允许的字符