Spaces:
Runtime error

File size: 1,260 Bytes
8a208cb
 
8b9b30d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a208cb
8b9b30d
 
 
8a208cb
 
8b9b30d
 
 
 
 
 
 
 
 
7943bcc
bcd53b9
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
43
44
45
# from mcp.server.fastmcp import FastMCP
from fastmcp import FastMCP
from textblob import TextBlob

mcp = FastMCP("custom_mcp")

@mcp.tool()
def sentiment_analysis(text: str) -> dict:
    """
    Analyze the sentiment of the given text.

    Args:
        text (str): The text to analyze

    Returns:
        dict: A dictionary containing polarity, subjectivity, and assessment
    """
    blob = TextBlob(text)
    sentiment = blob.sentiment
    
    return {
        "polarity": round(sentiment.polarity, 2),  # -1 (negative) to 1 (positive)
        "subjectivity": round(sentiment.subjectivity, 2),  # 0 (objective) to 1 (subjective)
        "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
    }


@mcp.tool()
def letter_counter(word: str, letter: str):
    """Count the occurrences of a specific letter in a word.
    
    Args:
        word (str): The word or phrase to analyze
        letter (str): The letter to count occurrences of
        
    Returns:
        The number of times the letter appears in the word
    """
    return word.lower().count(letter.lower())


if __name__ == "__main__":
    # Initialize and run the server
    mcp.run(transport='sse', host='0.0.0.0')
    #mcp.run()