Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.13.0
metadata
title: Mcp Sentiment Analysis
emoji: 📊
colorFrom: yellow
colorTo: blue
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
MCP Sentiment (Gradio MCP Server)
Run a local MCP server that exposes a simple sentiment analysis tool via Gradio.
Prerequisites
- Python 3.10–3.12 recommended. Python 3.13 may work but some packages may lag support.
- pip (or conda) available in your shell
- Optional (for clients without SSE): Node.js with
npxformcp-remote
Install
# From repo root or this folder
pip install -r mcp-sentiment/requirements.txt
If you hit Python 3.13 issues, create a 3.11 env:
conda create -n mcp-sentiment python=3.11 -y
conda activate mcp-sentiment
pip install -r mcp-sentiment/requirements.txt
Run the server
cd mcp-sentiment
python app.py
You should see URLs like:
- Streamable HTTP URL: http://127.0.0.1:7860/gradio_api/mcp/
- [Deprecated] SSE URL: http://127.0.0.1:7860/gradio_api/mcp/sse
Connect a client
If your client supports HTTP/streaming MCP
Point it directly at the HTTP URL printed by Gradio (example above).
If your client only supports stdio (no SSE/HTTP)
Use mcp-remote to bridge HTTP/SSE to stdio.
- Install Node (if you don’t have it):
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"; . "$NVM_DIR/nvm.sh"
# Install Node LTS (includes npx)
nvm install --lts
nvm use --lts
- Configure your MCP client. Example config block:
{
"mcpServers": {
"gradio": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:7860/gradio_api/mcp/sse"
]
}
}
}
Tip: If your Gradio prints a non-SSE “Streamable HTTP URL”, you can use that instead:
"args": ["mcp-remote", "http://localhost:7860/gradio_api/mcp/"]
- Restart your MCP client and look for a server named "gradio" with a sentiment tool.
Smoke test (optional)
Show available tools using the Inspector:
npx -y @modelcontextprotocol/inspector --command "npx" -- "mcp-remote" "http://localhost:7860/gradio_api/mcp/"
Notes
- The function
sentiment_analysisreturns a JSON string. Gradio uses the docstring to derive the tool schema exposed over MCP. - If you change ports, update the URL in your MCP client config accordingly.