MCP-server

ruparam88/MCP-server

3.1

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 dayong@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 ⭐!