fhir-mcp-server

fhir-mcp-server

Model Context Protocol (MCP) Server for seamless AI integration with FHIR healthcare APIs.

37
Stars
9
Forks
37
Watchers
2
Issues
fhir-mcp-server implements a Model Context Protocol (MCP) server that integrates Fast Healthcare Interoperability Resources (FHIR) APIs with modern AI and LLM tools. It acts as a bridge between AI clients and healthcare data, enabling secure, context-aware search, retrieval, and management of clinical information. The server supports multiple customizable transports—including HTTP, stdio, and Server-Sent Events (SSE)—and is compatible with a variety of MCP clients such as VS Code, Claude Desktop, and MCP Inspector. Features include SMART-on-FHIR authentication, support for standard FHIR operations, and comprehensive tooling for development and testing.

Key Features

MCP-compatible transport options (HTTP, stdio, SSE)
Integration with FHIR APIs
SMART-on-FHIR based OAuth2 authentication
Seamless tool integration with VS Code, Claude Desktop, and MCP Inspector
Customizable CLI and environment configuration
Support for standard FHIR operations (search, read, create, update, delete)
Secure handling of clinical and user context data
Test suite with async/await support and comprehensive coverage
Development and deployment via PyPI and source install
Extensive environment and command-line customization

Use Cases

Enabling AI-assisted access to healthcare data from FHIR servers
Integrating clinical information with language model workspaces in VS Code
Connecting Claude Desktop or similar AI platforms to enterprise health data
Automating patient record search, retrieval, and management in digital health tools
Securely authenticating AI clients via SMART-on-FHIR for health data analysis
Facilitating healthcare data workflows for research, integration, or innovation
Streamlining interoperability testing for FHIR-based services
Providing a gateway for LLM-based applications to utilize structured clinical information
Supporting rapid prototyping and testing of FHIR-based AI tools
Debugging and inspecting context flows with interactive tools like MCP Inspector

README

Model Context Protocol (MCP) Server for Fast Healthcare Interoperability Resources (FHIR) APIs

License Get Support on Stack Overflow Join the community on Discord X

Table of Contents

Overview

The FHIR MCP Server is a Model Context Protocol (MCP) server that provides seamless integration with FHIR APIs. Designed for developers, integrators, and healthcare innovators, this server acts as a bridge between modern AI/LLM tools and healthcare data, making it easy to search, retrieve, and analyze clinical information.

Demo

Demo with HAPI FHIR server

This video showcases the MCP server's functionality when connected to a public HAPI FHIR server. This example showcases direct interaction with an open FHIR server that does not require an authorization flow.

https://github.com/user-attachments/assets/cc6ac87e-8329-4da4-a090-2d76564a3abf

Demo with EPIC Sandbox

This video showcases the MCP server's capabilities within the Epic EHR ecosystem. It demonstrates the complete OAuth 2.0 Authorization Code Grant flow.

https://github.com/user-attachments/assets/96b433f1-3e53-4564-8466-65ab48d521de

Core Features

  • MCP-compatible transport: Serves FHIR via stdio, SSE, or streamable HTTP

  • SMART-on-FHIR based authentication support: Securely authenticate with FHIR servers and clients

  • Tool integration: Integratable with any MCP client such as VS Code, Claude Desktop, and MCP Inspector

Prerequisites

  • Python 3.8+
  • uv (for dependency management)
  • An accessible FHIR API server.

Installation

You can use the FHIR MCP Server by installing our Python package, or by cloning this repository.

Installing using PyPI Package

  1. Configure Environment Variables:

    To run the server, you must set FHIR_SERVER_BASE_URL. If you plan to use authorization, you'll also need to configure FHIR_SERVER_CLIENT_ID, FHIR_SERVER_CLIENT_SECRET, and FHIR_SERVER_SCOPES. By default, the MCP server will listen on http://localhost:8000. You can customize the host and port by setting FHIR_MCP_HOST and FHIR_MCP_PORT respectively.

    You can set these by exporting them as environment variables like below or by creating a .env file (referencing .env.example).

    bash
    export FHIR_SERVER_BASE_URL=""
    export FHIR_SERVER_CLIENT_ID=""
    export FHIR_SERVER_CLIENT_SECRET=""
    export FHIR_SERVER_SCOPES=""
    
    export FHIR_MCP_HOST="localhost"
    export FHIR_MCP_PORT="8000"
    
  2. Install the PyPI package and run the server

    If you are exposing a FHIR server with no security:

    bash
    uvx fhir-mcp-server --disable-auth
    

    else;

    bash
    uvx fhir-mcp-server
    

Installing from Source

  1. Clone the repository:

    bash
    git clone <repository_url>
    cd <repository_directory>
    
  2. Create a virtual environment and install dependencies:

    bash
    uv venv
    source .venv/bin/activate
    uv pip sync requirements.txt
    

    Or with pip:

    bash
    python -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
    
  3. Configure Environment Variables: Copy the example file and customize if needed:

    bash
    cp .env.example .env
    
  4. Run the server:

    bash
    uv run fhir-mcp-server
    

Integration with MCP Clients

The FHIR MCP Server is designed for seamless integration with various MCP clients.

VS Code

Install in VS Code Install in VS Code Insiders

Add the following JSON block to your User Settings (JSON) file in VS Code (> V1.101). You can do this by pressing Ctrl + Shift + P and typing Preferences: Open User Settings (JSON).

json
"mcp": {
    "servers": {
        "fhir": {
            "type": "http",
            "url": "http://localhost:8000/mcp",
        }
    }
}
json
"mcp": {
    "servers": {
        "fhir": {
            "command": "uv",
            "args": [
                "--directory",
                "/path/to/fhir-mcp-server",
                "run",
                "fhir-mcp-server",
                "--transport",
                "stdio"
            ],
            "env": {
                "FHIR_SERVER_ACCESS_TOKEN": "Your FHIR Access Token"
            }
        }
    }
}
json
"mcp": {
    "servers": {
        "fhir": {
            "type": "sse",
            "url": "http://localhost:8000/sse",
        }
    }
}

Claude Desktop

Add the following JSON block to your Claude Desktop settings to connect to your local MCP server.

  • Launch the Claude Desktop app, click on the Claude menu in the top bar, and select "Settings…".
  • In the Settings pane, click “Developer” in the left sidebar. Then click "Edit Config". This will open your configuration file in your file system. If it doesn’t exist yet, Claude will create one automatically at:
    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Open the claude_desktop_config.json file in any text editor. Replace its contents with the following JSON block to register the MCP server:
json
{
    "mcpServers": {
        "fhir": {
            "command": "npx",
            "args": [
                "-y",
                "mcp-remote",
                "http://localhost:8000/mcp"
            ]
        }
    }
}
json
{
    "mcpServers": {
        "fhir": {
            "command": "uv",
            "args": [
                "--directory",
                "/path/to/fhir-mcp-server",
                "run",
                "fhir-mcp-server",
                "--transport",
                "stdio"
            ],
            "env": {
                "FHIR_SERVER_ACCESS_TOKEN": "Your FHIR Access Token"
            }
        }
    }
}
json
{
    "mcpServers": {
        "fhir": {
            "command": "npx",
            "args": [
                "-y",
                "mcp-remote",
                "http://localhost:8000/sse"
            ]
        }
    }
}

MCP Inspector

Follow these steps to get the MCP Inspector up and running:

  • Open a terminal and run the following command:

    npx -y @modelcontextprotocol/inspector

  • In the MCP Inspector interface:

  • Transport Type: Streamable HTTP
  • URL: http://localhost:8000/mcp
  • Transport Type: STDIO
  • Command: uv
  • Arguments: --directory /path/to/fhir-mcp-server run fhir-mcp-server --transport stdio
  • Transport Type: SSE
  • URL: http://localhost:8000/sse

Make sure your MCP server is already running and listening on the above endpoint.

Once connected, MCP Inspector will allow you to visualize tool invocations, inspect request/response payloads, and debug your tool implementations easily.

Configuration

CLI Options

You can customize the behavior of the MCP server using the following command-line flags:

  • --transport

    • Description: Specifies the transport protocol used by the MCP server to communicate with clients.
    • Accepted values: stdio, sse, streamable-http
    • Default: streamable-http
  • --log-level

    • Description: Sets the logging verbosity level for the server.
    • Accepted values: DEBUG, INFO, WARN, ERROR (case-insensitive)
    • Default: INFO
  • --disable-auth

    • Description: Disables the security of the MCP Server. Allows you to connect with openly available FHIR servers.
    • Type: Flag (no value required)
    • Default: False (authentication enabled)
  • --help

    • Description: Displays a help message with available server options and exits.
    • Usage: Automatically provided by the command-line interface.

Sample Usages:

shell
uv run fhir-mcp-server --transport streamable-http --log-level DEBUG --disable-auth
uv run fhir-mcp-server --help

Environment Variables

MCP Server Configurations:

  • FHIR_MCP_HOST: The hostname or IP address the MCP server should bind to (e.g., localhost for local-only access, or 0.0.0.0 for all interfaces).
  • FHIR_MCP_PORT: The port on which the MCP server will listen for incoming client requests (e.g., 8000).
  • FHIR_MCP_SERVER_URL: If set, this value will be used as the server's base URL instead of generating it from host and port. Useful for custom URL configurations or when behind a proxy.
  • FHIR_MCP_REQUEST_TIMEOUT: Timeout duration in seconds for requests from the MCP server to the FHIR server (default: 30).

MCP Server OAuth2 with FHIR server Configuration (MCP Client ↔ MCP Server): These variables configure the MCP client's secure connection to the MCP server, using the OAuth2 authorization code grant flow with a FHIR server.

  • FHIR_SERVER_CLIENT_ID: The OAuth2 client ID used to authorize MCP clients with the FHIR server.
  • FHIR_SERVER_CLIENT_SECRET: The client secret corresponding to the FHIR client ID. Used during token exchange.
  • FHIR_SERVER_BASE_URL: The base URL of the FHIR server (e.g., https://hapi.fhir.org/baseR4). This is used to generate tool URIs and to route FHIR requests.
  • FHIR_SERVER_SCOPES: A space-separated list of OAuth2 scopes to request from the FHIR authorization server (e.g., user/Patient.read user/Observation.read). Add fhirUser openid to enable retrieval of user context for the get_user tool. If these two scopes are not configured, the get_user tool returns an empty result because the ID token lacks the user's FHIR resource reference.
  • FHIR_SERVER_ACCESS_TOKEN: The access token to use for authenticating requests to the FHIR server. If this variable is set, the server will bypass the OAuth2 authorization flow and use this token directly for all requests.

Tools

  • get_capabilities: Retrieves metadata about a specified FHIR resource type, including its supported search parameters and custom operations.

    • type: The FHIR resource type name (e.g., "Patient", "Observation", "Encounter")
  • search: Executes a standard FHIR search interaction on a given resource type, returning a bundle or list of matching resources.

    • type: The FHIR resource type name (e.g., "MedicationRequest", "Condition", "Procedure").
    • searchParam: A mapping of FHIR search parameter names to their desired values (e.g., {"family":"Simpson","birthdate":"1956-05-12"}).
  • read: Performs a FHIR "read" interaction to retrieve a single resource instance by its type and resource ID, optionally refining the response with search parameters or custom operations.

    • type: The FHIR resource type name (e.g., "DiagnosticReport", "AllergyIntolerance", "Immunization").
    • id: The logical ID of a specific FHIR resource instance.
    • searchParam: A mapping of FHIR search parameter names to their desired values (e.g., {"device-name":"glucometer"}).
    • operation: The name of a custom FHIR operation or extended query defined for the resource (e.g., "$everything").
  • create: Executes a FHIR "create" interaction to persist a new resource of the specified type.

    • type: The FHIR resource type name (e.g., "Device", "CarePlan", "Goal").
    • payload: A JSON object representing the full FHIR resource body to be created.
    • searchParam: A mapping of FHIR search parameter names to their desired values (e.g., {"address-city":"Boston"}).
    • operation: The name of a custom FHIR operation or extended query defined for the resource (e.g., "$evaluate").
  • update: Performs a FHIR "update" interaction by replacing an existing resource instance's content with the provided payload.

    • type: The FHIR resource type name (e.g., "Location", "Organization", "Coverage").
    • id: The logical ID of a specific FHIR resource instance.
    • payload: The complete JSON representation of the FHIR resource, containing all required elements and any optional data.
    • searchParam: A mapping of FHIR search parameter names to their desired values (e.g., {"patient":"Patient/54321","relationship":"father"}).
    • operation: The name of a custom FHIR operation or extended query defined for the resource (e.g., "$lastn").
  • delete: Execute a FHIR "delete" interaction on a specific resource instance.

    • type: The FHIR resource type name (e.g., "ServiceRequest", "Appointment", "HealthcareService").
    • id: The logical ID of a specific FHIR resource instance.
    • searchParam: A mapping of FHIR search parameter names to their desired values (e.g., {"category":"laboratory","issued:"2025-05-01"}).
    • operation: The name of a custom FHIR operation or extended query defined for the resource (e.g., "$expand").
  • get_user: Retrieves the currently authenticated user's FHIR resource (for example the linked Patient resource) and returns a concise profile containing available demographic fields such as id, name, and birthDate.

Development & Testing

Installing Development Dependencies

To run tests and contribute to development, install the test dependencies:

Using pip:

bash
# Install project in development mode with test dependencies
pip install -e '.[test]'

# Or install from requirements file
pip install -r requirements-dev.txt

Using uv:

bash
# Install development dependencies
uv sync --dev

Running Tests

The project includes a comprehensive test suite covering all major functionality:

bash
# Simple test runner
python run_tests.py

# Or direct pytest usage
PYTHONPATH=src python -m pytest tests/ -v --cov=src/fhir_mcp_server

Using pytest:

bash
pytest tests/

This will discover and run all tests in the tests/ directory.

Test Features:

  • 100+ tests with comprehensive coverage
  • Full async/await support using pytest-asyncio
  • Complete mocking of HTTP requests and external dependencies
  • Coverage reporting with terminal and HTML output
  • Fast execution with no real network calls

The test suite includes:

  • Unit tests: Core functionality testing
  • Integration tests: Component interaction validation
  • Edge case coverage: Error handling and validation scenarios
  • Mocked OAuth flows: Realistic authentication testing

Coverage reports are generated in htmlcov/index.html for detailed analysis.

Star History

Star History Chart

Repository Owner

wso2
wso2

Organization

Repository Details

Language Python
Default Branch main
Size 30,505 KB
Contributors 5
License Apache License 2.0
MCP Verified Sep 5, 2025

Programming Languages

Python
99.22%
Dockerfile
0.78%

Tags

Topics

fhir healthcare mcp mcp-server modelcontextprotocol

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • cloudflare/mcp-server-cloudflare

    cloudflare/mcp-server-cloudflare

    Connect Cloudflare services to Model Context Protocol (MCP) clients for AI-powered management.

    Cloudflare MCP Server enables integration between Cloudflare's suite of services and clients using the Model Context Protocol (MCP). It provides multiple specialized servers that allow AI models to access, analyze, and manage configurations, logs, analytics, and other features across Cloudflare's platform. Users can leverage natural language interfaces in compatible MCP clients to read data, gain insights, and perform automated actions on their Cloudflare accounts. This project aims to streamline the orchestration of security, development, monitoring, and infrastructure tasks through standardized MCP connections.

    • 2,919
    • MCP
    • cloudflare/mcp-server-cloudflare
  • awslabs/mcp

    awslabs/mcp

    Specialized MCP servers for seamless AWS integration in AI and development environments.

    AWS MCP Servers is a suite of specialized servers implementing the open Model Context Protocol (MCP) to bridge large language model (LLM) applications with AWS services, tools, and data sources. It provides a standardized way for AI assistants, IDEs, and developer tools to access up-to-date AWS documentation, perform cloud operations, and automate workflows with context-aware intelligence. Featuring a broad catalog of domain-specific servers, quick installation for popular platforms, and both local and remote deployment options, it enhances cloud-native development, infrastructure management, and workflow automation for AI-driven tools. The project includes Docker, Lambda, and direct integration instructions for environments such as Amazon Q CLI, Cursor, Windsurf, Kiro, and VS Code.

    • 6,220
    • MCP
    • awslabs/mcp
  • mcp

    mcp

    Universal remote MCP server connecting AI clients to productivity tools.

    WayStation MCP acts as a remote Model Context Protocol (MCP) server, enabling seamless integration between AI clients like Claude or Cursor and a wide range of productivity applications, such as Notion, Monday, Airtable, Jira, and more. It supports multiple secure connection transports and offers both general and user-specific preauthenticated endpoints. The platform emphasizes ease of integration, OAuth2-based authentication, and broad app compatibility. Users can manage their integrations through a user dashboard, simplifying complex workflow automations for AI-powered productivity.

    • 27
    • MCP
    • waystation-ai/mcp
  • 1mcp-app/agent

    1mcp-app/agent

    A unified server that aggregates and manages multiple Model Context Protocol servers.

    1MCP Agent provides a single, unified interface that aggregates multiple Model Context Protocol (MCP) servers, enabling seamless integration and management of external tools for AI assistants. It acts as a proxy, managing server configuration, authentication, health monitoring, and dynamic server control with features like asynchronous loading, tag-based filtering, and advanced security options. Compatible with popular AI development environments, it simplifies setup by reducing redundant server instances and resource usage. Users can configure, monitor, and scale model tool integrations across various AI clients through easy CLI commands or Docker deployment.

    • 96
    • MCP
    • 1mcp-app/agent
  • mcp-server-templates

    mcp-server-templates

    Deploy Model Context Protocol servers instantly with zero configuration.

    MCP Server Templates enables rapid, zero-configuration deployment of production-ready Model Context Protocol (MCP) servers using Docker containers and a comprehensive CLI tool. It provides a library of ready-made templates for common integrations—including filesystems, GitHub, GitLab, and Zendesk—and features intelligent caching, smart tool discovery, and flexible configuration options via JSON, YAML, environment variables, or CLI. Perfect for AI developers, data scientists, and DevOps teams, it streamlines the process of setting up and managing MCP servers and has evolved into the MCP Platform for enhanced capabilities.

    • 5
    • MCP
    • Data-Everything/mcp-server-templates
  • mcpmcp-server

    mcpmcp-server

    Seamlessly discover, set up, and integrate MCP servers with AI clients.

    mcpmcp-server enables users to discover, configure, and connect MCP servers with preferred clients, optimizing AI integration into daily workflows. It supports streamlined setup via JSON configuration, ensuring compatibility with various platforms such as Claude Desktop on macOS. The project simplifies the connection process between AI clients and remote Model Context Protocol servers. Users are directed to an associated homepage for further platform-specific guidance.

    • 17
    • MCP
    • glenngillen/mcpmcp-server
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results