Devpatel1901/pr-agent-mcp-server
If you are the rightful owner of pr-agent-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This document provides a structured summary of a Model Context Protocol (MCP) server designed to enhance pull request processes and integrate with GitHub Actions and Slack for comprehensive CI/CD workflows.
Module 1: Basic MCP Server - Starter Code
Welcome to Module 1! In this module, you'll build a basic MCP server that helps developers create better pull requests by analyzing code changes and suggesting appropriate templates.
Your Task
Implement an MCP server with three tools:
- analyze_file_changes - Retrieve git diff information and changed files
- get_pr_templates - List available PR templates
- suggest_template - Allow Claude to suggest the most appropriate template
Setup
1. Install uv
Follow the official installation instructions at: https://docs.astral.sh/uv/getting-started/installation/
2. Install dependencies
# Install all dependencies
uv sync
# Or install with dev dependencies for testing
uv sync --all-extras
3. Start implementing!
Open server.py and follow the TODO comments to implement each tool.
Note: The starter code includes stub implementations that return "Not implemented" errors. This allows you to:
- Run the server immediately
- Test your setup with Claude
- Replace each stub with your actual implementation
- See helpful hints about what each tool should do
Design Philosophy
Instead of using rigid rules based on file extensions or patterns, your tools should provide Claude with raw git data and let Claude's intelligence determine:
- What type of change is being made
- Which template is most appropriate
- How to customize the template for the specific changes
Testing Your Implementation
-
Run the unit tests:
uv run pytest test_server.py -v -
Configure the MCP server in Claude Code:
# Add the MCP server claude mcp add pr-agent -- uv --directory /absolute/path/to/module1/starter run server.py # Verify it's configured claude mcp list -
Make some changes in a git repository and ask Claude to analyze your changes and suggest a PR template
Need Help?
- Check the solution in
../solution/if you get stuck - Remember: The goal is to give Claude the data it needs, not to implement complex logic yourself
Module 2: GitHub Actions Integration
This module extends the PR Agent with GitHub Actions webhook integration and MCP Prompts for standardized CI/CD workflows.
Features Added in Module 2
-
GitHub Actions Tools:
get_recent_actions_events()- View recent webhook eventsget_workflow_status()- Check workflow statuses
-
MCP Prompts for CI/CD:
analyze_ci_results- Comprehensive CI/CD analysiscreate_deployment_summary- Team-friendly deployment updatesgenerate_pr_status_report- Combined code and CI/CD reporttroubleshoot_workflow_failure- Systematic debugging guide
-
Webhook Server:
- Separate script that runs on port 8080
- Receives GitHub Actions events
- Stores events in
github_events.jsonfor the MCP server to read
Installation
# From the solution directory
uv sync
Setting Up Cloudflare Tunnel
To receive GitHub webhooks locally, you'll need to set up Cloudflare Tunnel (cloudflared):
Step 1: Install cloudflared
macOS:
brew install cloudflared
Windows: Download the Windows installer from: https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.msi
Linux:
# For Debian/Ubuntu (amd64)
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb
# For other Linux distros, download the appropriate binary:
# https://github.com/cloudflare/cloudflared/releases/latest
Step 2: Start the Tunnel
# This creates a public URL that forwards to your local webhook server
cloudflared tunnel --url http://localhost:8080
You'll see output like:
Your quick tunnel has been created! Visit it at:
https://random-name-here.trycloudflare.com
Step 3: Configure GitHub Webhook
- Go to your GitHub repository → Settings → Webhooks
- Click "Add webhook"
- Set Payload URL to:
https://your-tunnel-url.trycloudflare.com/webhook/github - Set Content type to:
application/json - Select events:
- Workflow runs
- Check runs
- Or choose "Send me everything"
- Click "Add webhook"
Running the Server
For Development
# Terminal 1: Start the webhook server
python webhook_server.py
# Terminal 2: Start Cloudflare Tunnel (if testing with real GitHub)
cloudflared tunnel --url http://localhost:8080
# Terminal 3: Start the MCP server
uv run server.py
With Claude Code
- Add to Claude Code settings:
{
"pr-agent-actions": {
"command": "uv",
"args": ["run", "server.py"],
"cwd": "/path/to/github-actions-integration/solution"
}
}
- Restart Claude Code
- In a separate terminal, start the webhook server:
python webhook_server.py - (Optional) Start Cloudflare Tunnel if testing with real GitHub webhooks
Testing Webhooks
Manual Test
# Send a test webhook
curl -X POST http://localhost:8080/webhook/github \
-H "Content-Type: application/json" \
-H "X-GitHub-Event: workflow_run" \
-d '{
"action": "completed",
"workflow_run": {
"id": 123456789,
"name": "CI Tests",
"head_branch": "main",
"run_number": 42,
"status": "completed",
"conclusion": "success",
"html_url": "https://github.com/user/repo/actions/runs/123456789",
"updated_at": "2024-01-01T10:00:00Z"
},
"repository": {
"full_name": "user/repo"
},
"sender": {
"login": "test-user"
}
}'
With Claude Code
After setting up webhooks and pushing a commit:
-
Check recent events:
- Ask: "What GitHub Actions events have we received?"
- Claude will use
get_recent_actions_events()
-
Analyze CI status:
- Use the prompt: "Analyze CI Results"
- Claude will check workflows and provide insights
-
Create deployment summary:
- Use the prompt: "Create Deployment Summary"
- Claude will format a team-friendly update
Module Structure
server.py- Main MCP server with Tools and Promptswebhook_server.py- Separate webhook server that stores eventsgithub_events.json- File where webhook events are stored (created automatically)pyproject.toml- Dependencies for both serversREADME.md- This file
Next Steps
- Complete the exercises in the module
- Experiment with different prompt workflows
- Move on to Module 3 for Hugging Face Hub integration
Module 3: Slack Notification - Complete Solution
This is the complete implementation of Module 3, demonstrating how to integrate MCP Tools and Prompts for team communication via Slack.
What This Implements
This solution extends Modules 1 and 2 with:
send_slack_notificationtool - Sends formatted messages to Slack via webhook with proper error handlingformat_ci_failure_alertprompt - Creates rich failure alerts with Slack markdownformat_ci_success_summaryprompt - Creates celebration messages for successful deployments
Setup and Usage
-
Install dependencies:
uv sync -
Set up Slack webhook:
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL" -
Start services:
# Terminal 1: Webhook server python webhook_server.py # Terminal 2: MCP server uv run server.py # Terminal 3: Cloudflare tunnel (optional) cloudflared tunnel --url http://localhost:8080
Testing
See manual_test.md for comprehensive testing instructions using curl commands to simulate GitHub webhook events.
Key Learning Outcomes
This solution demonstrates all MCP primitives working together for real-world team automation.