agentleFS
MatanYeminiMatanYemini/bitbucket-mcp/CLAUDE.md

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
  1. Distinctive:

    Safety First: No DELETE operations are used to prevent accidental data loss.

    line 9
  2. Distinctive:

    All Bitbucket API operations grouped by category:

    line 54
  3. Very specific:

    All tools are registered in the ListToolsRequestSchema handler with JSON schemas for input validation.

    line 76
  4. Very specific:

    When BITBUCKET_ENABLE_DANGEROUS is true, enables tools like:

    line 111
  5. Distinctive:

    Project install: Add to MCP client config pointing to local or global install

    line 127
  6. Distinctive:

    All API responses are returned as JSON-stringified text content in MCP format

    line 135
  7. Distinctive:

    No test files currently exist in the repository

    line 138

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

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/**/*.ts

MCP Inspector

npm run inspector    # Launch MCP inspector for debugging tools

Publishing

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:patch

Architecture

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/workspace to 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_TOKEN OR BITBUCKET_USERNAME + BITBUCKET_PASSWORD: Authentication
  • BITBUCKET_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.org always has /2.0 suffix
  • Removes trailing slashes for consistent axios baseURL

Key Implementation Details

Authentication

Supports two methods (checked in order):

  1. Token authentication via BITBUCKET_TOKEN
  2. 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_name for branch/tag
  • Optional commit_hash for specific commit
  • Optional selector_type + selector_pattern for pipeline selection

Dangerous Operations

When BITBUCKET_ENABLE_DANGEROUS is true, enables tools like:

  • deletePullRequestComment
  • deletePullRequestTask

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-mcp command globally

Integration

Designed to be used via:

  1. NPX: npx -y bitbucket-mcp@latest (recommended)
  2. Global install: npm install -g bitbucket-mcp
  3. Project install: Add to MCP client config pointing to local or global install
  4. 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.