File size: 1,273 Bytes
30bc69b
 
b311b0f
30bc69b
 
b311b0f
30bc69b
b311b0f
 
 
 
 
 
 
 
30bc69b
 
 
 
 
b311b0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30bc69b
b311b0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)}"