A MCP server that intelligently splits large PRs into multiple smaller PRs for better code review
Project description
PR-Splitter-MCP ๐
A powerful Model Context Protocol (MCP) server that intelligently splits large Pull Requests into multiple smaller PRs for better code review and KPI tracking.
๐ค Designed to work seamlessly with coding-flow MCP!
๐ฆ Installation
Via PyPI (Recommended)
pip install pr-splitter-mcp
Via uvx (Quick Start)
uvx pr-splitter-mcp
From Source
git clone https://github.com/Polly2014/PR-Splitter-MCP.git
cd PR-Splitter-MCP
poetry install
โ๏ธ MCP Configuration
Add to your VS Code MCP settings (settings.json or mcp.json):
{
"mcp": {
"servers": {
"pr-splitter": {
"command": "uvx",
"args": ["pr-splitter-mcp"]
}
}
}
}
Or if installed via pip:
{
"mcp": {
"servers": {
"pr-splitter": {
"command": "pr-splitter-mcp"
}
}
}
}
๐ฏ Problem Statement
Many companies have PR count requirements as KPIs, and large features often need to be split into multiple smaller PRs for:
- Better code review quality
- Easier tracking and management
- Meeting PR count targets
- Incremental feature delivery
PR-Splitter-MCP automates this process by analyzing code structure and intelligently splitting changes.
๐ Workflow with coding-flow MCP
The recommended workflow combines PR-Splitter-MCP with coding-flow for optimal results:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PR Split Workflow โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 1. coding-flow.get_pr_content(prId) โ Get PR files & changes โ
โ โ โ
โ 2. pr-splitter.generate_split_plan_from_pr(files, count, strategy) โ
โ โ โ
โ 3. Git operations (create branches, copy files, push) โ
โ โ โ
โ 4. coding-flow.create_draft_pr() ร N โ Create sub-PRs โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Example Conversation
User: Split PR #6243094 into 5 smaller PRs
AI Agent:
1. Uses coding-flow.get_pr_content() to get 12 changed files
2. Uses pr-splitter.generate_split_plan_from_pr() to create split plan:
- PR 1/5: configs (4 files)
- PR 2/5: utils (3 files)
- PR 3/5: components (2 files)
- PR 4/5: models (2 files)
- PR 5/5: inference (1 file)
3. Creates branches and commits for each split
4. Uses coding-flow.create_draft_pr() to create 5 draft PRs
โจ Features
- ๐ Code Analysis: Analyze code structure, detect modules, and understand dependencies
- ๐ง Smart Splitting: AI-powered splitting strategies based on:
- Module boundaries
- File types
- Logical groupings
- Dependency order
- ๐ค coding-flow Integration:
generate_split_plan_from_prworks directly with PR data - ๐ Folder Support:
split_folder_to_planandsplit_and_push_folderfor local code - ๐ฟ Branch Management: Automatically create feature branches and sub-branches
- ๐ค Auto Push: Push all branches to remote repository
- ๐ PR Creation: Create draft PRs on Azure DevOps or GitHub
- ๐ Zero Config Auth: Uses system credentials (
az login,gh auth login)
๐ Authentication
Zero-Config Authentication - Same pattern as professional tools like coding-flow!
This tool uses native SDKs with system credentials:
Azure DevOps
Uses ChainedTokenCredential with automatic fallback:
- AzureCliCredential - Uses token from
az login - InteractiveBrowserCredential - Falls back to browser login if needed
# One-time setup
az login
GitHub
Token resolution order:
GITHUB_PAT_TOKENenvironment variableGITHUB_TOKENenvironment variablegh auth tokencommand output
# One-time setup
gh auth login
Required Python Packages
# For Azure DevOps
pip install azure-devops azure-identity msrest
# For GitHub
pip install PyGithub
๐ Quick Start
Installation
# Clone the repository
git clone https://github.com/Polly2014/PR-Splitter-MCP.git
cd PR-Splitter-MCP
# Install with Poetry
poetry install
# Or with pip
pip install -e .
Configuration
The config.env file is optional - mainly for setting defaults:
# Git configuration
DEFAULT_REMOTE=origin
DEFAULT_BASE_BRANCH=main
# Split configuration
DEFAULT_PR_COUNT=8
SPLIT_STRATEGY=by_module # by_module, by_file, by_type, balanced
Usage with VS Code + Copilot
Add to your VS Code mcp.json:
{
"servers": {
"pr-splitter": {
"command": "python",
"args": ["/path/to/PR-Splitter-MCP/server.py"],
"cwd": "/path/to/PR-Splitter-MCP",
"type": "stdio"
}
}
}
๐ ๏ธ MCP Tools
Core Tools (for coding-flow integration)
generate_split_plan_from_pr โญ NEW
Generate a split plan directly from PR file data (from coding-flow.get_pr_content).
This is the recommended tool to use with coding-flow MCP!
Input:
- pr_files: List of files from coding-flow.get_pr_content()
- target_pr_count: Target number of PRs (default: 5)
- strategy: Split strategy (by_module, by_file, by_type, balanced)
- base_branch: Base branch for split PRs
- branch_prefix: Prefix for branch names
- pr_title_prefix: Prefix for PR titles
Output:
- plan: { prs: [...], base_branch, branch_prefix }
- summary: { total_files, total_lines, files_per_pr, lines_per_pr }
- merge_order: Recommended merge sequence
- workflow_next_steps: Git commands to execute
generate_pr_descriptions โญ NEW
Generate detailed PR titles and descriptions for a split plan.
Input:
- plan: Split plan from generate_split_plan_from_pr
- project_name: Name for PR titles
- include_dependencies: Include dependency info
Output:
- prs: Enhanced PRs with professional titles and descriptions
- ready_for_creation: Boolean indicating readiness
Analysis Tools
check_auth_status
Check authentication and dependency status for PR creation.
Output:
- azure_devops: { authenticated, method, message }
- github: { authenticated, method, message }
- dependencies: { installed, missing, install_command }
- ready: { ado: bool, github: bool }
analyze_code_structure
Analyze the code structure of a directory or PR.
Input:
- source_path: Path to source directory
- include_patterns: File patterns to include (e.g., "*.py")
Output:
- modules: List of detected modules
- files: File inventory with metadata
- dependencies: Dependency graph between files
get_split_strategies
Get available split strategies with descriptions and workflow guidance.
Output:
- strategies: { by_module, by_file, by_type, balanced }
- workflow: Recommended steps with coding-flow
Folder-based Split Tools โญ NEW
split_folder_to_plan
Generate a split plan from a local folder (similar to generate_split_plan_from_pr).
Input:
- folder_path: Path to folder containing code to split
- target_pr_count: Target number of PRs (default: 5)
- strategy: Split strategy (by_module, by_file, by_type, balanced)
- base_branch: Base branch for split PRs
- branch_prefix: Prefix for branch names
- include_patterns: File patterns to include (e.g., ["*.py", "*.js"])
- exclude_patterns: File patterns to exclude (e.g., ["__pycache__/*"])
Output:
- plan: Split plan with PR definitions
- summary: { total_files, total_lines, files_per_pr, lines_per_pr }
- workflow_next_steps: Instructions for next steps
split_and_push_folder โญ End-to-End
All-in-one: Analyze folder, create branches, copy files, commit, and push.
Input:
- source_folder: Path to folder containing code
- target_repo_path: Path to target git repository
- target_pr_count: Target number of PRs (default: 5)
- strategy: Split strategy
- base_branch: Base branch in target repo
- branch_prefix: Prefix for branch names
- relative_path_in_repo: Where to put files in repo (e.g., "src/feature/")
- include_patterns: File patterns to include
- exclude_patterns: File patterns to exclude
- dry_run: Preview without changes (default: True)
- push: Push branches to remote (default: True)
Output:
- plan: The split plan used
- branches: Created branches with status
- next_steps: How to create the PRs
Planning & Execution Tools
generate_split_plan
Generate an intelligent split plan for local code directory.
Input:
- source_path: Path to source directory
- target_pr_count: Target number of PRs (default: 8)
- strategy: Split strategy (by_module, by_file, by_type)
- base_branch: Base branch name
Output:
- plan: List of PR definitions with files and order
- estimated_sizes: Size estimates per PR
- dependency_order: Recommended merge order
execute_split
Execute the split plan by creating branches and commits.
Input:
- plan: Split plan from generate_split_plan
- source_path: Path to source files
- target_repo_path: Target repository path
- dry_run: Preview without making changes (default: True)
Output:
- branches: List of created branches with commit hashes
- summary: Success/failure statistics
- status: Execution status
PR Creation Tools
create_ado_pr
Create a Pull Request in Azure DevOps.
Input:
- org_url: Azure DevOps org URL (e.g., https://dev.azure.com/your-org)
- project: Project name (e.g., MyProject)
- repo: Repository name (e.g., my-repo)
- source_branch: Source branch name
- target_branch: Target branch name
- title: PR title
- description: PR description (optional)
- draft: Create as draft (default: True)
- work_item_id: ADO work item to link (optional)
Output:
- pr_id: Created PR ID
- pr_url: PR URL
- status: Creation status
create_github_pr
Create a Pull Request in GitHub.
Input:
- repo: Repository in format "owner/repo"
- source_branch: Source branch name
- target_branch: Target branch name (default: main)
- title: PR title
- body: PR description (optional)
- draft: Create as draft (default: True)
Output:
- pr_id: Created PR ID
- pr_url: PR URL
- status: Creation status
create_prs_from_plan
Batch create PRs from a split plan.
Input:
- plan: Split plan from generate_split_plan
- platform: "ado" or "github"
- repo: Repository name
- org_url: ADO org URL (required for ADO)
- project: ADO project name (required for ADO)
- draft: Create as draft PRs (default: True)
Output:
- prs_created: Number of PRs created
- pr_urls: List of PR URLs
- results: Detailed results per PR
๐ Example Workflows
Workflow 1: Split Existing PR (with coding-flow) โญ Recommended
User: Split PR #6243094 into 5 PRs targeting user/feature-test
AI Agent + MCP Servers:
1. coding-flow.get_pr_content(prIdOrUrl="PR#6243094")
โ Returns 12 changed files with paths and change types
2. pr-splitter.generate_split_plan_from_pr(
pr_files=<files from step 1>,
target_pr_count=5,
strategy="by_module",
base_branch="user/feature-test"
)
โ Returns split plan with 5 PRs
3. Git operations:
- git checkout -b user/feature-test (base branch)
- For each PR in plan:
- git checkout -b <branch_name> user/feature-test
- git checkout <source_branch> -- <files>
- git commit && git push
4. For each PR:
coding-flow.create_draft_pr(
branchName=<branch>,
targetBranch="user/feature-test",
title=<title>,
description=<description>
)
Workflow 2: Split Local Folder (End-to-End) โญ NEW
User: Split /path/to/my-feature into 5 PRs and push to my-repo
AI Agent + MCP Server:
1. pr-splitter.split_and_push_folder(
source_folder="/path/to/my-feature",
target_repo_path="/path/to/my-repo",
target_pr_count=5,
strategy="by_module",
base_branch="user/myname/feature",
branch_prefix="user/myname/feature",
relative_path_in_repo="src/feature/",
dry_run=False,
push=True
)
โ Creates 5 branches, copies files, commits, and pushes
2. pr-splitter.create_prs_from_plan(
plan=<plan from step 1>,
platform="ado",
org_url="https://dev.azure.com/myorg",
project="MyProject",
repo="my-repo"
)
โ Creates 5 draft PRs
Done! 5 PRs created from local folder.
Workflow 3: Split Local Code (Step by Step)
User: Split my code into 8 PRs
Source: /path/to/my-feature
Target: user/myname/feature-x
AI + MCP Server:
1. check_auth_status โ Verify SDK authentication
2. split_folder_to_plan โ Generate split plan with preview
3. [User confirms plan]
4. split_and_push_folder(dry_run=False) โ Create branches and push
5. create_prs_from_plan โ Create all PRs at once
๐ Authentication Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PR-Splitter-MCP โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Azure DevOps GitHub โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ChainedTokenCred โ โ Token Resolution โ โ
โ โ โโ AzureCliCred โโโโผโโ az โ โโ GITHUB_PAT_TOKENโ โ
โ โ โ (from az login)โ login โ โโ GITHUB_TOKEN โ โ
โ โ โโ BrowserCred โ โ โโ gh auth token โโโผโgh โ
โ โ (fallback) โ โ โauthโ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โผ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ azure-devops SDK โ โ PyGithub SDK โ โ
โ โ (native API calls) โ โ (native API calls) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐๏ธ Project Structure
PR-Splitter-MCP/
โโโ server.py # Main MCP server
โโโ src/
โ โโโ __init__.py
โ โโโ analyzer.py # Code structure analyzer
โ โโโ splitter.py # Split plan generator
โ โโโ git_manager.py # Git operations
โ โโโ pr_creator.py # PR creation (ADO/GitHub)
โโโ config.env # Configuration (optional)
โโโ pyproject.toml # Dependencies
โโโ README.md
๐ง CLI Commands Reference
Azure DevOps CLI
# Login
az login
# Install DevOps extension
az extension add --name azure-devops
# Create PR manually
az repos pr create \
--org https://dev.azure.com/your-org \
--project MyProject \
--repository my-repo \
--source-branch user/yourname/feature \
--target-branch main \
--title "My PR" \
--draft
GitHub CLI
# Login
gh auth login
# Create PR manually
gh pr create \
--repo owner/repo \
--head feature-branch \
--base main \
--title "My PR" \
--draft
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
- Inspired by the need for better PR management in large teams
- Built with FastMCP
- Thanks to the MCP community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pr_splitter_mcp-1.0.0.tar.gz.
File metadata
- Download URL: pr_splitter_mcp-1.0.0.tar.gz
- Upload date:
- Size: 30.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.7 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7be7c1acd6c208b0904a2659e035430a3c6f83a64d6fbbb0209be8e22021e3c5
|
|
| MD5 |
e9ed4e24f18d7bb3389b7fa7828f2818
|
|
| BLAKE2b-256 |
ab1acc23d154afd31cdc10e96d8f5a6f82b0884393c0e410ff9b18a55bc95880
|
File details
Details for the file pr_splitter_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pr_splitter_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.7 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6ea16b529dae3e73b04371de881155ccbd532250ac6cfe192b9898f6722aa6f
|
|
| MD5 |
bce4516c5bc63d5957096f024e5eb807
|
|
| BLAKE2b-256 |
cd739241bb90fc17fc803d726503c6c2353a235f8cce2c084c35adea7c766b67
|