Bitbucket MCP Server

io.github.lawp09由 GitHub 账号 lawp09 发布v1.29.2更新于 Oct 26, 2026

MCP server for Bitbucket API - manage repositories, pull requests, comments, pipelines and more

概览

AI 生成的概览

本地 MCP 服务器,把 AI 助手连接到 Bitbucket Cloud,用于浏览仓库、审查拉取请求和监控流水线。

可以做什么
  • 浏览仓库、源码文件、目录、提交以及工作区成员与权限
  • 读取、创建、更新、批准、拒绝或合并拉取请求,包括草稿、审查人和批量审查
  • 读取、添加、编辑、解决或删除拉取请求评论与任务,以及差异、补丁和差异统计
  • 查看并控制 CI:构建状态、流水线运行、步骤与日志、流水线变量、计划和缓存
  • 管理议题与议题评论、部署与部署变量,以及分支限制
  • 使用内置提示模板完成 PR 审查、流水线失败排查、仓库概览和新审查人上手
适用场景
适合团队代码托管在 Bitbucket Cloud 的场景:希望助手在对话中直接审查拉取请求、排查 CI 失败,或回答关于仓库和流水线的问题。
运行要求
需要 Python 3.12+ 和 bitbucket-mcp-py 包,通常用 uvx 或 pip 运行。需要一个带明确权限范围的 Bitbucket API 令牌,并设置 BITBUCKET_USERNAME、BITBUCKET_TOKEN、BITBUCKET_WORKSPACE 环境变量(或使用系统钥匙串)。需要访问 Bitbucket API 的网络。
安装前请注意
该令牌可访问你的 Bitbucket 工作区,请使用限定范围的令牌而非全局令牌,并避免写入共享配置。许多工具会写入或删除数据(合并、拒绝、评论、议题、流水线变量、分支限制),其中部分默认关闭,需在工具配置中启用。HTTP 模式在非多租户情况下自身没有身份验证,能访问该端口的人都以你的令牌身份操作;请绑定本机地址或置于认证代理之后。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Bitbucket MCP Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Bitbucket MCP Server (Python)

[PyPI] [Python] [CI] [CodeQL] [License: MIT]

Connect Claude Code, OpenAI Codex, Cursor, VS Code (GitHub Copilot), and any MCP-compatible AI assistant to your Bitbucket Cloud repositories. Review pull requests, monitor pipelines, and manage your code — all through natural language.

Features

  • 60+ MCP tools — repositories, pull requests, comments, tasks, diffs, pipelines (runtime + config), build statuses, reviewers, draft PRs, batch review, issue tracker, commits, source/file browsing
  • MCP 2025 tool annotations — every tool advertises readOnlyHint / destructiveHint / idempotentHint / openWorldHint + a human-readable title, so clients (Claude Code, Cursor) auto-include read-only tools and warn before destructive operations
  • Slim responses — stripped API noise for lower LLM token usage
  • Configurable — enable/disable tools via configs/tools.json or BITBUCKET_TOOLS_CONFIG env var
  • Secure credentials — environment variables or system keychain

Quick Start

1. Install

The recommended way to run the server is via uvx (zero install, isolated environment):

bash
# Always latest versionuvx --from bitbucket-mcp-py bitbucket-mcp
# Pin a specific versionuvx --from bitbucket-mcp-py==1.8.1 bitbucket-mcp

Why --from? The PyPI package is bitbucket-mcp-py but the command entry point is bitbucket-mcp. The --from flag tells uvx which package to install.

Alternative install methods
ModeCommandBest for
pip globalpip install bitbucket-mcp-pySimple, persistent install
Local devpip install -e . in project dirContributing to the project
DockerSee Docker sectionContainer-based workflows

2. Configure credentials

Set the following environment variables — in your MCP client's env block, as shown above, or in the system keychain (see Credentials):

VariableDescription
BITBUCKET_USERNAMEYour Bitbucket email
BITBUCKET_TOKENYour Bitbucket API token
BITBUCKET_WORKSPACEYour workspace slug

Get your API token at: https://id.atlassian.com/manage-profile/security/api-tokens

⚠️ Use a scoped token, not a global one. When creating the token, select specific scopes (e.g. Repositories: Read, Pull requests: Read/Write). Global tokens without explicit scopes do not work with this MCP server.

3. Configure your AI assistant

Claude Code (recommended)

Option A — CLI (fastest):

bash
claude mcp add bitbucket-mcp \  -e [email protected] \  -e BITBUCKET_TOKEN=your-api-token \  -e BITBUCKET_WORKSPACE=your-workspace \  -- uvx --from bitbucket-mcp-py bitbucket-mcp

Option B — JSON config (~/.claude.json or project .mcp.json):

json
{  "mcpServers": {    "bitbucket-mcp": {      "type": "stdio",      "command": "uvx",      "args": ["--from", "bitbucket-mcp-py", "bitbucket-mcp"],      "env": {        "BITBUCKET_USERNAME": "[email protected]",        "BITBUCKET_TOKEN": "your-api-token",        "BITBUCKET_WORKSPACE": "your-workspace"      }    }  }}
OpenAI Codex

Option A — CLI (fastest):

bash
codex mcp add bitbucket-mcp \  --env [email protected] \  --env BITBUCKET_TOKEN=your-api-token \  --env BITBUCKET_WORKSPACE=your-workspace \  -- uvx --from bitbucket-mcp-py bitbucket-mcp

Option B — TOML config (~/.codex/config.toml):

toml
[mcp_servers.bitbucket-mcp]command = "uvx"args = ["--from", "bitbucket-mcp-py", "bitbucket-mcp"]env = { BITBUCKET_USERNAME = "[email protected]", BITBUCKET_TOKEN = "your-api-token", BITBUCKET_WORKSPACE = "your-workspace" }
Cursor

Add to ~/.cursor/mcp.json:

json
{  "mcpServers": {    "bitbucket-mcp": {      "command": "uvx",      "args": ["--from", "bitbucket-mcp-py", "bitbucket-mcp"],      "env": {        "BITBUCKET_USERNAME": "[email protected]",        "BITBUCKET_TOKEN": "your-api-token",        "BITBUCKET_WORKSPACE": "your-workspace"      }    }  }}
VS Code (GitHub Copilot)

Add to .vscode/mcp.json (workspace) or ~/Library/Application Support/Code/User/mcp.json (global, macOS):

json
{  "servers": {    "bitbucket-mcp": {      "type": "stdio",      "command": "uvx",      "args": ["--from", "bitbucket-mcp-py", "bitbucket-mcp"],      "env": {        "BITBUCKET_USERNAME": "[email protected]",        "BITBUCKET_TOKEN": "your-api-token",        "BITBUCKET_WORKSPACE": "your-workspace"      }    }  }}

Available Tools

CategoryTools
Repositorieslist_repositories, get_repository, get_repository_tags
Pull Requestsget_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
Commentsget_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
Tasks PRget_pull_request_tasks, get_pull_request_task, create_pull_request_task, update_pull_request_task, delete_pull_request_task
Diff / Reviewget_pull_request_diff, get_pull_request_patch, get_pull_request_diffstat, get_pull_request_commits
PR Discoveryget_pull_requests_pending_review
Build / CIget_pull_request_statuses, get_commit_statuses
Pipelineslist_pipeline_runs, get_pipeline_run, get_pipeline_steps, get_pipeline_step_logs, run_pipeline, stop_pipeline
Pipelines Configget_pipeline_config, list_pipeline_variables, get_pipeline_variable, create_pipeline_variable, update_pipeline_variable, delete_pipeline_variable, list_pipeline_schedules, get_pipeline_schedule, list_pipeline_schedule_executions, create_pipeline_schedule, update_pipeline_schedule, delete_pipeline_schedule, list_pipeline_caches, delete_pipeline_cache
Reviewersget_effective_default_reviewers, suggest_pull_request_reviewers
Draft PRcreate_draft_pull_request, publish_draft_pull_request, convert_pull_request_to_draft
Batch Reviewsubmit_pull_request_batch_review
Review Summaryget_pull_request_review_summary
Issueslist_issues, get_issue, create_issue, update_issue, delete_issue, get_issue_comments, get_issue_comment, add_issue_comment, update_issue_comment, delete_issue_comment
Commitslist_commits, get_commit, get_commit_comments, get_commit_comment, add_commit_comment
Sourceget_file_content, list_directory
Deploymentslist_environments, get_environment, create_environment, delete_environment, list_deployments, get_deployment, list_deployment_variables, create_deployment_variable, update_deployment_variable, delete_deployment_variable
Branch Restrictionslist_branch_restrictions, get_branch_restriction, create_branch_restriction, update_branch_restriction, delete_branch_restriction
Workspacelist_workspace_members, get_workspace_member, list_workspace_permissions, list_repository_permissions

Disabled by default: merge_pull_request (safety), stop_pipeline (safety), get_pull_request_patch (git am format — not useful for AI review), convert_pull_request_to_draft (not supported by Bitbucket API), delete_issue (safety), delete_issue_comment (safety), add_commit_comment (write op), create_pipeline_variable / update_pipeline_variable / delete_pipeline_variable (write ops), create_pipeline_schedule / update_pipeline_schedule / delete_pipeline_schedule (write ops), delete_pipeline_cache (safety), create_environment / delete_environment / create_deployment_variable / update_deployment_variable / delete_deployment_variable (write ops), create_branch_restriction / update_branch_restriction / delete_branch_restriction (write ops). Enable in configs/tools.json.

Governance scopes — Branch restriction read tools need the repository scope (repository:admin may be required depending on repo config); the write tools need repository:admin. Workspace member/permission tools need the account scope. The /members endpoint lists users without a per-user permission (use list_workspace_permissions for roles).

Deployments scopes — the read tools (list_environments, get_environment, list_deployments, get_deployment, list_deployment_variables) need the deployment scope; the write tools need deployment:write. Bitbucket has no server-side filter for deployments by environment (BCLOUD-18729) — filter on the environment field of list_deployments instead. There is no update_environment tool: Bitbucket exposes no PUT for environments (only POST .../changes for locking).

Custom tool configuration

By default the server reads configs/tools.json bundled with the package. You can point to a custom file at runtime without rebuilding:

bash
export BITBUCKET_TOOLS_CONFIG=/path/to/my-tools.json

Fallback chain (first match wins):

  1. BITBUCKET_TOOLS_CONFIG environment variable
  2. Built-in configs/tools.json

Fail-safe behaviour — If BITBUCKET_TOOLS_CONFIG is set but the file is missing or contains invalid JSON, the server raises an error on startup (explicit failure rather than silently ignoring the override). If the built-in default is missing, all tools are enabled.

Token tip — get_pull_request_diff accepts an optional path parameter to filter the diff to a single file, reducing token usage by ~95% on large PRs:

get_pull_request_diff(repo_slug, pull_request_id, path="src/services/myService.ts")

Token tip — get_pipeline_step_logs returns only the trailing 100 KiB of a step log by default (raw logs run to several MB on long steps). The response carries a truncated flag; widen the window with the absolute byte range start / end, or pass max_bytes=null for the whole log. Pass a service container UUID as log_uuid to read that service's log instead of the build container's. This endpoint needs a real pipeline UUID — resolve it via get_pipeline_run if you only have a build number.

get_pipeline_step_logs(repo_slug, pipeline_uuid="{adab6a1f-...}", step_uuid="{84fc6465-...}")

MCP Prompts

The server also exposes MCP Prompts — parameterised templates that compatible clients (Claude Code, Cursor, ...) surface as slash commands. Instead of remembering tool names, you invoke a prompt and the assistant orchestrates the right tools for you. They appear in the client's prompt picker (prompts/list).

PromptArgumentsWhat it does
review_pull_requestrepo_slug, pull_request_idFull AI review: metadata → diffstat → diff → comments → tasks, then Summary / Risk / Quality / Security / Recommendation
debug_pipeline_failurerepo_slug, pipeline_uuidDiagnose a failed pipeline: run → steps → failed-step logs, then Root cause / Failed step / Error / Fix
summarize_repositoryrepo_slugRepo overview: info → recent commits → open PRs → CI → issues, then Purpose / Activity / Health / Contributors
onboard_reviewerrepo_slug, pull_request_idHelp a new reviewer: PR context → commits → diff → review history, then Context / Changes / Review-so-far / Focus

Prompts are enabled/disabled in configs/tools.json under the top-level prompts key (separate from tools).

Credentials

Option 1: environment variables (recommended)

Put them in the env block of your MCP client configuration, as in the examples above, or export them in the shell that launches the server.

Option 2: System keychain (most secure)

bash
pip install 'bitbucket-mcp-py[keyring]'python3 -c "import keyring; keyring.set_password('bitbucket-mcp', 'bitbucket_token', 'YOUR_TOKEN')"

About .env: the server itself never reads a .env file. .env.example is a template for containers, which load it with --env-file .env or env_file: (the Docker, Makefile and docker-compose.yml setups); with uvx or python -m src.main, use option 1 or 2.

Docker (Alternative)

If you prefer running the server in a container:

bash
docker build -t bitbucket-mcp-py .docker run -d --name bitbucket-mcp --env-file .env bitbucket-mcp-py

Then configure your AI assistant to use docker exec:

json
{  "mcpServers": {    "bitbucket-mcp": {      "command": "docker",      "args": ["exec", "-i", "bitbucket-mcp", "python", "-m", "src.main", "--transport", "stdio"]    }  }}

Transports

The server speaks stdio by default (the standard transport for local MCP clients). For a network deployment it also supports Streamable HTTP (MCP spec 2025-03-26):

bash
# Streamable HTTP on localhost:8080python -m src.main --transport http --host 127.0.0.1 --port 8080

Clients connect to http://<host>:<port>/mcp (e.g. http://localhost:8080/mcp).

⚠️ --host defaults to 0.0.0.0, every interface. Without --multi-tenant the server has no authentication of its own: anyone who can reach the port acts with your Bitbucket token. Bind to 127.0.0.1 unless the port sits behind an authenticating proxy.

--transport sse (legacy Server-Sent Events) is still accepted but deprecated — it emits a DeprecationWarning. Prefer --transport http.

Stateless HTTP (horizontal scaling / serverless)

--stateless runs the Streamable HTTP transport without server-side sessions: no Mcp-Session-Id, a fresh transport per HTTP request. Any instance behind a load balancer can serve any request — no sticky sessions required.

bash
python -m src.main --transport http --host 0.0.0.0 --port 8080 --stateless

⚠️ Single-tenant by default. Without --multi-tenant the server serves its own process-wide Bitbucket token to every caller. Deploy it on a private network or behind an authenticated reverse proxy — or use multi-tenant mode, where each caller brings their own credentials.

--stateless requires --transport http (it is rejected on stdio and on the legacy sse, whose app ignores the setting). It also forces a single JSON response instead of an SSE stream, because edge/serverless runtimes cannot hold a streaming response open — there is currently no way to combine stateless with streaming.

A liveness endpoint is exposed on both HTTP transports for load balancers:

bash
curl http://localhost:8080/healthz    # {"status": "ok"}

In a container — the image's default CMD keeps it idle for exec-based stdio usage, so server mode is started by overriding the command:

bash
podman run -d --name bitbucket-mcp-http -p 127.0.0.1:8000:8000 --env-file .env bitbucket-mcp-py \  python -m src.main --transport http --host 0.0.0.0 --port 8000 --stateless

Inside the container --host 0.0.0.0 is required; -p 127.0.0.1:8000:8000 is what keeps the published port off the network, since this single-tenant server answers every caller with the .env token.

Works identically with docker run. The image exposes port 8000.

Environment variableDefaultPurpose
BITBUCKET_ALLOWED_HOSTS(unset)Comma-separated Host allowlist. Enables DNS-rebinding protection when set.
BITBUCKET_ALLOWED_ORIGINS(unset)Comma-separated Origin allowlist.
BITBUCKET_MAX_PAGES_HARD_CAP10Max pages a single tool call may fetch in stateless mode. Beyond it the response carries truncated: true — never a silent cut.

The two allowlists must be set together: an empty Host allowlist rejects every request (421), and an empty Origin allowlist rejects every browser client (403). Setting only one is refused at startup rather than silently locking the server out.

bash
export BITBUCKET_ALLOWED_HOSTS="mcp.example.com"export BITBUCKET_ALLOWED_ORIGINS="https://app.example.com"

With neither allowlist set, no DNS-rebinding protection is applied — appropriate for a server reached through a private network or a trusted proxy. Set them as soon as the server is exposed on a real hostname.

Multi-tenant HTTP (per-request credentials)

By default an HTTP deployment is single-tenant: every caller acts with the process-wide Bitbucket token. --multi-tenant changes that — each request carries the caller's own Bitbucket OAuth access token as Authorization: Bearer, and runs under that identity. The server holds no Bitbucket credential of its own.

bash
BITBUCKET_RESOURCE_SERVER_URL=https://mcp.example.com/mcp \  python -m src.main --transport http --host 0.0.0.0 --port 8080 --stateless --multi-tenant

The token is verified against GET /2.0/user, which yields the caller's account_id and default workspace; the same token is then reused for the downstream API calls, so no credential is ever stored or mapped. Unauthenticated requests get a 401 with a WWW-Authenticate challenge pointing at /.well-known/oauth-protected-resource/mcp. Since Bitbucket publishes no OAuth metadata, the server serves /.well-known/oauth-authorization-server itself, pointing at Bitbucket's endpoints — which is what lets it be added to claude.ai as a custom connector (Bitbucket sign-in through the Atlassian login); setup, what was verified and the residual risks in docs/deployment-modes.md.

What this buys you:

  • Isolation — one Bitbucket client per (identity, workspace); two callers never share one, and there is no process token to fall back on.
  • workspace=None means your workspace — resolved from the caller's memberships, never from BITBUCKET_WORKSPACE. With zero or several memberships there is no default and calls must name their workspace.
  • Audit trail — every call is logged to the bitbucket_mcp.audit logger with the tool, the account_id and the workspace. Never credentials.
  • Tighter defaults — tools flagged destructiveHint are refused unless explicitly enabled. The other write tools (comment, approve, create a pull request, run a pipeline…) stay available to every caller: set BITBUCKET_MULTITENANT_READ_ONLY=1 for a first deployment.
Environment variableDefaultPurpose
BITBUCKET_RESOURCE_SERVER_URL(required)Public URL of the MCP endpoint, e.g. https://mcp.example.com/mcp — the OAuth resource identifier
BITBUCKET_OAUTH_ISSUER_URL(this server's origin)Advertised authorization server. Leave unset: the server then publishes the OAuth metadata itself
BITBUCKET_CLIENT_CACHE_SIZE / _TTL128 / 900Bound on the per-identity client cache (LRU + TTL, seconds). TTL 0 builds a fresh client per request
BITBUCKET_TOKEN_CACHE_SIZE / _TTL256 / 300Bound on cached token verifications. The TTL is the revocation window — set it to 0 to verify every request
BITBUCKET_MULTITENANT_ALLOW_DESTRUCTIVE(off)Allow the destructive tools that configs/tools.json enables — by default decline_pull_request, delete_pull_request_comment, delete_pull_request_task; merge, stop_pipeline and delete_issue* stay disabled there
BITBUCKET_MULTITENANT_READ_ONLY(off)Expose read-only tools only
BITBUCKET_MULTITENANT_ALLOWED_WORKSPACES(unset: any account)Comma-separated workspace slugs — only their members are admitted, and no call can reach another workspace. Set it on any public endpoint

Spec deviation: the caller's Bitbucket token is accepted without an audience check and forwarded upstream as-is, which the MCP authorization spec (2025-11-25) forbids — trade-offs and residual risks in docs/deployment-modes.md.

Not supported in this mode: Bitbucket Repository/Workspace Access Tokens — they are not bound to a user account, so no identity can be derived. Use single-tenant HTTP for that. Bearer tokens require TLS: terminate HTTPS in front of the server.

stdio is unaffected — it stays single-user with environment variables, exactly as documented above.

See docs/deployment-modes.md for the full matrix of the three deployment modes and the threat model of each.

Kubernetes (k3s, datacenter, GKE)

Each release publishes a multi-arch image (ghcr.io/lawp09/bitbucket-mcp) and a Helm chart (oci://ghcr.io/lawp09/charts/bitbucket-mcp) that deploy the multi-tenant HTTP mode; publicUrl is the only required value:

bash
helm upgrade --install bitbucket-mcp oci://ghcr.io/lawp09/charts/bitbucket-mcp --version <version> \  -n bitbucket-mcp --create-namespace --set publicUrl=https://mcp.example.com

Ingress, GKE and network-policy notes: docs/deployment-kubernetes.md.

Development

bash
# Install dev dependenciesuv sync --extra dev
# Run testsuv run pytest tests/ -v
# Run specific testuv run pytest tests/test_client.py -v

Requirements

  • Python 3.12+
  • Bitbucket API token

License

MIT

References

来源:README.md,提交 a92ce75

工具

0
SourceWeft 曾在隔离沙箱中以无凭据方式启动该软件包一次,以列出其工具,但未能完成:软件包安装失败。

版本历史

5
  1. v1.29.2最新Oct 26, 2026
  2. v1.29.1Oct 9, 2026
  3. v1.29.0Oct 8, 2026
  4. v1.28.0Oct 8, 2026
  5. v1.26.1Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分