Add MCP PR agent project (Units 1-3)
Browse files- LICENSE +21 -0
- README.md +134 -0
- mcp-server/server.py +181 -0
- quiz-answers/QUIZ_ANSWERS.md +85 -0
- requirements.txt +2 -0
- templates/bug.md +18 -0
- templates/docs.md +13 -0
- templates/feature.md +22 -0
- templates/performance.md +15 -0
- templates/refactor.md +18 -0
- templates/security.md +18 -0
- templates/test.md +16 -0
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 ISLAM-PO
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MCP PR Agent — Model Context Protocol Course Project
|
| 2 |
+
|
| 3 |
+
[](https://huggingface.co/ISLAM-PO)
|
| 4 |
+
[](LICENSE)
|
| 5 |
+
|
| 6 |
+
> **MCP Course (Units 1–3)** project for the [Hugging Face MCP Course](https://huggingface.co/learn/mcp-course), built in partnership with Anthropic.
|
| 7 |
+
|
| 8 |
+
A production-ready **MCP server** that helps developers create better pull requests by analyzing git changes and suggesting appropriate PR templates. The server exposes 3 tools, 2 resources, and 1 prompt via the Model Context Protocol.
|
| 9 |
+
|
| 10 |
+
## Table of Contents
|
| 11 |
+
|
| 12 |
+
- [Overview](#overview)
|
| 13 |
+
- [Project Structure](#project-structure)
|
| 14 |
+
- [Tools](#tools)
|
| 15 |
+
- [Quick Start](#quick-start)
|
| 16 |
+
- [Usage with Claude Code](#usage-with-claude-code)
|
| 17 |
+
- [Quiz Answers (Unit 1)](#quiz-answers-unit-1)
|
| 18 |
+
- [Certifications](#certifications)
|
| 19 |
+
- [License](#license)
|
| 20 |
+
|
| 21 |
+
## Overview
|
| 22 |
+
|
| 23 |
+
This project demonstrates the full MCP workflow:
|
| 24 |
+
|
| 25 |
+
1. **Unit 1 (Fundamentals)**: MCP architecture (Host/Client/Server), three capability types (Tools/Resources/Prompts), transport mechanisms (stdio/HTTP+SSE), JSON-RPC 2.0
|
| 26 |
+
2. **Unit 2 (Building with MCP)**: Implementing MCP clients and servers using SDKs
|
| 27 |
+
3. **Unit 3 (Deployed Use Case)**: Building a deployed MCP application (PR agent with GitHub/Slack integration)
|
| 28 |
+
|
| 29 |
+
## Project Structure
|
| 30 |
+
|
| 31 |
+
```
|
| 32 |
+
mcp_course_project/
|
| 33 |
+
├── README.md
|
| 34 |
+
├── LICENSE
|
| 35 |
+
├── requirements.txt
|
| 36 |
+
├── mcp-server/
|
| 37 |
+
│ └── server.py # MCP PR agent server (3 tools, 2 resources, 1 prompt)
|
| 38 |
+
├── templates/
|
| 39 |
+
│ ├── bug.md
|
| 40 |
+
│ ├── feature.md
|
| 41 |
+
│ ├── docs.md
|
| 42 |
+
│ ├── refactor.md
|
| 43 |
+
│ ├── test.md
|
| 44 |
+
│ ├── performance.md
|
| 45 |
+
│ └── security.md
|
| 46 |
+
└── quiz-answers/
|
| 47 |
+
└── QUIZ_ANSWERS.md # Unit 1 quiz (5/5 correct)
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Tools
|
| 51 |
+
|
| 52 |
+
| Tool | Description |
|
| 53 |
+
|------|-------------|
|
| 54 |
+
| `analyze_file_changes` | Get git diff, changed files, commits, and statistics. Supports truncation for large diffs. |
|
| 55 |
+
| `get_pr_templates` | List all available PR templates with their content. |
|
| 56 |
+
| `suggest_template` | Suggest the most appropriate PR template based on change type. |
|
| 57 |
+
|
| 58 |
+
## Resources
|
| 59 |
+
|
| 60 |
+
| Resource | Description |
|
| 61 |
+
|----------|-------------|
|
| 62 |
+
| `templates://list` | List all available PR templates |
|
| 63 |
+
| `config://project` | Project configuration and metadata |
|
| 64 |
+
|
| 65 |
+
## Prompts
|
| 66 |
+
|
| 67 |
+
| Prompt | Description |
|
| 68 |
+
|--------|-------------|
|
| 69 |
+
| `review_code` | Generate a code review prompt for a given code snippet |
|
| 70 |
+
|
| 71 |
+
## Quick Start
|
| 72 |
+
|
| 73 |
+
### 1. Install dependencies
|
| 74 |
+
|
| 75 |
+
```bash
|
| 76 |
+
pip install -r requirements.txt
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### 2. Run the MCP server
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
python mcp-server/server.py
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
The server uses stdio transport by default, compatible with Claude Code, Cursor, and other MCP clients.
|
| 86 |
+
|
| 87 |
+
### 3. Test with Claude Code
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
# Add the MCP server
|
| 91 |
+
claude mcp add pr-agent -- python /absolute/path/to/mcp-server/server.py
|
| 92 |
+
|
| 93 |
+
# Verify it's configured
|
| 94 |
+
claude mcp list
|
| 95 |
+
|
| 96 |
+
# Use it
|
| 97 |
+
# "Analyze my changes and suggest a PR template"
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
## Usage with Claude Code
|
| 101 |
+
|
| 102 |
+
Once configured, you can ask Claude:
|
| 103 |
+
- "Analyze my file changes and suggest a PR template"
|
| 104 |
+
- "What PR templates are available?"
|
| 105 |
+
- "Review this code for issues"
|
| 106 |
+
|
| 107 |
+
## Quiz Answers (Unit 1)
|
| 108 |
+
|
| 109 |
+
All 5 quiz questions with correct answers are in `quiz-answers/QUIZ_ANSWERS.md`.
|
| 110 |
+
|
| 111 |
+
**Key concepts:**
|
| 112 |
+
- **Host**: User-facing AI application (Claude Desktop, Cursor)
|
| 113 |
+
- **Client**: Manages 1:1 communication with an MCP Server
|
| 114 |
+
- **Server**: Exposes tools, resources, and prompts via MCP
|
| 115 |
+
- **M×N Problem**: M apps × N tools = M×N integrations → MCP reduces to M + N
|
| 116 |
+
|
| 117 |
+
Take the interactive quiz: https://huggingface.co/spaces/mcp-course/unit_1_quiz
|
| 118 |
+
|
| 119 |
+
## Certifications
|
| 120 |
+
|
| 121 |
+
| Certificate | Requirements | Link |
|
| 122 |
+
|-------------|-------------|------|
|
| 123 |
+
| **Fundamentals** | Complete Unit 1 (pass quiz ≥80%) | https://huggingface.co/spaces/mcp-course/unit_1_quiz |
|
| 124 |
+
| **Completion** | Complete Units 2 & 3 (build + deploy MCP app) | Project-based (this repo demonstrates Unit 3) |
|
| 125 |
+
|
| 126 |
+
## License
|
| 127 |
+
|
| 128 |
+
MIT License. See `LICENSE`.
|
| 129 |
+
|
| 130 |
+
## Acknowledgements
|
| 131 |
+
|
| 132 |
+
Built as the Unit 3 project of the [Hugging Face MCP Course](https://huggingface.co/learn/mcp-course),
|
| 133 |
+
built in partnership with [Anthropic](https://www.anthropic.com). Source starter code from
|
| 134 |
+
[huggingface/mcp-course](https://github.com/huggingface/mcp-course).
|
mcp-server/server.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
MCP PR Agent Server — MCP Course (Unit 3)
|
| 4 |
+
|
| 5 |
+
A deployed MCP server that helps developers create better pull requests by
|
| 6 |
+
analyzing git changes and suggesting appropriate PR templates.
|
| 7 |
+
|
| 8 |
+
Built for the Hugging Face MCP Course (https://huggingface.co/learn/mcp-course).
|
| 9 |
+
Adapted to use mcp.server.MCPServer (mcp 2.x) instead of the deprecated FastMCP.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import subprocess
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
from typing import Optional
|
| 17 |
+
|
| 18 |
+
from mcp.server import MCPServer
|
| 19 |
+
|
| 20 |
+
mcp = MCPServer("pr-agent")
|
| 21 |
+
|
| 22 |
+
# PR template directory
|
| 23 |
+
TEMPLATES_DIR = Path(__file__).parent.parent / "templates"
|
| 24 |
+
|
| 25 |
+
DEFAULT_TEMPLATES = {
|
| 26 |
+
"bug.md": "Bug Fix",
|
| 27 |
+
"feature.md": "Feature",
|
| 28 |
+
"docs.md": "Documentation",
|
| 29 |
+
"refactor.md": "Refactor",
|
| 30 |
+
"test.md": "Test",
|
| 31 |
+
"performance.md": "Performance",
|
| 32 |
+
"security.md": "Security",
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
TYPE_MAPPING = {
|
| 36 |
+
"bug": "bug.md",
|
| 37 |
+
"fix": "bug.md",
|
| 38 |
+
"feature": "feature.md",
|
| 39 |
+
"enhancement": "feature.md",
|
| 40 |
+
"docs": "docs.md",
|
| 41 |
+
"documentation": "docs.md",
|
| 42 |
+
"refactor": "refactor.md",
|
| 43 |
+
"cleanup": "refactor.md",
|
| 44 |
+
"test": "test.md",
|
| 45 |
+
"testing": "test.md",
|
| 46 |
+
"performance": "performance.md",
|
| 47 |
+
"optimization": "performance.md",
|
| 48 |
+
"security": "security.md",
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@mcp.tool()
|
| 53 |
+
async def analyze_file_changes(
|
| 54 |
+
base_branch: str = "main",
|
| 55 |
+
include_diff: bool = True,
|
| 56 |
+
max_diff_lines: int = 500,
|
| 57 |
+
working_directory: Optional[str] = None,
|
| 58 |
+
) -> str:
|
| 59 |
+
"""Get the full diff and list of changed files in the current git repository.
|
| 60 |
+
|
| 61 |
+
Args:
|
| 62 |
+
base_branch: Base branch to compare against (default: main)
|
| 63 |
+
include_diff: Include the full diff content (default: true)
|
| 64 |
+
max_diff_lines: Maximum number of diff lines to include (default: 500)
|
| 65 |
+
working_directory: Directory to run git commands in (default: current directory)
|
| 66 |
+
"""
|
| 67 |
+
try:
|
| 68 |
+
cwd = working_directory if working_directory else os.getcwd()
|
| 69 |
+
|
| 70 |
+
files_result = subprocess.run(
|
| 71 |
+
["git", "diff", "--name-status", f"{base_branch}...HEAD"],
|
| 72 |
+
capture_output=True,
|
| 73 |
+
text=True,
|
| 74 |
+
check=True,
|
| 75 |
+
cwd=cwd,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
stat_result = subprocess.run(
|
| 79 |
+
["git", "diff", "--stat", f"{base_branch}...HEAD"],
|
| 80 |
+
capture_output=True,
|
| 81 |
+
text=True,
|
| 82 |
+
cwd=cwd,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
diff_content = ""
|
| 86 |
+
truncated = False
|
| 87 |
+
total_diff_lines = 0
|
| 88 |
+
if include_diff:
|
| 89 |
+
diff_result = subprocess.run(
|
| 90 |
+
["git", "diff", f"{base_branch}...HEAD"],
|
| 91 |
+
capture_output=True,
|
| 92 |
+
text=True,
|
| 93 |
+
cwd=cwd,
|
| 94 |
+
)
|
| 95 |
+
diff_lines = diff_result.stdout.split("\n")
|
| 96 |
+
total_diff_lines = len(diff_lines)
|
| 97 |
+
|
| 98 |
+
if len(diff_lines) > max_diff_lines:
|
| 99 |
+
diff_content = "\n".join(diff_lines[:max_diff_lines])
|
| 100 |
+
diff_content += f"\n\n... Output truncated. Showing {max_diff_lines} of {len(diff_lines)} lines ..."
|
| 101 |
+
diff_content += "\n... Use max_diff_lines parameter to see more ..."
|
| 102 |
+
truncated = True
|
| 103 |
+
else:
|
| 104 |
+
diff_content = diff_result.stdout
|
| 105 |
+
|
| 106 |
+
commits_result = subprocess.run(
|
| 107 |
+
["git", "log", "--oneline", f"{base_branch}..HEAD"],
|
| 108 |
+
capture_output=True,
|
| 109 |
+
text=True,
|
| 110 |
+
cwd=cwd,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
analysis = {
|
| 114 |
+
"base_branch": base_branch,
|
| 115 |
+
"files_changed": files_result.stdout,
|
| 116 |
+
"statistics": stat_result.stdout,
|
| 117 |
+
"commits": commits_result.stdout,
|
| 118 |
+
"diff": diff_content if include_diff else "Diff not included",
|
| 119 |
+
"truncated": truncated,
|
| 120 |
+
"total_diff_lines": total_diff_lines,
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
return json.dumps(analysis, indent=2)
|
| 124 |
+
|
| 125 |
+
except subprocess.CalledProcessError as e:
|
| 126 |
+
return json.dumps({"error": f"Git error: {e.stderr}"})
|
| 127 |
+
except Exception as e:
|
| 128 |
+
return json.dumps({"error": str(e)})
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
@mcp.tool()
|
| 132 |
+
async def get_pr_templates() -> str:
|
| 133 |
+
"""List available PR templates with their content."""
|
| 134 |
+
templates = []
|
| 135 |
+
for filename, template_type in DEFAULT_TEMPLATES.items():
|
| 136 |
+
template_path = TEMPLATES_DIR / filename
|
| 137 |
+
if template_path.exists():
|
| 138 |
+
templates.append(
|
| 139 |
+
{
|
| 140 |
+
"filename": filename,
|
| 141 |
+
"type": template_type,
|
| 142 |
+
"content": template_path.read_text(encoding="utf-8"),
|
| 143 |
+
}
|
| 144 |
+
)
|
| 145 |
+
if not templates:
|
| 146 |
+
return json.dumps({"error": "No templates found", "templates_dir": str(TEMPLATES_DIR)})
|
| 147 |
+
return json.dumps(templates, indent=2)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
@mcp.tool()
|
| 151 |
+
async def suggest_template(changes_summary: str, change_type: str) -> str:
|
| 152 |
+
"""Let Claude analyze the changes and suggest the most appropriate PR template.
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
changes_summary: Your analysis of what the changes do
|
| 156 |
+
change_type: The type of change you've identified (bug, feature, docs, refactor, test, etc.)
|
| 157 |
+
"""
|
| 158 |
+
templates_response = await get_pr_templates()
|
| 159 |
+
templates = json.loads(templates_response)
|
| 160 |
+
|
| 161 |
+
if "error" in templates:
|
| 162 |
+
return templates_response
|
| 163 |
+
|
| 164 |
+
template_file = TYPE_MAPPING.get(change_type.lower(), "feature.md")
|
| 165 |
+
selected_template = next(
|
| 166 |
+
(t for t in templates if t["filename"] == template_file),
|
| 167 |
+
templates[0],
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
suggestion = {
|
| 171 |
+
"recommended_template": selected_template,
|
| 172 |
+
"reasoning": f"Based on your analysis: '{changes_summary}', this appears to be a {change_type} change.",
|
| 173 |
+
"template_content": selected_template["content"],
|
| 174 |
+
"usage_hint": "Claude can help you fill out this template based on the specific changes in your PR.",
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
return json.dumps(suggestion, indent=2)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
if __name__ == "__main__":
|
| 181 |
+
mcp.run()
|
quiz-answers/QUIZ_ANSWERS.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MCP Course — Quiz Answers Reference
|
| 2 |
+
|
| 3 |
+
This file compiles the correct answers for the Unit 1 quiz (MCP Fundamentals).
|
| 4 |
+
Use it as a study guide when taking the interactive quiz on Hugging Face.
|
| 5 |
+
|
| 6 |
+
**Quiz link:** https://huggingface.co/spaces/mcp-course/unit_1_quiz
|
| 7 |
+
|
| 8 |
+
**Passing score:** 80% or higher (EXAM_PASSING_SCORE = 0.8)
|
| 9 |
+
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
## Unit 1: MCP Fundamentals (5 questions)
|
| 13 |
+
|
| 14 |
+
| # | Question | Correct Answer |
|
| 15 |
+
|---|----------|----------------|
|
| 16 |
+
| 1 | What is the primary purpose of Model Context Protocol (MCP)? | **B** — To enable AI models to connect with external data sources, tools, and environments |
|
| 17 |
+
| 2 | What problem does MCP primarily aim to solve? | **C** — The M×N Integration Problem |
|
| 18 |
+
| 3 | Which of the following is a key benefit of MCP? | **C** — Standardization and interoperability in the AI ecosystem |
|
| 19 |
+
| 4 | In MCP terminology, what is a "Host"? | **B** — The user-facing AI application |
|
| 20 |
+
| 5 | What does "M×N Integration Problem" refer to in the context of AI applications? | **B** — The challenge of connecting M AI applications to N external tools without a standard |
|
| 21 |
+
|
| 22 |
+
**Score: 5/5 = 100% ✅**
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## Key Concepts (from Unit 1)
|
| 27 |
+
|
| 28 |
+
### Architecture
|
| 29 |
+
- **Host**: The user-facing AI application (e.g., Claude Desktop, Cursor)
|
| 30 |
+
- **Client**: Component within the host that manages communication with a specific MCP Server (1:1 connection)
|
| 31 |
+
- **Server**: External program/service that exposes tools, resources, and prompts via MCP
|
| 32 |
+
|
| 33 |
+
### Three Capability Types
|
| 34 |
+
1. **Tools** — Executable functions that perform actions (model-controlled, require user approval)
|
| 35 |
+
2. **Resources** — Read-only data sources for context retrieval (application-controlled, like GET endpoints)
|
| 36 |
+
3. **Prompts** — Predefined templates/workflows that guide interactions
|
| 37 |
+
|
| 38 |
+
### Transport Mechanisms
|
| 39 |
+
- **stdio** — Local process communication (stdin/stdout)
|
| 40 |
+
- **HTTP + SSE** — Remote server communication (Server-Sent Events)
|
| 41 |
+
|
| 42 |
+
### JSON-RPC 2.0
|
| 43 |
+
MCP uses JSON-RPC 2.0 as the message format. Three message types:
|
| 44 |
+
1. **Requests** — Client → Server (initiate operations)
|
| 45 |
+
2. **Responses** — Server → Client (reply to requests)
|
| 46 |
+
3. **Notifications** — One-way messages (no response needed)
|
| 47 |
+
|
| 48 |
+
### M×N Integration Problem
|
| 49 |
+
Without MCP: M AI apps × N data sources = M×N custom integrations
|
| 50 |
+
With MCP: M + N (write once, use everywhere)
|
| 51 |
+
|
| 52 |
+
### Key Terminology
|
| 53 |
+
- **Sampling**: Server requests LLM interactions from the Client (human-in-the-loop)
|
| 54 |
+
- **Dynamic Capability Discovery**: Client queries available Tools/Resources/Prompts at runtime
|
| 55 |
+
- **Stateless transport**: Each request is independent (no session state on server)
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## Certification
|
| 60 |
+
|
| 61 |
+
| Certificate | Requirements | Link |
|
| 62 |
+
|-------------|-------------|------|
|
| 63 |
+
| **Fundamentals** | Complete Unit 1 (pass quiz ≥80%) | https://huggingface.co/spaces/mcp-course/unit_1_quiz |
|
| 64 |
+
| **Completion** | Complete Units 2 & 3 (build + deploy MCP app) | (project-based, no separate quiz) |
|
| 65 |
+
|
| 66 |
+
## Project: PR Agent MCP Server
|
| 67 |
+
|
| 68 |
+
The Unit 3 project is a PR (Pull Request) agent MCP server that:
|
| 69 |
+
- Analyzes git changes (`analyze_file_changes`)
|
| 70 |
+
- Lists PR templates (`get_pr_templates`)
|
| 71 |
+
- Suggests appropriate templates (`suggest_template`)
|
| 72 |
+
|
| 73 |
+
Source code: `mcp-server/server.py`
|
| 74 |
+
Templates: `templates/` (7 templates: bug, feature, docs, refactor, test, performance, security)
|
| 75 |
+
|
| 76 |
+
### Running the server
|
| 77 |
+
```bash
|
| 78 |
+
python mcp-server/server.py
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
### Testing
|
| 82 |
+
```bash
|
| 83 |
+
# With Claude Code:
|
| 84 |
+
claude mcp add pr-agent -- python /path/to/mcp-server/server.py
|
| 85 |
+
```
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mcp>=1.0.0
|
| 2 |
+
huggingface_hub>=0.25.0
|
templates/bug.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Bug Fix
|
| 2 |
+
|
| 3 |
+
### Description
|
| 4 |
+
<!-- Brief description of the bug being fixed -->
|
| 5 |
+
|
| 6 |
+
### Root Cause
|
| 7 |
+
<!-- What caused the bug? -->
|
| 8 |
+
|
| 9 |
+
### Solution
|
| 10 |
+
<!-- How does this PR fix the bug? -->
|
| 11 |
+
|
| 12 |
+
### Testing
|
| 13 |
+
- [ ] Added/updated tests
|
| 14 |
+
- [ ] Manually tested the fix
|
| 15 |
+
- [ ] Verified no regressions
|
| 16 |
+
|
| 17 |
+
### Related Issues
|
| 18 |
+
Fixes #<!-- issue number -->
|
templates/docs.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Documentation Update
|
| 2 |
+
|
| 3 |
+
### Description
|
| 4 |
+
<!-- What documentation is being updated? -->
|
| 5 |
+
|
| 6 |
+
### Changes
|
| 7 |
+
<!-- List of specific changes made -->
|
| 8 |
+
|
| 9 |
+
### Review Checklist
|
| 10 |
+
- [ ] Grammar and spelling checked
|
| 11 |
+
- [ ] Technical accuracy verified
|
| 12 |
+
- [ ] Examples tested
|
| 13 |
+
- [ ] Links verified
|
templates/feature.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## New Feature
|
| 2 |
+
|
| 3 |
+
### Description
|
| 4 |
+
<!-- Brief description of the new feature -->
|
| 5 |
+
|
| 6 |
+
### Motivation
|
| 7 |
+
<!-- Why is this feature needed? -->
|
| 8 |
+
|
| 9 |
+
### Implementation
|
| 10 |
+
<!-- High-level overview of the implementation -->
|
| 11 |
+
|
| 12 |
+
### Testing
|
| 13 |
+
- [ ] Added unit tests
|
| 14 |
+
- [ ] Added integration tests
|
| 15 |
+
- [ ] Tested edge cases
|
| 16 |
+
|
| 17 |
+
### Documentation
|
| 18 |
+
- [ ] Updated relevant documentation
|
| 19 |
+
- [ ] Added usage examples
|
| 20 |
+
|
| 21 |
+
### Breaking Changes
|
| 22 |
+
<!-- List any breaking changes -->
|
templates/performance.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Performance Improvement
|
| 2 |
+
|
| 3 |
+
### Description
|
| 4 |
+
<!-- What performance issue is being addressed? -->
|
| 5 |
+
|
| 6 |
+
### Metrics
|
| 7 |
+
<!-- Before/after performance metrics -->
|
| 8 |
+
|
| 9 |
+
### Changes
|
| 10 |
+
<!-- Specific optimizations made -->
|
| 11 |
+
|
| 12 |
+
### Testing
|
| 13 |
+
- [ ] Benchmarks added/updated
|
| 14 |
+
- [ ] No functionality regression
|
| 15 |
+
- [ ] Tested under various loads
|
templates/refactor.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Code Refactoring
|
| 2 |
+
|
| 3 |
+
### Description
|
| 4 |
+
<!-- What code is being refactored? -->
|
| 5 |
+
|
| 6 |
+
### Motivation
|
| 7 |
+
<!-- Why is this refactoring needed? -->
|
| 8 |
+
|
| 9 |
+
### Changes
|
| 10 |
+
<!-- List of specific refactoring changes -->
|
| 11 |
+
|
| 12 |
+
### Testing
|
| 13 |
+
- [ ] All existing tests pass
|
| 14 |
+
- [ ] No functional changes
|
| 15 |
+
- [ ] Performance impact assessed
|
| 16 |
+
|
| 17 |
+
### Risk Assessment
|
| 18 |
+
<!-- Any risks with this refactoring? -->
|
templates/security.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Security Update
|
| 2 |
+
|
| 3 |
+
### Description
|
| 4 |
+
<!-- Brief description of security issue (be careful not to expose vulnerabilities) -->
|
| 5 |
+
|
| 6 |
+
### Impact
|
| 7 |
+
<!-- Who/what is affected? -->
|
| 8 |
+
|
| 9 |
+
### Solution
|
| 10 |
+
<!-- How does this PR address the security issue? -->
|
| 11 |
+
|
| 12 |
+
### Testing
|
| 13 |
+
- [ ] Security tests added
|
| 14 |
+
- [ ] Penetration testing performed
|
| 15 |
+
- [ ] No new vulnerabilities introduced
|
| 16 |
+
|
| 17 |
+
### References
|
| 18 |
+
<!-- Link to security advisories if applicable -->
|
templates/test.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Test Update
|
| 2 |
+
|
| 3 |
+
### Description
|
| 4 |
+
<!-- What tests are being added or updated? -->
|
| 5 |
+
|
| 6 |
+
### Coverage
|
| 7 |
+
- Previous coverage: <!-- X% -->
|
| 8 |
+
- New coverage: <!-- Y% -->
|
| 9 |
+
|
| 10 |
+
### Test Types
|
| 11 |
+
- [ ] Unit tests
|
| 12 |
+
- [ ] Integration tests
|
| 13 |
+
- [ ] End-to-end tests
|
| 14 |
+
|
| 15 |
+
### Related Features
|
| 16 |
+
<!-- List features/components being tested -->
|