
Bitbucket服务器
STDIOBitbucket服务器拉取请求管理工具
Bitbucket服务器拉取请求管理工具
MCP (Model Context Protocol) server for Bitbucket Server Pull Request management. This server provides tools and resources to interact with the Bitbucket Server API through the MCP protocol.
search
toolget_file_content
and browse_repository
get_comments
toollist_projects
list_repositories
BITBUCKET_DEFAULT_PROJECT
To install Bitbucket Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @garc33/bitbucket-server-mcp-server --client claude
npm install
npm run build
The server provides the following tools for comprehensive Bitbucket Server integration:
list_projects
Discover and explore Bitbucket projects: Lists all accessible projects with their details. Essential for project discovery and finding the correct project keys to use in other operations.
Use cases:
Parameters:
limit
: Number of projects to return (default: 25, max: 1000)start
: Start index for pagination (default: 0)list_repositories
Browse and discover repositories: Explore repositories within specific projects or across all accessible projects. Returns comprehensive repository information including clone URLs and metadata.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)limit
: Number of repositories to return (default: 25, max: 1000)start
: Start index for pagination (default: 0)create_pull_request
Propose code changes for review: Creates a new pull request to submit code changes, request reviews, or merge feature branches. Automatically handles branch references and reviewer assignments.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugtitle
(required): Clear, descriptive PR titledescription
: Detailed description with context (supports Markdown)sourceBranch
(required): Source branch containing changestargetBranch
(required): Target branch for mergingreviewers
: Array of reviewer usernamesget_pull_request
Comprehensive PR information: Retrieves detailed pull request information including status, reviewers, commits, and all metadata. Essential for understanding PR state before taking actions.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugprId
(required): Pull request IDmerge_pull_request
Integrate approved changes: Merges an approved pull request into the target branch. Supports different merge strategies based on your workflow preferences.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugprId
(required): Pull request IDmessage
: Custom merge commit messagestrategy
: Merge strategy:
merge-commit
(default): Creates merge commit preserving historysquash
: Combines all commits into onefast-forward
: Moves branch pointer without merge commitdecline_pull_request
Reject unsuitable changes: Declines a pull request that should not be merged, providing feedback to the author.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugprId
(required): Pull request IDmessage
: Reason for declining (helpful for author feedback)add_comment
Participate in code review: Adds comments to pull requests for review feedback, discussions, and collaboration. Supports threaded conversations.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugprId
(required): Pull request IDtext
(required): Comment content (supports Markdown)parentId
: Parent comment ID for threaded repliesget_diff
Analyze code changes: Retrieves the code differences showing exactly what was added, removed, or modified in the pull request. Supports per-file truncation to manage large diffs effectively.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugprId
(required): Pull request IDcontextLines
: Context lines around changes (default: 10)maxLinesPerFile
: Maximum lines to show per file (optional, uses BITBUCKET_DIFF_MAX_LINES_PER_FILE env var if not specified, set to 0 for no limit)Large File Handling:
When a file exceeds the maxLinesPerFile
limit, it shows:
get_reviews
Track review progress: Fetches review history, approval status, and reviewer feedback to understand the review state.
Use cases:
get_activities
Retrieve pull request activities: Gets the complete activity timeline for a pull request including comments, reviews, commits, and other events.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugprId
(required): Pull request IDget_comments
Extract PR comments only: Filters pull request activities to return only the comments, making it easier to focus on discussion content without reviews or other activities.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugprId
(required): Pull request IDsearch
Advanced code and file search: Search across repositories using the Bitbucket search API with support for project/repository filtering and query optimization. Searches both file contents and filenames. Note: Search only works on the default branch of repositories.
Use cases:
Parameters:
query
(required): Search query stringproject
: Bitbucket project key to limit search scoperepository
: Repository slug for repository-specific searchtype
: Query optimization - "file" (wraps query in quotes for exact filename matching) or "code" (default search behavior)limit
: Number of results to return (default: 25, max: 100)start
: Start index for pagination (default: 0)Query syntax examples:
"README.md"
- Find exact filenameconfig ext:yml
- Find config in YAML filesfunction project:MYPROJECT
- Search for "function" in specific projectbug fix repo:PROJ/my-repo
- Search in specific repositoryget_file_content
Read file contents with pagination: Retrieve the content of specific files from repositories with support for large files through pagination.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugfilePath
(required): Path to the file in the repositorybranch
: Branch or commit hash (optional, defaults to main/master)limit
: Maximum lines per request (default: 100, max: 1000)start
: Starting line number for pagination (default: 0)browse_repository
Explore repository structure: Browse files and directories in repositories to understand project organization and locate specific files.
Use cases:
Parameters:
project
: Bitbucket project key (optional, uses BITBUCKET_DEFAULT_PROJECT if not provided)repository
(required): Repository slugpath
: Directory path to browse (optional, defaults to root)branch
: Branch or commit hash (optional, defaults to main/master)limit
: Maximum items to return (default: 50)# List all accessible projects list_projects # List repositories in the default project (if BITBUCKET_DEFAULT_PROJECT is set) list_repositories # List repositories in a specific project list_repositories --project "MYPROJECT" # List projects with pagination list_projects --limit 10 --start 0
# Search for README files across all projects search --query "README" --type "file" --limit 10 # Search for specific code patterns in a project search --query "function getUserData" --type "code" --project "MYPROJECT" # Search with file extension filter search --query "config ext:yml" --project "MYPROJECT" # Browse repository structure browse_repository --project "MYPROJECT" --repository "my-repo" # Browse specific directory browse_repository --project "MYPROJECT" --repository "my-repo" --path "src/components" # Read file contents get_file_content --project "MYPROJECT" --repository "my-repo" --filePath "package.json" --limit 20 # Read specific lines from a large file get_file_content --project "MYPROJECT" --repository "my-repo" --filePath "docs/CHANGELOG.md" --start 100 --limit 50
# Create a pull request (using default project) create_pull_request --repository "my-repo" --title "Feature: New functionality" --sourceBranch "feature/new-feature" --targetBranch "main" # Create a pull request with specific project create_pull_request --project "MYPROJECT" --repository "my-repo" --title "Bugfix: Critical issue" --sourceBranch "bugfix/critical" --targetBranch "develop" --description "Fixes critical issue #123" # Get pull request details get_pull_request --repository "my-repo" --prId 123 # Get only comments from a PR (no reviews/commits) get_comments --project "MYPROJECT" --repository "my-repo" --prId 123 # Get full PR activity timeline get_activities --repository "my-repo" --prId 123 # Merge a pull request with squash strategy merge_pull_request --repository "my-repo" --prId 123 --strategy "squash" --message "Feature: New functionality (#123)"
@modelcontextprotocol/sdk
- SDK for MCP protocol implementationaxios
- HTTP client for API requestswinston
- Logging frameworkThe server requires configuration in the VSCode MCP settings file. Here's a sample configuration:
{ "mcpServers": { "bitbucket": { "command": "node", "args": ["/path/to/bitbucket-server/build/index.js"], "env": { "BITBUCKET_URL": "https://your-bitbucket-server.com", // Authentication (choose one): // Option 1: Personal Access Token "BITBUCKET_TOKEN": "your-access-token", // Option 2: Username/Password "BITBUCKET_USERNAME": "your-username", "BITBUCKET_PASSWORD": "your-password", // Optional: Default project "BITBUCKET_DEFAULT_PROJECT": "your-default-project" } } } }
BITBUCKET_URL
(required): Base URL of your Bitbucket Server instanceBITBUCKET_TOKEN
: Personal access tokenBITBUCKET_USERNAME
and BITBUCKET_PASSWORD
: Basic authentication credentialsBITBUCKET_DEFAULT_PROJECT
(optional): Default project key to use when not specified in tool callsBITBUCKET_DIFF_MAX_LINES_PER_FILE
(optional): Default maximum lines to show per file in diffs. Set to prevent large files from overwhelming output. Can be overridden by the maxLinesPerFile
parameter in get_diff
calls.BITBUCKET_READ_ONLY
(optional): Set to true
to enable read-only modeNote: With the new optional project support, you can now:
BITBUCKET_DEFAULT_PROJECT
to work with a specific project by defaultlist_projects
to discover available projectslist_repositories
to browse repositories across projectsproject
parameter in any tool callThe server supports a read-only mode for deployments where you want to prevent any modifications to your Bitbucket repositories. When enabled, only safe, non-modifying operations are available.
To enable read-only mode: Set the environment variable BITBUCKET_READ_ONLY=true
Available tools in read-only mode:
list_projects
- Browse and list projectslist_repositories
- Browse and list repositoriesget_pull_request
- View pull request detailsget_diff
- View code changes and diffsget_reviews
- View review history and statusget_activities
- View pull request timelineget_comments
- View pull request commentssearch
- Search code and files across repositoriesget_file_content
- Read file contentsbrowse_repository
- Browse repository structureDisabled tools in read-only mode:
create_pull_request
- Creating new pull requestsmerge_pull_request
- Merging pull requestsdecline_pull_request
- Declining pull requestsadd_comment
- Adding comments to pull requestsBehavior:
BITBUCKET_READ_ONLY
is not set or set to any value other than true
, all tools function normally (backward compatible)BITBUCKET_READ_ONLY=true
, write operations are filtered out and will return an error if calledThe server logs all operations to bitbucket.log
using Winston for debugging and monitoring purposes.