Skip to content

Commit 4727092

Browse files
authored
Merge pull request #83 from huggingface/release/unit3
[RELEASE] Unit 3 and 3.1 for 12/6/25
2 parents 1e6a195 + fcdd02a commit 4727092

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+11809
-13
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ cython_debug/
173173
# PyPI configuration file
174174
.pypirc
175175

176-
.DS_Store
176+
.DS_Store
177+
178+
videos/
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Module 1: Basic MCP Server with PR Template Tools
2+
3+
This module implements a basic MCP server that provides tools for analyzing git changes and suggesting appropriate PR templates.
4+
5+
## Setup
6+
7+
### 1. Install uv
8+
9+
Follow the official installation instructions at: https://docs.astral.sh/uv/getting-started/installation/
10+
11+
### 2. Install dependencies
12+
13+
```bash
14+
# Install all dependencies
15+
uv sync
16+
17+
# Or install with dev dependencies for testing
18+
uv sync --all-extras
19+
```
20+
21+
### 3. Configure the MCP Server
22+
23+
Add the server to Claude Code:
24+
25+
```bash
26+
# Add the MCP server
27+
claude mcp add pr-agent -- uv --directory /absolute/path/to/module1/solution run server.py
28+
29+
# Verify it's configured
30+
claude mcp list
31+
```
32+
33+
## Tools Available
34+
35+
1. **analyze_file_changes** - Get the full diff and list of changed files
36+
2. **get_pr_templates** - List available PR templates with their content
37+
3. **suggest_template** - Let Claude analyze changes and suggest a template
38+
39+
## Usage Example
40+
41+
1. Make some changes in a git repository
42+
2. Ask Claude: "Can you analyze my changes and suggest a PR template?"
43+
3. Claude will:
44+
- Use `analyze_file_changes` to see what changed
45+
- Analyze the diff to understand the nature of changes
46+
- Use `suggest_template` to recommend the most appropriate template
47+
- Help you fill out the template based on the specific changes
48+
49+
## How It Works
50+
51+
Unlike traditional template systems that rely on file extensions or simple patterns, this MCP server provides Claude with raw git data and lets Claude's intelligence determine:
52+
- What type of change is being made (bug fix, feature, refactor, etc.)
53+
- Which template is most appropriate
54+
- How to fill out the template based on the actual code changes
55+
56+
This approach leverages Claude's understanding of code and context rather than rigid rules.
57+
58+
## Running Tests
59+
60+
```bash
61+
# Run the validation script
62+
uv run python validate_solution.py
63+
64+
# Run unit tests
65+
uv run pytest test_server.py -v
66+
```
67+
68+
## Running the Server Directly
69+
70+
```bash
71+
# Start the MCP server
72+
uv run server.py
73+
```
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Manual Testing Guide for Module 1 Solution
2+
3+
## Prerequisites
4+
5+
1. Ensure you're in a git repository with some changes
6+
2. Install uv following instructions at: https://docs.astral.sh/uv/getting-started/installation/
7+
3. Install dependencies:
8+
```bash
9+
uv sync --all-extras
10+
```
11+
12+
## Test 1: Validate the Solution
13+
14+
Run the automated validation script:
15+
```bash
16+
uv run python validate_solution.py
17+
```
18+
19+
This will check:
20+
- Git environment
21+
- Python imports
22+
- Server creation
23+
- Tool registration
24+
- Tool execution
25+
- Template creation
26+
27+
## Test 2: Run Unit Tests
28+
29+
```bash
30+
uv run pytest test_server.py -v
31+
```
32+
33+
## Test 3: Test with Claude Code
34+
35+
1. **Configure MCP Server**
36+
37+
Add the server to Claude Code:
38+
```bash
39+
# Add the MCP server
40+
claude mcp add pr-agent -- uv --directory /absolute/path/to/module1/solution run server.py
41+
42+
# Verify it's configured
43+
claude mcp list
44+
```
45+
46+
2. **Restart Claude Code** to pick up the new server
47+
48+
3. **Make Some Git Changes**
49+
50+
In any git repository:
51+
```bash
52+
echo "test change" >> README.md
53+
git add README.md
54+
```
55+
56+
4. **Test with Claude**
57+
58+
Ask Claude:
59+
- "Can you analyze my git changes?"
60+
- "What PR templates are available?"
61+
- "Based on my changes, which PR template should I use?"
62+
63+
## Test 4: Direct Server Testing
64+
65+
You can also test the server directly:
66+
67+
```python
68+
import asyncio
69+
from server import analyze_file_changes, get_pr_templates, suggest_template
70+
71+
async def test():
72+
# Test analyze_file_changes
73+
changes = await analyze_file_changes("main", True)
74+
print("Changes:", changes[:200] + "...")
75+
76+
# Test get_pr_templates
77+
templates = await get_pr_templates()
78+
print("Templates available:", len(json.loads(templates)))
79+
80+
# Test suggest_template
81+
suggestion = await suggest_template(
82+
"Fixed authentication bug",
83+
"bug"
84+
)
85+
print("Suggestion:", json.loads(suggestion)["recommended_template"]["type"])
86+
87+
asyncio.run(test())
88+
```
89+
90+
## Expected Behavior
91+
92+
1. **analyze_file_changes** should return JSON with:
93+
- base_branch
94+
- files_changed
95+
- statistics
96+
- commits
97+
- diff (if include_diff=True)
98+
99+
2. **get_pr_templates** should return JSON array of templates with:
100+
- filename
101+
- type
102+
- content
103+
104+
3. **suggest_template** should return JSON with:
105+
- recommended_template
106+
- reasoning
107+
- template_content
108+
- usage_hint
109+
110+
## Troubleshooting
111+
112+
- **"Git not found"**: Ensure you're in a git repository
113+
- **Import errors**: Check virtual environment is activated
114+
- **MCP connection failed**: Verify the path in the claude mcp add command is absolute
115+
- **No tools showing**: Restart Claude Code after adding the server
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[project]
2+
name = "pr-agent"
3+
version = "1.0.0"
4+
description = "MCP server for PR template suggestions"
5+
readme = "README.md"
6+
requires-python = ">=3.10"
7+
dependencies = [
8+
"mcp[cli]>=1.0.0",
9+
]
10+
11+
[project.optional-dependencies]
12+
dev = [
13+
"pytest>=8.3.0",
14+
"pytest-asyncio>=0.21.0",
15+
]
16+
17+
[build-system]
18+
requires = ["hatchling"]
19+
build-backend = "hatchling.build"
20+
21+
[tool.hatch.build.targets.wheel]
22+
packages = ["."]
23+
24+
[tool.uv]
25+
dev-dependencies = [
26+
"pytest>=8.3.0",
27+
"pytest-asyncio>=0.21.0",
28+
]

0 commit comments

Comments
 (0)