ruparam88/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 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
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
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
- API Endpoint: http://127.0.0.1:8000/compare?q=your_query
š 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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: your.email@example.com
š Links
- Live Demo: https://mcp-server-demo.herokuapp.com
- API Documentation: https://mcp-server-demo.herokuapp.com/docs
- Hugging Face Model: https://huggingface.co/gpt2
If this project helped you, please give it a ā!