使用说明
BitBucket MCP服务器
用于BitBucket云操作的模型上下文协议(MCP)服务器。此服务器使Claude Code CLI和Codex CLI等AI编码代理能够与BitBucket存储库、分支和拉取请求进行交互。
特性
- 库管理:创建、删除、更新和列出存储库
- 分行管理:创建、删除和列出分支
- 拉取请求操作:创建、审核、批准、评论拉取请求
- 代码搜索:搜索存储库并浏览文件内容
- 记忆系统:存储和检索工作空间标准以及从公关评审中获得的经验
- 自动检测:从git remote自动检测当前BitBucket存储库
安装
使用uvx(推荐)
uvx bitbucket-python-mcp
使用pip
pip install bitbucket-python-mcp
来源
git clone https://github.com/yourusername/bitbucket-python-mcp.git
cd bitbucket-python-mcp
uv sync
配置
服务器需要以下环境变量:
| 变量 | 必填 | 描述 |
|---|---|---|
BITBUCKET_USERNAME |
是 | 您的BitBucket用户名(不是电子邮件) |
BITBUCKET_API_TOKEN |
是 | BitBucket设置中的应用程序密码/API令牌 |
BITBUCKET_WORKSPACE |
是 | 默认工作区段塞 |
BITBUCKET_MCP_DEBUG |
否 | 启用调试日志记录(1/true/yes) |
创建应用程序密码
- 首选 BitBucket应用程序密码
- 点击“创建应用密码”
- 给它一个描述性的名称(例如“MCP服务器”)
- 选择所需的权限:
- 存储库:读取、写入、管理(用于创建/删除)
- 拉取请求:读取、写入
- 点击“创建”并复制生成的密码
使用AI代理
克劳德代码CLI
添加到您的 ~/.claude/claude_desktop_config.json:
{
"mcpServers": {
"bitbucket": {
"command": "uvx",
"args": ["bitbucket-python-mcp"],
"env": {
"BITBUCKET_USERNAME": "your-username",
"BITBUCKET_API_TOKEN": "your-api-token",
"BITBUCKET_WORKSPACE": "your-workspace"
}
}
}
}
OpenAI Codex命令行界面
添加到您的 ~/.codex/config.toml:
[mcp_servers.bitbucket]
command = "uvx"
args = ["bitbucket-python-mcp"]
[mcp_servers.bitbucket.env]
BITBUCKET_USERNAME = "your-username"
BITBUCKET_API_TOKEN = "your-api-token"
BITBUCKET_WORKSPACE = "your-workspace"
或者,使用Codex CLI添加服务器:
codex mcp add bitbucket \
--env BITBUCKET_USERNAME=your-username \
--env BITBUCKET_API_TOKEN=your-api-token \
--env BITBUCKET_WORKSPACE=your-workspace \
-- uvx bitbucket-python-mcp
验证服务器是否已配置:
codex mcp list
本地运行
# Set environment variables
export BITBUCKET_USERNAME="your-username"
export BITBUCKET_API_TOKEN="your-api-token"
export BITBUCKET_WORKSPACE="your-workspace"
# Run the server
uvx bitbucket-python-mcp
# or
uv run bitbucket-python-mcp
可用工具
存储库工具
| 工具 | 说明 |
|---|---|
list_repositories |
列出工作区中的所有存储库 |
get_repository |
获取详细的存储库信息 |
create_repository |
创建新存储库 |
delete_repository |
删除存储库(需要确认) |
update_repository |
更新存储库设置 |
分支工具
| 工具 | 说明 |
|---|---|
list_branches |
列出存储库中的所有分支 |
get_branch |
获取分行详细信息 |
create_branch |
创建新分支 |
delete_branch |
删除分支(需要确认) |
拉取请求工具
| 工具 | 说明 |
|---|---|
list_pull_requests |
列出拉取请求(打开/合并/拒绝) |
get_pull_request |
获取PR详细信息(默认为最新) |
get_pull_request_diff |
获取PR的差异 |
get_pull_request_comments |
获取PR上的所有评论 |
add_pull_request_comment |
添加注释(常规或内联) |
approve_pull_request |
批准PR |
request_changes |
请求更改PR |
create_pull_request |
创建新的PR |
搜索工具
| 工具 | 说明 |
|---|---|
search_repositories |
按名称搜索存储库 |
get_repository_contents |
浏览存储库文件/目录 |
search_code |
搜索代码模式 |
get_file_content |
获取原始文件内容 |
内存工具
| 工具 | 说明 |
|---|---|
add_memory |
存储新的学习/标准以供将来参考 |
list_memories |
列出按工作区/类别筛选的存储内存 |
search_memories |
按关键字搜索记忆 |
get_relevant_memories |
获取与当前上下文相关的记忆 |
delete_memory |
删除存储的内存 |
remember_from_pr_comment |
从公关评论中提取并存储学习内容 |
记忆存储在 ~/.bitbucket-python-mcp/memory/ 并在会话中持续存在。
例子
创建存储库
User: Create a new private repository named "my-new-project" with description "My awesome project"
创建分支
User: Create a new branch named "feature-login" from development
查看拉取请求
User: Show me the details of the newest pull request
User: What are the comments on PR #42?
User: Approve PR #42
搜索代码
User: Search for "authentication" in the project-api repository
User: Show me the contents of src/main.py
存储和检索记忆
User: Remember that we should use shared-pipeline for SonarQube scans
User: What standards should I follow for this workspace?
User: Search memories for "pipeline"
发展
设置
# Clone the repository
git clone https://github.com/yourusername/bitbucket-python-mcp.git
cd bitbucket-python-mcp
# Install dependencies
uv sync --all-extras
# or using just
just install-dev
运行测试
uv run pytest
# or using just
just test
掉毛
uv run ruff check src tests
uv run ruff format src tests
# or using just
just fmt
just lint
建筑
uv build
# or using just
just build
贡献
欢迎投稿!请随时提交拉取请求。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add some amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
致谢
- 模型上下文协议 -协议规范
- atlassian python api -BitBucket API客户端
