Skip to content

Commit 9f88871

Browse files
committed
feat: Add Module 2 - Smart File Analysis with MCP Resources
- Implement MCP Resources for project context and team guidelines - Add solution with four resource types: templates, team guidelines, git history, and review process - Create starter code building on Module 1 solution - Add comprehensive documentation and solution walkthrough - Create shared team-guidelines directory with coding standards and PR guidelines - Include manual testing guide for resource validation - Update Module 1 comment to reflect templates are shared across all modules
1 parent 0c29dfd commit 9f88871

File tree

12 files changed

+1757
-10
lines changed

12 files changed

+1757
-10
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Module 2: Smart File Analysis - Solution
2+
3+
This is the complete solution for Module 2, which enhances the PR Agent with MCP Resources.
4+
5+
## What's New in Module 2
6+
7+
Building on Module 1's tools, this solution adds:
8+
9+
1. **Resources** for exposing project context to Claude
10+
2. **Dynamic URI patterns** for accessing specific files
11+
3. **Team-specific guidelines** that help Claude make better decisions
12+
13+
## Key Resources Implemented
14+
15+
- `file://templates/{filename}` - Read individual PR templates
16+
- `file://team-guidelines/{filename}` - Access coding standards and PR guidelines
17+
- `git://recent-changes` - Analyze recent commit patterns
18+
- `team://review-process` - Understand team review requirements
19+
20+
## Running the Solution
21+
22+
```bash
23+
# Install dependencies
24+
uv sync --all-extras
25+
26+
# Run the server
27+
uv run server.py
28+
```
29+
30+
## Testing
31+
32+
Configure in Claude Desktop:
33+
```json
34+
{
35+
"mcpServers": {
36+
"pr-agent": {
37+
"command": "uv",
38+
"args": [
39+
"--directory",
40+
"/path/to/smart-file-analysis/solution",
41+
"run",
42+
"server.py"
43+
]
44+
}
45+
}
46+
}
47+
```
48+
49+
Then import to Claude Code:
50+
```bash
51+
claude mcp import-from-desktop
52+
```
53+
54+
## Project Structure
55+
56+
```
57+
solution/
58+
├── server.py # MCP server with Tools and Resources
59+
├── pyproject.toml # Dependencies
60+
└── README.md # This file
61+
62+
Shared resources:
63+
../../../team-guidelines/ # Team coding standards and PR guidelines
64+
../../../templates/ # PR templates
65+
```
66+
67+
## Key Improvements from Module 1
68+
69+
1. **Context Awareness**: Claude can now read team guidelines to understand your specific requirements
70+
2. **Git History**: Claude can analyze recent commits to understand project patterns
71+
3. **Resource URIs**: Clean, intuitive paths for accessing different types of data
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Manual Testing Guide for Module 2 Solution
2+
3+
## Prerequisites
4+
5+
1. Ensure you're in a git repository with commit history
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: Verify Resources Setup
13+
14+
Check that the shared directories exist:
15+
```bash
16+
# From the solution directory
17+
ls ../../templates/
18+
ls ../../team-guidelines/
19+
```
20+
21+
You should see:
22+
- Templates: bug.md, feature.md, docs.md, etc.
23+
- Team guidelines: coding-standards.md, pr-guidelines.md
24+
25+
## Test 2: Test with Claude
26+
27+
1. **Configure MCP Settings**
28+
29+
Add to your Claude Desktop MCP settings (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
30+
31+
```json
32+
{
33+
"mcpServers": {
34+
"pr-agent": {
35+
"command": "uv",
36+
"args": [
37+
"--directory",
38+
"/absolute/path/to/smart-file-analysis/solution",
39+
"run",
40+
"server.py"
41+
]
42+
}
43+
}
44+
}
45+
```
46+
47+
2. **Import to Claude Code** ([documentation](https://docs.anthropic.com/en/docs/claude-code/tutorials#import-mcp-servers-from-claude-desktop)):
48+
```bash
49+
claude mcp import-from-desktop
50+
```
51+
52+
3. **Restart Claude Desktop/Code** to pick up the new server
53+
54+
4. **Test Resource Access**
55+
56+
Ask Claude to test the new resources:
57+
- "What are our team's coding standards?"
58+
- "Show me the PR guidelines"
59+
- "What are the recent commits in this repository?"
60+
- "What's our team's review process?"
61+
- "Can you read the bug.md template?"
62+
63+
## Test 3: Combined Tool and Resource Usage
64+
65+
Test how Claude uses both tools and resources together:
66+
67+
1. **Make some changes in your repo**:
68+
```bash
69+
echo "# New feature" >> feature.py
70+
git add feature.py
71+
```
72+
73+
2. **Ask Claude for comprehensive help**:
74+
- "Can you analyze my changes and suggest a PR based on our team guidelines?"
75+
- "What template should I use given our coding standards?"
76+
- "Based on recent commits, does my change follow the project patterns?"
77+
78+
## Expected Behavior
79+
80+
### Resources Should Return:
81+
82+
1. **read_template("filename.md")**
83+
- Full content of the template file
84+
- Error message if file not found
85+
86+
2. **read_team_guidelines("filename.md")**
87+
- Content of the guideline file
88+
- Error message if file not found
89+
90+
3. **get_recent_changes()**
91+
- JSON with recent_commits array
92+
- Each commit has: hash, author, email, date, message
93+
- Includes change_statistics
94+
95+
4. **get_team_review_process()**
96+
- JSON with pr_size_limits, review_sla, merge_requirements, communication
97+
98+
### Claude Should Be Able To:
99+
100+
1. **Access team context** when making suggestions
101+
2. **Reference specific guidelines** in responses
102+
3. **Analyze commit patterns** to suggest consistent changes
103+
4. **Apply team processes** when recommending workflows
104+
105+
## Troubleshooting
106+
107+
- **"File not found"**: Check that team-guidelines and templates directories exist at the correct path
108+
- **Resources not showing in Claude**: Ensure the server restarted after adding resources
109+
- **Git errors**: Make sure you're in a git repository with commit history
110+
- **Path issues**: Verify TEAM_GUIDELINES_DIR and TEMPLATES_DIR point to correct locations
111+
112+
## Integration Testing
113+
114+
Test that Module 2 builds on Module 1:
115+
116+
1. All Module 1 tools should still work
117+
2. Resources should enhance tool suggestions
118+
3. Claude should reference guidelines when analyzing changes
119+
120+
Example test:
121+
- "Analyze my changes and suggest a template that follows our team guidelines"
122+
123+
This should use:
124+
- `analyze_file_changes` tool (from Module 1)
125+
- `read_team_guidelines` resource (new in Module 2)
126+
- `suggest_template` tool with context from resources
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 = "2.0.0"
4+
description = "MCP server with Resources for smart file analysis"
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)