Provides a sentiment analysis tool based on the Hugging Face MCP Course, offering polarity scoring, subjectivity assessment, and overall sentiment classification (positive, negative, or neutral) for text inputs.
MCP Testbed
This project demonstrates sentiment analysis using the Model Context Protocol (MCP) and is based on the Hugging Face MCP Course. Instead of using the gradio
library in the HuggingFace course, this project utilizes the fastmcp
library to implement an MCP server and client.
Folder Structure
mcp-sentiment/app_fastmcp.py
: MCP server script for sentiment analysis.mcp-sentiment/mcp_client_stdio.py
: MCP client that connects to the server and requests sentiment analysis via command line.mcp-sentiment/mcp_client_sse.py
: MCP client that connects to the server and requests sentiment analysis via SSE transport.
Usage
To run sentiment analysis from the command line using stdio transport:
To run sentiment analysis from the command line using SSE transport:
If no text is provided, the program will exit with an error message.
How It Works
The application uses Model Context Protocol (MCP) to facilitate communication between a client and a sentiment analysis server. When you run the client with a text string, it:
- Connects to the server script (
app_fastmcp.py
) or SSE endpoint - Sends your text for sentiment analysis
- Returns the sentiment result (positive, negative, or neutral)
Server (app_fastmcp.py)
The app_fastmcp.py
file implements an MCP server using FastMCP that:
- Exposes a sentiment analysis tool via the Model Context Protocol
- Uses TextBlob library to analyze sentiment of provided text
- Returns JSON results with:
- Polarity score (-1 to 1, negative to positive)
- Subjectivity score (0 to 1, objective to subjective)
- Overall assessment (positive, negative, or neutral)
- Supports
stdio
orsse
transport for communication with clients
Client (mcp_client_stdio.py)
The mcp_client_stdio.py
file implements an MCP client that:
- Accepts text input from the command line
- Establishes a connection to the MCP server using stdio transport
- Lists available tools on the connected server
- Sends the input text to the sentiment_analysis tool
- Receives and displays the JSON response with sentiment results
- Properly manages resources with async context managers
Client (mcp_client_sse.py)
The mcp_client_sse.py
file implements an MCP client that:
- Accepts text input from the command line
- Establishes a connection to the MCP server using SSE transport
- Lists available tools on the connected server
- Sends the input text to the sentiment_analysis tool
- Receives and displays the JSON response with sentiment results
- Properly manages resources with async context managers
Example Usage with stdio
Transport
Example Usage with sse
Transport
Client
SSE Server
MCP Inspector
The MCP Inspector is a tool for exploring and interacting with Model Context Protocol (MCP) servers. It provides a user-friendly interface for:
- Discovering available tools and their capabilities
- Sending requests to tools and viewing responses
- Debugging and testing MCP interactions
Running MCP Inspector with stdio
Transport
To run the MCP Inspector for server using stdio
transport, use the following command:
Sample output will show the available tools and their descriptions, allowing you to interact with the sentiment analysis tool.
MCP Inspector Listing Tools
MCP Inspector Testing Sentiment Analysis
Running MCP Inspector with sse
Transport
Starting the sse
Server for testing
To run the MCP Inspector for server using sse
transport, use the following command:
Connecting to the MCP Inspector
Open the browser to access the MCP Inspector interface, change from http
to https
if necessary. Once the MCP Inspector is running, configure "Transport Type" for sse
and set the server URL to point to your running MCP server (e.g., http://localhost:8000/sse
) and click "Connect" button.
MCP Inspector Testing Sentiment Analysis
Requirements
- Python 3.12+
- Dependencies:
pip install -r requirements.txt
- Required NLP libraries for sentiment analysis
- Required version of
node
> v20.x to run MCP Inspector (see GH Issue on unexpected token)
This server cannot be installed
This server implements the Model Context Protocol to provide sentiment analysis of text, returning polarity, subjectivity, and overall assessment (positive, negative, or neutral).
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol server that provides tools for analyzing text documents, including counting words and characters. This server helps LLMs perform text analysis tasks by exposing simple document statistics functionality.Last updated -12669JavaScriptApache 2.0
- AsecurityAlicenseAqualityThis server implements the Model Context Protocol to facilitate meaningful interaction and understanding development between humans and AI through structured tools and progressive interaction patterns.Last updated -1351TypeScriptMIT License
- -securityAlicense-qualityProvides advanced analytical, research, and natural language processing capabilities through a Model Context Protocol server, enabling dataset analysis, decision analysis, and enhanced NLP features like entity recognition and fact extraction.Last updated -2TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables users to query, retrieve details, and manage reviews/ratings for NetMind AI servers through simple endpoints.Last updated -PythonMIT License