An intelligent PR Agent that analyzes code changes, suggests appropriate PR templates, monitors GitHub Actions workflows, and sends Slack notifications. Built with the Model Context Protocol (MCP) for seamless integration with Claude Code.
This MCP server combines three powerful modules:
- PR Template Analysis - Analyzes git diffs and suggests appropriate PR templates
- GitHub Actions Monitoring - Receives webhook events and tracks CI/CD workflow status
- Slack Integration - Sends formatted notifications to your team about CI/CD results
- ๐ Intelligent PR template suggestions based on code changes
- ๐ Real-time GitHub Actions workflow monitoring via webhooks
- ๐ฌ Slack notifications for CI/CD failures and successes
- ๐ ๏ธ Multiple MCP Tools and Prompts for automated workflows
- โก Handles large diffs with smart output truncation
Before you begin, ensure you have the following installed:
- Python 3.10 or higher - Download Python
- Git - Install Git
- uv package manager - Install uv
- Cloudflare Tunnel (cloudflared) - Install cloudflared (for webhook server)
- Claude Code - Install Claude Code
- A Slack Workspace with webhook permissions
You'll need to set up:
SLACK_WEBHOOK_URL- Your Slack incoming webhook URL (Create a Slack webhook)
git clone https://github.com/medhakimbedhief/pr-github-agent
cd pr-github-agentCreate and activate a virtual environment:
# Create virtual environment
uv venv .venv
# Activate on Windows
.venv\Scripts\activate
# Activate on macOS/Linux
source .venv/bin/activateInstall all required dependencies including dev dependencies:
uv sync --all-extrasThis will install:
mcp[cli]>=1.0.0- Model Context Protocol server frameworkaiohttp>=3.10.0- Async HTTP for webhook serverrequests>=2.32.0- HTTP library for Slack notificationspytest>=8.3.0- Testing frameworkpytest-asyncio>=0.21.0- Async test support
Create a .env file or set the environment variable:
Windows (PowerShell):
$env:SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"macOS/Linux (Bash):
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"Run the validation script to check your implementation:
uv run python src/validate_starter.pyThis script verifies:
- All required tools are implemented
- All required prompts are defined
- Function signatures are correct
- The server can be imported without errors
Test your implementation with the provided test suite:
uv run pytest src/test_server.py -vThe tests cover:
- Tool functionality
- Error handling
- Output formatting
- Large diff truncation
- Webhook event processing
Add the MCP server to Claude Code using the CLI:
# Navigate to the src directory
cd src
# Add the MCP server
claude mcp add pr-agent-slack -- uv --directory . run server.py
# Verify the server is configured
claude mcp listAlternative: Manual Configuration
You can also manually add the server to Claude Code's configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"pr-agent-slack": {
"command": "uv",
"args": ["--directory", "C:\\path\\to\\pr-github-agent\\src", "run", "server.py"]
}
}
}Start the MCP server to use PR analysis tools:
cd src
uv run server.pyAvailable Tools:
analyze_file_changes()- Get git diff and changed filesget_pr_templates()- List available PR templatessuggest_template()- Get AI-suggested template based on changes
Available Prompts:
generate_pr_status_report- Comprehensive PR status with CI/CD infotroubleshoot_workflow_failure- Debug failing workflows
To receive real-time GitHub Actions events:
In one terminal:
cd src
python webhook_server.pyThis starts a local server on http://localhost:8080
In another terminal:
cloudflared tunnel --url http://localhost:8080This will output a public URL like: https://random-words.trycloudflare.com
- Go to your GitHub repository settings
- Navigate to Settings > Webhooks > Add webhook
- Set the payload URL:
https://your-tunnel-url.trycloudflare.com/webhook/github - Content type:
application/json - Select events: Workflow runs and Check runs
- Click Add webhook
Available Tools (added):
get_recent_actions_events()- View recent webhook eventsget_workflow_status()- Check current workflow states
Available Prompts (added):
analyze_ci_results- Analyze recent CI/CD resultscreate_deployment_summary- Generate deployment summariesgenerate_pr_status_report- PR status with CI/CD integrationtroubleshoot_workflow_failure- Debug workflow failures
Ensure SLACK_WEBHOOK_URL is set, then use:
Available Tools (added):
send_slack_notification()- Send messages to Slack
Available Prompts (added):
format_ci_failure_alert- Format CI failure alerts for Slackformat_ci_success_summary- Format success messages for Slack
# Start Claude Code
claude
# In Claude, ask:
"Analyze my current branch changes and suggest a PR template"Claude will:
- Call
analyze_file_changes()to get the diff - Analyze the changes to determine the type
- Call
suggest_template()with its analysis - Provide you with a filled-out template
# Make sure webhook server and MCP server are running
# In Claude, ask:
"Check recent CI events and notify the team about any failures or successful workflows"Claude will:
- Call
get_recent_actions_events()to fetch events - Call
get_workflow_status()to check states - Use
format_ci_failure_alertorformat_ci_success_summaryprompts - Call
send_slack_notification()to send the message
# In Claude, ask:
"Generate a comprehensive PR status report"Claude will use the generate_pr_status_report prompt to:
- Analyze file changes
- Check CI/CD status
- Suggest appropriate PR template
- Provide recommendations and risk assessment
pr-github-agent/
โโโ src/
โ โโโ server.py # Main MCP server (all 3 modules)
โ โโโ webhook_server.py # GitHub webhook receiver
โ โโโ test_server.py # Unit tests
โ โโโ validate_starter.py # Validation script
โ โโโ github_events.json # Stored webhook events (auto-generated)
โ โโโ .claude/ # Claude Code configuration
โโโ templates/ # PR templates
โ โโโ bug.md
โ โโโ feature.md
โ โโโ docs.md
โ โโโ refactor.md
โ โโโ test.md
โ โโโ performance.md
โ โโโ security.md
โโโ team-guidelines/ # Team coding standards
โ โโโ coding-standards.md
โ โโโ pr-guidelines.md
โโโ pyproject.toml # Project dependencies
โโโ uv.lock # Dependency lock file
โโโ README.md # This file
Tools provide Claude with capabilities to interact with external systems:
- analyze_file_changes - Retrieves git data
- get_recent_actions_events - Reads webhook events from file
- send_slack_notification - Sends HTTP requests to Slack
Prompts guide Claude on how to use tools for specific workflows:
- analyze_ci_results - Step-by-step CI analysis workflow
- format_ci_failure_alert - Slack formatting guidelines
- generate_pr_status_report - Comprehensive PR analysis
MCP servers run in their installation directory by default. The server uses MCP roots to access Claude Code's current working directory:
context = mcp.get_context()
roots_result = await context.session.list_roots()
working_dir = roots_result.roots[0].uri.pathLarge git diffs can exceed token limits. The server implements smart truncation:
@mcp.tool()
async def analyze_file_changes(
base_branch: str = "main",
include_diff: bool = True,
max_diff_lines: int = 500
):
# Truncates output with informative messagesImport errors:
# Ensure dependencies are installed
uv sync --all-extrasGit errors:
# Make sure you're in a git repository
git statusNo webhook events received:
- Check that
webhook_server.pyis running - Verify Cloudflare tunnel is active
- Confirm GitHub webhook is configured correctly
- Check webhook delivery history in GitHub settings
Slack notifications not working:
# Verify environment variable is set
echo $SLACK_WEBHOOK_URL # Linux/macOS
echo $env:SLACK_WEBHOOK_URL # Windows PowerShell"Response too large" errors:
- Use
max_diff_linesparameter to limit output - Set
include_diff=falseto exclude full diff - The server defaults to 500 lines, adjust as needed
Git commands run in wrong directory:
- The server uses MCP roots to access Claude's working directory
- Ensure Claude Code is opened in the correct project folder
MCP server not showing in Claude Code:
# Verify configuration
claude mcp list
# Check the configuration file exists and is valid JSON- MCP Documentation
- FastMCP Guide
- Hugging Face MCP Course - Unit 3
- GitHub Webhooks Documentation
- Slack Incoming Webhooks
- Cloudflare Tunnel Documentation
This project is part of the Hugging Face MCP Course Unit 3:
- Module 1: Build MCP Server - Core PR analysis tools
- Module 2: GitHub Actions Integration - Webhook monitoring and prompts
- Module 3: Slack Notification - Team communication integration
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Start simple - Test each module independently before combining
- Use validation scripts - They catch common issues early
- Monitor logs - Both MCP server and webhook server provide detailed logging
- Test incrementally - Verify each tool works before moving to prompts
- Read the course materials - The Hugging Face course has detailed explanations
After setting up the basic agent, you can:
- Customize PR templates in the
templates/directory - Add more workflow analysis tools
- Integrate with other communication platforms
- Extend with custom prompts for your team's workflows
- Add more sophisticated CI/CD analytics
Built with โค๏ธ using Model Context Protocol