--- title: 'MediAgent AI: Conversational Health Navigator & MCP Tool Server' emoji: 🧬 colorFrom: indigo colorTo: purple sdk: gradio sdk_version: 5.33.1 # Note: I've updated this to a more recent version, adjust if needed sdk_version: 5.33.1 app_file: app.py pinned: false secrets: - MODAL_BACKEND_URL tags: - mcp-server-track - agent-demo-track --- # 🧬 MediAgent AI: Conversational Health Navigator & MCP Tool Server **[➡️ Try the Live Demo Here!](https://huggingface.co/spaces/Agents-MCP-Hackathon/medical_ai)** **Powered by Modal and LlamaIndex. Special thanks for their support!** **MediAgent AI** is a sophisticated, conversational health assistant and a fully MCP-compliant tool server, built on Modal and Gradio. It provides reliable, sourced, and role-adapted answers to a wide range of medical questions. This project is a submission for the **Gradio Agents & MCP Hackathon 2025**, competing in two tracks: - **🔧 MCP Tool / Server Track:** Our backend exposes a robust, MCP-compliant endpoint for any agent to use. - **🤖 Agentic Demo Showcase Track:** The Gradio UI provides a powerful demonstration of an agent using these tools to help users. --- ## 🌟 Key Features * 🌐 **Multilingual Support**: Automatically detects and responds in **English, Spanish, Hindi, and French**. * 👤 **Role-Based Adaptation**: * **Patient Mode**: Simplified, easy-to-understand health information. * **Doctor Mode**: In-depth, technical insights using specialized medical databases. * 🛡️ **Critical Safety Layer**: Identifies keywords related to medical emergencies (e.g., "chest pain") and immediately instructs the user to seek professional help, bypassing the AI. * 🔗 **Sourced & Verifiable**: All information is backed by citations from authoritative sources. * 💬 **Stateful Conversations**: Remembers chat history for contextual follow-up questions. * 🛠️ **Fully Compliant MCP Tool Server**: Our tools can be called externally by any MCP client. --- ## 🛠️ Tools & Technology Stack Our agent leverages a powerful, specialized toolkit to provide accurate information. These tools are exposed via our public MCP endpoint. | Tool Name | Description | Data Source(s) | | ----------------------------- | --------------------------------------------------------------------------- | -------------------------- | | `search_web` | For general health queries and patient-level explanations. | DuckDuckGo | | `search_pubmed` | Accesses peer-reviewed medical literature for evidence-based information. | PubMed / NCBI | | `get_drug_label_info` | Retrieves detailed, official FDA-approved prescribing information. | openFDA / DailyMed | | `check_drug_side_effects` | Finds known side effects for a specific medication. | openFDA / DailyMed | | `check_drug_interactions` | Checks for adverse interactions between two or more drugs. | RxNorm API (NIH) | | `search_clinical_trials` | Discovers ongoing or completed clinical studies for conditions/treatments. | ClinicalTrials.gov (NIH) | **Core Technologies:** * **Backend & Compute:** [**Modal**](https://modal.com/) for scalable, serverless GPU and CPU functions. * **AI Agent Framework:** [**LlamaIndex**](https://www.llamaindex.ai/) for orchestrating the agent's think-plan-act loop. * **LLM:** [**Mistral 7B**](https://mistral.ai/) for high-quality reasoning. * **Frontend UI:** [**Gradio**](https://www.gradio.app/) for the interactive chat interface. --- ## 🏛️ Architecture: Hybrid Single-Server MCP Our single Modal application serves as **both the core Agent and its own MCP-compliant Tool Server**. 1. **Agent Endpoint (`/`):** A private endpoint that takes a user query and orchestrates the full agentic workflow (planning, tool selection, synthesis). 2. **MCP Tool Endpoint (hidden in backend):** A public endpoint that exposes our individual tools. This makes our application a valid MCP Server, proving compliance and allowing any external MCP client to use our medical tools. --- ## 🚀 Test our MCP Tool Server Live! You can call our tools from any MCP-compatible client or directly with `curl`. > ⚠️ **Note:** The first call may take 30-60 seconds as the serverless backend spins up. Subsequent calls are much faster. ```bash # Example: Check for a critical drug interaction curl -X POST 'https://sunilpanda992--medi-agent-ai-final-backend-mediagentai-m-3f699b.modal.run' \ --header 'Content-Type: application/json' \ --data '{ "tool_name": "check_drug_interactions", "tool_args": { "drugs": ["warfarin", "amiodarone"] } }' # Example: Search for PubMed articles curl -X POST 'https://sunilpanda992--medi-agent-ai-final-backend-mediagentai-m-3f699b.modal.run' \ --header 'Content-Type: application/json' \ --data '{ "tool_name": "search_pubmed", "tool_args": {"query": "metformin AND cardiovascular outcomes", "max_results": 2} }' # Example: Get official FDA label information (CORRECTED) curl -X POST 'https://sunilpanda992--medi-agent-ai-final-backend-mediagentai-m-3f699b.modal.run' \ --header 'Content-Type: application/json' \ --data '{ "tool_name": "get_drug_label_info", "tool_args": {"drug_name": "atorvastatin"} }' ``` IGNORE_WHEN_COPYING_START Use code with caution. Markdown IGNORE_WHEN_COPYING_END --- ## 🧪 Try It Out in the App! Select the appropriate "patient" or "doctor" role in the chat interface above and try these prompts: Patient Query: "What are the most common side effects of metformin?" Doctor Query: "My patient with Crohn's is on methotrexate and we are considering adding infliximab. I need the latest PubMed literature on efficacy and a check for interactions between the two drugs." Spanish Query: "¿Cuáles son los síntomas de la diabetes tipo 2?" Interaction Check: "Can I take ibuprofen with lisinopril?"