比特桶MCP服务器(Python)
    
连接 克劳德代码, VS代码(GitHub副本), 光标,以及任何与MCP兼容的AI助手到您的Bitbucket Cloud存储库。审查拉取请求、监控管道和管理代码——所有这些都是通过自然语言完成的。
特性
- 45个MCP工具 --存储库、拉取请求、注释、任务、差异、管道、构建状态、审阅者、PR草案、批处理审阅
- 反应平淡 -去除API噪声以降低LLM令牌使用率
- 可配置的 --通过启用/禁用工具
configs/tools.json或BITBUCKET_TOOLS_CONFIGenv 是 - 安全凭据 --环境变量或系统密钥链
快速开始
1.安装
运行服务器的推荐方式是通过 uvx (零安装,隔离环境):
# Always latest version
uvx --from bitbucket-mcp-py bitbucket-mcp
# Pin a specific version
uvx --from bitbucket-mcp-py==1.8.1 bitbucket-mcp为什么--from? PyPI包是bitbucket-mcp-py但命令入口点是bitbucket-mcpThe--fromflag告诉uvx要安装哪个程序包。
Alternative install methods
| 模式 | 命令 | 最适合 |
|---|---|---|
| pip全球 | pip install bitbucket-mcp-py | 简单、持久的安装 |
| 本地开发人员 | pip install -e . 在项目目录中 | 为项目做出贡献 |
| 码头工人 | 请参阅 | 基于容器的工作流 |
2.配置凭据
设置以下环境变量(或使用 .env 文件--请参见 凭证):
| 变量 | 描述 |
|---|---|
BITBUCKET_USERNAME | 您的Bitbucket电子邮件 |
BITBUCKET_TOKEN | 您的Bitbucket API代币 |
BITBUCKET_WORKSPACE | 你的工作空间蛞蝓 |
获取您的API代币 在:https://id.atlassian.com/manage-profile/security/api-tokens ⚠️ 使用作用域令牌,而不是全局令牌。 创建令牌时,选择特定范围(例如。Repositories: Read,Pull requests: Read/Write).没有显式作用域的全局令牌不适用于此MCP服务器。
3.配置您的AI助手
克劳德代码(推荐)
选项A-CLI(最快):
claude mcp add bitbucket-mcp \
-e BITBUCKET_USERNAME=your-email@example.com \
-e BITBUCKET_TOKEN=your-api-token \
-e BITBUCKET_WORKSPACE=your-workspace \
-- uvx --from bitbucket-mcp-py bitbucket-mcp选项B-JSON配置 (~/.claude.json 或项目 .mcp.json):
{
"mcpServers": {
"bitbucket-mcp": {
"type": "stdio",
"command": "uvx",
"args": ["--from", "bitbucket-mcp-py", "bitbucket-mcp"],
"env": {
"BITBUCKET_USERNAME": "your-email@example.com",
"BITBUCKET_TOKEN": "your-api-token",
"BITBUCKET_WORKSPACE": "your-workspace"
}
}
}
}VS代码(GitHub副本)
添加 .vscode/mcp.json (工作空间)或 ~/Library/Application Support/Code/User/mcp.json (全局,macOS):
{
"servers": {
"bitbucket-mcp": {
"type": "stdio",
"command": "uvx",
"args": ["--from", "bitbucket-mcp-py", "bitbucket-mcp"],
"env": {
"BITBUCKET_USERNAME": "your-email@example.com",
"BITBUCKET_TOKEN": "your-api-token",
"BITBUCKET_WORKSPACE": "your-workspace"
}
}
}
}光标
添加 ~/.cursor/mcp.json:
{
"mcpServers": {
"bitbucket-mcp": {
"command": "uvx",
"args": ["--from", "bitbucket-mcp-py", "bitbucket-mcp"],
"env": {
"BITBUCKET_USERNAME": "your-email@example.com",
"BITBUCKET_TOKEN": "your-api-token",
"BITBUCKET_WORKSPACE": "your-workspace"
}
}
}
}可用工具
| 类别 | 工具 |
|---|---|
| 仓库 | list_repositories, get_repository |
| 拉取请求 | get_pull_requests, get_pull_request, create_pull_request, update_pull_request, approve_pull_request, unapprove_pull_request, request_changes_pull_request, unrequest_changes_pull_request, decline_pull_request, merge_pull_request |
| 评论 | get_pull_request_comments, add_pull_request_comment, get_pull_request_comment, update_pull_request_comment, delete_pull_request_comment, resolve_pull_request_comment, reopen_pull_request_comment, get_pull_request_activity |
| 任务公关 | get_pull_request_tasks, get_pull_request_task, create_pull_request_task, update_pull_request_task, delete_pull_request_task |
| 差异/评论 | get_pull_request_diff, get_pull_request_patch, get_pull_request_diffstat, get_pull_request_commits |
| 公关发现 | get_pull_requests_pending_review |
| 构建/CI | get_pull_request_statuses, get_commit_statuses |
| 管道 | list_pipeline_runs, get_pipeline_run, get_pipeline_steps, get_pipeline_step_logs, run_pipeline, stop_pipeline |
| 审稿人 | get_effective_default_reviewers, suggest_pull_request_reviewers |
| PR草案 | create_draft_pull_request, publish_draft_pull_request, convert_pull_request_to_draft |
| 批量审核 | submit_pull_request_batch_review |
| 评审总结 | get_pull_request_review_summary |
默认情况下禁用:merge_pull_request(安全),stop_pipeline(安全),get_pull_request_patch(git am格式——不适用于AI审查),convert_pull_request_to_draft(API不支持Bitbucket)。启用configs/tools.json.
自定义工具配置
默认情况下,服务器读取 configs/tools.json 与包裹捆绑在一起。您可以在运行时指向自定义文件,而无需重新生成:
export BITBUCKET_TOOLS_CONFIG=/path/to/my-tools.json后备链 (首场比赛获胜):
BITBUCKET_TOOLS_CONFIG环境变量- 内建
configs/tools.json
故障安全行为 --如果 BITBUCKET_TOOLS_CONFIG 如果设置了,但文件丢失或包含无效的JSON,服务器将在启动时引发错误(显式失败,而不是默默地忽略覆盖)。如果缺少内置默认值,则启用所有工具。代币提示 —get_pull_request_diff接受可选path用于将差异过滤到单个文件的参数,在大型PR上将令牌使用量减少约95%: ``get_pull_request_diff(repo_slug, pull_request_id, path="src/services/myService.ts")``
凭证
选项1: .env 文件(推荐)
cp .env.example .env
# Edit .env with your credentials选项2:系统钥匙链(最安全)
pip install 'bitbucket-mcp-py[keyring]'
python3 -c "import keyring; keyring.set_password('bitbucket-mcp', 'bitbucket_token', 'YOUR_TOKEN')"Docker(替代方案)
如果您更喜欢在容器中运行服务器:
docker build -t bitbucket-mcp-py .
docker run -d --name bitbucket-mcp --env-file .env bitbucket-mcp-py然后配置您的AI助手以使用 docker exec:
{
"mcpServers": {
"bitbucket-mcp": {
"command": "docker",
"args": ["exec", "-i", "bitbucket-mcp", "python", "-m", "src.main", "--transport", "stdio"]
}
}
}发展
# Install dev dependencies
uv sync --extra dev
# Run tests
uv run pytest tests/ -v
# Run specific test
uv run pytest tests/test_client.py -v需求
- Python 3.12+
- 比特桶API代币
许可证
麻省理工学院
参考文献
- MCP注册表 --MCP服务器官方注册表
- PyPI包 --Python包
- MCP Python SDK
- 比特桶API 2.0
- FastMCP框架

