Bitbucket MCP server

Integrates with Bitbucket Cloud and Server APIs to manage pull request workflows including creation, updates, merging, branch management, code review operations, and diff retrieval with configurable context lines.
Back to servers
Setup instructions
Provider
Parth Dogra
Release date
Jun 05, 2025
Language
TypeScript
Stats
6 stars

The Bitbucket MCP server provides a powerful interface for interacting with Bitbucket repositories (both Cloud and Server versions) through the Model Context Protocol. It offers tools for managing pull requests, branches, files, and code reviews programmatically.

Installation and Configuration

Using npx (Recommended)

The easiest way to get started is using npx. Add this configuration to your MCP settings file:

{
  "mcpServers": {
    "bitbucket": {
      "command": "npx",
      "args": [
        "-y",
        "@nexus2520/bitbucket-mcp-server"
      ],
      "env": {
        "BITBUCKET_USERNAME": "your-username",
        "BITBUCKET_APP_PASSWORD": "your-app-password"
      }
    }
  }
}

For Bitbucket Server users, use this configuration instead:

{
  "mcpServers": {
    "bitbucket": {
      "command": "npx",
      "args": [
        "-y",
        "@nexus2520/bitbucket-mcp-server"
      ],
      "env": {
        "BITBUCKET_USERNAME": "[email protected]",
        "BITBUCKET_TOKEN": "your-http-access-token",
        "BITBUCKET_BASE_URL": "https://bitbucket.yourcompany.com"
      }
    }
  }
}

From Source

If you prefer to run from source:

  1. Clone or download the repository
  2. Install dependencies:
    npm install
    
  3. Build the TypeScript code:
    npm run build
    

Authentication Setup

Creating a Bitbucket App Password

  1. Log in to your Bitbucket account
  2. Navigate to: https://bitbucket.org/account/settings/app-passwords/
  3. Click "Create app password"
  4. Give it a descriptive label (e.g., "MCP Server")
  5. Select the following permissions:
    • Account: Read
    • Repositories: Read, Write
    • Pull requests: Read, Write
  6. Click "Create"
  7. Important: Copy the generated password immediately (you won't be able to see it again!)

Running the Setup Script

node scripts/setup-auth.js

This will guide you through the authentication setup process.

Usage Examples

Working with Pull Requests

Get Pull Request Details

{
  "tool": "get_pull_request",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123
  }
}

List Pull Requests

{
  "tool": "list_pull_requests",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "state": "OPEN",
    "author": "username",
    "limit": 25,
    "start": 0
  }
}

Create a Pull Request

{
  "tool": "create_pull_request",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "title": "Add new feature",
    "source_branch": "feature/new-feature",
    "destination_branch": "main",
    "description": "This PR adds a new feature...",
    "reviewers": ["john.doe", "jane.smith"],
    "close_source_branch": true
  }
}

Update a Pull Request

{
  "tool": "update_pull_request",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "title": "Updated title",
    "description": "Updated description",
    "destination_branch": "develop",
    "reviewers": ["new.reviewer"]
  }
}

Add Comments to a Pull Request

// General comment
{
  "tool": "add_comment",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "comment_text": "Great work on this PR!"
  }
}

// Inline comment on specific line
{
  "tool": "add_comment",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "comment_text": "Consider extracting this into a separate function",
    "file_path": "src/utils/helpers.js",
    "line_number": 42,
    "line_type": "CONTEXT"
  }
}

// Reply to existing comment
{
  "tool": "add_comment",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "comment_text": "I agree with this suggestion",
    "parent_comment_id": 456
  }
}

Merge a Pull Request

{
  "tool": "merge_pull_request",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "merge_strategy": "squash",
    "close_source_branch": true,
    "commit_message": "Custom merge message"
  }
}

Branch Management

List Branches

{
  "tool": "list_branches",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "filter": "feature",
    "limit": 25,
    "start": 0
  }
}

Get Branch Details

{
  "tool": "get_branch",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "branch_name": "feature/new-feature",
    "include_merged_prs": false
  }
}

List Branch Commits

{
  "tool": "list_branch_commits",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "branch_name": "feature/new-feature",
    "author": "[email protected]",
    "since": "2025-01-01T00:00:00Z",
    "include_merge_commits": false,
    "search": "feature",
    "limit": 100
  }
}

Delete a Branch

{
  "tool": "delete_branch",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "branch_name": "feature/old-feature",
    "force": false
  }
}

Code Review Actions

Get Pull Request Diff

{
  "tool": "get_pull_request_diff",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "include_patterns": ["src/**/*"],
    "exclude_patterns": ["*.test.js", "*.spec.js"],
    "context_lines": 5
  }
}

Approve a Pull Request

{
  "tool": "approve_pull_request",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123
  }
}

Request Changes on a Pull Request

{
  "tool": "request_changes",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "comment": "Please address the following issues..."
  }
}

File Operations

List Directory Content

{
  "tool": "list_directory_content",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "path": "src/components",
    "branch": "main"
  }
}

Get File Content

{
  "tool": "get_file_content",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "file_path": "src/index.ts",
    "branch": "main",
    "start_line": 1,
    "line_count": 100
  }
}

Advanced Features

Adding Comments with Code Snippets

Instead of using line numbers, you can find the right location with code snippets:

{
  "tool": "add_comment",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "comment_text": "This variable name could be more descriptive",
    "file_path": "src/components/Button.res",
    "code_snippet": "let isDisabled = false",
    "search_context": {
      "before": ["let onClick = () => {"],
      "after": ["setLoading(true)"]
    },
    "match_strategy": "best"
  }
}

Adding Code Suggestions

{
  "tool": "add_comment",
  "arguments": {
    "workspace": "PROJ",
    "repository": "my-repo",
    "pull_request_id": 123,
    "comment_text": "This function could be simplified using array methods.",
    "file_path": "src/utils/calculations.js",
    "line_number": 50,
    "suggestion_end_line": 55,
    "line_type": "CONTEXT",
    "suggestion": "function calculateTotal(items) {\n  return items.reduce((sum, item) => sum + item.price, 0);\n}"
  }
}

Troubleshooting

  1. Authentication errors: Double-check your username and app password
  2. 404 errors: Verify the workspace, repository slug, and PR ID
  3. Permission errors: Ensure your app password has the required permissions

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","@nexus2520/bitbucket-mcp-server"],"env":{"BITBUCKET_USERNAME":"your-username","BITBUCKET_APP_PASSWORD":"your-app-password"}}'

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",
                "@nexus2520/bitbucket-mcp-server"
            ],
            "env": {
                "BITBUCKET_USERNAME": "your-username",
                "BITBUCKET_APP_PASSWORD": "your-app-password"
            }
        }
    }
}

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",
                "@nexus2520/bitbucket-mcp-server"
            ],
            "env": {
                "BITBUCKET_USERNAME": "your-username",
                "BITBUCKET_APP_PASSWORD": "your-app-password"
            }
        }
    }
}

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