Sponsored by Deepsite.site

Python Medical MCP Server

Created By
HeyBatlle16 months ago
this is a cloned version of
Content

Python Medical MCP Server

This project provides a Python-based server with a dual interface:

  1. A direct Model Context Protocol (MCP) interface (handled by your existing script, e.g., your_original_mcp_script.py).
  2. An HTTP REST API interface (via FastAPI in api_server.py) for web clients like Bolt.new.

Both interfaces utilize a shared core medical logic module (medical_core.py).

Features

  • Shared Medical Logic: Core medical assessment functions are centralized in medical_core.py.
  • FastAPI HTTP Server: Exposes medical logic via RESTful endpoints.
    • POST /api/medical/trauma-assessment: For performing trauma assessments.
    • GET /api/status: To check the server's operational status.
  • CORS Enabled: Configured for frontend applications.
  • Pydantic Validation: Automatic request and response validation for API endpoints.
  • PM2 Ready: Instructions provided for running both the direct MCP script and the API server using PM2.

Project Structure

python_mcp_server/
├── your_original_mcp_script.py  (Your existing script for direct MCP communication)
├── medical_core.py        (Shared core medical logic)
├── api_server.py          (FastAPI HTTP server)
├── requirements.txt       (Python dependencies)
├── .gitignore             (Standard Python .gitignore)
└── README.md              (This file)

Setup and Installation

  1. Clone the repository (if you haven't already for your existing script): If this code is part of a larger repository that you've cloned, navigate to the python_mcp_server directory.

  2. Create and Activate a Python Virtual Environment: It's highly recommended to use a virtual environment. If you don't have one for this project yet:

    cd python_mcp_server
    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install Dependencies:

    pip install -r requirements.txt
    

Running the Servers

You will typically run two Python processes:

  • Your original script for direct MCP communication.
  • The new api_server.py for HTTP REST API access.

It's recommended to use a process manager like PM2.

Using PM2

Ensure PM2 is installed (npm install -g pm2).

  1. Start your existing Python MCP script (for direct MCP protocol): (Replace your_original_mcp_script.py with the actual name of your script. Ensure it's updated to import logic from medical_core.py.)

    # Navigate to python_mcp_server directory first if not already there
    # Ensure your virtual environment is NOT active when running PM2 with --interpreter,
    # or provide the full path to the python interpreter from the venv.
    # Best practice: Deactivate venv, then let PM2 use the venv's interpreter path.
    # Example: pm2 start your_original_mcp_script.py --name "python-mcp-direct" --interpreter /path/to/your/venv/bin/python
    
    # Simpler if running from an already activated venv (but PM2 might behave differently):
    pm2 start your_original_mcp_script.py --name "python-mcp-direct" --interpreter python3
    
  2. Start the FastAPI HTTP API server (e.g., on port 8002):

    # Ensure you are in the python_mcp_server directory
    pm2 start "uvicorn api_server:app --host 0.0.0.0 --port 8002" --name "python-mcp-http-api"
    

    Note: Adjust the port 8002 if needed.

  3. Check Status:

    pm2 list
    
  4. Save PM2 Process List (for auto-restart on boot):

    pm2 save
    

    (You might need to run pm2 startup first to configure PM2 startup scripts for your OS.)

Manual Startup (for development/testing without PM2)

  1. Terminal 1 (Direct MCP Script):

    cd python_mcp_server
    source venv/bin/activate
    python your_original_mcp_script.py
    
  2. Terminal 2 (FastAPI HTTP Server):

    cd python_mcp_server
    source venv/bin/activate
    uvicorn api_server:app --reload --host 0.0.0.0 --port 8002
    

API Endpoints

  • GET /api/status

    • Description: Returns the status of the HTTP API server.
    • Response: {"status": "Medical MCP API Server is running", "version": "0.1.0", "active_protocols": ["trauma_assessment"]}
  • POST /api/medical/trauma-assessment

    • Description: Performs a trauma assessment.
    • Request Body (JSON):
      {
        "mechanismOfInjury": "Fall from 10ft ladder",
        "reportedSymptoms": ["severe leg pain", "dizziness"],
        "conscious": true,
        "age": 35, // optional
        "gender": "female", // optional
        "obviousBleeding": false // optional
      }
      
    • Response Body (JSON):
      {
        "severity_level": "serious",
        "immediate_actions": ["Ensure scene safety.", "Call for emergency medical services..."],
        "assessment_steps": ["Check for responsiveness...", "..."],
        "red_flags": ["High-risk mechanism of injury..."],
        "next_steps": ["Reassess ABCDEs frequently...", "..."]
      }
      

Development

  • The core medical logic resides in medical_core.py.
  • The FastAPI application and its endpoints are defined in api_server.py.
  • Remember to update the origins list in api_server.py for CORS if your frontend URLs change.
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
WindsurfThe new purpose-built IDE to harness magic
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
CursorThe AI Code Editor
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Playwright McpPlaywright MCP server
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
DeepChatYour AI Partner on Desktop
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Amap Maps高德地图官方 MCP Server
Tavily Mcp
ChatWiseThe second fastest AI chatbot™
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Serper MCP ServerA Serper MCP Server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.