MCP-server

ruparam88/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 an AI-powered API designed to recommend medicines based on user health queries, leveraging Hugging Face models and FastAPI.

🧠 MCP Server – AI-Powered Medicine Recommendation API

Python FastAPI Hugging Face License Status

A Model Comparison Platform (MCP) server that uses a pretrained Hugging Face model to compare user health queries with a structured medicine database and return the most relevant products. The API generates intelligent descriptions and product URLs using FastAPI.


šŸš€ Features

  • šŸ” Natural Language Processing: Accepts queries like "headache and fever"
  • šŸ“Š Smart Comparison: Compares queries with medicine database from CSV
  • 🧠 AI-Powered Descriptions: Uses Hugging Face models for custom descriptions
  • 🌐 RESTful API: Clean FastAPI endpoints with automatic documentation
  • šŸ“± JSON Response: Returns structured data including:
    • Medicine name
    • AI-generated description
    • Image URL
    • Product detail URL

šŸ—‚ļø Project Structure

mcp-server/
ā”œā”€ā”€ app/
│   ā”œā”€ā”€ __init__.py
│   ā”œā”€ā”€ model_loader.py     # Load pretrained model
│   ā”œā”€ā”€ database.py         # Load CSV into pandas
│   ā”œā”€ā”€ comparator.py       # Query comparison logic
│   └── routes.py           # FastAPI endpoints
ā”œā”€ā”€ data/
│   └── products.csv        # CSV database
ā”œā”€ā”€ main.py                 # App entry point
ā”œā”€ā”€ requirements.txt        # Dependencies
ā”œā”€ā”€ README.md              # This file
└── .gitignore             # Git ignore file

āš™ļø Setup Instructions

Prerequisites

  • Python 3.8 or higher
  • pip package manager

1. Clone the repository

git clone https://github.com/ruparam88/MCP-server.git
cd MCP-server

2. Create virtual environment (recommended)

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Prepare your data

Place your products.csv file in the data/ folder with the following structure:

name,composition,uses,side_effects,image_url
Crocin,Paracetamol 500mg,Fever and pain relief,Nausea in rare cases,https://example.com/crocin.jpg
Aspirin,Acetylsalicylic acid 325mg,Pain and inflammation,Stomach irritation,https://example.com/aspirin.jpg

5. Run the server

uvicorn main:app --reload

6. Access the API


šŸ”Œ API Endpoints

GET /compare?q=<query>

Returns a list of matching medicines with AI-generated descriptions.

Parameters:

  • q (string): Natural language health query

Example Request:

GET /compare?q=headache and fever

Example Response:

[
  {
    "name": "Crocin",
    "description": "Crocin is an effective pain reliever that helps alleviate headaches and reduce fever symptoms.",
    "image_url": "https://example.com/crocin.jpg",
    "url": "http://127.0.0.1:8000/product/Crocin"
  },
  {
    "name": "Aspirin",
    "description": "Aspirin provides relief from headaches and helps reduce fever through its anti-inflammatory properties.",
    "image_url": "https://example.com/aspirin.jpg",
    "url": "http://127.0.0.1:8000/product/Aspirin"
  }
]

GET /product/{product_name}

Returns detailed information about a specific product.

Parameters:

  • product_name (string): Name of the medicine

Example Request:

GET /product/Crocin

Example Response:

{
  "name": "Crocin",
  "composition": "Paracetamol 500mg",
  "uses": "Fever, pain relief, headache",
  "side_effects": "Nausea, dizziness (rare)",
  "image_url": "https://example.com/crocin.jpg"
}

🧠 AI Model Configuration

The system uses Hugging Face transformers for generating intelligent descriptions:

  • Default Model: gpt2 (lightweight and fast)
  • Alternative Models: Any text-generation model from Hugging Face
  • Customization: Modify app/model_loader.py to use your preferred model

Supported Model Types:

  • text-generation (GPT-2, GPT-3, etc.)
  • text2text-generation (T5, BART, etc.)

šŸ› ļø Development

Running Tests

pytest tests/

Code Formatting

black app/
flake8 app/

Environment Variables

Create a .env file for configuration:

MODEL_NAME=gpt2
MAX_LENGTH=100
TEMPERATURE=0.7
CSV_PATH=data/products.csv

šŸ“¦ Dependencies

fastapi==0.104.1
uvicorn==0.24.0
pandas==2.1.3
transformers==4.35.2
torch==2.1.1
python-multipart==0.0.6

šŸš€ Deployment

Local Development

uvicorn main:app --reload --host 0.0.0.0 --port 8000

Production (Docker)

FROM python:3.9-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Cloud Deployment Options

  • Heroku: git push heroku main
  • Render: Connect GitHub repository
  • AWS Lambda: Use Mangum adapter
  • Google Cloud Run: Deploy container

šŸ”§ Future Improvements

  • Authentication: JWT token-based user authentication
  • Frontend: React/Vue.js web interface
  • Database: PostgreSQL/MongoDB integration
  • Caching: Redis for faster response times
  • Model Fine-tuning: Domain-specific medical model
  • Analytics: Usage tracking and metrics
  • Rate Limiting: API usage limits
  • Logging: Structured logging with ELK stack
  • Testing: Comprehensive unit and integration tests

šŸ¤ Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guide
  • Write descriptive commit messages
  • Add tests for new features
  • Update documentation as needed

šŸ“ License

This project is licensed under the MIT License - see the file for details.


šŸ™ Acknowledgments

  • Hugging Face for transformer models
  • FastAPI for the web framework
  • Pandas for data manipulation
  • Contributors and the open-source community

šŸ“ž Support


šŸ”— Links


Made with ā¤ļø by [Your Name]
If this project helped you, please give it a ⭐!