Module 3: Slack Notification

The Communication Gap Crisis

Week 3 at CodeCraft Studios. Your automation system is already transforming how the team works:

The team is feeling much more confident… until Monday morning brings a new crisis.

The frontend team (Emma and Jake) spent the entire weekend debugging a nasty API integration issue. They tried everything: checked their network calls, validated request formats, even rewrote the error handling. Finally, at 2 AM Sunday, they discovered the backend team had fixed this exact issue on Friday and deployed the fix to staging - but forgot to announce it.

“We wasted 12 hours solving a problem that was already fixed!” Emma says, frustrated.

Meanwhile, the design team finished the new user onboarding flow illustrations last week, but the frontend team didn’t know they were ready. Those beautiful assets are still sitting unused while the team ships a temporary design.

The team realizes they have an information silo problem. Everyone’s working hard, but they’re not communicating effectively about what’s happening when.

Your mission: Complete the automation system with intelligent Slack notifications that keep the whole team informed about important developments automatically.

What You’ll Build

This final module completes the CodeCraft Studios transformation. You’ll integrate Tools and Prompts to create a smart notification system that sends formatted Slack messages about CI/CD events, demonstrating how all MCP primitives work together in a real-world scenario.

Building on the foundation from Modules 1 and 2, you’ll add the final piece of the puzzle:

Screencast: The Complete Automation System! 🎉

The Final Piece: Watch how your complete automation system prevents those Monday morning surprises that plagued Emma and Jake!

What You’ll See:

The Smart Notification: Claude doesn’t just spam the team—it crafts a professional alert with:

Why This Matters: Remember the communication gap crisis? No more! This system ensures that when CI fails on demo-bad-pr branch, the whole team knows immediately. No more weekend debugging sessions for issues that were already fixed!

The Complete Journey: From Module 1’s PR chaos to Module 3’s intelligent team notifications—you’ve built a system that transforms how CodeCraft Studios collaborates. The weekend warriors become informed teammates! 🚀

Learning Objectives

By the end of this module, you’ll understand:

  1. How to integrate external APIs with MCP Tools
  2. How to combine Tools and Prompts for complete workflows
  3. How to format rich messages using Slack markdown
  4. How all MCP primitives work together in practice

Prerequisites

You’ll need everything from the previous modules plus:

Key Concepts

MCP Integration Pattern

This module demonstrates the complete workflow:

  1. Events → GitHub Actions webhook (from Module 2)
  2. Prompts → Format events into readable messages
  3. Tools → Send formatted messages to Slack
  4. Result → Professional team notifications

Slack Markdown Formatting

You’ll use Slack’s markdown for rich messages:

Project Structure

slack-notification/
├── starter/          # Your starting point
│   ├── server.py     # Modules 1+2 code + TODOs
│   ├── webhook_server.py  # From Module 2
│   ├── pyproject.toml
│   └── README.md
└── solution/         # Complete implementation
    ├── server.py     # Full Slack integration
    ├── webhook_server.py
    └── README.md

Implementation Steps

Step 1: Set Up Slack Integration (10 min)

  1. Create a Slack webhook:

  2. Test webhook works (following webhook posting examples):

    curl -X POST -H 'Content-type: application/json' \
      --data '{"text":"Hello from MCP Course!"}' \
      YOUR_WEBHOOK_URL
  3. Set environment variable:

    export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"

    ⚠️ Security Note: The webhook URL is a sensitive secret that grants permission to post messages to your Slack channel. Always:

Security Alert: Webhook URLs are sensitive credentials! Anyone with your webhook URL can send messages to your Slack channel. Always store them as environment variables and never commit them to version control.

Step 2: Add Slack Tool (15 min)

Now that you have a working webhook, you’ll add a new MCP tool to your existing server.py from Module 2. This tool will handle sending notifications to Slack by making HTTP requests to the webhook URL.

Note: The starter code includes all improvements from Modules 1 & 2 (output limiting, webhook handling). Focus on the new Slack integration!

Add this tool to your server.py:

send_slack_notification:

import os
import requests
from mcp.types import TextContent

@mcp.tool()
def send_slack_notification(message: str) -> str:
    """Send a formatted notification to the team Slack channel."""
    webhook_url = os.getenv("SLACK_WEBHOOK_URL")
    if not webhook_url:
        return "Error: SLACK_WEBHOOK_URL environment variable not set"
    
    try:
        # TODO: Send POST request to webhook_url
        # TODO: Include message in JSON payload with "mrkdwn": true
        # TODO: Handle response and return status
        pass
    except Exception as e:
        return f"Error sending message: {str(e)}"

Step 3: Create Formatting Prompts (15 min)

Next, you’ll add MCP Prompts to your server - this is where the magic happens! These prompts will work with Claude to automatically format your GitHub webhook data into well-structured Slack messages. Remember from Module 1 that Prompts provide reusable instructions that Claude can use consistently.

Implement two prompts that generate Slack-formatted messages:

  1. format_ci_failure_alert:

    @mcp.prompt()
    def format_ci_failure_alert() -> str:
        """Create a Slack alert for CI/CD failures."""
        return """Format this GitHub Actions failure as a Slack message:
    
    Use this template:
    :rotating_light: *CI Failure Alert* :rotating_light:
    
    A CI workflow has failed:
    *Workflow*: workflow_name
    *Branch*: branch_name
    *Status*: Failed
    *View Details*: <LOGS_LINK|View Logs>
    
    Please check the logs and address any issues.
    
    Use Slack markdown formatting and keep it concise for quick team scanning."""
  2. format_ci_success_summary:

    @mcp.prompt()
    def format_ci_success_summary() -> str:
        """Create a Slack message celebrating successful deployments."""
        return """Format this successful GitHub Actions run as a Slack message:
    
    Use this template:
    :white_check_mark: *Deployment Successful* :white_check_mark:
    
    Deployment completed successfully for [Repository Name]
    
    *Changes:*
    - Key feature or fix 1
    - Key feature or fix 2
    
    *Links:*
    <PR_LINK|View Changes>
    
    Keep it celebratory but informative. Use Slack markdown formatting."""

Step 4: Test Complete Workflow (10 min)

Now comes the exciting part - testing your complete MCP workflow! You’ll have all three components working together: webhook capture from Module 2, prompt formatting from this module, and Slack notifications.

  1. Start all services (just like in Module 2, but now with Slack integration):

    # Terminal 1: Start webhook server
    python webhook_server.py
    
    # Terminal 2: Start MCP server
    uv run server.py
    
    # Terminal 3: Start Cloudflare Tunnel  
    cloudflared tunnel --url http://localhost:8080
  2. Test the complete integration with Claude Code:

Step 5: Verify Integration (5 min)

You can test your implementation without setting up a real GitHub repository! See manual_test.md for curl commands that simulate GitHub webhook events.

Understanding the webhook event flow:

Quick Test Workflow:

  1. Use curl to send fake GitHub events to your webhook server
  2. Ask Claude to check recent events and format them
  3. Send formatted messages to Slack
  4. Verify everything works end-to-end

Manual Testing Alternative: For a complete testing experience without GitHub setup, follow the step-by-step curl commands in manual_test.md.

Example Workflow in Claude Code

User: "Check recent CI events and notify the team about any failures"

Claude: 
1. Uses get_recent_actions_events (from Module 2)
2. Finds a workflow failure
3. Uses format_ci_failure_alert prompt to create message
4. Uses send_slack_notification tool to deliver it
5. Reports back: "Sent failure alert to #dev-team channel"

Expected Slack Message Output

Failure Alert:

🚨 *CI Failure Alert* 🚨

A CI workflow has failed:
*Workflow*: CI (Run #42)
*Branch*: feature/slack-integration
*Status*: Failed
*View Details*: <https://github.com/user/mcp-course/actions/runs/123|View Logs>

Please check the logs and address any issues.

Success Summary:

✅ *Deployment Successful* ✅

Deployment completed successfully for mcp-course

*Changes:*
- Added team notification system
- Integrated MCP Tools and Prompts

*Links:*
<https://github.com/user/mcp-course/pull/42|View Changes>

Common Issues

Webhook URL Issues

Message Formatting

Network Errors

Key Takeaways

You’ve now built a complete MCP workflow that demonstrates:

This shows the power of MCP for building practical development automation tools!

Key Learning: You’ve now built a complete MCP workflow that combines Tools (for external API calls) with Prompts (for consistent formatting). This pattern of Tools + Prompts is fundamental to advanced MCP development and can be applied to many other automation scenarios.

Next Steps

Congratulations! You’ve completed the final module of Unit 3 and built a complete end-to-end automation system. Your journey through all three modules has given you hands-on experience with:

What to do next:

  1. Test your complete system - Try triggering real GitHub events and watch the full pipeline work
  2. Experiment with customization - Modify the Slack message formats or add new notification types
  3. Review the Unit 3 Conclusion - Reflect on everything you’ve learned and explore next steps
  4. Share your success - Show teammates how MCP can automate your development workflows

You now have a solid foundation for building intelligent automation systems with MCP!

The transformation is complete!

CodeCraft Studios has gone from chaotic development to a well-oiled machine. The automation system you built handles:

The team can now focus on building great products instead of fighting process problems. And you’ve learned advanced MCP patterns that you can apply to any automation challenge!

Additional Resources

< > Update on GitHub