mcp-server / README.md
Peter Yang
follow HF
92e3d17

A newer version of the Gradio SDK is available: 6.5.1

Upgrade
metadata
title: MCP Sentiment Analysis Server
emoji: 🎭
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.0.0
app_file: app.py
pinned: false
license: mit

MCP Sentiment Analysis Server

This is a Model Context Protocol (MCP) server that provides sentiment analysis capabilities using an improved TextBlob-based approach with negation detection.

Features

  • Comprehensive Sentiment Analysis: Detailed sentiment analysis with polarity and subjectivity scores
  • Numerical Sentiment Scoring: Simple numerical scoring from -1 (very negative) to 1 (very positive)
  • Emotion Classification: Basic emotion classification (Joy, Sadness, Anger, etc.)
  • Batch Text Processing: Analyze multiple texts at once with summary statistics
  • Improved Negation Handling: Better detection of negated sentiments compared to vanilla TextBlob
  • Full MCP Protocol Support: Compatible with MCP clients and AI applications

Usage

Web Interface

Use the interface above to test the sentiment analysis tools directly.

MCP Endpoint

Connect your MCP clients to: https://YOUR_USERNAME-SPACE_NAME.hf.space/gradio_api/mcp/sse

Available Tools

  • analyze_sentiment: Comprehensive sentiment analysis with debug information
  • get_sentiment_score: Numerical sentiment scoring (-1 to 1)
  • classify_emotion: Basic emotion classification with confidence scores
  • batch_analyze: Analyze multiple texts at once with summary statistics

Example with smolagents

from smolagents.mcp_client import MCPClient

with MCPClient(
    {"url": "https://YOUR_USERNAME-SPACE_NAME.hf.space/gradio_api/mcp/sse"}
) as tools:
    for tool in tools:
        print(f"{tool.name}: {tool.description}")

Example with Cursor IDE

Add to your MCP configuration:

{
  "mcpServers": {
    "sentiment-analysis": {
      "command": "npx",
      "args": [
        "-y", 
        "mcp-remote", 
        "https://YOUR_USERNAME-SPACE_NAME.hf.space/gradio_api/mcp/sse", 
        "--transport", 
        "sse-only"
      ]
    }
  }
}

Improvements Over Standard TextBlob

This implementation includes several improvements over standard TextBlob sentiment analysis:

  1. Negation Detection: Automatically detects common negation patterns (don't, can't, not, etc.)
  2. Sentiment Correction: Corrects TextBlob's tendency to misclassify negated positive statements
  3. Conservative Thresholds: Uses more conservative thresholds for sentiment classification
  4. Debug Information: Provides transparency into the analysis process

Example Results

Input: "I don't like this kind of things happen"

  • Standard TextBlob: Positive (0.6) ❌
  • This Implementation: Negative (-0.48) ✅

Input: "This is not good"

  • Standard TextBlob: Positive (0.7) ❌
  • This Implementation: Negative (-0.35) ✅

Technical Details

  • Built with Gradio and TextBlob
  • Uses regex-based negation detection
  • Implements conservative sentiment thresholds
  • Provides JSON-formatted responses
  • Full MCP protocol compatibility via Server-Sent Events (SSE)

License

MIT License - see the course repository for details.