Skip to main content
Glama
cegme

Emotion Dataset Analysis MCP Server

by cegme

count_by_emotion

Count and calculate percentages of Twitter messages labeled with specific emotions (sadness, joy, love, anger, fear, surprise) in the dair-ai/emotion dataset for statistical analysis.

Instructions

Count samples for a specific emotion.

Args: emotion: One of 'sadness', 'joy', 'love', 'anger', 'fear', 'surprise'

Returns: JSON string with count and percentage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
emotionYes

Implementation Reference

  • Implementation of the `count_by_emotion` MCP tool, which counts dataset entries matching a specified emotion and returns the count and percentage as a JSON string.
    @mcp.tool()
    def count_by_emotion(emotion: str) -> str:
        """Count samples for a specific emotion.
    
        Args:
            emotion: One of 'sadness', 'joy', 'love', 'anger', 'fear', 'surprise'
    
        Returns:
            JSON string with count and percentage
        """
        emotion = emotion.lower().strip()
    
        if emotion not in EMOTION_TO_ID:
            return json.dumps({
                "error": f"Invalid emotion. Choose from: {list(EMOTION_TO_ID.keys())}"
            })
    
        emotion_id = EMOTION_TO_ID[emotion]
        dataset = get_dataset()
    
        count = sum(1 for sample in dataset if sample["label"] == emotion_id)
        percentage = (count / len(dataset)) * 100
    
        return json.dumps({
            "emotion": emotion,
            "count": count,
            "total": len(dataset),
            "percentage": round(percentage, 2)
        }, indent=2)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cegme/cis6930sp26-assignment1.5'

If you have feedback or need assistance with the MCP directory API, please join our Discord server