A comprehensive Model Context Protocol (MCP) server that enables Claude to interact with Bitbucket Cloud repositories through simple token-based authentication. Provides full repository management, pull request workflows, branch operations, commit analysis, and issue tracking capabilities.
- π Simple Token Authentication - API Token or Repository Access Token (no OAuth complexity)
- π οΈ 6 Consolidated MCP Tools - Complete Bitbucket API integration with action-based routing (46 total actions)
- π Repository Management - Full CRUD operations for repositories
- πΏ Branch Operations - Git Flow support with branching model integration
- π Pull Request Workflows - Complete code review lifecycle with approvals and comments
- π Commit Analysis - History tracking, diffs, and patch generation
- π Issue Tracking - Comprehensive issue management with project organization
- π Type-Safe - Full TypeScript implementation with Zod validation
- π High Performance - Rate limiting and optimized connection pooling
- π File-Based Logging - Structured logging to files (no web server overhead)
- π― Action-Based Routing - Single tool per category with action parameter for cleaner API
- Node.js 18+
- Bitbucket Cloud account
- Claude Desktop, Web, or API access
# Clone the repository
git clone https://bitbucket.org/gohcl/bitbucket-mcp.git
cd bitbucket-mcp
# Install dependencies
npm install
# Build the project
npm run buildChoose ONE of the following authentication methods:
-
Generate API Token:
- Go to Bitbucket Personal Settings β API tokens
- Click "Create API token"
- Give it a descriptive label (e.g., "Claude MCP Server")
- Select permissions: Repositories (Read/Write), Pull requests (Read/Write)
- Copy the token immediately (cannot retrieve later)
-
Configure Environment:
# Copy environment template cp .env.example .env # Edit .env and add: BITBUCKET_USERNAME=your_bitbucket_username BITBUCKET_API_TOKEN=your_api_token_here BITBUCKET_WORKSPACE=your_workspace_slug # Optional default workspace
-
Generate Repository Token:
- Go to Repository β Settings β Access tokens
- Click "Create repository access token"
- Give it a label and select permissions
- Copy the token immediately
-
Configure Environment:
# Edit .env and add: BITBUCKET_REPOSITORY_ACCESS_TOKEN=your_repo_token_here BITBUCKET_WORKSPACE=your_workspace_slug # Optional
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"bitbucket": {
"command": "node",
"args": ["/absolute/path/to/bitbucket-mcp/dist/index.js"],
"env": {
"BITBUCKET_USERNAME": "your_username",
"BITBUCKET_API_TOKEN": "your_token",
"BITBUCKET_WORKSPACE": "your_workspace"
}
}
}
}# Start the server (if running standalone)
npm start
# Or restart Claude Desktop to load the MCP serverv2.1 introduces action-based routing: Each category now has a single consolidated tool that accepts an action parameter to determine the specific operation. This simplifies the tool interface while maintaining all functionality.
| Category | Actions | Consolidated Tool |
|---|---|---|
| Workspace | 2 | manage_workspaces (list, get) |
| Repository | 5 | manage_repositories (list, get, create, update, delete) |
| Branch | 7 | manage_branches (list, get, create, delete, get_model, get_permissions, get_reviewers) |
| Pull Request | 9 | manage_pull_requests (list, get, create, approve, unapprove, merge, decline, add_comment, get_comments) |
| Commit | 4 | manage_commits (list, get, get_diff, get_patch) |
| Issue | 19 | manage_issues (19 actions for CRUD, comments, metadata, and workflow operations) |
Tool: manage_workspaces with actions: list, get
"List all my Bitbucket workspaces"
β manage_workspaces({ action: 'list' })
"Show details for workspace my-org"
β manage_workspaces({ action: 'get', workspace: 'my-org' })
Tool: manage_repositories with actions: list, get, create, update, delete
"List all repositories in my-workspace"
β manage_repositories({ action: 'list', workspaceSlug: 'my-workspace' })
"Create a new private repository called 'awesome-project'"
β manage_repositories({ action: 'create', workspaceSlug: 'my-workspace', name: 'awesome-project', isPrivate: true })
"Update the description for my-workspace/my-repo"
β manage_repositories({ action: 'update', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', description: 'New description' })
"Delete repository my-workspace/old-project"
β manage_repositories({ action: 'delete', workspaceSlug: 'my-workspace', repoSlug: 'old-project' })
Tool: manage_branches with actions: list, get, create, delete, get_model, get_permissions, get_reviewers
"List all branches in my-workspace/my-repo"
β manage_branches({ action: 'list', workspaceSlug: 'my-workspace', repoSlug: 'my-repo' })
"Create a new branch called 'feature/auth' from develop"
β manage_branches({ action: 'create', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', branchName: 'feature/auth', sourceBranch: 'develop' })
"Show the branching model for my-workspace/my-repo"
β manage_branches({ action: 'get_model', workspaceSlug: 'my-workspace', repoSlug: 'my-repo' })
"Delete the old-feature branch"
β manage_branches({ action: 'delete', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', branchName: 'old-feature' })
Tool: manage_pull_requests with actions: list, get, create, approve, unapprove, merge, decline, add_comment, get_comments
"List open pull requests in my-workspace/my-repo"
β manage_pull_requests({ action: 'list', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', state: 'OPEN' })
"Create a pull request from feature/auth to main titled 'Add authentication'"
β manage_pull_requests({ action: 'create', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', title: 'Add authentication', sourceBranch: 'feature/auth', destinationBranch: 'main' })
"Approve pull request #42"
β manage_pull_requests({ action: 'approve', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', pullRequestId: 42 })
"Add a comment to PR #15: 'Great work! Just one suggestion...'"
β manage_pull_requests({ action: 'add_comment', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', pullRequestId: 15, content: 'Great work! Just one suggestion...' })
"Merge pull request #42"
β manage_pull_requests({ action: 'merge', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', pullRequestId: 42 })
Tool: manage_commits with actions: list, get, get_diff, get_patch
"List recent commits on the main branch"
β manage_commits({ action: 'list', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', branch: 'main' })
"Show me the diff for commit abc123"
β manage_commits({ action: 'get_diff', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', commitHash: 'abc123' })
"Get details for commit abc123def456"
β manage_commits({ action: 'get', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', commitHash: 'abc123def456' })
"Generate a patch for commit abc123"
β manage_commits({ action: 'get_patch', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', commitHash: 'abc123' })
Tool: manage_issues with 19 actions for comprehensive issue management including CRUD operations, comments, components, milestones, versions, assignment, voting, and watching
"Create a bug report titled 'Login page crashes on mobile'"
β manage_issues({ action: 'create', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', title: 'Login page crashes on mobile', kind: 'bug' })
"List all open issues assigned to john-doe"
β manage_issues({ action: 'list', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', state: 'open', assignee: 'john-doe' })
"Add a comment to issue #123: 'Fixed in latest commit'"
β manage_issues({ action: 'add_comment', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', issueId: 123, content: 'Fixed in latest commit' })
"Assign issue #45 to jane-smith"
β manage_issues({ action: 'assign', workspaceSlug: 'my-workspace', repoSlug: 'my-repo', issueId: 45, assignee: 'jane-smith' })
# Method 1: API Token (Recommended - Full Access)
BITBUCKET_USERNAME=your_username
BITBUCKET_API_TOKEN=your_api_token
# Method 2: Repository Access Token (Alternative - Single Repo)
BITBUCKET_REPOSITORY_ACCESS_TOKEN=your_repo_token
# Optional Default Workspace
BITBUCKET_WORKSPACE=your_workspace_slug# Log level: debug, info, warn, error
LOG_LEVEL=info
# Enable console logging
ENABLE_CONSOLE_LOGGING=true
# Enable file logging
ENABLE_FILE_LOGGING=false
# Log file path (if file logging enabled)
LOG_FILE_PATH=./logs/bitbucket-mcp.log
# Enable structured logging with metadata
ENABLE_STRUCTURED_LOGGING=true# Maximum concurrent requests
RATE_LIMIT_MAX_CONCURRENT=10
# Minimum time between requests (ms)
RATE_LIMIT_MIN_TIME=100
# Request reservoir size (burst capacity)
RATE_LIMIT_RESERVOIR=100
# Amount to refill reservoir
RATE_LIMIT_RESERVOIR_REFRESH_AMOUNT=100
# Refresh interval (ms) - 1 minute default
RATE_LIMIT_RESERVOIR_REFRESH_INTERVAL=60000| Feature | API Token | Repository Token |
|---|---|---|
| Username Required | β Yes | β No |
| Access Scope | All repositories user can access | Single repository only |
| Use Case | General development, multiple repos | CI/CD, single repo automation |
| Token Format | Starts with ATBBT |
Repository-specific |
| Atlassian Recommendation | β Official recommendation | Specialized use cases |
| Generate At | Personal Settings β API tokens | Repository β Settings β Access tokens |
The v2.0 architecture removes OAuth complexity and persistent web services in favor of simple token-based authentication:
Removed in v2.0:
- β OAuth 2.0 authorization flow and token refresh logic
- β Persistent Express web server
- β Web-based log viewer with WebSockets
- β Encrypted token storage infrastructure
- β OAuth callback handling
Simplified in v2.0:
- β Direct API Token or Repository Token authentication
- β File-based logging only (no web viewer)
- β ~40% code reduction (~1,900 lines removed)
- β 7 fewer npm dependencies
- β Faster startup time
- β Easier multi-instance support
bitbucket-mcp/
βββ src/
β βββ tools/ # MCP tool implementations (6 categories)
β β βββ base-tool.ts # Base tool infrastructure
β β βββ workspace-tools.ts
β β βββ repository-tools.ts
β β βββ branch-tools.ts
β β βββ pull-request-tools.ts
β β βββ commit-tools.ts
β β βββ issue-tools.ts
β β βββ index.ts # Tool exports and documentation
β βββ types.ts # TypeScript types and Zod schemas
β βββ config.ts # Configuration management
β βββ logger.ts # Structured logging system
β βββ bitbucket-client.ts # HTTP API client
β βββ auth-service.ts # Token authentication service
β βββ rate-limiter.ts # API rate limiting
β βββ error-handler.ts # Centralized error handling
β βββ index.ts # Main MCP server
βββ dist/ # Compiled JavaScript
βββ docs/ # Documentation
βββ .env.example # Environment template
βββ package.json
- Tool System - 6 consolidated MCP tools with action-based routing (46 total actions across Workspace, Repository, Branch, PR, Commit, Issue domains)
- Authentication - Simple token-based auth with dual method support
- HTTP Client - Axios-based Bitbucket API client with rate limiting
- Type Safety - Full TypeScript with Zod runtime validation
- Error Handling - Comprehensive error management and user-friendly messages
- Logging - Structured logging with multiple transports (console, file)
npm run build # Compile TypeScript to dist/
npm run dev # Watch mode for development
npm run start # Start the MCP server
npm run lint # ESLint code checking
npm test # Run Jest tests (if configured)# Clone the repository
git clone https://bitbucket.org/gohcl/bitbucket-mcp.git
cd bitbucket-mcp
# Install dependencies
npm install
# Compile TypeScript
npm run build
# Start the server
npm start- Make changes to TypeScript files in
src/ - Run
npm run buildto compile - Test with Claude Desktop or standalone
- Run
npm run lintbefore committing - Follow existing TypeScript patterns and conventions
- Token-Based Authentication - Simple, secure API token or repository token authentication
- No Token Storage - Tokens provided via environment variables (not stored on disk)
- Input Validation - Comprehensive sanitization and Zod schema validation
- Rate Limiting - Built-in throttling to respect Bitbucket API limits
- Audit Logging - Comprehensive logging with sensitive data redaction
- Minimal Attack Surface - No web server, no OAuth callbacks, no persistent storage
- Never commit tokens - Use
.envfile (excluded from git) - Limit token permissions - Only grant necessary repository and PR permissions
- Rotate tokens regularly - Generate new tokens periodically
- Use workspace-scoped tokens - Limit API tokens to specific workspaces when possible
- Repository tokens for CI/CD - Use repository tokens for automated workflows (single repo only)
- Monitor token usage - Review Bitbucket audit logs regularly
- API Reference - Complete tool documentation with examples
- Configuration Guide - Advanced configuration options
- Architecture Guide - System design and patterns
- Getting Started - Detailed setup instructions
- Logging Guide - Logging configuration and best practices
- Repository: bitbucket.org/gohcl/bitbucket-mcp
- Workspace:
gohcl(Health Care Logistics) - Project:
SOLN(Stat Solutions) - Type: Private Repository
- Language: TypeScript
- Version: 2.1.0
- Bitbucket Cloud API - Official API documentation
- Model Context Protocol - MCP specification
- Claude Documentation - Claude AI documentation
- Bitbucket API Tokens - API token setup guide
If you're upgrading from v1.x (OAuth-based):
- Authentication: OAuth 2.0 removed β Simple token-based auth added
- Web Server: Removed (no OAuth callbacks or log viewer)
- Token Storage: Removed (tokens now via environment variables only)
- Tools: 26 β 24 tools (removed
get_auth_urlandexchange_code_for_token) - v2.1 Tools: 24 β 6 consolidated tools with action-based routing (46 actions total)
-
Remove OAuth Environment Variables:
# Remove these from .env: BITBUCKET_CLIENT_ID BITBUCKET_CLIENT_SECRET BITBUCKET_REFRESH_TOKEN MCP_SERVER_PORT TOKEN_ENCRYPTION_KEY TOKEN_STORAGE_FILE_PATH -
Add Token Authentication:
# Add these to .env: BITBUCKET_USERNAME=your_username BITBUCKET_API_TOKEN=your_api_token -
Generate API Token (see Quick Start above)
-
Update Claude Desktop Config:
- Replace OAuth env vars with token env vars
- Remove any OAuth-related configuration
-
Test: Restart Claude Desktop and verify tools work
See MIGRATION.md for detailed migration guide.
User: "List all repositories in my-workspace"
Claude: *uses manage_repositories with action: 'list'*
User: "Create a new private repository called 'api-service' in my-workspace with description 'Backend API service'"
Claude: *uses manage_repositories with action: 'create'*
User: "Show me details for my-workspace/api-service"
Claude: *uses manage_repositories with action: 'get'*
User: "Create a feature branch called 'feature/user-auth' from develop in my-workspace/api-service"
Claude: *uses manage_branches with action: 'create'*
User: "Make some changes..."
User: "Create a pull request from feature/user-auth to develop titled 'Add user authentication system'"
Claude: *uses manage_pull_requests with action: 'create'*
User: "Add a comment to PR #5: 'Please review the error handling in auth.ts'"
Claude: *uses manage_pull_requests with action: 'add_comment'*
User: "Approve PR #5"
Claude: *uses manage_pull_requests with action: 'approve'*
User: "Merge PR #5"
Claude: *uses manage_pull_requests with action: 'merge'*
User: "Show me the last 10 commits on the main branch of my-workspace/api-service"
Claude: *uses manage_commits with action: 'list'*
User: "Get the diff for commit abc123"
Claude: *uses manage_commits with action: 'get_diff'*
User: "Generate a patch file for commit abc123"
Claude: *uses manage_commits with action: 'get_patch'*
User: "Create a bug report in my-workspace/api-service titled 'Login endpoint returns 500 on invalid credentials'"
Claude: *uses manage_issues with action: 'create'*
User: "List all open bugs"
Claude: *uses manage_issues with action: 'list' and filters*
User: "Add a comment to issue #12: 'Fixed in commit abc123'"
Claude: *uses manage_issues with action: 'add_comment'*
User: "Assign issue #12 to john-doe"
Claude: *uses manage_issues with action: 'assign'*
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add documentation
- Run tests:
npm test - Lint your code:
npm run lint - Commit:
git commit -m 'Add amazing feature' - Push:
git push origin feature/amazing-feature - Submit a pull request to the
developbranch
- Follow existing TypeScript patterns and conventions
- Add comprehensive JSDoc documentation for all public APIs
- Include input validation and error handling
- Update tests and documentation for all changes
- Follow the established architecture patterns
- Use semantic commit messages
MIT License - see LICENSE file for details.
Authentication Errors:
- Verify token is copied correctly (no extra spaces)
- Ensure username matches your Bitbucket username exactly
- Check token permissions include Repository and Pull Request access
- Verify token hasn't expired or been revoked
Tool Not Working:
- Verify workspace and repository slugs are correct (case-sensitive)
- Check you have appropriate permissions for the operation
- Review logs for detailed error messages
- Ensure you're using the correct authentication method
Rate Limiting:
- Bitbucket has rate limits (default: 1000 requests/hour)
- Server includes built-in rate limiting to prevent quota exhaustion
- Adjust
RATE_LIMIT_*environment variables if needed
- Setup Questions: See Getting Started Guide
- Configuration Issues: Check Configuration Guide
- API Questions: Reference API Documentation
- Architecture Questions: Review Architecture Guide
- Bitbucket API: Official Bitbucket Cloud API Docs
- β Action-Based Routing - 6 consolidated tools instead of 24 individual tools
- β
Cleaner API - Single tool per domain with
actionparameter - β 46 Total Actions - All functionality preserved across workspace, repository, branch, PR, commit, and issue domains
- β Better Organization - Logical grouping of related operations
- β Simplified Discovery - Easier to find and use the right tool
- β Backward Compatible - Maintains all existing capabilities
- β Simplified Authentication - Removed OAuth, added simple token-based auth
- β No Web Server - Removed persistent Express server and log viewer
- β Reduced Dependencies - 7 fewer npm packages
- β 40% Code Reduction - ~1,900 lines of code removed
- β Faster Startup - No OAuth initialization or web server startup
- β Easier Configuration - Simple environment variables only
- β Better Multi-Instance Support - No port conflicts or shared state
- π΄ OAuth Removed - Must migrate to API Token or Repository Token
- π΄ Web Server Removed - No log viewer or OAuth callbacks
- π΄ Tools Removed -
get_auth_urlandexchange_code_for_tokenremoved - π΄ Configuration Changed - New environment variables required
- π‘ Tool Consolidation - 24 individual tools β 6 consolidated tools with actions
- π‘ Action Parameter Required - All tools now require an
actionparameter to specify the operation - π‘ Tool Name Changes - Use
manage_*tools instead of individual operation tools
See MIGRATION.md for upgrade instructions.
Ready to supercharge your Bitbucket workflows with Claude?
Get started in minutes with simple token-based authentication - no OAuth complexity, no web servers, just powerful Bitbucket integration! π