This walkthrough guides you through the complete solution for Unit 3’s Pull Request Agent - an MCP server that helps developers create better pull requests by analyzing code changes, monitoring CI/CD pipelines, and automating team communications. The solution demonstrates all three MCP primitives (Tools, Resources, and Prompts) working together in a real-world workflow.
The PR Agent consists of interconnected modules that progressively build a complete automation system:
A minimal MCP server that analyzes file changes and suggests appropriate PR templates using MCP Tools.
# The server registers three essential tools:
# - analyze_file_changes: Returns structured data about changed files
# - get_pr_templates: Lists available templates with metadata
# - suggest_template: Provides intelligent template recommendationsThe server uses the MCP SDK to expose these tools to Claude Code, allowing it to gather information and make intelligent decisions about which PR template to use.
The analyze_file_changes tool examines the git diff to identify:
This structured data enables Claude to understand the nature of the changes without hard-coding decision logic.
Templates are stored as markdown files in the templates/ directory:
bug.md - For bug fixesfeature.md - For new featuresdocs.md - For documentation updatesrefactor.md - For code refactoringEach template includes placeholders that Claude can fill based on the analysis.
analyze_file_changes to understand what changedget_pr_templates to see available optionssuggest_template with the analysis dataEnhanced file analysis using MCP Resources to provide project context and team guidelines.
The server exposes four types of resources:
# Resources provide read-only access to:
# - file://templates/ - PR template files
# - file://project-context/ - Coding standards, conventions
# - git://recent-changes/ - Commit history and patterns
# - team://guidelines/ - Review processes and standardsThe project-context/ directory contains:
coding-standards.md - Language-specific conventionsreview-guidelines.md - What reviewers look forarchitecture.md - System design patternsdependencies.md - Third-party library policiesClaude can read these to understand project-specific requirements.
The git://recent-changes/ resource provides:
This helps Claude suggest templates consistent with team practices.
team://guidelines/review-process.md to understand PR requirementsfile://project-context/coding-standards.md for style guidesgit://recent-changes/ to match team patternsWith resources, Claude can now:
Real-time CI/CD monitoring using webhooks and standardized prompts for consistent team communication.
Uses Cloudflare Tunnel to receive GitHub Actions events:
# Webhook endpoint handles:
# - workflow_run events
# - check_run events
# - pull_request status updates
# - deployment notificationsFour standardized prompts ensure consistency:
Example prompt usage:
# When tests fail, Claude uses the "Analyze CI Results" prompt:
prompt_data = {
"event_type": "workflow_run",
"status": "failure",
"failed_jobs": ["unit-tests", "lint"],
"error_logs": "...",
"pr_context": {...}
}
# Claude generates:
# - Root cause analysis
# - Suggested fixes
# - Impact assessment
# - Next stepsPrompts ensure that regardless of who’s working:
Integration with Hugging Face Hub for LLM and dataset PRs, adding specialized workflows for teams working with language models.
# Tools for Hugging Face workflows:
# - analyze_model_changes: Detect LLM file modifications
# - validate_dataset_format: Check training data compliance
# - generate_model_card: Create/update model documentation
# - suggest_hub_template: PR templates for LLMs/datasets# Resources for Hub context:
# - hub://model-cards/ - LLM card templates and examples
# - hub://dataset-formats/ - Training data specifications
# - hub://community-standards/ - Hub community guidelines
# - hub://license-info/ - License compatibility checks# Prompts for LLM workflows:
# - "Analyze Model Changes" - Understand LLM updates
# - "Generate Benchmark Summary" - Create evaluation metrics
# - "Check Dataset Quality" - Validate training data
# - "Draft Model Card Update" - Update documentationWhen a PR modifies LLM files:
analyze_model_changes detects model architecture changeshub://model-cards/llm-template.mdgenerate_model_card updates documentationhub://license-info/ for compatibilityFor training data updates:
Automated team notifications combining Tools, Resources, and Prompts for complete workflow automation.
# Three tools for team updates:
# - send_slack_message: Post to team channels
# - get_team_members: Identify who to notify
# - track_notification_status: Monitor delivery# Resources for team data:
# - team://members/ - Developer profiles and preferences
# - slack://channels/ - Channel configurations
# - notification://templates/ - Message formats# Prompts for communication:
# - "Format Team Update" - Style messages appropriately
# - "Choose Communication Channel" - Select right audience
# - "Escalate if Critical" - Handle urgent issuesWhen CI fails on a critical PR:
get_team_members identifies the PR author and reviewersteam://members/{user}/preferences checks notification settingssend_slack_message delivers to right channelnotification://templates/ci-failure ensures consistent formatThe system considers:
Here’s how all components work together for a typical PR:
Developer creates PR
analyze_file_changes examines the diffCI/CD Pipeline Runs
Hugging Face Hub Integration
Team Notification
Follow-up Actions
Each module includes comprehensive unit tests:
End-to-end tests cover:
tests/
├── unit/
│ ├── test_tools.py
│ ├── test_resources.py
│ ├── test_prompts.py
│ └── test_integration.py
├── integration/
│ ├── test_workflow.py
│ ├── test_webhooks.py
│ └── test_notifications.py
└── fixtures/
├── sample_events.json
└── mock_responses.jsonpython server.pycloudflared tunnel --url http://localhost:3000Simple file-based configuration for easy setup:
.env filetemplates/Webhook not receiving events
Tools not appearing in Claude
Resources not accessible
Prompts producing inconsistent results
This PR Agent demonstrates the power of MCP’s three primitives working together. Tools provide capabilities, Resources offer context, and Prompts ensure consistency. Combined, they create an intelligent automation system that enhances developer productivity while maintaining team standards.
The modular architecture ensures each component can be understood, tested, and extended independently, while the integration showcases real-world patterns you’ll use in production MCP servers.
< > Update on GitHub