mayanks0369/mcp-server
If you are the rightful owner of mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The MCP Server is a FastAPI-based HTTP server providing NLP capabilities through three endpoints: summarization, keyword extraction, and sentiment analysis.
MCP Server - Model Context Protocol API
The MCP Server is a FastAPI-based HTTP server that exposes three powerful NLP endpoints:
- ๐น
/v1/summarize
: Generate a concise summary of input text. - ๐น
/v1/keywords
: Extract key phrases from text. - ๐น
/v1/sentiment
: Perform sentiment analysis on input text.
It includes request logging, API key authorization, OpenAPI schema, test coverage, and a minimal web frontend.
๐ Features
- โ 3 NLP Tasks via Hugging Face Transformers
- โ API Key Authentication (middleware-based)
- โ
Structured Error Handling with unique
requestId
- โ Request Logging (path, status, duration)
- โ
OpenAPI Docs available at
/docs
- โ
Minimal Frontend UI to test endpoints visually (
index.html
) - โ
Test Suite using
pytest
+httpx
๐ฆ Project Structure
MCP_Server/
โโโ app/
โ โโโ main.py
โ โโโ routes/
โ โ โโโ summarize.py
โ โ โโโ keywords.py
โ โ โโโ sentiment.py
โ โโโ utils/
โ โโโ logger.py
โโโ static/
โ โโโ index.html
โโโ tests/
โ โโโ conftest.py
โ โโโ test_keywords.py
โ โโโ test_sentiment.py
โ โโโ test_summarize.py
โโโ openapi.json
โโโ requirements.txt
โโโ README.md
๐ API Key Protection
All routes are protected with API key authentication, except:
/
/docs
/openapi.json
/static/*
Use this test key in your headers:
X-Api-Key: my-secret-api-key
๐ Example Usage
โ 1. Health Check
curl http://localhost:8000/health
โ 2. Sentiment Analysis
curl -X POST http://localhost:8000/v1/sentiment \
-H "Content-Type: application/json" \
-H "X-Api-Key: my-secret-api-key" \
-d '{ "text": "I love working on AI projects!" }'
โ 3. Summarize
curl -X POST http://localhost:8000/v1/summarize \
-H "Content-Type: application/json" \
-H "X-Api-Key: my-secret-api-key" \
-d '{ "text": "Artificial Intelligence is transforming industries by enabling machines to learn from data..." }'
โ 4. Keyword Extraction
curl -X POST http://localhost:8000/v1/keywords \
-H "Content-Type: application/json" \
-H "X-Api-Key: my-secret-api-key" \
-d '{ "text": "Transformers like BERT and GPT have revolutionized NLP." }'
๐งช Running Tests
To run all unit tests:
python -m pytest -v tests/
๐ฅ๏ธ Frontend UI
A minimal client interface is available at:
๐ http://localhost:8000/
You can:
- Paste input text
- Choose task (Summarize, Keywords, Sentiment)
- View output directly in the browser
- API key is auto-attached via frontend JS
๐ OpenAPI Spec
The server is OpenAPI 3.0 compliant.
Download the OpenAPI spec with:
curl http://localhost:8000/openapi.json -H "X-Api-Key: my-secret-api-key" -o openapi.json
Swagger UI available at:
๐ http://localhost:8000/docs
โ Setup Instructions
# Create virtual environment
python -m venv venv
# Activate
# Linux/macOS
source venv/bin/activate
# Windows
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the server
uvicorn app.main:app --reload
๐ง Models Used
Task | Model Name |
---|---|
Summarization | facebook/bart-large-cnn |
Keywords | Custom logic via KeyBERT |
Sentiment | distilbert-base-uncased-finetuned-sst-2-english |
โจ Future Enhancements
- ๐ Switch to token-based auth (OAuth2 / JWT)
- ๐ป Frontend improvements using React/Vue
- โก Add caching for repeated results
๐ Author
Mayank Singh
AI/ML Engineer โ Take-home assignment
Built with โค๏ธ using FastAPI + HuggingFace + HTML