mcp-server

mayanks0369/mcp-server

3.2

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.

Python FastAPI


๐Ÿš€ 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

TaskModel Name
Summarizationfacebook/bart-large-cnn
KeywordsCustom logic via KeyBERT
Sentimentdistilbert-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