比特桶云MCP服务器
](https://badge.fury.io/py/bitbucket-mcp-cloud)   
A. 生产就绪模型上下文协议(MCP) 服务器与Bitbucket Cloud API无缝集成。该服务器基于企业级质量标准构建,通过标准化的MCP接口提供对Bitbucket Cloud功能的全面访问。
🌟 亮点
- ✅ 完成Bitbucket云API覆盖 -已实现所有基本功能
- ✅ 生产就绪 -全面的错误处理、日志记录和类型安全
- ✅ 多种安装方式 -PyPI、直接执行或开发模式
- ✅ Claude桌面集成 -为AI助手工作流程做好准备
- ✅ 经过全面测试 -具有自动化CI/CD的全面测试套件
- ✅ 清洁建筑 -遵循SOLID原则的模块化设计
🛠️ 功能(15个工具)
🎯 项目和存储库管理
list_projects-列出工作区中所有可访问的项目list_repositories-按工作区或项目列出存储库list_commits-使用筛选选项浏览提交历史记录
🔄 拉取请求生命周期
list_pull_requests-列出具有状态过滤的PR(打开、合并、取消)get_pull_request-获取详细的公关信息create_pull_request-与审阅者一起创建新的拉取请求update_pull_request-更新拉取请求标题和/或描述approve_pull_request-批准拉取请求decline_pull_request-拒绝拉取请求merge_pull_request-将批准的PR与策略选择合并
💬 评论系统
list_pull_request_comments-列出所有公关评论create_pull_request_comment-添加一般性评论create_pull_request_inline_comment-添加特定行的代码注释
📊 代码分析
get_pull_request_diff-获取代码审查的完整差异get_pull_request_diffstat-获取更改摘要(文件、添加/删除的行)
🚀 安装与使用
方法1:通过uvx直接执行(推荐)
# No installation needed - run directly from PyPI
uvx bitbucket-mcp-cloud
# For MCP tools that support it
mcp run bitbucket-mcp-cloud方法2:全球安装
# Install globally
pip install bitbucket-mcp-cloud
# Run the server
bitbucket-mcp-cloud方法三:开发模式
# Clone and setup for development
git clone https://github.com/jhonymiler/Bitbucket-MCP-Cloud.git
cd Bitbucket-MCP-Cloud
# Using uv (recommended)
uv sync
uv run server.py
# Or using pip
pip install -e .
python server.py方法4:MCP工具集成
# Using the MCP CLI
mcp run server.py
# For development and testing
uv run mcp dev server.py📋 先决条件
- Python 3.10+
- Bitbucket云账户
- 已配置Bitbucket应用程序密码
⚙️ 设置
1.创建Bitbucket应用密码
- 首选 帐户设置>应用程序密码
- 点击“创建应用密码”
- 选择所需的权限:
- 仓库:读,写 - 拉取请求:读,写 - 项目:阅读
2.配置环境变量
# Option 1: Using .env file (for development)
cp .env.example .env
# Edit .env with your credentials
# Option 2: Export environment variables
export BITBUCKET_USERNAME=your_username
export BITBUCKET_TOKEN=your_app_password
export BITBUCKET_DEFAULT_WORKSPACE=your_workspace3.克劳德桌面集成
添加到您的Claude Desktop配置(~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"bitbucket": {
"command": "uvx",
"args": ["bitbucket-mcp-cloud"],
"env": {
"BITBUCKET_USERNAME": "your_username",
"BITBUCKET_TOKEN": "your_app_password",
"BITBUCKET_DEFAULT_WORKSPACE": "your_workspace"
}
}
}
}🔧 工具使用示例
项目和存储库
# List projects
await list_projects(workspace="my-workspace", limit=25)
# List all repositories
await list_repositories(workspace="my-workspace")
# List repositories for a specific project
await list_repositories(workspace="my-workspace", project="PROJ")拉取请求
# List open PRs
await list_pull_requests(repository="my-repo", state="OPEN")
# Get PR details
await get_pull_request(repository="my-repo", pr_id=123)
# Create new PR
await create_pull_request(
repository="my-repo",
title="New feature",
source_branch="feature/new-feature",
target_branch="main",
description="Implements new feature X"
)
# Update PR description
await update_pull_request(
repository="my-repo",
pr_id=123,
description="Updated description with more details"
)
# Approve and merge PR
await approve_pull_request(repository="my-repo", pr_id=123)
await merge_pull_request(repository="my-repo", pr_id=123, merge_strategy="squash")评论和代码审查
# Create inline comment on specific line
await create_pull_request_inline_comment(
repository="my-repo",
pr_id=123,
content="This function could be optimized",
filename="src/main.py",
line_number=42
)
# Get diff for analysis
diff_text = await get_pull_request_diff(repository="my-repo", pr_id=123)
# Get summary of changes
diffstat = await get_pull_request_diffstat(repository="my-repo", pr_id=123)🏗️ 建筑
bitbucket-mcp-cloud/
├── server.py # Main MCP server (entry point)
├── src/
│ ├── models.py # Pydantic models for type safety
│ ├── utils.py # Utility functions and logging
│ └── __init__.py
├── tests/ # Comprehensive test suite
│ └── test_bitbucket_mcp.py
├── pyproject.toml # Project configuration
├── .env.example # Configuration template
├── .github/
│ └── workflows/
│ └── publish.yml # CI/CD pipeline
└── README.md # This documentation关键组件
BitbucketCloudClient:异步HTTP客户端,具有全面的API覆盖范围FastMCP:具有自动生成工具定义的MCP服务器- Pydantic模型:所有API响应的类型安全数据结构
- 综合录井:详细的运行跟踪和调试
- 错误处理:使用适当的HTTP状态代码进行稳健的错误处理
🧪 测试
# Run all tests
uv run pytest
# Run with coverage report
uv run pytest --cov=src --cov-report=html
# Run specific test categories
uv run pytest tests/test_bitbucket_mcp.py::TestMCPTools -v
# Type checking
uv run mypy server.py src/
# Code formatting
uv run black server.py src/ tests/🔒 安全功能
- 安全认证:使用Bitbucket应用程序密码(无OAuth复杂性)
- 输入验证:使用Pydantic模型进行全面验证
- 错误处理:山宁泰错误消息(无凭据泄漏)
- 限速意识:遵守Bitbucket API费率限制
- 仅限HTTPS:所有通信均加密
📊 质量保证
- 类型安全:带有mypy验证的完整类型注释
- 代码质量:黑色格式化和全面的linting
- 测试:17个测试用例,涵盖所有主要功能
- CI/CD:自动化测试和PyPI发布
- 文档:综合文档和示例
🔗 api参考
此MCP服务器实现了完整的 Bitbucket云REST API v2.0.涵盖的API关键端点:
/workspaces/{workspace}/projects-项目管理/repositories/{workspace}-存储库操作/repositories/{workspace}/{repo}/pullrequests-PR生命周期/repositories/{workspace}/{repo}/commits-提交历史记录/pullrequests/{pr_id}/comments-评论系统/pullrequests/{pr_id}/diff-代码分析
🤝 贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 运行测试(
uv run pytest) - 提交更改(
git commit -m 'Add amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 打开拉取请求
开发设置
# Clone and setup
git clone https://github.com/jhonymiler/Bitbucket-MCP-Cloud.git
cd Bitbucket-MCP-Cloud
uv sync --extra dev
# Run quality checks
uv run pytest
uv run mypy server.py src/
uv run black --check server.py src/ tests/📝 更新日志
v1.3.5(最新)
- ✅ 重新构造包以实现最佳PyPI分布
- ✅ 具有条件导入的根目录中的Server.py
- ✅ 所有执行方法都经过测试并正常工作
- ✅ 增强的构建系统和CI/CD
- ✅ 生产就绪的包装结构
v1.3.4
- ✅ 服务器正确包含在PyPI轮中
- ✅ 所有有效的执行方法(uvx、pip、开发)
- ✅ 完整的测试覆盖率
- ✅ Claude桌面集成就绪
v1.3.x系列
- ✅ 完成Bitbucket Cloud API实现
- ✅ 全面的错误处理和记录
- ✅ 带有mypy验证的类型安全
- ✅ 生产就绪架构
📄 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
🆘 支持
- 问题:
- 文档:此README和内联代码文档
- api参考: Bitbucket云REST API
🔗 相关链接
______________________________________________________________________
由以下材料制成❤️ 对于MCP社区
