Logo: FHIR MCP Server

FHIR MCP Server

Organisatioun
the-momentum

FHIR MCP Server for handling medical data standard.

Editeurthe-momentum
Repositoryfhir-mcp-server
SproochPython
Forks
18
Stären
100
Disponibel Tools
0
Transporttypstdio
Kategorien
LizenzMIT
Linken
  • Tools mat KI-Workflows verbannen

    FHIR MCP Server bitt MCP-Funktiounen un, déi vu kompatibele KI-Clienten a KI-Agente kënne benotzt ginn.

  • Disponibel Tools: 0

    Kuckt Iech déi opruffbar Aktiounen hei drënner un, mat Nimm a Beschreiwungen, wa se vum Server geliwwert ginn.

  • Konfiguratioun fir ze kopéieren

    Benotzt d'Installatiounsbeispiller, fir dëse Server an deem MCP-Client ze konfiguréieren, deen Dir am léifste benotzt.

  • Interessi vun der Communautéit um Open-Source-Projet

    Zuele vum verlinkte Repository – Stären: 100, Forks: 18.

Contact us Visit Momentum MIT License

📋 Table of Contents

🔍 About The Project

FHIR MCP Server implements a complete Model Context Protocol (MCP) server, designed to facilitate seamless interaction between LLM-based agents and a FHIR-compliant backend. It provides a standardized interface that enables full CRUD operations on FHIR resources through a comprehensive suite of tools - accessible from MCP-compatible clients such as Claude Desktop, allowing users to query and manipulate clinical data using natural-language prompts.

✨ Key Features

  • 🚀 FastMCP Framework: Built on FastMCP for high-performance MCP server capabilities
  • 🏥 FHIR Resource Management: Full CRUD operations for all major FHIR resources
  • 📄 Intelligent Document Processing: AI-powered document ingestion and chunking for multiple formats including TXT, CSV, JSON, and PDF
  • 🔍 Semantic Search: Advanced document search using vector embeddings (via Pinecone)
  • 🧠 RAG-Ready: Retrieval-Augmented Generation pipeline with context-aware document queries
  • 🔐 Secure Authentication: OAuth2 token management for FHIR API integration
  • 📊 LOINC Integration: Standardized medical terminology lookup and validation
  • 🐳 Container Ready: Docker support for easy deployment and scaling
  • 🔧 Configurable: Extensive .env-based configuration options

🏗️ Architecture

The server is built with a modular architecture:

  • MCP Tools: Dedicated tools for selected FHIR resource types, with others handled by a generic tool
  • Fhir Server Client: Handles FHIR API communication and authentication (OAuth2 and more planned)
  • RAG Services: Embedding-based document processing and semantic retrieval
  • Vector Store: Pinecone integration for similarity-based search
  • LOINC Client: Integration with LOINC API for terminology resolution and validation

💡 Demo

This demo shows how Claude uses the fhir-mcp-server to communicate with a FHIR server (in this case Medplum) to answer questions. You will see, among other things:

  • utilization of the request_patient_resource tool which retrieves basic patient information
  • utilization of the request_condition_resource tool to answer the question whether any of the previously diagnosed diseases may cause symptoms that the patient is currently complaining about
  • utilization of the request_medication_resource, request_encounter_resource, request_generic_resource tools to answer the question whether the patient has already received any treatment for hypertension

You can observe how Claude automatically selects the tools worth using to answer the question based on the user's query.

https://github.com/user-attachments/assets/3a3a8ed3-f881-447d-af03-5f24432a2cdd

Here you can observe how Claude first uses the tool searching for LOINC codes for the lipid panel specific codes, but not finding any related observations in FHIR server, it repeats the search for individual biomarkers that make up such a panel.

https://github.com/user-attachments/assets/2fb39801-d5d6-4461-bedd-9f58ab4d52ec

Developers working with FHIR often need to generate specific test data to validate FHIR server functionality, such as search capabilities and data relationships. While you can use Synthea to generate synthetic data and then manually import the resulting bundles to your server, fhir-mcp-server streamlines this process by allowing you to generate and deploy test data directly through Claude.

This eliminates the typical workflow of running synthea separately, downloading bundles, and manually importing them to your FHIR server. Instead, you can create targeted test scenarios, generate appropriate synthetic data, and populate your server all within Claude's interface.

https://github.com/user-attachments/assets/d87da1d8-6401-4a9e-a6f0-50ba23396e12

Note: fhir-mcp-server was not designed with this use case in mind, so as you'll see in the demo, it doesn't work perfectly - what can be observed, however, is how well the LLM handles using trial and error to correct any wrong choices.

🚀 Getting Started

Follow these steps to set up FHIR MCP Server in your environment.

Prerequisites

  • Docker (recommended) or uv: For dependency management

    👉 uv Installation Guide

  • FHIR Server Account: Access to FHIR API (e.g. Medplum)

  • Pinecone API key (required for document search): Enables vector-based search over processed documents. Without it, semantic retrieval features will be unavailable.

    👉 Create Pinecone Account

  • LOINC Account (optional): Enables retrieval of the latest LOINC codes from the official API. Without it, the system relies on static or language model-inferred codes, which may be outdated or imprecise.

    👉Create LOINC Account

Installation & Setup

  1. Clone the repository:

    sh
    git clone https://github.com/the-momentum/fhir-mcp-server
    cd fhir-mcp-server
  2. Set up environment variables:

    sh
    cp config/.env.example config/.env

    Edit the config/.env file with your credentials and configuration. See Environment Variables

  3. Install Dependencies

    For Docker-based execution run:

    sh
    make build

    For uv-based execution run:

    sh
    make uv
  4. Update the MCP Client configuration

    e.g. Claude Desktop -> edit claude_desktop_config.json

  • Docker

    json
    {
       "mcpServers": {
          "docker-mcp-server": {
             "command": "docker",
             "args": [
                "run",
                "-i",
                "--rm",
                "--init",
                "--name",
                "fhir-mcp-server",
                "--mount", // optional - volume for reload
                "type=bind,source=<your-project-path>/app,target=/root_project/app", // optional - volume for reload
                "--mount",
                "type=bind,source=<your-project-path>/config/.env,target=/root_project/config/.env",
                "-e", "TRANSPORT_MODE=stdio", // Set transport mode: stdio, http, or https
                "mcp-server:latest"
             ]
          }
       }
    }

    Make sure to replace <your-project-path> with the actual path to your installation

  • uv

    Firstly, get uv path from terminal:

    • Windows:

      (Get-Command uv).Path
    • MacOS/Linux:

      which uv

    Then, update config file:

    json
    {
       "mcpServers": {
          "uv-mcp-server": {
             "command": "uv",
             "args": [
                "run",
                "--frozen",
                "--directory",
                "<your-project-path>",
                "start"
             ],
             "env": {
             "PATH": "<uv-bin-folder-path>"
             }
          }
       }
    }

    Make sure to replace with the actual uv path (to bin folder)

  1. Restart MCP Client

    After completing all of the above steps, restart the MCP Client to apply the changes. In some cases, you may need to terminate all related processes using Task Manager or your system's process manager. This ensures that:

    • The updated configuration is properly loaded
    • Environment variables are correctly applied
    • The FHIR MCP client initializes with the correct settings

🔧 Configuration

🔐 Security & Encryption

The FHIR MCP Server includes built-in encryption infrastructure to protect sensitive configuration values. Sensitive fields like API keys and passwords are automatically encrypted and decrypted at runtime.

You are allowed to store passwords as a plain text, but if you want to have them encrypted, follow the instruction below.

Setting Up Encryption

For most users, use the automated setup script:

bash
# uv method
uv run scripts/cryptography/setup_encryption.py

# docker method
docker exec fhir-mcp-server uv run scripts/cryptography/setup_encryption.py

This script will:

  1. Check for MASTER_KEY in config/.env and generate one if needed
  2. Automatically encrypt all sensitive values (LOINC_PASSWORD, FHIR_SERVER_CLIENT_SECRET, PINECONE_API_KEY)
  3. Update your .env file with encrypted values
  4. Skip empty variables and already encrypted values
  1. Generate a Master Key:

    bash
    # uv method
    uv run scripts/cryptography/generate_master_key.py
    
    # docker method
    docker exec fhir-mcp-server uv run scripts/cryptography/generate_master_key.py

    Put that key as a MASTER_KEY environment variable in .env.

  2. Encrypt Sensitive Values:

    bash
    # uv method
    uv run scripts/cryptography/encrypt_setting.py "your_secret_value"
    
     # docker method
    docker exec fhir-mcp-server uv run scripts/cryptography/encrypt_setting.py "your_secret_value"
  3. Decrypt Values (for verification):

    bash
    # uv method
    uv run scripts/cryptography/decrypt_setting.py "encrypted_value"
    
     # docker method
    docker exec fhir-mcp-server uv run scripts/cryptography/decrypt_setting.py "encrypted_value"

Encrypted Configuration Fields

The following fields are automatically encrypted when using EncryptedField:

  • FHIR_SERVER_CLIENT_SECRET - OAuth2 client secret for FHIR server
  • LOINC_PASSWORD - LOINC account password
  • PINECONE_API_KEY - Pinecone API key for vector search

Environment Variables

VariableDescriptionExample ValueEncryption
MASTER_KEYMaster encryption keygAAAAABl...Required
FHIR_SERVER_HOSTFHIR API host URLhttps://api.medplum.comNo
FHIR_BASE_URLFHIR base path/fhir/R4No
FHIR_SERVER_CLIENT_IDOAuth2 client ID for FHIR019720e7...No
FHIR_SERVER_CLIENT_SECRETOAuth2 client secret for FHIRgAAAAABl...Yes
LOINC_ENDPOINTLOINC API search endpointhttps://loinc.regenstrief.org/searchapi/loincsNo
LOINC_USERNAMELOINC account usernameloinc-userNo
LOINC_PASSWORDLOINC account passwordgAAAAABl...Yes
PINECONE_API_KEYPinecone API keygAAAAABl...Yes
EMBEDDING_MODELHugging Face embedding model nameNeuML/pubmedbert-base-embeddingsNo

🛠️ MCP Tools

The FHIR MCP Server provides a comprehensive set of tools for interacting with FHIR resources and document management:

FHIR Resource Tools

ToolResource TypeDescription
request_patient_resourcePatientManage patient demographic and administrative information
request_observation_resourceObservationHandle clinical measurements and assessments
request_condition_resourceConditionManage patient problems and diagnoses
request_medication_resourceMedicationHandle medication information and orders
request_immunization_resourceImmunizationManage vaccination records
request_encounter_resourceEncounterHandle patient visits and interactions
request_allergy_intolerance_resourceAllergyIntoleranceManage patient allergy information
request_family_member_history_resourceFamilyMemberHistoryHandle family health history
request_generic_resourceAny FHIR ResourceOperate on any FHIR resource not covered by specific tools

Document Management Tools

ToolDescription
request_document_reference_resourceManage FHIR DocumentReference resources
add_document_to_pineconeIngests documents into the vector database for semantic search
search_pineconePerforms semantic search across indexed documents using vector embeddings

LOINC Terminology Tools

ToolDescription
get_loinc_codesRetrieves standardized LOINC codes for medical observations and laboratory tests

Tool Features

  • Full Resource Management: All FHIR resource tools support Create, Read, Update, and Delete operations
  • Data Validation: Tools enforce FHIR resource validation and prevent data corruption
  • Error Handling: Comprehensive error responses with detailed failure information
  • Security: OAuth2 authentication and proper access control for all operations
  • Semantic Search: AI-powered document search using vector embeddings
  • Multi-format Support: Document ingestion supports TXT, PDF, CSV, and JSON formats

🗺️ Roadmap

We're continuously enhancing FHIR MCP Server with new capabilities. Here's what's on the horizon:

  • Extended Authentication Options: In addition to OAuth2 (already supported), we plan to add support for other authentication methods for connecting to FHIR servers
  • Expanded File Format Support for RAG: Extend document ingestion capabilities to support additional formats
  • Table-Aware Document Chunking: Improve the document chunking pipeline by detecting tables in documents and treating them as separate, atomic chunks.
  • OCR Support for Scanned Documents: Implement Optical Character Recognition capabilities to enable extraction of text from scanned PDFs and image files before chunking and indexing

Have a suggestion? We'd love to hear from you! Contact us or contribute directly.

👥 Contributors

📄 License

Distributed under the MIT License. See MIT License for more information.


Installatioun

TypingMind
Viraussetzungen:

Node.js 18+

{
  "mcpServers": {
    "the-momentum-fhir-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "fhir-mcp-server"
      ]
    }
  }
}

FHIR MCP Server MCP mat verschiddene KI-Modeller benotzen

TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Soubal FHIR MCP Server verbonnen ass, kënnt Dir et mat verschiddene KI-Modeller an TypingMind benotzen, amplaz et fir all Modell separat anzeriichten. Dës MCP-Integratioun leeft lokal iwwer den TypingMind-MCP-Connector op Ärem Apparat.

Ariichtungsuleedung, fir de lokale Connector ze benotzen

Benotzt dës Optioun, wann den MCP-Server Zougrëff op lokal Fichieren, Appen oder privat Ressourcen op Ärem Computer brauch.

1

D'MCP-Astellungen opmaachen

Gitt an TypingMind op „Astellungen“, „Erweidert Astellungen“, dann op „Model Context Protocol“ a wielt „Connector ariichten“.

  1. Maacht TypingMind an Ärem Browser op.
  2. Klickt op d'Astellungssymbol.
  3. Gitt op „Erweidert Astellungen“.
  4. Maacht d'Sektioun „Model Context Protocol“ op.
  5. Klickt op „Connector ariichten“ a wielt „Dësen Apparat“.
Ariichtungsbildschierm vum TypingMind-MCP-Connector: D'Optioun „Dësen Apparat“ ass ausgewielt
2

De Connector-Befeel ausféieren

Wielt „Dësen Apparat“, kopéiert de Befeel aus TypingMind a féiert en am Terminal aus. Loosst de Prozess lafen, wärend Dir MCP benotzt.

  1. Kopéiert den Ariichtungsbefeel, deen TypingMind uweist.
  2. Maacht Terminal op macOS oder Windows Terminal op Windows op.
  3. Setzt de kopéierte Befeel an a féiert en aus.
  4. Bestätegt d'Installatioun vum Package, wann den Terminal Iech freet, ob Dir weiderfuere wëllt.
  5. Loosst den Terminal an de Prozess doranner lafen, wärend Dir MCP-Tools benotzt.
3

FHIR MCP Server als Server derbäisetzen

Wann de Connector-Status „Prett“ ass, klickt op „Serveren änneren“ a setzt d'MCP-Serverkonfiguratioun an.

  1. Waart, bis de Connector-Status „Prett“ weist.
  2. Klickt op „Serveren änneren“.
  3. Setzt d'MCP-Serverkonfiguratioun fir FHIR MCP Server an.
  4. Späichert d'Serverlëscht.
  5. Aktualiséiert d'Säit, wann Dir kontrolléiere wëllt, ob de Connector nach ëmmer prett ass.
MCP-Astellunge vun TypingMind mat aktivem Server an dem Knäppchen „Serveren änneren“
{
  "mcpServers": {
    "the-momentum-fhir-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "fhir-mcp-server"
      ]
    }
  }
}
4

D'Verbindung mat verschiddene Modeller benotzen

Späichert d'Serverlëscht, maacht „Plugins“ op an aktivéiert d'MCP-Tools vun der Integratioun FHIR MCP Server. Wielt dann e belibegen ënnerstëtzte KI-Modell an TypingMind a benotzt d'Tools am Chat oder weist se engem KI-Agent zou.

  1. Maacht d'Säit „Plugins“ an TypingMind op.
  2. Aktivéiert d'MCP-Tools vun der Integratioun FHIR MCP Server.
  3. Start e Chat a wielt de KI-Modell, deen Dir benotze wëllt.
  4. Benotzt d'MCP-Tools am Chat oder weist se engem KI-Agent zou.
  5. Wiesselt bei Bedarf op en anere KI-Modell, ouni MCP nei ze verbannen.
TypingMind-Chat mat aktivéierten MCP-Tools an engem ausgewielte KI-Modell
Kënnt Dir mir mat FHIR MCP Server bei dëser Aufgab hëllefen?
FHIR MCP Server
Jo. Ech hunn et gelies.
Dat hunn ech mat FHIR MCP Server fonnt.

Heefeg gestallte Froen

Fir wat gëtt den MCP-Server FHIR MCP Server benotzt?

FHIR MCP Server ass en MCP-Server, deen et kompatibele KI-Clienten erlaabt, op extern Tools a Kontextinformatioune zouzegräifen. An TypingMind kënnt Dir dësen MCP-Server eemol derbäisetzen a seng Tools an Ärem KI-Aarbechtsberäich zur Verfügung stellen.

Kann ech FHIR MCP Server MCP mat méi KI-Modeller an TypingMind benotzen?

Jo. TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Sou kënnt Dir FHIR MCP Server mat verschiddene KI-Modeller wéi Claude, ChatGPT, Gemini oder anere Modeller benotzen, déi Dir an TypingMind konfiguréiert hutt, ouni den MCP-Server fir all Modell separat anzeriichten.

Firwat FHIR MCP Server MCP mat TypingMind benotzen?

TypingMind ass eng vun de beschte Benotzeruewerfläche fir LLM-Chat, well et méi KI-Modeller, Prompts, Plugins, KI-Agenten, API-Schlësselen a MCP-Tools an engem Aarbechtsberäich zesummebréngt. Wann FHIR MCP Server verbonnen ass, kënnt Dir seng MCP-Tools mat Äre bevorzugte Modeller benotzen a gläichzäiteg Ären Aarbechtsoflaf beim Chatten an TypingMind organiséieren.

Wéi verbannen ech FHIR MCP Server MCP mat TypingMind?

FHIR MCP Server leeft iwwer de lokale MCP-Connector vun TypingMind. Dat eegent sech am beschten, wann den MCP-Server Zougrëff op lokal Fichieren, Desktop-Apps, Kommandozeilen-Tools oder privat Ressourcen op Ärem Computer brauch.

Wéi eng Tools stellt FHIR MCP Server MCP an TypingMind zur Verfügung?

FHIR MCP Server stellt MCP-Funktioune zur Verfügung, déi Dir op der Plugins-Säit vun TypingMind aktivéiere kënnt, fir se am Chat ze benotzen oder KI-Agente zouzeweisen.

Muss ech meng API-Schlëssele mat TypingMind deelen, fir FHIR MCP Server MCP ze benotzen?

Nee. TypingMind ass nom Local-first-Prinzip opgebaut a léisst Iech d'Kontroll iwwer Är Modellubidder, API-Schlësselen, Prompts a MCP-Konfiguratioun. Wann FHIR MCP Server eng Authentifizéierung verlaangt, setzt déi néideg Headeren, OAuth-Astellungen oder lokal Konfiguratioun fir deen MCP-Server derbäi, wann Dir d'Verbindung erstallt.

Änlech MCP-Serveren

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇