Bitbucket MCP
Bitbucket MCP 是一个基于 Model Context Protocol (MCP) 的服务器,用于与 Bitbucket Cloud 和 Server API 进行集成。该 MCP 服务器使 AI 助手(如 Cursor)能够与您的 Bitbucket 仓库、拉取请求(Pull Request)及其他资源进行交互。
安全第一
这是一个安全且负责任的包 —— 不包含任何 DELETE 操作,因此不存在数据丢失的风险。每个拉取请求都会通过 CodeQL 进行分析,以确保代码的安全性。
概述
- 列出和获取仓库
- 获取仓库详情
- 获取拉取请求
- 以及其他功能...
安装
使用 NPX(推荐)
最简单的方式是通过 NPX 运行该 MCP 服务器,无需全局安装:
手动安装
您也可以选择全局安装或将其作为项目的一部分安装:
然后运行:
配置
环境变量
通过以下环境变量配置服务器:
变量 | 描述 | 必填 |
BITBUCKET_URL | Bitbucket 基础 URL(例如 "https://bitbucket.org/your-workspace") | 是 |
BITBUCKET_USERNAME | 您的 Bitbucket 用户名 | 是* |
BITBUCKET_PASSWORD | 您的 Bitbucket 应用密码 | 是* |
BITBUCKET_TOKEN | 您的 Bitbucket 访问令牌(可替代用户名/密码) | 否 |
BITBUCKET_WORKSPACE | 未指定时使用的默认工作区 | 否 |
* 必须提供
BITBUCKET_TOKEN
或同时提供 BITBUCKET_USERNAME
和 BITBUCKET_PASSWORD
。创建 Bitbucket 应用密码
- 登录您的 Bitbucket 账户。
- 进入 Personal Settings > App Passwords。
- 创建一个新的应用密码,并赋予以下权限:
- Repositories: Read
- Pull requests: Read, Write
- 复制生成的密码,并将其用作
BITBUCKET_PASSWORD
环境变量。
与 Cursor 集成
要将此 MCP 服务器与 Cursor 集成:
- 打开 Cursor。
- 进入 Settings > Extensions。
- 点击 "Model Context Protocol"。
- 添加一个新的 MCP 配置:
- 保存配置。
- 在 Cursor 中使用
/bitbucket
命令访问 Bitbucket 仓库和拉取请求。
使用本地构建与 Cursor 集成
如果您在本地开发并希望测试更改:
可用工具
该 MCP 服务器提供了与 Bitbucket 仓库和拉取请求交互的工具。以下是可用操作的完整列表:
仓库操作
listRepositories
列出工作区中的仓库。
参数:
workspace
(可选):Bitbucket 工作区名称
limit
(可选):返回的仓库数量上限
getRepository
获取特定仓库的详情。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
拉取请求操作
getPullRequests
获取仓库的拉取请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
state
(可选):拉取请求状态(OPEN
、MERGED
、DECLINED
、SUPERSEDED
)
limit
(可选):返回的拉取请求数量上限
createPullRequest
创建新的拉取请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
title
:拉取请求标题
description
:拉取请求描述
sourceBranch
:源分支名称
targetBranch
:目标分支名称
reviewers
(可选):审阅者用户名列表
getPullRequest
获取特定拉取请求的详情。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
updatePullRequest
更新拉取请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
- 其他可选更新参数(标题、描述等)
getPullRequestActivity
获取拉取请求的活动日志。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
approvePullRequest
批准拉取请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
unapprovePullRequest
取消拉取请求的批准。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
declinePullRequest
拒绝拉取请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
message
(可选):拒绝原因
mergePullRequest
合并拉取请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
message
(可选):合并提交信息
strategy
(可选):合并策略(merge-commit
、squash
、fast-forward
)
requestChanges
请求更改拉取请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
removeChangeRequest
移除拉取请求的更改请求。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
拉取请求评论操作
getPullRequestComments
列出拉取请求的评论。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
createPullRequestComment
在拉取请求上创建评论。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
content
:评论内容
inline
(可选):内联评论信息
getPullRequestComment
获取拉取请求的特定评论。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
comment_id
:评论 ID
updatePullRequestComment
更新拉取请求的评论。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
comment_id
:评论 ID
content
:更新后的评论内容
deletePullRequestComment
删除拉取请求的评论。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
comment_id
:评论 ID
resolveComment
解决拉取请求的评论线程。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
comment_id
:评论 ID
reopenComment
重新打开已解决的评论线程。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
comment_id
:评论 ID
拉取请求差异操作
getPullRequestDiff
获取拉取请求的差异。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
getPullRequestDiffStat
获取拉取请求的差异统计。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
getPullRequestPatch
获取拉取请求的补丁。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
拉取请求任务操作
getPullRequestTasks
列出拉取请求的任务。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
createPullRequestTask
在拉取请求上创建任务。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
content
:任务内容
comment
(可选):关联的评论 ID
pending
(可选):任务是否为待处理状态
getPullRequestTask
获取拉取请求的特定任务。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
task_id
:任务 ID
updatePullRequestTask
更新拉取请求的任务。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
task_id
:任务 ID
content
(可选):更新后的任务内容
state
(可选):更新后的任务状态
deletePullRequestTask
删除拉取请求的任务。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
task_id
:任务 ID
其他拉取请求操作
getPullRequestCommits
列出拉取请求的提交。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
getPullRequestStatuses
列出拉取请求的提交状态。
参数:
workspace
:Bitbucket 工作区名称
repo_slug
:仓库 slug
pull_request_id
:拉取请求 ID
开发
先决条件
- Node.js 18 或更高版本
- npm 或 yarn
设置
许可证
本项目基于 MIT 许可证,详情请参阅 LICENSE 文件。
链接
- Author:waytomcp
- URL:https://www.waytomcp.com/article/MatanYemini/bitbucket-mcp
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!