MCP Gitee拉取请求服务器
一个MCP服务器,用于在Gitee上创建Pull Requests,支持多实例。
特性
- ✅ 通过API在Gitee上创建Pull请求
- ✅ 具有存储库名称隔离的多实例支持
- ✅ 可配置的审阅者(指定人员和测试人员)
- ✅ 标签支持验证
- ✅ 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配置
设置环境变量:
# Required: Gitee account credentials (with scope_ prefix to avoid system env conflicts)
export scope_username="your-email@example.com"
export scope_password="your-password"
# Required: OAuth application credentials
# Create an OAuth application at: https://gitee.com/oauth/applications
export scope_client_id="your_client_id"
export scope_client_secret="your_client_secret"
# Note: OAuth scope is hardcoded as "user_info pull_requests enterprises"
# Required: Repository owner (organization or user path)
export owner="your-username-or-org"
# Required: Repository name
export repo="your-repo-name"
# Required: Source branch (the branch to merge from)
# You can input just the branch name (e.g., "dev") and it will be auto-formatted to "branch (dev)"
export head="dev"
# Required: Target branch (the branch to merge into)
# You can input just the branch name (e.g., "main") and it will be auto-formatted to "branch (main)"
export base="main"
# Optional: Reviewers (comma-separated usernames)
export assignees="username1,username2"
# Optional: Testers (comma-separated usernames)
# Note: This option is invalid if reviewers are assigned in repository settings
export testers="tester1,tester2"
# Optional: Default labels (comma-separated)
# Each label must be 2-20 characters and contain only alphanumeric characters, underscores, or Chinese characters
# Example: "bug,performance,enhancement"
# If labels are provided in the tool call, they will override this environment variable
export labels="bug,performance"
# Optional: Project name for multi-instance support
# REPO_NAME is auto-generated from repo name
export PROJECT_NAME="custom-mgit"
# Optional: Automatic workflow flags (default: false)
# AUTO_REVIEW: Automatically review PR after creation (returns 204 No Content on success)
export AUTO_REVIEW="false"
# AUTO_TEST: Automatically test PR after review (returns 204 No Content on success)
export AUTO_TEST="false"
# AUTO_MERGE: Automatically merge PR after test succeeds (only merges if AUTO_TEST is false or test succeeds)
export AUTO_MERGE="false"获取OAuth应用程序凭据
- 首选 Gitee OAuth应用程序 创建您的应用程序
- Click "创建应用" (Create Application)
- 填写申请详情:
- 应用程序名称:您的应用程序名称 - 应用程序URL:您的应用程序URL(可以是任何有效的URL) - 应用程序描述:您的应用程序描述
- 创建后,您将获得
client_id和client_secret - 将它们与您的Gitee帐户凭据一起设置为环境变量
注: 访问令牌在需要时使用OAuth自动获得。您还可以使用 token 手动检索令牌的工具。
用法
1.直接运行(全局安装)
mcp-server-gitee-pull-request2.使用npx(推荐)
npx @liangshanli/mcp-server-gitee-pull-request3.直接启动(源安装)
npm start4.管理启动(建议用于生产)
npm run start-managedIDE配置
光标/VS代码
添加到MCP设置(.cursor/mcp.json 或VS代码设置):
{
"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"
}
}
}
}多实例配置
您可以为不同的存储库运行多个实例。这 REPO_NAME 由自动生成 repo 名字。使用 PROJECT_NAME 为了区分不同的实例:
{
"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"
}
}
}
}可用工具
pr
在Gitee上创建Pull Request。
参数:
title(必填):拉取请求标题body(可选):Pull Request描述/正文draft(可选):这是否是PR草案(默认值:false)
注: 标签可以通过以下方式配置 labels 环境变量。如果设置,它们将自动添加到此工具创建的所有Pull Request中。
自动工作流:
- 如果
AUTO_REVIEW=true,PR创建后将自动审核 - 如果
AUTO_TEST=true,PR将在审核后自动测试(如果禁用审核,则在创建后自动测试) - 如果
AUTO_MERGE=true,PR将在测试成功后自动合并(如果测试被禁用,则在创建后自动合并)
工作流顺序:
- 创建PR
- 自动审查(如果
AUTO_REVIEW=true) - 自动测试(如果
AUTO_TEST=true) - 自动合并(如果
AUTO_MERGE=true测试成功或测试被禁用)
例子:
{
"title": "Add new feature",
"body": "This PR adds a new feature to improve performance.",
"labels": "enhancement,performance",
"draft": false
}答复:
{
"success": true,
"pull_request": {
"id": 12345,
"number": 42,
"title": "Add new feature",
"html_url": "https://gitee.com/owner/repo/pulls/42",
...
},
"url": "https://gitee.com/owner/repo/pulls/42",
"number": 42,
"message": "Pull Request created successfully. PR #42: Add new feature",
"auto_review": {
"success": true,
"review": null,
"message": "Auto review completed for PR #42"
},
"auto_test": {
"success": true,
"test": null,
"message": "Auto test completed for PR #42"
},
"auto_merge": {
"success": true,
"merge": {
"sha": "...",
"merged": true,
"message": "Pull Request 已成功合并"
},
"message": "Auto merge completed for PR #42"
}
}注: 这 auto_review, auto_test,以及 auto_merge 仅当启用并成功执行相应的自动工作流时,才会包含字段。审核和测试API成功后返回204 No Content,因此 review 和 test 字段将是 null 当成功时。
token
使用OAuth获取Gitee访问令牌。
该工具使用配置的凭据从Gitee OAuth API检索访问令牌。令牌缓存在内存中,需要时会自动刷新。
参数: 无
例子:
{}答复:
{
"success": true,
"access_token": "your_access_token_here",
"expires_at": "2025-11-26T12:00:00.000Z",
"message": "Access token retrieved successfully"
}注: 创建Pull Requests时会自动使用令牌,因此您通常不需要手动调用此工具。
logs
获取调试和监控的操作日志。
参数:
limit(可选):限制计数,默认50,最大1000offset(可选):偏移,默认值为0
例子:
{
"limit": 10,
"offset": 0
}多实例支持
此服务器通过以下方式支持多个实例 REPO_NAME 它是由以下内容自动生成的 repo 名字。工具名称以存储库名称作为前缀,以避免冲突。
注: PROJECT_NAME 是可选的,仅用于工具描述品牌。它不会影响工具命名。
例子:
- 随着
repo="mcp-server-gitee-pull-request":工具名称为mcp-server-gitee-pull-request_pr - 随着
repo="my-project":工具名称为my-project_pr
这允许您同时为不同的存储库运行多个实例。
日志记录
所有操作都记录到文件中,以便调试和监控:
- 日志目录:
.setting/或.setting./(可通过以下方式配置MCP_LOG_DIR) - 日志文件:
mcp-gitee-pr.log(可通过以下方式配置MCP_LOG_FILE)
日志包括:
- 请求参数
- 响应数据
- 错误消息
- 时间戳
api参考
此服务器使用Gitee API v5:
- 端点:
POST https://gitee.com/api/v5/repos/{owner}/{repo}/pulls - 内容类型:
application/json;charset=UTF-8 - 认证:通过查询参数访问令牌
有关更多信息,请参见 Gitee API文档.
错误处理
服务器处理各种错误情况:
- 缺少必要参数:返回明确的错误消息
- 标签无效:验证标签格式(2-20个字符,仅限字母数字/下划线/中文)
- API错误:返回带有状态代码的Gitee API错误消息
- 网络错误:优雅地处理连接失败
故障排除
常见问题
- 401未经授权:检查您的
access_token有效且具有所需范围 - 404未找到:验证
owner和repo是正确的 - 422不可处理实体:检查分支名称(
head和base)存在且有效 - 标签无效:确保标签为2-20个字符,并且只包含允许的字符
调试模式
通过检查中的日志文件启用详细日志记录 .setting/ 目录。
许可证
麻省理工学院
作者
李亮山
仓库
https://github.com/liliangshan/mcp-server-gitee-pull-request
