使用说明
比特桶MCP服务器
这是一个连接到自托管Bitbucket服务器实例的MCP(模型上下文协议)服务器实现。服务器通过stdio通信,可以与MetaMCP集成。
概述
此服务器提供对Bitbucket服务器功能的访问,包括:
- 项目和存储库管理
- 文件浏览和内容检索
- 分支、提交和拉取请求管理
- 用户和权限管理
- 存储库搜索功能
服务器连接到http://bitbucket.digital.vn(一个自托管的Bitbucket服务器实例,而不是Bitbucket云)使用Atlassian Python API库。
特性
-
连接到自托管Bitbucket服务器
- 连接到http://bitbucket.digital.vn(不是Bitbucket云)
- 使用官方Atlassian Python API,而不是手动HTTP请求
- 支持多种身份验证方法(用户名/密码、令牌)
-
项目和存储库检索
- 从Bitbucket服务器获取项目列表
- 获取特定项目的存储库
- 正确处理API的分页响应
-
存储库文件浏览
- 浏览存储库文件和目录
- 获取特定文件的内容
- 浏览存储库结构
-
存储库历史和分支
- 获取存储库中的分支列表
- 获取存储库的提交历史记录
- 访问特定提交及其详细信息
-
拉取请求管理
- 获取存储库中的拉取请求列表
- 检索特定拉取请求的详细信息
- 按状态过滤拉取请求(OPEN、MERGED、DECLINED)
-
用户和权限管理
- 在项目中获取用户
- 检索组和用户的项目权限
- 查看访问控制和权限级别
-
存储库搜索
- 按名称、slug或描述搜索存储库
- 在所有项目中查找存储库
-
MCP服务器集成
- 使用FastMCP的基于流媒体stdio的MCP服务器
- 遵循MCP协议的基于stdio的正确通信
- 配置已准备好进行MetaMCP集成
- 作为标准MCP服务器工作
项目结构
bitbucket-mcp-server/
├── src/
│ ├── __init__.py
│ ├── main.py # Main application entry point
│ ├── bitbucket_client.py # Bitbucket client implementation
│ └── config.py # Configuration management
├── tests/
│ ├── __init__.py
│ ├── conftest.py # Pytest configuration
│ └── test_bitbucket_client.py
│ └── test_connection.py # Connection testing script
├── setup.sh # Script to install dependencies and setup environment
├── test.sh # Standalone test suite for functionality verification
├── pyproject.toml # Project metadata and dependencies
├── uv.lock # Dependency lock file
├── .env.example # Example environment variables
└── README.md # Project documentation
依赖项
fastmcp:用于构建MCP服务器的FastMCP框架atlassian-python-api:Atlassian产品的客户端库requests:用于发出请求的HTTP库pydantic-settings:配置管理
设置和使用
先决条件
- 安装 UV包管理器 用于依赖关系管理
- 确保您已安装Python 3.10+
环境配置
-
复制示例环境文件:
cp .env.example .env -
编辑
.env文件中包含您的Bitbucket服务器凭据:# Update these values in .env BITBUCKET_URL=http://bitbucket.digital.vn BITBUCKET_USERNAME=your-username BITBUCKET_PASSWORD=your-password # Or use a token-based authentication # BITBUCKET_TOKEN=your-token
安装
- 使用安装脚本安装依赖项:
./setup.sh install
测试
-
测试与Bitbucket服务器的连接:
./setup.sh test-connection -
运行测试套件:
./setup.sh test # Or run standalone tests ./test.sh
运行服务器
- 启动MCP服务器:
uv run python src/main.py
该服务器作为基于stdio的MCP服务器运行,并连接到您配置的Bitbucket服务器实例。
MetaMCP配置
要将此服务器与MetaMCP一起使用,请添加以下配置(更新路径以匹配您的主目录):
{
"mcpServers": {
"bitbucket-mcp": {
"type": "STDIO",
"command": "/home/[YOUR_USERNAME]/ai-workspace/bitbucket-mcp-server/.venv/bin/python",
"args": [
"/home/[YOUR_USERNAME]/ai-workspace/bitbucket-mcp-server/src/main.py"
]
}
}
}
此配置使用虚拟环境的Python解释器,该解释器已经安装了所有必需的依赖项。
可用工具
connection_status-检查与Bitbucket的连接状态get_projects-从Bitbucket获取项目列表get_repositories-获取特定项目的存储库(需要project_key参数、可选的开始和分页限制)get_repository_files-获取特定存储库路径中的文件(需要project_key、repository_slug、可选路径、开始和分页限制)get_file_content-获取存储库中特定文件的内容(需要project_key、repository_slug、filename)get_branches-获取特定存储库中的分支(需要project_key、repository_slug、可选的开始和分页限制)get_commits-获取特定存储库中的提交(需要project_key、repository_slug、可选的until、start和分页限制)get_pull_requests-在特定存储库中获取pull请求(需要project_key、repository_slug、可选状态、开始和分页限制)get_pull_request-获取特定的pull请求(需要project_key、repository_slug、pull_request_id)get_users-在Bitbucket中获取用户,可选择按项目筛选(可选project_key、开始和限制分页)get_project_permissions-获取特定项目的权限(分页需要project_key、可选groups_start、groups_limit、users_start、users_limit)search_repositories-按名称或描述搜索存储库(需要Search_query、可选的开始和分页限制)
配置
可以使用中的环境变量配置应用程序 .env 文件:
BITBUCKET_URL:Bitbucket服务器的URL(默认值:http://bitbucket.digital.vn)BITBUCKET_USERNAME:身份验证用户名(可选)BITBUCKET_PASSWORD:身份验证密码(可选)BITBUCKET_TOKEN:身份验证令牌(可选)
测试
使用以下命令运行测试:
./setup.sh test
# or
uv run pytest tests/ -v
发展
该项目使用UV进行依赖关系管理。要完成此项目,请执行以下操作:
- 安装依赖项:
uv sync - 在开发模式下运行:
uv run python src/main.py - 运行测试:
uv run pytest tests/ -v
