import os import requests from typing import Union from mcp.types import TextContent def send_slack_notification(message: str) -> str: """Send a formatted notification to the team Slack channel. Args: message: The message text to send (supports markdown formatting) Returns: str: Success message or error description """ webhook_url = os.getenv("SLACK_WEBHOOK_URL") if not webhook_url: return "Error: SLACK_WEBHOOK_URL environment variable not set" try: payload = { "text": message, "mrkdwn": True # Enable markdown formatting } response = requests.post( webhook_url, json=payload, headers={'Content-Type': 'application/json'}, timeout=10 # 10 second timeout ) # Check if the request was successful if response.status_code == 200: return "Message sent successfully" else: return f"Slack API error: {response.status_code} - {response.text}" except requests.exceptions.RequestException as e: return f"Error sending message: {str(e)}" except Exception as e: return f"Unexpected error: {str(e)}"