Bitbucket MCP server

Integrates with Bitbucket's REST APIs to enable repository management, pull request handling, and workspace operations with TypeScript-based error handling and pagination support
Back to servers
Setup instructions
Provider
Andi Ashari
Release date
Mar 25, 2025
Language
TypeScript
Package
Stats
51.2K downloads
91 stars

This MCP server connects AI assistants like Claude and Cursor to your Bitbucket repositories, allowing you to interact with your code, pull requests, and repositories using natural language.

Installation

Get Your Bitbucket Credentials

Option A: Scoped API Token (Recommended)

  1. Go to Atlassian API Tokens
  2. Click "Create API token with scopes"
  3. Select "Bitbucket" as the product
  4. Choose appropriate scopes:
    • For read-only access: repository, workspace
    • For full functionality: repository, workspace, pullrequest
  5. Copy the generated token (starts with ATATT)

Option B: App Password (Legacy - Will be deprecated by June 2026)

  1. Go to Bitbucket App Passwords
  2. Click "Create app password"
  3. Give it a name like "AI Assistant"
  4. Select necessary permissions:
    • Workspaces: Read
    • Repositories: Read (and Write for creating PRs/comments)
    • Pull Requests: Read (and Write for PR management)

Quick Test

# Set credentials (choose one method)

# Method 1: Scoped API Token (recommended)
export ATLASSIAN_USER_EMAIL="[email protected]"
export ATLASSIAN_API_TOKEN="your_scoped_api_token"

# OR Method 2: Legacy App Password
export ATLASSIAN_BITBUCKET_USERNAME="your_username"
export ATLASSIAN_BITBUCKET_APP_PASSWORD="your_app_password"

# List your workspaces
npx -y @aashari/mcp-server-atlassian-bitbucket get --path "/workspaces"

# List repositories in a workspace
npx -y @aashari/mcp-server-atlassian-bitbucket get --path "/repositories/your-workspace"

Connecting to AI Assistants

For Claude Desktop

Add this to your Claude configuration file (~/.claude/claude_desktop_config.json):

{
  "mcpServers": {
    "bitbucket": {
      "command": "npx",
      "args": ["-y", "@aashari/mcp-server-atlassian-bitbucket"],
      "env": {
        "ATLASSIAN_USER_EMAIL": "[email protected]",
        "ATLASSIAN_API_TOKEN": "your_scoped_api_token"
      }
    }
  }
}

Restart Claude Desktop, and you'll see the bitbucket server in the status bar.

For Other AI Assistants

Most AI assistants that support MCP can use this server:

Option 1: Use npx (recommended): Configure your AI assistant to run: npx -y @aashari/mcp-server-atlassian-bitbucket

Option 2: Install globally:

npm install -g @aashari/mcp-server-atlassian-bitbucket

Alternative: Configuration File

Create ~/.mcp/configs.json for system-wide configuration:

{
  "bitbucket": {
    "environments": {
      "ATLASSIAN_USER_EMAIL": "[email protected]",
      "ATLASSIAN_API_TOKEN": "your_scoped_api_token",
      "BITBUCKET_DEFAULT_WORKSPACE": "your_main_workspace"
    }
  }
}

Available Tools

This MCP server provides 6 generic tools that can access any Bitbucket API endpoint:

Tool Description Parameters
bb_get GET any Bitbucket API endpoint (read data) path, queryParams?, jq?, outputFormat?
bb_post POST to any endpoint (create resources) path, body, queryParams?, jq?, outputFormat?
bb_put PUT to any endpoint (replace resources) path, body, queryParams?, jq?, outputFormat?
bb_patch PATCH any endpoint (partial updates) path, body, queryParams?, jq?, outputFormat?
bb_delete DELETE any endpoint (remove resources) path, queryParams?, jq?, outputFormat?
bb_clone Clone a repository locally workspaceSlug?, repoSlug, targetPath

Common Parameters

  • path (required): API endpoint path starting with / (the /2.0 prefix is added automatically)
  • queryParams (optional): Query parameters as key-value pairs
  • jq (optional): JMESPath expression to filter/transform the response
  • outputFormat (optional): "toon" (default, uses 30-60% fewer tokens) or "json"
  • body (required for POST/PUT/PATCH): Request body as JSON object

Common API Paths

# Workspaces & Repositories
/workspaces
/repositories/{workspace}
/repositories/{workspace}/{repo}
/repositories/{workspace}/{repo}/refs/branches
/repositories/{workspace}/{repo}/commits
/repositories/{workspace}/{repo}/src/{commit}/{filepath}

# Pull Requests
/repositories/{workspace}/{repo}/pullrequests
/repositories/{workspace}/{repo}/pullrequests/{id}
/repositories/{workspace}/{repo}/pullrequests/{id}/diff
/repositories/{workspace}/{repo}/pullrequests/{id}/comments

Usage Examples

Explore Repositories

# List all repositories in a workspace
npx -y @aashari/mcp-server-atlassian-bitbucket get \
  --path "/repositories/myworkspace" \
  --jq "values[].name"

# Get repository details
npx -y @aashari/mcp-server-atlassian-bitbucket get \
  --path "/repositories/myworkspace/myrepo" \
  --jq "{name: name, language: language}"

# List branches
npx -y @aashari/mcp-server-atlassian-bitbucket get \
  --path "/repositories/myworkspace/myrepo/refs/branches"

Working with Pull Requests

# List open pull requests
npx -y @aashari/mcp-server-atlassian-bitbucket get \
  --path "/repositories/myworkspace/myrepo/pullrequests" \
  --query-params '{"state": "OPEN"}' \
  --jq "values[*].{id: id, title: title}"

# Create a pull request
npx -y @aashari/mcp-server-atlassian-bitbucket post \
  --path "/repositories/myworkspace/myrepo/pullrequests" \
  --body '{"title": "My PR", "source": {"branch": {"name": "feature"}}, "destination": {"branch": {"name": "main"}}}'

# Add a comment to a PR
npx -y @aashari/mcp-server-atlassian-bitbucket post \
  --path "/repositories/myworkspace/myrepo/pullrequests/42/comments" \
  --body '{"content": {"raw": "Looks good!"}}'

Optimizing Token Usage

  1. Always use JMESPath filtering to extract only needed fields
  2. Use pagination by setting pagelen query parameter to limit results
  3. Leverage TOON format (default) for 30-60% token savings vs JSON
  4. Use query parameters for server-side filtering before results are returned
# Example of optimized query
npx -y @aashari/mcp-server-atlassian-bitbucket get \
  --path "/repositories/workspace/repo/pullrequests" \
  --query-params '{"state": "OPEN", "pagelen": "5"}' \
  --jq "values[*].{id: id, title: title}"

Troubleshooting

Authentication Issues

If you see "Authentication failed" or "403 Forbidden":

  1. Verify your credentials match the authentication method:

    • For Scoped API Tokens: Use ATLASSIAN_USER_EMAIL + ATLASSIAN_API_TOKEN
    • For App Passwords: Use ATLASSIAN_BITBUCKET_USERNAME + ATLASSIAN_BITBUCKET_APP_PASSWORD
  2. Test credentials with CLI:

    export ATLASSIAN_USER_EMAIL="[email protected]"
    export ATLASSIAN_API_TOKEN="your_token"
    npx -y @aashari/mcp-server-atlassian-bitbucket get --path "/workspaces"
    

Resource Not Found (404)

  1. Check API path case-sensitivity
  2. Use workspace slug (from URL), not display name
  3. Verify the resource exists by listing parent resources first

Enable Debug Mode

# For CLI testing
DEBUG=true npx -y @aashari/mcp-server-atlassian-bitbucket get --path "/workspaces"

# For Claude Desktop - add to config
{
  "mcpServers": {
    "bitbucket": {
      "env": {
        "DEBUG": "true",
        "ATLASSIAN_USER_EMAIL": "...",
        "ATLASSIAN_API_TOKEN": "..."
      }
    }
  }
}

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "bitbucket" '{"command":"npx","args":["-y","@aashari/mcp-server-atlassian-bitbucket"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "bitbucket": {
            "command": "npx",
            "args": [
                "-y",
                "@aashari/mcp-server-atlassian-bitbucket"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "bitbucket": {
            "command": "npx",
            "args": [
                "-y",
                "@aashari/mcp-server-atlassian-bitbucket"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later