File size: 947 Bytes
2ef9bf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from textblob import TextBlob

def analyze_sentiment(text):
    """Analyze the sentiment of a given text.
    Args:
        text (str): The text to analyze
    Returns:
        dict: A dictionary containing polarity, subjectivity, and assessment
    """
    blob = TextBlob(text)

    return {
        "polarity": round(blob.polarity, 2), 
        "subjectivity": round(blob.subjectivity, 2),
        "assessment": "positive" if blob.polarity > 0 else "negative" if blob.polarity < 0 else "neutral"
    }


def register_sentiment_tool(mcp):
    """Register the sentiment analysis tool with the MCP server."""
    
    @mcp.tool()
    def sentiment_analysis(text: str) -> dict:
        """
        Analyze the sentiment of a given text.
        
        Args:
            text: The text to analyze
            
        Returns:
            A dictionary with polarity, subjectivity, and assessment
        """
        return analyze_sentiment(text)