Skip to main content
Glama
pashaarshad

AI Doctor Assistant MCP Server

by pashaarshad
README.md
# ๐Ÿฉบ MCP-Based AI Doctor Assistant

> **Your Virtual Medical Advisor powered by Model Context Protocol (MCP)**

[![Python](https://img.shields.io/badge/Python-3.11+-blue.svg)](https://python.org)
[![MCP](https://img.shields.io/badge/MCP-1.0-green.svg)](https://modelcontextprotocol.io)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

---

## โš ๏ธ IMPORTANT DISCLAIMER

> **This AI assistant is NOT a replacement for professional medical advice, diagnosis, or treatment.**
>
> - โŒ Cannot diagnose diseases
> - โŒ Cannot prescribe medications  
> - โŒ Cannot replace a real doctor
> - โœ… CAN provide health information
> - โœ… CAN detect potential emergencies
> - โœ… CAN explain medical terms
>
> **Always consult a qualified healthcare provider for medical decisions.**

---

## ๐ŸŒŸ Features

### 12 Medical Tools

| Tool | Description |
|------|-------------|
| ๐Ÿ” **check_symptoms** | Analyze symptoms, assess risk level, provide self-care tips |
| ๐Ÿšจ **detect_emergency** | Detect life-threatening situations, provide immediate guidance |
| ๐Ÿ”ฌ **explain_lab_report** | Explain blood tests, lab values in simple language |
| ๐Ÿ’ช **health_advice** | Exercise, sleep, stress management, lifestyle tips |
| ๐Ÿ’Š **medicine_info** | Medicine information (NOT prescriptions) |
| ๐Ÿง  **mental_health_support** | Anxiety, stress, depression resources, crisis helplines |
| ๐Ÿฅ— **diet_nutrition** | Diet plans for diabetes, heart health, weight loss |
| ๐Ÿ†˜ **first_aid_guide** | Step-by-step first aid for emergencies |
| ๐Ÿคฐ **pregnancy_guide** | Trimester-specific pregnancy information |
| ๐Ÿ‘ถ **child_health** | Vaccination schedules, pediatric guidance |
| ๐Ÿฅ **chronic_disease_info** | Diabetes, hypertension, heart disease management |
| ๐Ÿ“ **find_hospital** | Help finding nearby healthcare facilities |

### Safety Features

- โœ… **Emergency Detection**: Automatically detects life-threatening symptoms
- โœ… **Medical Disclaimers**: Every response includes appropriate warnings
- โœ… **No Prescriptions**: Never recommends specific medications or dosages
- โœ… **Doctor Referral**: Always encourages professional consultation
- โœ… **Audit Logging**: All interactions can be logged for review

---

## ๐Ÿš€ Quick Start

### Prerequisites

- Python 3.11 or higher
- pip (Python package manager)

### Installation

1. **Clone the repository**
   ```bash
   git clone <repository-url>
   cd "MCP-Based AI Doctor Assistant"
   ```

2. **Create virtual environment**
   ```bash
   python -m venv venv
   
   # Windows
   .\venv\Scripts\activate
   
   # Mac/Linux
   source venv/bin/activate
   ```

3. **Install dependencies**
   ```bash
   pip install -r requirements.txt
   ```

4. **Configure environment variables**
   ```bash
   # Copy example env file
   cp .env.example .env
   
   # Edit .env and add your Gemini API key (optional, for enhanced AI responses)
   # Get free key at: https://makersuite.google.com/app/apikey
   ```

5. **Run the server**
   ```bash
   python -m src.server
   ```

---

## ๐Ÿ”ง Configuration

### Environment Variables

| Variable | Description | Required |
|----------|-------------|----------|
| `GEMINI_API_KEY` | Google Gemini API key for AI responses | Optional |
| `SERVER_HOST` | Server host (default: 0.0.0.0) | No |
| `SERVER_PORT` | Server port (default: 8000) | No |
| `DEBUG_MODE` | Enable debug mode (default: true) | No |
| `LOG_LEVEL` | Logging level (default: INFO) | No |

### MCP Configuration

The server can be configured in Claude Desktop or other MCP clients:

```json
{
  "mcpServers": {
    "ai-doctor": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/MCP-Based AI Doctor Assistant"
    }
  }
}
```

---

## ๐Ÿ“– Usage Examples

### Checking Symptoms

```python
# Using the MCP tool
{
    "tool": "check_symptoms",
    "arguments": {
        "symptoms": ["headache", "fever", "fatigue"],
        "age": 35,
        "gender": "male",
        "duration": "2 days"
    }
}
```

### Explaining Lab Reports

```python
{
    "tool": "explain_lab_report",
    "arguments": {
        "tests": {
            "hemoglobin": 12.5,
            "wbc": 7500,
            "fasting_glucose": 110
        },
        "gender": "female"
    }
}
```

### Getting Health Advice

```python
{
    "tool": "health_advice",
    "arguments": {
        "topic": "sleep"
    }
}
```

### Emergency Detection

```python
{
    "tool": "detect_emergency",
    "arguments": {
        "symptoms": ["chest pain", "shortness of breath"],
        "context": "Started suddenly while walking"
    }
}
```

---

## ๐Ÿ—๏ธ Project Structure

```
MCP-Based AI Doctor Assistant/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ server.py           # Main MCP server
โ”‚   โ”œโ”€โ”€ config.py           # Configuration
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ safety_engine.py    # Emergency detection, disclaimers
โ”‚   โ”‚   โ”œโ”€โ”€ llm_client.py       # Gemini API client
โ”‚   โ”‚   โ””โ”€โ”€ memory.py           # Conversation memory
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ tools/
โ”‚       โ”œโ”€โ”€ symptom_checker.py
โ”‚       โ”œโ”€โ”€ emergency_detector.py
โ”‚       โ”œโ”€โ”€ lab_report.py
โ”‚       โ”œโ”€โ”€ health_advisor.py
โ”‚       โ”œโ”€โ”€ medicine_info.py
โ”‚       โ”œโ”€โ”€ mental_health.py
โ”‚       โ”œโ”€โ”€ diet_nutrition.py
โ”‚       โ”œโ”€โ”€ first_aid.py
โ”‚       โ”œโ”€โ”€ pregnancy.py
โ”‚       โ”œโ”€โ”€ child_health.py
โ”‚       โ”œโ”€โ”€ chronic_disease.py
โ”‚       โ””โ”€โ”€ hospital_finder.py
โ”‚
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ mcp_config.json
โ”œโ”€โ”€ .env.example
โ””โ”€โ”€ README.md
```

---

## ๐Ÿ”’ Safety & Compliance

### Emergency Detection

The system automatically detects critical symptoms like:
- Chest pain / Heart attack signs
- Difficulty breathing
- Signs of stroke (FAST)
- Severe bleeding
- Loss of consciousness
- Suicidal thoughts
- Poisoning

**When detected**: AI reasoning stops immediately, emergency instructions are provided.

### Medical Disclaimers

Every response includes:
- Clear statement that this is not medical advice
- Recommendation to consult healthcare providers
- Emergency contact numbers when appropriate

### What This System Does NOT Do

- โŒ Diagnose diseases
- โŒ Prescribe medications
- โŒ Recommend specific dosages
- โŒ Replace professional medical judgment
- โŒ Store personal health information persistently

---

## ๐ŸŒ Free Deployment Options

### Option 1: Render.com

1. Create account at [render.com](https://render.com)
2. New Web Service โ†’ Connect GitHub
3. Add environment variables
4. Deploy (Free tier: 750 hours/month)

### Option 2: Railway.app

1. Create account at [railway.app](https://railway.app)
2. New Project โ†’ Deploy from GitHub
3. Add environment variables
4. Deploy (Free tier: $5 credit/month)

---

## ๐Ÿงช Testing

```bash
# Run tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=src --cov-report=html
```

---

## ๐Ÿ“ž Emergency Contact Numbers

| Country | Service | Number |
|---------|---------|--------|
| ๐Ÿ‡ฎ๐Ÿ‡ณ India | National Emergency | 112 |
| ๐Ÿ‡ฎ๐Ÿ‡ณ India | Ambulance | 108 |
| ๐Ÿ‡บ๐Ÿ‡ธ USA | Emergency | 911 |
| ๐Ÿ‡ฌ๐Ÿ‡ง UK | Emergency | 999 |
| ๐Ÿ‡ช๐Ÿ‡บ EU | Emergency | 112 |
| ๐ŸŒ International | Varies | [IASP Directory](https://www.iasp.info/resources/Crisis_Centres/) |

---

## ๐Ÿค Contributing

Contributions are welcome! Please:

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Submit a pull request

### Guidelines

- Always maintain safety features
- Add appropriate disclaimers
- Test emergency detection
- Document new features

---

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

## ๐Ÿ™ Acknowledgments

- Built using [Model Context Protocol (MCP)](https://modelcontextprotocol.io)
- Medical information sourced from WHO, CDC, NIH public guidelines
- Emergency protocols based on standard first aid guidelines

---

## โš ๏ธ Final Reminder

> **This AI assistant provides INFORMATION, not MEDICAL ADVICE.**
>
> For any health concerns:
> 1. ๐Ÿฅ Consult a qualified healthcare provider
> 2. ๐Ÿ“ž Call emergency services for urgent situations
> 3. ๐Ÿš‘ Visit the nearest hospital for serious symptoms
>
> **Your health matters. Trust professionals, not AI.**

---

*Made with โค๏ธ for better health awareness*