Skip to main content

FHIR MCP Server - A Model Context Protocol server for interacting with FHIR servers

Project description

FHIR MCP Server

A Model Context Protocol (MCP) server that provides secure, standardized access to FHIR (Fast Healthcare Interoperability Resources) servers. This server acts as a bridge between MCP clients and FHIR APIs, offering a simplified and secure way to access healthcare data.

Features

  • MCP Protocol Support: Full Model Context Protocol implementation
  • FHIR R4 Compatibility: Works with any FHIR R4-compliant server
  • Simplified Configuration: Easy setup with environment variables
  • Docker Ready: Containerized for easy deployment
  • Health Monitoring: Built-in health check endpoints
  • Security: Optional OAuth/Bearer token authentication
  • Two Server Modes: Simple server for development, full server for production

Supported FHIR Operations

The server provides the following MCP tools for FHIR operations:

  • get_capabilities - Get FHIR server capabilities for a resource type
  • search - Search for FHIR resources with parameters
  • read - Read a specific FHIR resource by ID
  • create - Create a new FHIR resource
  • update - Update an existing FHIR resource
  • delete - Delete a FHIR resource

Quick Start

Using Docker Compose (Recommended)

  1. Clone the repository and navigate to the project root
  2. Copy the environment template:
    cp env.template .env
    
  3. Edit .env with your FHIR server configuration
  4. Start the server:
    docker-compose up fhir-mcp-server
    

Manual Installation

  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Set environment variables:

    export FHIR_MCP_FHIR__BASE_URL="https://hapi.fhir.org/baseR4"
    export FHIR_MCP_HOST="localhost"
    export FHIR_MCP_PORT="8004"
    
  3. Run the server:

    python -m fhir_mcp_server
    

Configuration

Environment Variables

Variable Description Default
FHIR_MCP_HOST Server host address localhost
FHIR_MCP_PORT Server port 8004
FHIR_MCP_FHIR__BASE_URL FHIR server base URL https://hapi.fhir.org/baseR4
FHIR_MCP_FHIR__ACCESS_TOKEN Bearer token for FHIR server (empty)
FHIR_MCP_FHIR__TIMEOUT Request timeout in seconds 30
FHIR_MCP_USE_SIMPLE Use simplified server true

Server Modes

Simple Server (Default)

  • Lightweight implementation
  • Basic FHIR operations
  • Minimal dependencies
  • Best for development and testing

Full Server

  • Complete OAuth2/OIDC support
  • Advanced authentication flows
  • Production-ready features
  • Set FHIR_MCP_USE_SIMPLE=false to enable

Usage Examples

Using with Healthcare AI UI

The FHIR MCP server integrates seamlessly with the Healthcare AI UI:

  1. Enable MCP mode in UI Settings
  2. Set MCP server URL to http://localhost:8004
  3. Configure your FHIR server URL
  4. Test the connection

Direct MCP Protocol Usage

// Example MCP request to search for patients
const request = {
  jsonrpc: "2.0",
  id: 1,
  method: "tools/call",
  params: {
    name: "search",
    arguments: {
      type: "Patient",
      searchParam: {
        name: "John"
      }
    }
  }
};

fetch('http://localhost:8004/mcp', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(request)
});

API Endpoints

  • POST /mcp - MCP protocol endpoint
  • GET /health - Health check endpoint
  • GET /oauth/callback - OAuth callback (full server only)
  • GET /fhir/callback - FHIR OAuth callback (full server only)

Health Check

The server provides a health check endpoint at /health:

curl http://localhost:8004/health

Response:

{
  "status": "healthy",
  "service": "FHIR MCP Server",
  "version": "1.0.0",
  "fhir_url": "https://hapi.fhir.org/baseR4"
}

Development

Running Tests

# Install test dependencies
pip install pytest pytest-asyncio

# Run tests
pytest tests/

Code Structure

fhir_mcp_server/
├── Dockerfile              # Docker configuration for the service
├── README.md               # This README file
├── __init__.py             # Package initialization
├── __main__.py             # Main entry point for the service
├── fhir_mcp_service.py     # Main FHIR MCP service implementing business logic and tool definitions
└── requirements.txt        # Python dependencies

Security Considerations

  • Always use HTTPS in production
  • Configure proper FHIR server authentication
  • Validate all input parameters
  • Monitor access logs
  • Keep dependencies updated

Troubleshooting

Common Issues

  1. Connection Refused

    • Check if the server is running
    • Verify host and port configuration
    • Ensure firewall allows connections
  2. FHIR Authentication Errors

    • Verify FHIR server URL is correct
    • Check access token if using authentication
    • Ensure FHIR server is accessible
  3. MCP Protocol Errors

    • Verify JSON-RPC 2.0 format
    • Check method and parameter names
    • Review server logs for details

Logs

Enable debug logging for troubleshooting:

python -m fhir_mcp_server --log-level DEBUG

Contributing

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

License

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

Support

For support and questions:

  • Open an issue on GitHub
  • Check the documentation
  • Review the troubleshooting guide

Related Projects

New File Structure

fhir_mcp_server/
├── Dockerfile              # Docker configuration for the service
├── README.md               # This README file
├── __init__.py             # Package initialization
├── __main__.py             # Main entry point for the service
├── fhir_mcp_service.py     # Main FHIR MCP service implementing business logic and tool definitions
└── requirements.txt        # Python dependencies

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_amitpuri_fhir_mcp_server-1.0.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_amitpuri_fhir_mcp_server-1.0.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_amitpuri_fhir_mcp_server-1.0.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_amitpuri_fhir_mcp_server-1.0.0.tar.gz
Algorithm Hash digest
SHA256 431d2d15aa459b2a703945f9c42a2655ffb7cc418aa86c923cb1711418c176bc
MD5 1bdecf25bb7f781260c6ce856cc316ec
BLAKE2b-256 4dec71e3bfde270ef65e5def5b6eea6360f42253d731fd7b918c9ebe193b1af2

See more details on using hashes here.

File details

Details for the file iflow_mcp_amitpuri_fhir_mcp_server-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_amitpuri_fhir_mcp_server-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_amitpuri_fhir_mcp_server-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be59562d80dd67160d34d5ec456f8e1ee1cdeb22372fe08c2d5e5a1b3f0f815f
MD5 94da807e1b5e5a9d64846f3e1caa46b0
BLAKE2b-256 f7ce4a32b274642ba738ac9f93e5f7ba64e02cc7af370a42c2d60c9d00dc8486

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page