A comprehensive Model Context Protocol (MCP) server that helps developers create better pull requests by analyzing git repository changes, managing PR templates, providing intelligent template suggestions, and monitoring GitHub Actions workflows.
- Change Detection: Automatically detects modified, added, and deleted files
- Diff Generation: Provides complete git diffs with intelligent truncation
- Commit History: Shows relevant commit messages and statistics
- Branch Comparison: Compares changes against any base branch (default: main)
- Multiple Templates: Supports 7 different PR template types
- Template Categories: Bug fixes, features, documentation, refactoring, testing, performance, and security
- Content Management: Stores and retrieves complete template content
- Customizable: Easy to add or modify templates
- Smart Mapping: Automatically suggests appropriate templates based on change analysis
- Context Awareness: Considers file types, change patterns, and keywords
- Flexible Matching: Supports multiple aliases for change types
- Webhook Server: Receives and stores GitHub Actions events
- Workflow Monitoring: Tracks workflow status and results
- CI/CD Analysis: Provides insights into deployment and test results
- Event History: Maintains history of GitHub Actions events
- Python 3.13+
- uv (Python package manager)
- Git repository
- MCP-compatible client (like Claude Code)
- (Optional) GitHub repository for Actions integration
-
Clone the repository:
git clone <repository-url> cd mcp-pr-agent
-
Install dependencies using uv:
uv sync
-
Run the MCP server:
uv run server.py
-
(Optional) Run the GitHub webhook server for GitHub Actions integration:
uv run webhook_server.py
The webhook server runs on port 8000 by default and receives GitHub Actions events.
Analyzes git repository changes and provides comprehensive diff information.
Parameters:
base_branch(str, optional): Base branch to compare against (default: "main")include_diff(bool, optional): Include full diff content (default: true)max_diff_lines(int, optional): Maximum diff lines to include (default: 500)working_directory(str, optional): Directory to run git commands in (default: auto-detected)
Returns: JSON object containing:
files_changed: List of modified files with statusstatistics: Diff statistics summarycommits: Recent commit messagesdiff: Complete diff content (if requested)truncated: Whether diff was truncatedtotal_diff_lines: Total number of diff lines
Example Usage:
# Basic usage
result = await analyze_file_changes()
# Compare against develop branch
result = await analyze_file_changes(base_branch="develop")
# Get summary without full diff
result = await analyze_file_changes(include_diff=False)
# Limit diff size
result = await analyze_file_changes(max_diff_lines=100)Retrieves all available PR templates with their content.
Parameters: None
Returns: JSON array of template objects containing:
filename: Template file nametype: Template category/typecontent: Complete template content
Available Templates:
- bug.md: Bug Fix template
- feature.md: New Feature template
- docs.md: Documentation Update template
- refactor.md: Code Refactoring template
- test.md: Test Update template
- performance.md: Performance Improvement template
- security.md: Security Update template
Analyzes change descriptions and suggests the most appropriate PR template.
Parameters:
changes_summary(str): Description of what the changes dochange_type(str): Type of change (bug, feature, docs, refactor, test, etc.)
Returns: JSON object containing:
recommended_template: Complete template objectreasoning: Explanation for the suggestiontemplate_content: Ready-to-use template contentusage_hint: Instructions for using the template
Supported Change Types:
- Bug/Fix: Maps to bug.md template
- Feature/Enhancement: Maps to feature.md template
- Docs/Documentation: Maps to docs.md template
- Refactor/Cleanup: Maps to refactor.md template
- Test/Testing: Maps to test.md template
- Performance/Optimization: Maps to performance.md template
- Security: Maps to security.md template
Retrieves recent GitHub Actions events received via webhook.
Parameters:
limit(int, optional): Maximum number of events to return (default: 10)
Returns: JSON array of GitHub Actions events with:
- Event type and timestamp
- Workflow run information
- Repository details
- Action outcomes
Gets the current status of GitHub Actions workflows.
Parameters:
workflow_name(str, optional): Specific workflow name to filter by
Returns: JSON array of workflow status objects containing:
name: Workflow namestatus: Current status (queued, in_progress, completed)conclusion: Final result (success, failure, cancelled, etc.)run_number: Workflow run numberupdated_at: Last update timestamphtml_url: Link to workflow run
Each template follows a consistent structure:
## [Template Type]
### Description
<!-- Brief description of the change -->
### [Template-specific sections]
<!-- Varies by template type -->
### Testing
- [ ] Relevant tests added/updated
- [ ] Manual testing completed
### [Additional sections as needed]Templates are stored in the templates/ directory. To add or modify templates:
- Create/edit
.mdfiles in thetemplates/directory - Update
DEFAULT_TEMPLATESinserver.pyif adding new templates - Update
TYPE_MAPPINGfor new change type aliases
# Analyze current repository changes
result = mcp.call_tool("analyze_file_changes", {
"base_branch": "main",
"include_diff": True
})
# Get all available templates
templates = mcp.call_tool("get_pr_templates", {})
# Get template suggestion
suggestion = mcp.call_tool("suggest_template", {
"changes_summary": "Added user authentication system",
"change_type": "feature"
})- Analyze Changes: Use
analyze_file_changesto understand what was modified - Get Suggestions: Use
suggest_templateto get appropriate template recommendations - Create PR: Use the suggested template content to create a comprehensive PR description
To enable GitHub Actions monitoring, you need to set up a webhook in your GitHub repository:
-
Start the webhook server:
uv run webhook_server.py
-
Configure GitHub webhook:
- Go to your repository Settings → Webhooks
- Add webhook with URL:
http://your-server:8000/webhook - Select "Workflow runs" events
- Set content type to "application/json"
-
Access GitHub Actions data:
# Get recent events events = mcp.call_tool("get_recent_actions_events", {"limit": 5}) # Check workflow status status = mcp.call_tool("get_workflow_status", {"workflow_name": "CI"})
The server includes several pre-built prompts for GitHub Actions analysis:
analyze_ci_results: Comprehensive CI/CD results analysiscreate_deployment_summary: Generate deployment status summariesgenerate_pr_status_report: Complete PR status including CI/CDtroubleshoot_workflow_failure: Help debug failing workflows
MCP_PR_AGENT_TEMPLATES_DIR: Custom templates directory pathMCP_PR_AGENT_DEFAULT_BRANCH: Default base branch (default: "main")WEBHOOK_PORT: Port for webhook server (default: 8000)
The project includes a .mcp.json configuration file for easy MCP client setup:
{
"mcpServers": {
"pr-agent-actions": {
"command": "uv",
"args": ["run", "server.py"],
"cwd": "/Users/David/Dev/mcp/mcp-pr-agent"
}
}
}Add this MCP server to Claude Code using the following command:
claude mcp add pr-agent -- uv --directory <mcp-pr-agent-directory> run server.pyReplace <mcp-pr-agent-directory> with the full path to your mcp-pr-agent directory.
Example:
claude mcp add pr-agent -- uv --directory /Users/username/projects/mcp-pr-agent run server.pyFor other MCP clients, add to your configuration:
{
"mcpServers": {
"pr-agent": {
"command": "uv",
"args": ["--directory", "/path/to/mcp-pr-agent", "run", "server.py"]
}
}
}uv run pytest test_server.py -v- Create template file in
templates/directory - Add to
DEFAULT_TEMPLATESdictionary - Add type mappings to
TYPE_MAPPING - Update documentation
The server includes comprehensive error handling:
- Git command failures
- Missing repositories
- Template file errors
- Invalid parameters
"Git error" responses:
- Ensure you're in a git repository
- Check that the base branch exists
- Verify git is accessible in PATH
Empty results:
- Check if you're on the correct branch
- Ensure there are changes to analyze
- Verify the base branch comparison
Template not found:
- Ensure templates directory exists
- Check template file permissions
- Verify template files are properly formatted
The analyze_file_changes tool includes debug information in the _debug field:
- Working directory paths
- MCP roots detection
- Server process information
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request using the appropriate template!
[Add your license information here]
[Add support contact information here]