bitbucket-mcp
CLAUDE.md166 starsChanged 13 months agoMITView on GitHub
This is a Model Context Protocol (MCP) server that provides AI assistants with programmatic access to Bitbucket Cloud and Server APIs. It's published as an npm package (bitbucket-mcp) and enables operations on repositories, pull requests, pipelines, and more through a standardized MCP interface. Safety First: No DELETE operations are used to prevent accidental data loss. Every PR is analyzed with CodeQL for security. BitbucketClient Class: Main API wrapper that handles: - Axios-based HTTP client with authentication (token or username/password) -…
- Installs packages
The file
We split this CLAUDE.md into the rules it gives an agent
7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Safety First: No DELETE operations are used to prevent accidental data loss.
- Distinctive: line 54
All Bitbucket API operations grouped by category:
- Very specific: line 76
All tools are registered in the ListToolsRequestSchema handler with JSON schemas for input validation.
- Very specific: line 111
When BITBUCKET_ENABLE_DANGEROUS is true, enables tools like:
- Distinctive: line 127
Project install: Add to MCP client config pointing to local or global install
- Distinctive: line 135
All API responses are returned as JSON-stringified text content in MCP format
- Distinctive: line 138
No test files currently exist in the repository
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a Model Context Protocol (MCP) server that provides AI assistants with programmatic access to Bitbucket Cloud and Server APIs. It's published as an npm package (bitbucket-mcp) and enables operations on repositories, pull requests, pipelines, and more through a standardized MCP interface.
Safety First: No DELETE operations are used to prevent accidental data loss. Every PR is analyzed with CodeQL for security.
Development Commands
Build and Run
npm install # Install dependencies
npm run build # Compile TypeScript to dist/ (also sets executable permission)
npm start # Run compiled server from dist/index.js
npm run dev # Run in development mode with watch (uses tsx)Testing and Quality
npm test # Run Jest tests
npm run lint # Run ESLint on src/**/*.tsMCP Inspector
npm run inspector # Launch MCP inspector for debugging toolsPublishing
npm run publish:patch # Bump patch version and publish
npm run publish:minor # Bump minor version and publish
npm run publish:major # Bump major version and publish
npm run release # Alias for publish:patchArchitecture
Single-File Design
The entire server implementation lives in src/index.ts (~4,500 lines). This includes:
- Type definitions for Bitbucket API entities
- BitbucketClient class with all API methods
- MCP server setup and tool registration
- Logging configuration
Core Components
BitbucketClient Class: Main API wrapper that handles:
- Axios-based HTTP client with authentication (token or username/password)
- URL normalization (converts web URLs like
bitbucket.org/workspaceto API URLs) - All Bitbucket API operations grouped by category:
- Repository operations (list, get details)
- Pull request operations (CRUD, approve, merge, decline, etc.)
- PR comments (general and inline)
- PR tasks (TODO items)
- PR diffs and patches
- Pipeline operations (list, run, stop, get logs)
Environment Configuration:
BITBUCKET_URL: API base URL (defaults to https://api.bitbucket.org/2.0)BITBUCKET_TOKENORBITBUCKET_USERNAME+BITBUCKET_PASSWORD: AuthenticationBITBUCKET_WORKSPACE: Default workspace (auto-extracted from URL if not provided)BITBUCKET_ENABLE_DANGEROUS: Enable destructive operations (disabled by default)BITBUCKET_LOG_*: Logging configuration (file, directory, disable, per-CWD)
Logging: Uses Winston with file-based logging to OS-specific directories:
- macOS:
~/Library/Logs/bitbucket-mcp/ - Windows:
%LOCALAPPDATA%/bitbucket-mcp/ - Linux:
~/.local/state/bitbucket-mcp/or$XDG_STATE_HOME/bitbucket-mcp/
MCP Tool Registration
All tools are registered in the ListToolsRequestSchema handler with JSON schemas for input validation. Tools are then routed to corresponding BitbucketClient methods in the CallToolRequestSchema handler.
URL Normalization Logic
The normalizeBitbucketConfig() function handles backward compatibility:
- Converts
https://bitbucket.org/<workspace>→https://api.bitbucket.org/2.0(auto-extracts workspace) - Ensures
https://api.bitbucket.orgalways has/2.0suffix - Removes trailing slashes for consistent axios baseURL
Key Implementation Details
Authentication
Supports two methods (checked in order):
- Token authentication via
BITBUCKET_TOKEN - Basic auth via
BITBUCKET_USERNAME+BITBUCKET_PASSWORD
Note: BITBUCKET_USERNAME is typically your email address for Bitbucket Cloud.
Inline PR Comments
Uses special inline parameter format:
{
path: "src/file.ts",
to: 15, // Line in NEW version (for added/modified lines)
from: 10 // Line in OLD version (for deleted/modified lines)
}Pipeline Operations
Requires "Pipelines: Read" permission in Bitbucket app password. Target configuration uses:
ref_type+ref_namefor branch/tag- Optional
commit_hashfor specific commit - Optional
selector_type+selector_patternfor pipeline selection
Dangerous Operations
When BITBUCKET_ENABLE_DANGEROUS is true, enables tools like:
deletePullRequestCommentdeletePullRequestTask
Build System
- TypeScript: Compiles ES2020 with strict mode to
dist/ - Module System: ESM (type: "module" in package.json)
- Entry Point:
dist/index.js(has shebang for CLI usage) - Bin: Package exposes
bitbucket-mcpcommand globally
Integration
Designed to be used via:
- NPX:
npx -y bitbucket-mcp@latest(recommended) - Global install:
npm install -g bitbucket-mcp - Project install: Add to MCP client config pointing to local or global install
- Docker: Dockerfile provided for containerized deployment
MCP clients (like Cursor) communicate via stdio transport using the MCP protocol.
Important Notes
- Single source file makes navigation straightforward but requires discipline with organization
- All API responses are returned as JSON-stringified text content in MCP format
- Error handling uses McpError with appropriate ErrorCodes
- Logger writes structured JSON logs (not console output, which would break stdio transport)
- No test files currently exist in the repository
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

