mcp-pr-companion
Automatically analyzes Git diffs and Bitbucket PR data to generate compact JSON payloads for AI-powered PR description generation, reducing token consumption.
README
š mcp-pr-companion
mcp-pr-companion is a Local Model Context Protocol (MCP) Server and Standalone CLI Tool designed to run offline on developer workstations or connect directly to Bitbucket Cloud REST API.
It automatically parses Git diffs, commit histories, and code structures, categorizing changes into architectural layers (Database, API Controllers, Services, gRPC, Unit Tests) via AST/Regex extraction rules. It then packages the extracted data into a compact JSON payload (~1-2KB) tailored for AI PR description generation.
šÆ Purpose & Key Benefits
- Dual-Mode Execution: Works seamlessly as an Automated MCP Server (invoked by AI) OR as a Standalone Terminal CLI (run manually by developers).
- Token Optimization: Reduces AI context token consumption by 80% - 90% by eliminating raw diff dumps.
- Speed: Accelerates PR description generation by 5x - 10x.
- Privacy & Security: Operates 100% locally or via secure read-only Bitbucket API. Raw git diffs remain on your machine; only sanitized JSON summary metadata is passed to the AI.
- Auto-Archiving Each Execution: Every execution automatically saves a timestamped JSON snapshot to
./output/description_kb_{PR_ID}_{TIMESTAMP}.jsonfor historical tracking and easy AI retrieval.
š» Manual CLI Execution (Run Directly from Terminal)
You can run mcp-pr-companion manually from your Terminal at any time!
1. Generate via Bitbucket PR URL:
npm run generate -- --url https://bitbucket.org/workspace/repo/pull-requests/123
2. Generate via Local Git Branch Comparison:
npm run generate -- --source feature/WCE-815-staging --target main
3. Display Help & Options:
npm run generate -- --help
š¾ Automatic JSON File Archiving (./output/)
Every time mcp-pr-companion executes (via CLI or MCP Server), a unique JSON file is automatically written to ./output/:
- Filename Pattern:
description_kb_{ticketId_or_prId}_{timestamp}.json - Example File:
./output/description_kb_WCE-815_pr_123_20260728_181235.json
[!NOTE] The
./output/directory is GIT IGNORED via.gitignoreto prevent any temporary data files from being committed to your source code repository.
š Bitbucket API Credentials & Token Setup Guide
To fetch Pull Request data directly via Bitbucket PR URLs (https://bitbucket.org/{workspace}/{repo}/pull-requests/{id}), create a Bitbucket App Password with Read-Only permissions.
š How to Generate a Bitbucket App Password (Token):
- Log into Bitbucket Cloud.
- Click your Avatar profile icon (Settings) -> Select Personal settings.
- In the left navigation menu under Access Management, click App Passwords.
- Click the Create app password button.
- Set a Label (e.g.,
mcp-pr-companion). - Check ONLY the following 2 Read permissions for maximum security:
- ā
Pull requests:
Read(pullrequest:read) - ā
Repositories:
Read(repository:read)
- ā
Pull requests:
- Click Create and copy the generated App Password token.
āļø Configuring config.json:
Paste your Bitbucket username and the generated App Password token into config.json (which is .gitignore protected):
{
"ticket_prefix": ["WCE-", "PROJ-", "JIRA-"],
"output_language": "vi",
"default_target_branch": "main",
"bitbucket": {
"workspace": "your-company-workspace",
"username": "your_email@company.com",
"app_password": "ATBBxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
š” Real-Time Console Progress Logs
During execution, mcp-pr-companion outputs detailed step-by-step progress logs to stderr so you can monitor execution status:
[STEP 1/5] š Parsing Bitbucket PR URL: https://bitbucket.org/workspace/repo/pull-requests/123
[STEP 2/5] š Fetching PR Metadata for workspace/repo PR #123...
ā Found PR: "[WCE-815] Tiered Call Outcomes" (feature/WCE-815 -> main) by Ninh Duong
[STEP 3/5] š Fetching PR Commit History...
ā Retrieved 3 commits
[STEP 4/5] š Fetching PR Diffstat and Raw Code Diff...
ā Found 12 changed files (+450 / -60 lines)
[STEP 5/5] š§© Classifying changed files into Modules & extracting Code Highlights...
ā
[SUCCESS] Payload generated and saved to: ./output/description_kb_WCE-815_pr_123_20260728_181235.json
š Repository Structure & Security Guidelines
mcp-pr-companion/
āāā bin/
ā āāā cli.js # CLI execution entrypoint (Supports CLI flags & Stdio)
āāā scripts/
ā āāā setup.js # 1-Click Auto-Setup & Healthcheck bootstrapper
āāā src/
ā āāā cli/ # Manual Terminal CLI Runner
ā ā āāā cli.runner.ts
ā āāā healthcheck/ # Environment pre-flight check (Node, Git CLI)
ā ā āāā healthcheck.ts
ā āāā config/ # Configuration schema & loader
ā ā āāā config.loader.ts
ā ā āāā config.schema.ts
ā āāā core/ # Core Git & Bitbucket extraction logic
ā ā āāā bitbucket/ # Bitbucket REST API v2 connector
ā ā ā āāā bitbucket.service.ts
ā ā āāā git/ # Local Git CLI runner & parsers
ā ā āāā analyzer/ # Module classifier & code highlight extractor
ā ā āāā generator/ # Payload JSON builder (~1-2KB output & file saver)
ā āāā mcp/ # MCP Protocol implementation (Stdio Transport)
ā ā āāā server.ts
ā ā āāā tools/ # Registered tool: generate_pr_payload
ā āāā utils/
ā āāā logger.ts # Safe stderr logging (prevents stdio corruption)
ā
āāā ā ļø config.json # [SENSITIVE] Local configuration (GIT IGNORED)
āāā config.example.json # Safe default configuration template
āāā š output/ # [GIT IGNORED] Auto-saved PR JSON payload archives
āāā package.json
āāā tsconfig.json
āāā README.md
āļø Available Commands & Scripts
- Run Manual Payload Generation:
npm run generate -- --url https://bitbucket.org/workspace/repo/pull-requests/123 - 1-Click Setup & Installation Bootstrapper:
npm run setup - Start Production MCP Server:
npm start - Start Development Mode (Hot Reload / Live TS):
npm run dev - Run Pre-flight Healthcheck:
npm run healthcheck - Build TypeScript Project:
npm run build
š ļø MCP Client Integration Setup
Add the relative path execution command to your MCP configuration file:
{
"mcpServers": {
"mcp-pr-companion": {
"command": "node",
"args": [
"./dist/mcp/server.js"
],
"env": {}
}
}
}
š Usage Example
Provide a Bitbucket PR link to your AI assistant:
"Here is my PR link:
https://bitbucket.org/workspace/repo/pull-requests/123. Please usegenerate_pr_payloadto fetch data and write a PR description for Bitbucket."
The AI assistant will invoke generate_pr_payload locally, stream step-by-step progress to your console log, save a snapshot file to ./output/description_kb_WCE-815_pr_123_20260728_181235.json, receive a lightweight ~1KB JSON summary, and render a formatted PR description.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.