Skip to content

Commit a317493

Browse files
committed
feat: Complete Unit 3 Module 3 - Slack Notification Integration
- Remove Hugging Face Hub Integration module (will be in separate PR huggingface#69) - Restructure Unit 3 to 3 modules: Build MCP Server, GitHub Actions, Slack Notification - Build complete Slack Notification module demonstrating Tools + Prompts integration - Add comprehensive manual testing with curl commands for easy verification - Include security guidance for webhook URLs and environment variables - Fix Slack markdown formatting with proper <url|text> syntax - Create complete starter/solution project structure
1 parent 937d1f3 commit a317493

File tree

16 files changed

+3141
-38
lines changed

16 files changed

+3141
-38
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Module 3: Slack Notification - Complete Solution
2+
3+
This is the complete implementation of Module 3, demonstrating how to integrate MCP Tools and Prompts for team communication via Slack.
4+
5+
## What This Implements
6+
7+
This solution extends Modules 1 and 2 with:
8+
9+
1. **`send_slack_notification` tool** - Sends formatted messages to Slack via webhook with proper error handling
10+
2. **`format_ci_failure_alert` prompt** - Creates rich failure alerts with Slack markdown
11+
3. **`format_ci_success_summary` prompt** - Creates celebration messages for successful deployments
12+
13+
## Setup and Usage
14+
15+
1. Install dependencies:
16+
```bash
17+
uv sync
18+
```
19+
20+
2. Set up Slack webhook:
21+
```bash
22+
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
23+
```
24+
25+
3. Start services:
26+
```bash
27+
# Terminal 1: Webhook server
28+
python webhook_server.py
29+
30+
# Terminal 2: MCP server
31+
uv run server.py
32+
33+
# Terminal 3: Cloudflare tunnel (optional)
34+
cloudflared tunnel --url http://localhost:8080
35+
```
36+
37+
## Testing
38+
39+
See `manual_test.md` for comprehensive testing instructions using curl commands to simulate GitHub webhook events.
40+
41+
## Key Learning Outcomes
42+
43+
This solution demonstrates all MCP primitives working together for real-world team automation.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"timestamp": "2025-05-30T22:42:00.904997",
4+
"event_type": "workflow_run",
5+
"action": "completed",
6+
"workflow_run": {
7+
"name": "CI",
8+
"status": "completed",
9+
"conclusion": "failure",
10+
"run_number": 42,
11+
"html_url": "https://github.com/test/repo/actions/runs/123",
12+
"head_branch": "test",
13+
"head_sha": "abc123"
14+
},
15+
"check_run": null,
16+
"repository": null,
17+
"sender": null
18+
}
19+
]
Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
# Manual Testing Guide - Slack Notification Module
2+
3+
This guide provides curl-based tests so you can verify your implementation without setting up a full GitHub repository and Actions workflow.
4+
5+
## Prerequisites
6+
7+
1. MCP server running: `uv run server.py`
8+
2. Webhook server running: `python webhook_server.py`
9+
3. Slack webhook URL set: `export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."`
10+
11+
## Test 1: Direct Slack Tool Test
12+
13+
Test your `send_slack_notification` tool directly via Claude Code:
14+
15+
```bash
16+
# Start your MCP server and connect with Claude Code, then ask:
17+
# "Send a test message to Slack: 'Hello from MCP Course Module 3!'"
18+
```
19+
20+
Expected result: Message appears in your Slack channel.
21+
22+
## Test 2: Simulate GitHub Webhook Events
23+
24+
### 2a. Simulate CI Failure Event
25+
26+
Send a fake GitHub Actions failure event to your webhook server:
27+
28+
```bash
29+
curl -X POST http://localhost:8080/webhook/github \
30+
-H "Content-Type: application/json" \
31+
-H "X-GitHub-Event: workflow_run" \
32+
-d '{
33+
"action": "completed",
34+
"workflow_run": {
35+
"id": 123456789,
36+
"name": "CI",
37+
"status": "completed",
38+
"conclusion": "failure",
39+
"run_number": 42,
40+
"created_at": "2024-01-15T10:30:00Z",
41+
"updated_at": "2024-01-15T10:35:00Z",
42+
"html_url": "https://github.com/user/repo/actions/runs/123456789",
43+
"head_branch": "feature/slack-integration",
44+
"head_sha": "abc123f456789",
45+
"repository": {
46+
"name": "mcp-course",
47+
"full_name": "user/mcp-course",
48+
"html_url": "https://github.com/user/mcp-course"
49+
},
50+
"pull_requests": [{
51+
"number": 42,
52+
"url": "https://api.github.com/repos/user/mcp-course/pulls/42",
53+
"html_url": "https://github.com/user/mcp-course/pull/42"
54+
}]
55+
}
56+
}'
57+
```
58+
59+
### 2b. Simulate CI Success Event
60+
61+
```bash
62+
curl -X POST http://localhost:8080/webhook/github \
63+
-H "Content-Type: application/json" \
64+
-H "X-GitHub-Event: workflow_run" \
65+
-d '{
66+
"action": "completed",
67+
"workflow_run": {
68+
"id": 123456790,
69+
"name": "Deploy",
70+
"status": "completed",
71+
"conclusion": "success",
72+
"run_number": 43,
73+
"created_at": "2024-01-15T11:30:00Z",
74+
"updated_at": "2024-01-15T11:35:00Z",
75+
"html_url": "https://github.com/user/repo/actions/runs/123456790",
76+
"head_branch": "main",
77+
"head_sha": "def456g789012",
78+
"repository": {
79+
"name": "mcp-course",
80+
"full_name": "user/mcp-course",
81+
"html_url": "https://github.com/user/mcp-course"
82+
},
83+
"pull_requests": [{
84+
"number": 43,
85+
"url": "https://api.github.com/repos/user/mcp-course/pulls/43",
86+
"html_url": "https://github.com/user/mcp-course/pull/43"
87+
}]
88+
}
89+
}'
90+
```
91+
92+
## Test 3: End-to-End Workflow Tests
93+
94+
After sending the webhook events above, test the complete workflow via Claude Code:
95+
96+
### 3a. Test Failure Alert Workflow
97+
98+
Ask Claude Code:
99+
```
100+
"Check recent CI events, find any failures, format them as a Slack alert, and send to the team"
101+
```
102+
103+
Expected workflow:
104+
1. Claude calls `get_recent_actions_events()` → finds failure event
105+
2. Claude calls `format_ci_failure_alert()` → generates formatted message
106+
3. Claude calls `send_slack_notification()` → sends to Slack
107+
108+
Expected Slack message:
109+
```
110+
❌ *CI Failed* - mcp-course
111+
112+
> CI workflow failed on feature/slack-integration
113+
114+
*Details:*
115+
• Workflow: `CI`
116+
• Branch: `feature/slack-integration`
117+
• Commit: `abc123f`
118+
119+
*Next Steps:*
120+
• <https://github.com/user/mcp-course/pull/42|View Pull Request>
121+
• <https://github.com/user/repo/actions/runs/123456789|Check Action Logs>
122+
```
123+
124+
### 3b. Test Success Summary Workflow
125+
126+
Ask Claude Code:
127+
```
128+
"Check recent CI events, find any successful deployments, format them as a celebration message, and send to the team"
129+
```
130+
131+
Expected workflow:
132+
1. Claude calls `get_recent_actions_events()` → finds success event
133+
2. Claude calls `format_ci_success_summary()` → generates formatted message
134+
3. Claude calls `send_slack_notification()` → sends to Slack
135+
136+
Expected Slack message:
137+
```
138+
✅ *Deployment Successful* - mcp-course
139+
140+
> Deploy workflow completed successfully on main
141+
142+
*Changes:*
143+
• Module 3 Slack integration added
144+
• Team notification system implemented
145+
146+
*Links:*
147+
• <https://github.com/user/mcp-course/pull/43|View Changes>
148+
• <https://github.com/user/mcp-course|Visit Repository>
149+
```
150+
151+
## Test 4: Error Handling Tests
152+
153+
### 4a. Test Missing Webhook URL
154+
155+
```bash
156+
# Temporarily unset the environment variable
157+
unset SLACK_WEBHOOK_URL
158+
159+
# Ask Claude Code to send a message
160+
# Expected: Error message about missing environment variable
161+
```
162+
163+
### 4b. Test Invalid Webhook URL
164+
165+
```bash
166+
# Set invalid webhook URL
167+
export SLACK_WEBHOOK_URL="https://invalid-webhook-url.com/test"
168+
169+
# Ask Claude Code to send a message
170+
# Expected: Error message about connection failure
171+
```
172+
173+
### 4c. Restore Valid Webhook URL
174+
175+
```bash
176+
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/ACTUAL/URL"
177+
```
178+
179+
## Test 5: Prompt-Only Tests
180+
181+
Test the formatting prompts without sending to Slack:
182+
183+
### 5a. Test Failure Alert Prompt
184+
185+
Ask Claude Code:
186+
```
187+
"Use the format_ci_failure_alert prompt to create a failure message for the recent CI failure, but don't send it to Slack yet"
188+
```
189+
190+
### 5b. Test Success Summary Prompt
191+
192+
Ask Claude Code:
193+
```
194+
"Use the format_ci_success_summary prompt to create a success message for the recent deployment, but don't send it to Slack yet"
195+
```
196+
197+
## Test 6: Integration with Previous Modules
198+
199+
Test that all previous module functionality still works:
200+
201+
### 6a. Module 1 Integration
202+
203+
Ask Claude Code:
204+
```
205+
"Analyze current file changes, suggest a PR template, then create a Slack message about the PR status"
206+
```
207+
208+
### 6b. Module 2 Integration
209+
210+
Ask Claude Code:
211+
```
212+
"Check workflow status, analyze the CI results, and create a comprehensive team update for Slack"
213+
```
214+
215+
## Verification Checklist
216+
217+
After running these tests, verify:
218+
219+
- [ ] Direct Slack tool works (Test 1)
220+
- [ ] Webhook server receives and stores events (Test 2)
221+
- [ ] Failure alert workflow works end-to-end (Test 3a)
222+
- [ ] Success summary workflow works end-to-end (Test 3b)
223+
- [ ] Error handling works properly (Test 4)
224+
- [ ] Prompts work independently (Test 5)
225+
- [ ] Integration with previous modules works (Test 6)
226+
- [ ] Slack messages display with proper formatting
227+
- [ ] All tools and prompts are accessible to Claude Code
228+
229+
## Troubleshooting
230+
231+
### Webhook Server Issues
232+
```bash
233+
# Check if webhook server is running
234+
curl http://localhost:8080/health
235+
236+
# Check stored events
237+
cat github_events.json
238+
```
239+
240+
### MCP Server Issues
241+
```bash
242+
# Check if MCP server is responding
243+
# Should see server startup messages when running uv run server.py
244+
```
245+
246+
### Slack Issues
247+
```bash
248+
# Test webhook URL directly
249+
curl -X POST -H 'Content-type: application/json' \
250+
--data '{"text":"Direct webhook test"}' \
251+
$SLACK_WEBHOOK_URL
252+
```
253+
254+
This testing approach lets you validate your implementation without needing to set up a real GitHub repository with Actions workflows!
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[project]
2+
name = "pr-agent-slack"
3+
version = "3.0.0"
4+
description = "MCP server with Slack notifications integrating Tools and Prompts"
5+
readme = "README.md"
6+
requires-python = ">=3.10"
7+
dependencies = [
8+
"mcp[cli]>=1.0.0",
9+
"aiohttp>=3.10.0,<4.0.0",
10+
"requests>=2.32.0,<3.0.0",
11+
]
12+
13+
[project.optional-dependencies]
14+
dev = [
15+
"pytest>=8.3.0",
16+
"pytest-asyncio>=0.21.0",
17+
]
18+
19+
[build-system]
20+
requires = ["hatchling"]
21+
build-backend = "hatchling.build"
22+
23+
[tool.hatch.build.targets.wheel]
24+
packages = ["."]
25+
26+
[tool.uv]
27+
dev-dependencies = [
28+
"pytest>=8.3.0",
29+
"pytest-asyncio>=0.21.0",
30+
]

0 commit comments

Comments
 (0)