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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。