mcp-pr-companion
This server exposes a single tool for turning a Bitbucket pull request (or a local Git branch comparison) into a compact JSON payload that an AI can use to write PR descriptions.
Generate a PR payload from a Bitbucket PR URL (
pr_url): extracts the PR diff, commits, and AST-based module categorization into a ~1–2KB JSON schema.Generate a payload from a local Git repo (
repo_path): works from an absolute path to a target Git repository instead of a PR URL.Choose the branch range: set
source_branch(defaults to the currently checked-out branch) andtarget_branch(defaults tomain) to define the comparison.Output is optimized for AI consumption: compact, structured JSON (diff + commits + module categorization) intended as input for automated PR-description generation.
Note: the provided schema contains only this one tool; the broader read-only PR context-pack / MCP tool set described in the README (e.g., get_pr_context_pack, search_pr_files, get_pr_comments) is not present in the schema supplied.
Fetches pull request metadata, commit history, and diffs from Bitbucket Cloud to generate a compact JSON summary for AI-powered PR description generation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-pr-companion Generate PR payload for https://bitbucket.org/workspace/repo/pull-requests/123"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-pr-companion
A read-only Bitbucket Cloud pull request tool that turns PRs into compact context packs for AI agents such as Claude, Copilot, and Cursor.
You can use it in three ways:
Use | Command | Purpose |
Interactive terminal menu | .\run.cmd cmd | Browse your PRs, sync one PR, generate several PRs, or view decrypted context |
Batch generation | .\run.cmd generate-all | Generate context for all of your open PRs across the configured repositories |
MCP server | .\run.cmd | Let an AI client retrieve PR context directly or through mcp-hub |
1. Quick start
Step 1: Clone the repository
git clone <repo-url>
cd mcp-pr-companionStep 2: Start the tool
Platform | Command |
Windows PowerShell | .\run.cmd cmd |
Windows Command Prompt | run.cmd cmd |
macOS / Linux | ./run.sh cmd |
On first launch, the tool prepares the environment:
Installs Node.js if it is missing or older than 20.12.
Runs npm ci if dependencies are missing.
Builds the project if needed.
Creates a .env file if one does not exist, then stops so you can fill it in.
The check command checks Node.js, installed dependencies, build output, and required configuration. It does not install dependencies, build, create .env, or call Bitbucket. The run.cmd and run.sh wrappers may still install Node.js before invoking check. To install dependencies and build without starting the app, run .\run.cmd prepare or ./run.sh prepare. The MCP tool check_bitbucket_connection separately checks the live Bitbucket credentials and account allowlist.
Step 3: Configure .env
Fill in the repository root .env file:
BITBUCKET_EMAIL=user@example.com
BITBUCKET_API_TOKEN=ATATT...
BITBUCKET_WORKSPACE=acme
BITBUCKET_REPOSITORY=api,webBITBUCKET_REPOSITORY accepts comma-separated repositories. Entries without a workspace use BITBUCKET_WORKSPACE. Use workspace/repo for a repository in another workspace, such as api,other-team/tool.
Run .\run.cmd check. A successful check looks like this:
✓ Node.js: Node.js 22.20.0 (requires >=20.12)
✓ Dependencies: dependencies match package-lock.json
✓ Build: dist/ is up to date
✓ Config (.env): required settings presentCreate an API token in Bitbucket under Personal settings → API tokens → Create API token with scopes. Grant only the read scopes read:user:bitbucket, read:pullrequest:bitbucket, and read:repository:bitbucket. Do not grant write, admin, or delete scopes.
Related MCP server: Bitbucket Cloud MCP Server
2. Daily use
.\run.cmd cmd
.\run.cmd generate-all
.\run.cmd sync open
.\run.cmd sync draft
.\run.cmd sync merged
.\run.cmd sync declined
.\run.cmd sync all
.\run.cmd check
.\run.cmd purge-plaintextThe sync command accepts exactly one mode: open, draft, merged, declined, or all. It syncs PRs authored by the configured account across every repository in BITBUCKET_REPOSITORY. The groups do not overlap: open excludes drafts; draft includes open draft PRs; merged and declined use their matching Bitbucket states; all includes all four groups. If Bitbucket stops pagination early, the command reports incomplete results and exits with an error code. A failed PR is reported while the remaining PRs continue.
The older generate-all command keeps its existing behavior and generates context for your open PRs. The sync_my_open_prs MCP tool also keeps its existing meaning.
With Node.js 20.12 or newer, these npm commands are equivalent:
npm command | Equivalent |
npm run cmd | .\run.cmd cmd |
npm run mcp-pr-companion | .\run.cmd generate-all |
npm start | .\run.cmd (MCP server) |
npm run healthcheck | .\run.cmd check |
In PowerShell, prefix the command with .\ (for example, .\run.cmd). Typing run.cmd by itself will not find the command.
Where data is stored
The canonical directory for each synced PR is:
ai-context/[<AI_CONTEXT_COMPANY>/]<workspace>/<repo>/<open|draft|merged|declined>/pr_<id>/
├── current.json
├── context.md
├── files.md
├── actions.md
├── manifest.json
├── files/file_NNNN.md
├── live-review/
│ ├── current.json
│ ├── last-attempt.json
│ └── snapshots/<snapshot-id>/{index.json,comments.jsonl}
└── revisions/rev_<src7>_<dst7>/The status directory reflects the last successful sync. The active commits are stored in current.json; the PR state and draft flag are stored in the manifest. Review comments are kept in an independently refreshed encrypted sidecar, outside commit-bound revision folders. A complete snapshot contains sanitized comment records; last-attempt.json records only the latest refresh outcome and warnings. Sidecars move with PR status-directory migrations, which preserve the newest complete snapshot. If migration is interrupted, the source directory remains readable and the next successful sync retries, even when the PR itself is unchanged. Readers also find legacy directories during migration. The file names and schema v4 layout inside each revision remain unchanged. Files under ai-context are encrypted; AI agents must read them through MCP tools.
CLI logs are written under Logs//. MCP server logs are written to Logs/mcp-server.log.
3. Use with an AI client
Add the server to the MCP configuration for Claude Code, Cursor, VS Code, or another MCP client. Replace the placeholder path:
{
"mcpServers": {
"mcp-pr-companion": {
"command": "node",
"args": ["<path-to>/mcp-pr-companion/bin/cli.js", "server"]
}
}
}Give the AI a Bitbucket PR URL, for example: Summarize https://bitbucket.org///pull-requests/123.
The MCP tools (prefixed with pr__ when exposed through mcp-hub) are:
Tool | Purpose |
get_pr_context_pack | Get the PR context pack. Start here; it checks PR freshness on each call and syncs when missing, when commits/state/draft status changed, or when directory migration is pending. Set refresh=true to force a sync. |
search_pr_files | Find files by path, language, status, change kind, or risk tag. |
get_pr_file_context | Read one file summary and a paged sanitized diff. |
get_pr_file_changes | Get a file's classification, risk, up to 50 symbols, and an optional diff page as JSON. |
get_pr_sync_status | Check whether a PR is cached and view its PR status, revision, sync time, and commit hashes. |
list_synced_prs | List locally synced PRs, optionally filtered by repository and open, draft, merged, or declined status. Results are paged. |
get_pr_comments | Read paged comments from the latest complete encrypted review snapshot. Each row has a bounded 4,000-character preview and continuation metadata; after an incomplete first fetch it reports |
get_pr_comment | Read a single comment's sanitized full text in bounded pages using |
list_my_open_prs | List your open PRs and their pr_url for a configured repository or all configured repositories. |
sync_my_open_prs | Sync your open PRs for one or all configured repositories. PRs whose cached revision matches the listing cost no extra request. This existing tool retains its open-only behavior. |
check_bitbucket_connection | Check live Bitbucket credentials and the account allowlist; also reports where each setting group came from (env, hub, local, unset). |
The context pack checks the latest PR head before returning data and refreshes all comment pages on every report, even when commits are unchanged. Sanitized full comment bodies are stored in the encrypted review sidecar; report summaries show a bounded preview. If a comment fetch is incomplete, the previous complete snapshot stays active and the report identifies its age and the sanitized warning. If the PR metadata check is unavailable, comments are still refreshed independently. Approval and build counts are fetched live and never stored; build statuses are limited to two pages. The companion does not assign severity to review comments; the AI agent interprets their text.
PRIVACY_REMOVE_AUTHOR is true by default. Set it to false only in a deployment that permits sanitized commenter display names. author_kind remains available in either setting.
To discover cached PRs, call list_synced_prs and filter by status. Then start each report with get_pr_context_pack, which checks current commits/state/draft and refreshes the comment snapshot. Use get_pr_comments for bounded comment previews and follow text_next_offset with get_pr_comment until next_offset is null. Do not read ai-context files directly because they are encrypted.
Run the CLI sync command locally to fetch historical groups, then use list_synced_prs through MCP to browse the encrypted cache. Every PR-specific read checks the latest head by default (FRESHNESS_TTL_SECONDS=0); unchanged revisions avoid another commits/diff download, while changed or missing revisions sync before data is returned. Comment reads use the last complete encrypted snapshot; only a context-pack report refreshes comments from Bitbucket. list_my_open_prs discovers open PRs live. If freshness metadata is unavailable, cached revision data is labeled with a warning, and comment refresh is still attempted independently. The Hub's pr__sync_my_open_prs tool keeps its existing open-only behavior. AUTO_SYNC_ON_START=true syncs open PRs in the background whenever the MCP server starts.
Run under mcp-hub
Clone this repository beside mcp-hub: /mcp-hub and /mcp-pr-companion. The Hub template runs node bin/cli.js server from the child repository.
Run node bin/cli.js prepare once to install dependencies and build.
Put credentials in the Hub's bitbucket block (the Hub passes its file as CENTRAL_CONFIG_PATH) or in this repository's .env. Per value, process env wins over the Hub block, which wins over .env; empty values count as unset. A missing or broken Hub file logs a warning and .env is used. check and check_bitbucket_connection report where each value group came from (env, hub, local, or unset), never the values.
The Hub exposes child tools with the pr__ prefix.
See docs/HUB_INTEGRATION.md and the Hub contract at ../mcp-hub/docs/mcps/mcp-pr-companion.md.
4. Configuration
All configuration is stored in .env. Under mcp-hub, the five Bitbucket values below can also come from the Hub's bitbucket block (priority: process env > Hub block > .env > default; empty = unset). See .env.example for the full list.
Variable | Required | Purpose |
BITBUCKET_EMAIL | Yes | Atlassian account email. Hub: bitbucket.email. |
BITBUCKET_API_TOKEN | Yes | Read-only Bitbucket API token. Hub: bitbucket.api_token. |
BITBUCKET_REPOSITORY | For cmd, generate-all, sync, and check | Comma-separated repository list. generate-all and sync process all configured repositories; |
BITBUCKET_WORKSPACE | No | Default workspace for repository entries without workspace/repo. Hub: bitbucket.workspace. |
ALLOWED_EMAILS | No | Comma-separated account allowlist; empty allows any account with valid repository access. Hub: bitbucket.allowed_emails (string or array). |
CENTRAL_CONFIG_PATH | No | Set by mcp-hub: path to the Hub's JSON file (relative to this repository). Only its bitbucket block is read; the file is never written. |
AUTO_SYNC_ON_START | No | true syncs the account's open PRs in configured repositories in the background. Default: false. |
FRESHNESS_TTL_SECONDS | No | Seconds after a successful freshness check during which PR-specific reads do not re-check the PR on Bitbucket. 0 checks on every call. Default: 0. |
TICKET_PREFIXES | No | Preferred ticket prefixes. Default: WCE-,PROJ-,JIRA-. The tool also detects KEY-123 in branch names or [KEY-123] in titles. |
PRIVACY_* | No | Privacy controls for returned and stored PR content. |
PRIVACY_MAX_COMMIT_SUBJECTS | No | Maximum commit subjects stored and shown per PR. Default: 10; merge commits are excluded. |
AI_CONTEXT_ROOT | No | Context storage directory. Default: ai-context. |
AI_CONTEXT_COMPANY | No | Optional directory inserted before . |
DEBUG | No | true enables additional MCP log messages. Default: false. |
Security
.env is ignored by Git and excluded from the Docker image.
The API token stays in .env and process memory. The tool never writes or prints it.
Only the empty template .env.example is committed.
Secrets in diffs and emails in titles, descriptions, and commit messages are redacted before storage and output.
Encrypted ai-context data
Every file under ai-context is encrypted with AES-256-GCM. File names reveal the workspace, repository, PR number, and file ids, but file content is not readable in a file browser.
Read content through MCP tools or the CLI menu after a Bitbucket access check using .env credentials and ALLOWED_EMAILS. The successful repository check is cached for 60 seconds. If a later PR metadata request fails during that window, get_pr_context_pack can show the cached revision with a note; if the repository access check fails or expires, the encrypted cache stays sealed.
The encryption key is derived from the repository UUID returned by Bitbucket and held only in memory.
Data created before encryption can be removed with .\run.cmd purge-plaintext; sync the PRs again afterward.
See docs/ENCRYPTION.md for details and limitations.
5. Docker (optional)
docker build -t mcp-pr-companion .
# Generate context for all open PRs
docker run --rm --env-file .env -v "$PWD/ai-context:/app/ai-context" mcp-pr-companion generate-all
# Sync selected PR states
docker run --rm --env-file .env -v "$PWD/ai-context:/app/ai-context" mcp-pr-companion sync all
# Interactive menu
docker run --rm -it --env-file .env -v "$PWD/ai-context:/app/ai-context" mcp-pr-companion cmd
# MCP server
docker run --rm -i --env-file .env -v "$PWD/ai-context:/app/ai-context" mcp-pr-companion6. Troubleshooting
Run .\run.cmd check first.
Message | Resolution |
Fill in BITBUCKET_... in .env or the Hub's bitbucket block | Fill in the missing setting in .env or, under mcp-hub, in the Hub's bitbucket block. ( |
Email or API token invalid | Check the account email and token or create a new token. |
Repository read access failed | Check BITBUCKET_REPOSITORY and the read:repository scope. |
No access: this account cannot read / | The configured account cannot read the repository, so it cannot unlock the encrypted cache. |
No access: cannot connect to Bitbucket | Restore network access; encrypted data cannot be unlocked offline. |
Unencrypted ai-context file | Run purge-plaintext or sync the PR again. |
npm ci failed | Check network or proxy access to the npm registry. |
Node.js requires >=20.12 | Use run.cmd or run.sh to install Node.js, or install it from https://nodejs.org. |
run.cmd is not recognized | In PowerShell, use .\run.cmd. |
Linux requests sudo | Installing Node.js requires administrator permissions. |
7. How it works
flowchart LR
A[PR URL / CLI] --> B[Read-only Bitbucket API]
B --> C[Analyze changes and risks]
C --> D[Redact sensitive information]
D --> E[Encrypt and write context pack]
E --> F[AI reads through MCP]Small PRs receive concise summaries. Large or high-risk PRs identify the files that need closer review. Writes are staged and validated so an interrupted sync does not replace the previous active revision.
8. Development
npm run dev
npm run build
npm testrun.cmd and run.sh check and install Node.js when required.
bin/cli.js checks dependencies, builds when needed, loads .env, and starts the requested command.
The build refreshes when src/, tsconfig.json, package-lock.json, or package.json changes.
CI tests Windows, macOS, and Ubuntu with Node.js 20.12.0 and 22; Ubuntu also builds the Docker image.
Source code is in src/ and tests are in tests/.
Developer and agent documentation:
File | Contents |
Required agent rules, invariants, code map, MCP tool reference, and definition of done | |
Pipeline, storage layout, atomic writes, and freshness checks | |
Coding conventions, MCP contract, and privacy contract | |
Dependency rationale and packages deliberately avoided | |
Running as an mcp-hub child | |
ai-context encryption, key source, access gate, limitations, and migration |
Available Tools
1 toolgenerate_pr_payloadA
Extracts Bitbucket PR or local Git branch diffs, commits, and AST module categorizations into a compact JSON schema (~1-2KB) for AI PR description generation.
Inputs: pr_url, repo_path, source_branch, target_branch.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 1 tool
With only one tool, there is no possibility of confusion between tools. The single tool's purpose is clearly defined.
The single tool name 'generate_pr_payload' follows a consistent verb_noun pattern with underscores, making it clear and predictable.
A single tool feels too few for a server named 'PR companion', which implies a broader set of PR-related operations. This narrow scope limits the server's utility.
The server only provides a means to generate a payload for PR description generation, lacking essential operations such as listing PRs, reviewing, merging, or managing comments. This is severely incomplete for a PR companion.
Maintenance
Related MCP Connectors
Risk-scan a diff, flag AI-generated-code tells, find secrets. 5 of 7 tools need no account.
AI-native git hosting — repos, PRs, issues, CI gates, and AI code review over MCP (60 tools).
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
A Model Context Protocol (MCP) application for automated GitHub PR analysis and issue management.…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAutomatically generates comprehensive merge request summaries from git logs, analyzing commit history and categorizing changes into structured descriptions. Provides tools to analyze git repositories, compare branches, and create detailed summaries with change categorization, impact analysis, and review time estimates.1MIT
- AlicenseBqualityDmaintenanceEnables AI assistants to read Bitbucket Cloud pull requests and diffs through natural conversation.223 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables AI-powered pull request review and analysis for Bitbucket Cloud, plus tools to list, create, diff, comment on, and analyze PRs. Supports stdio or HTTP transports with OAuth/bearer auth and pluggable LLM providers.94 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants to interact with Bitbucket Cloud workspaces, repositories, branches, commits, and pull requests through generic GET, POST, PUT, PATCH, DELETE, and clone tools, including reading PR diffs, adding comments, approving, merging, and filtering responses with JMESPath. It connects LLMs directly to version control workflows so tasks like code review, repository search, and PR management can be done in natural language.MIT