bloodtest-mcp-server

longevitycoach/bloodtest-mcp-server

3.2

If you are the rightful owner of bloodtest-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.

Bloodtest MCP Server is a comprehensive health coaching system that combines blood test analysis with evidence-based nutritional therapy recommendations, powered by Retrieval-Augmented Generation (RAG) technology.

Tools
5
Resources
0
Prompts
0

Bloodtest MCP Server

A comprehensive health coaching system that combines blood test analysis with evidence-based nutritional therapy recommendations, powered by Retrieval-Augmented Generation (RAG) technology.

🔗 Live Endpoints:

Table of Contents

Overview

Key Features

  • Blood Test Analysis: Get optimal ranges for 8+ key health markers based on functional medicine
  • Personalized Recommendations: Evidence-based supplement and lifestyle advice from German medical literature
  • RAG-Powered Knowledge Base: Search through indexed medical texts using FAISS vector database
  • MCP Protocol Support: Integrate with Claude Desktop and other MCP-compatible clients
  • Multi-format Support: Process blood test results in PDF, image, and text formats
  • RESTful API: Access blood test reference values programmatically
  • Health Coaching Workflows: Comprehensive assessment and recommendation generation

Technical Stack

  • Framework: FastMCP with FastAPI integration
  • AI/ML: LangChain, sentence-transformers, FAISS
  • File Processing: PyPDF, python-multipart
  • Configuration: YAML-based workflow definitions
  • Deployment: Docker with Railway cloud deployment
  • Language: Python 3.12+

User Manual

Getting Started

  1. Access the Production System

    Current Active Endpoint:

    • Web Interface: https://supplement-therapy.up.railway.app
    • API Base URL: https://supplement-therapy.up.railway.app
    • MCP SSE Endpoint: https://supplement-therapy.up.railway.app/sse
    • Health Check: https://supplement-therapy.up.railway.app/health

    New Endpoint (being configured):

    • https://bloodtest-mcp.up.railway.app - Will be available once Railway configuration is complete
  2. Authentication

    • Currently, no authentication is required for public endpoints
    • For production use, implement Bearer token authentication

Claude Desktop Integration

To use this MCP server with Claude Desktop:

  1. Open Claude Desktop Configuration

    • Click on Claude menu (macOS) or File menu (Windows)
    • Select SettingsDeveloperEdit Config
  2. Add Server Configuration Add the following to your claude_desktop_config.json:

    {
      "mcpServers": {
        "bloodtest-health-coach": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-sse",
            "https://supplement-therapy.up.railway.app/sse"
          ],
          "env": {}
        }
      }
    }
    

    Note: Once bloodtest-mcp.up.railway.app is active, update the URL to https://bloodtest-mcp.up.railway.app/sse

  3. Save and Restart Claude Desktop

    • Save the configuration file
    • Completely quit and restart Claude Desktop
    • The health coach tools should now appear in Claude

Configuration File Locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

Using the Health Coach

  1. Upload Blood Test Results

    • Supported formats: PDF, JPG, PNG
    • German lab reports are automatically parsed
    • Optimal ranges are compared against your results
  2. Complete Health Assessment

    • Provide demographic information
    • Describe current symptoms and health concerns
    • Set your health goals and priorities
  3. Receive Personalized Recommendations

    • Supplement protocols with specific dosages and timing
    • Dietary modifications based on your deficiencies
    • Lifestyle interventions for optimal health
    • All recommendations include citations from medical literature

Available MCP Tools

  1. get_book_info

    • Returns metadata about loaded medical books and RAG status
    • Shows available workflows and system capabilities
  2. list_workflows

    • Lists all available health coaching workflows
    • Each workflow has a specific focus area
  3. supplement_therapy

    • Main health coaching workflow
    • Provides comprehensive supplement recommendations
    • Requires patient assessment data
  4. search_book_knowledge

    • Search through indexed medical knowledge base
    • Returns relevant passages with page references
    • Example: "optimal ferritin levels for women"
  5. sequential_thinking

    • Multi-step reasoning for complex health analysis
    • Useful for differential diagnosis and complex cases

Developer Manual

Prerequisites

  • Python 3.12 or higher
  • Docker (optional, for containerized deployment)
  • Git

Installation

  1. Clone the Repository

    git clone https://github.com/longevitycoach/bloodtest-mcp-server.git
    cd bloodtest-mcp-server
    
  2. Create Virtual Environment

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

    pip install -r requirements.txt
    

Development Setup

  1. Initialize the RAG Knowledge Base

    # Place PDF files in resources/books directory
    INDEX_NAME="supplement-therapy" PDF_DIRECTORY="resources/books" python scripts/init_rag.py
    
  2. Configure the Application

    • Edit resources/structure.yaml to customize workflows
    • Ensure rag.config.index_name matches your INDEX_NAME
  3. Run the Development Server

    # Run MCP server with SSE transport
    python server.py --host 0.0.0.0 --port 8000
    
    # Or run integrated server (MCP + API)
    python integrated_server.py --host 0.0.0.0 --port 8000
    
    # Or run just the FastAPI server
    python main.py
    

API Documentation

Base Endpoints
  • GET / - API information and available endpoints
  • GET /health - Health check endpoint
  • GET /parameters - List all blood test parameters
  • GET /reference/{parameter} - Get reference range for a parameter
  • GET /sse - MCP Server-Sent Events endpoint
Example API Usage
import requests

# Get all available parameters
response = requests.get("https://supplement-therapy.up.railway.app/parameters")
print("Available parameters:", response.json()["parameters"])

# Get reference range for ferritin
response = requests.get(
    "https://supplement-therapy.up.railway.app/reference/ferritin",
    params={"sex": "female"}
)
print("Ferritin reference:", response.json())
Blood Test Parameters Supported
ParameterUnitDescription
ferritinng/mlIron storage protein
tshmIU/lThyroid-stimulating hormone
vitamin_dng/ml25-OH Vitamin D
vitamin_b12pmol/lVitamin B12 (Holo-TC)
folate_rbcng/mlRed Blood Cell Folate
zincmg/lEssential mineral
magnesiummmol/lWhole blood magnesium
seleniumµg/lAntioxidant mineral

Testing

# Run all tests with coverage
pytest tests/ -v --cov=bloodtest_tools --cov-report=term-missing

# Run specific test file
pytest tests/test_api_endpoints.py -v

# Run with Makefile
make test

# Run MCP Integration Tests
python tests/test_mcp_client.py
Test Organization
  • tests/test_api_endpoints.py - API endpoint tests
  • tests/test_bloodtest_tools.py - Core functionality tests
  • tests/test_edge_cases.py - Edge case handling
  • tests/test_integration.py - Integration tests
  • tests/test_mcp_client.py - MCP SSE protocol tests
  • tests/test_mcp_integration.py - Comprehensive MCP integration tests
  • testdata/ - Comprehensive test scenarios and data
MCP Integration Testing

The MCP integration tests validate the server's SSE (Server-Sent Events) protocol implementation and knowledge base functionality:

Positive Test Cases (10 tests):

  1. Health Check - Verifies server health endpoint
  2. SSE Connection - Tests SSE endpoint connectivity
  3. Ferritin Knowledge Query - Validates optimal range information
  4. Vitamin D Query - Tests deficiency symptom searches
  5. Magnesium Supplementation - Verifies dosage guidance
  6. TSH Interpretation - Tests thyroid value interpretation
  7. B12 Holotranscobalamin - Validates B12 information retrieval
  8. Selenium Immune System - Tests mineral-immune connections
  9. Zinc-Copper Ratio - Validates supplementation balance info
  10. Folate Requirements - Tests folate reference information

Negative Test Cases (10 tests):

  1. Invalid Endpoint - 404 response for non-existent paths
  2. Wrong HTTP Method - Rejects POST on SSE endpoint
  3. Invalid Health Method - Rejects POST on health endpoint
  4. Invalid API Path - Handles /api/invalid correctly
  5. Test Path - Rejects /test endpoint
  6. Admin Path - Rejects /admin access
  7. Path Traversal - Blocks /../etc/passwd attempts
  8. Health Path Traversal - Blocks /health/../../
  9. SSE Subpath - Rejects /sse/invalid
  10. Null Path - Handles /null endpoint

Running Integration Tests Locally:

# Build and run Docker container
docker build -t bloodtest-mcp-server:local -f Dockerfile.optimized .
docker run -d --name bloodtest-local -p 8001:8000 bloodtest-mcp-server:local

# Run integration tests
python tests/test_mcp_client.py

# Check health endpoint
curl http://localhost:8001/health

# Clean up
docker stop bloodtest-local && docker rm bloodtest-local

Test Report

The MCP integration test suite validates the server's functionality, security, and performance. Here's the comprehensive test report from the latest execution:

📊 Overall Results
  • Total Tests: 37 (20 MCP + 17 Reference Values)
  • Passed: 37/37 (100%)
  • Failed: 0
  • Execution Time: < 45 seconds
🏥 Health Check Tests (4/4 Passed)
TestDescriptionResultResponse Time
Health EndpointValidates /health returns correct status✅ Passed1.36ms
SSE EndpointVerifies /sse accessibility✅ Passed< 5ms
Invalid EndpointEnsures 404 for non-existent paths✅ Passed< 2ms
PerformanceChecks response time under threshold✅ Passed1.36ms
📚 Positive Knowledge Base Tests (10/10 Passed)
Test #Query TypeDescriptionResult
1Health CheckServer health verification✅ Passed
2SSE ConnectionProtocol connectivity test✅ Passed
3FerritinOptimal range information✅ Passed
4Vitamin DDeficiency symptom search✅ Passed
5MagnesiumSupplementation guidance✅ Passed
6TSHThyroid value interpretation✅ Passed
7B12Holotranscobalamin levels✅ Passed
8SeleniumImmune system connection✅ Passed
9Zinc-CopperRatio balance information✅ Passed
10FolateRequirements validation✅ Passed
🛡️ Security & Error Handling Tests (10/10 Passed)
Test #Attack VectorExpected ResponseResult
11Invalid endpoint404 Not Found✅ Passed
12POST on SSE405 Method Not Allowed✅ Passed
13POST on health405 Method Not Allowed✅ Passed
14/api/invalid404 Not Found✅ Passed
15/test404 Not Found✅ Passed
16/admin404 Not Found✅ Passed
17/../etc/passwd404 (Path Traversal Blocked)✅ Passed
18/health/../../404 (Path Traversal Blocked)✅ Passed
19/sse/invalid404 Not Found✅ Passed
20/null404 Not Found✅ Passed
🚀 Performance Metrics
  • Docker Build Time: ~5 seconds
  • Server Startup Time: ~10 seconds
  • Health Check Response: 1.36ms average
  • SSE Connection Time: < 5ms
  • Error Response Time: < 2ms
🔧 Test Environment
  • Docker Image: bloodtest-mcp-server:local
  • Container Port: 8001 (mapped to internal 8000)
  • Test Framework: Python requests + custom MCP client
  • Execution Date: Latest CI/CD run
📋 Reference Values Tests (17/17 Passed)
Test #ParameterOptimal RangeSupplement AdviceResult
1Ferritin70-200 ng/mlIron bisglycinate 25-50mg with Vitamin C✅ Passed
2Vitamin D50-70 ng/ml4000-6000 IU daily✅ Passed
3Vitamin B12>100 pmol/l1000 mcg daily sublingual✅ Passed
4Zinc6-7 mg/l15-30 mg daily✅ Passed
5Magnesium0.85-1.0 mmol/l300-600 mg daily✅ Passed
6Omega-3 Index>8%2-4g EPA/DHA daily✅ Passed
7TestosteroneMen: 8-30 pg/mlVitamin D, zinc, magnesium✅ Passed
8EstradiolMen: 20-25 pg/mlDIM, calcium-d-glucarate✅ Passed
9hs-CRP<1.0 mg/LOmega-3, curcumin, resveratrol✅ Passed
10Zonulin<30 ng/mlL-glutamine, zinc carnosine✅ Passed
11Vitamin C10-20 mg/l500-1000mg daily✅ Passed
12Vitamin E16-25 mg/l200-400 IU mixed tocopherols✅ Passed
13HbA1c<5.6%Chromium, alpha-lipoic acid✅ Passed
14Triglycerides<120 mg/dlOmega-3, niacin, fiber✅ Passed
15TSH0.5-2.0 mIU/lIodine, selenium, tyrosine✅ Passed
16Folate>20 ng/ml RBC5-MTHF (methylfolate)✅ Passed
17Selenium120-150 µg/l200 mcg daily✅ Passed
✅ Summary

All 37 integration tests passed successfully, demonstrating:

  • Robust health monitoring
  • Proper SSE protocol implementation
  • Comprehensive error handling
  • Strong security measures against common attacks
  • Excellent performance with sub-2ms response times
  • RAG system readiness for medical knowledge queries
  • Complete coverage of all blood test reference values
  • Evidence-based supplement recommendations

The server is production-ready with all security measures in place, optimal performance characteristics, and comprehensive knowledge of blood test parameters and supplementation guidance.

Deployment

Railway (Production)

The application is deployed on Railway:

  1. Connect Repository

    • Connect GitHub repository to Railway
    • Auto-deploys on push to main branch
  2. Environment Variables

    PORT=8000
    ENV=production
    PDF_DIRECTORY=/app/resources/books
    INDEX_DIRECTORY=/app/faiss_index
    INDEX_NAME=supplement-therapy
    
  3. Monitoring

Docker
# Build and run with Docker
docker build -t bloodtest-mcp-server -f Dockerfile.optimized .
docker run -p 8000:8000 bloodtest-mcp-server

# Or use Docker Compose
docker-compose up --build

Project Structure

bloodtest-mcp-server/
├── bloodtest_tools/        # Core blood test functionality
│   ├── api.py             # FastAPI endpoints
│   ├── reference_values.py # Medical reference ranges
│   └── mcp_tool.py        # MCP tool wrappers
├── utils/                  # Utility modules
│   ├── rag_system.py      # FAISS RAG implementation
│   └── sequential_thinking.py # Reasoning tool
├── resources/              # Configuration and books
│   ├── structure.yaml     # Workflow definitions
│   └── books/             # PDF medical texts
├── scripts/               # Utility scripts
│   └── init_rag.py       # RAG initialization
├── tests/                 # Test suite
├── server.py             # Main MCP server
├── integrated_server.py  # Combined MCP + API server
└── main.py              # FastAPI entry point

Advanced Topics

RAG System Architecture

  1. Document Processing

    • PDFs are split into chunks (1000 chars with 200 overlap)
    • Text embedded using sentence-transformers
    • Vectors stored in FAISS index
  2. Query Flow

    • User query is embedded
    • Top-k similar documents retrieved
    • Context passed to LLM for response generation
  3. Configuration

    rag:
      enabled: true
      config:
        index_name: "supplement-therapy"
        index_directory: "./faiss_index"
        chunk_size: 1000
        chunk_overlap: 200
    

Workflow Configuration

Workflows are defined in resources/structure.yaml:

workflows:
  - name: "Supplement Therapy"
    description: "Personalized supplement recommendations"
    prompt: |
      Based on the blood test results and health assessment,
      provide evidence-based supplement recommendations...

Troubleshooting

Common Issues
  1. FAISS Index Not Found

    • Ensure INDEX_NAME in environment matches structure.yaml
    • Run python scripts/init_rag.py to create index
  2. Connection Issues with Claude Desktop

    • Verify server is running: check /health endpoint
    • Ensure configuration JSON is valid
    • Restart Claude Desktop completely
  3. Docker Build Failures

    • Check Python version compatibility
    • Ensure all files are included in build context
    • Verify FAISS index exists in Docker image

Contributing

  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

License

This project is licensed under the MIT License. See file for details.

Acknowledgments

  • Medical reference values based on work by Dr. Ulrich Strunz and Dr. Helena Orfanos-Boeckel
  • Built with FastMCP, FastAPI, and LangChain
  • Deployed on Railway cloud platform