FHIR MCP Server
A Model Context Protocol server for seamless interaction with FHIR resources and AI tools.
Key Features
Use Cases
README
π Table of Contents
- π About
- π‘ Demo
- π Getting Started
- π Usage
- π§ Configuration
- π³ Docker Setup
- π οΈ MCP Tools
- πΊοΈ Roadmap
- π₯ Contributors
- π License
π 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_resourcetool which retrieves basic patient information - utilization of the
request_condition_resourcetool 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_resourcetools 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
-
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.
-
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.
Installation & Setup
-
Clone the repository:
shgit clone https://github.com/the-momentum/fhir-mcp-server cd fhir-mcp-server -
Set up environment variables:
shcp config/.env.example config/.envEdit the
config/.envfile with your credentials and configuration. See Environment Variables -
Install Dependencies
For Docker-based execution run:
shmake buildFor uv-based execution run:
shmake uv -
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)
-
-
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:
# 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:
- Check for
MASTER_KEYinconfig/.envand generate one if needed - Automatically encrypt all sensitive values (
LOINC_PASSWORD,FHIR_SERVER_CLIENT_SECRET,PINECONE_API_KEY) - Update your
.envfile with encrypted values - Skip empty variables and already encrypted values
-
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.pyPut that key as a MASTER_KEY environment variable in .env.
-
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" -
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 serverLOINC_PASSWORD- LOINC account passwordPINECONE_API_KEY- Pinecone API key for vector search
Environment Variables
| Variable | Description | Example Value | Encryption |
|---|---|---|---|
| MASTER_KEY | Master encryption key | gAAAAABl... |
Required |
| FHIR_SERVER_HOST | FHIR API host URL | https://api.medplum.com |
No |
| FHIR_BASE_URL | FHIR base path | /fhir/R4 |
No |
| FHIR_SERVER_CLIENT_ID | OAuth2 client ID for FHIR | 019720e7... |
No |
| FHIR_SERVER_CLIENT_SECRET | OAuth2 client secret for FHIR | gAAAAABl... |
Yes |
| LOINC_ENDPOINT | LOINC API search endpoint | https://loinc.regenstrief.org/searchapi/loincs |
No |
| LOINC_USERNAME | LOINC account username | loinc-user |
No |
| LOINC_PASSWORD | LOINC account password | gAAAAABl... |
Yes |
| PINECONE_API_KEY | Pinecone API key | gAAAAABl... |
Yes |
| EMBEDDING_MODEL | Hugging Face embedding model name | NeuML/pubmedbert-base-embeddings |
No |
π οΈ MCP Tools
The FHIR MCP Server provides a comprehensive set of tools for interacting with FHIR resources and document management:
FHIR Resource Tools
| Tool | Resource Type | Description |
|---|---|---|
request_patient_resource |
Patient | Manage patient demographic and administrative information |
request_observation_resource |
Observation | Handle clinical measurements and assessments |
request_condition_resource |
Condition | Manage patient problems and diagnoses |
request_medication_resource |
Medication | Handle medication information and orders |
request_immunization_resource |
Immunization | Manage vaccination records |
request_encounter_resource |
Encounter | Handle patient visits and interactions |
request_allergy_intolerance_resource |
AllergyIntolerance | Manage patient allergy information |
request_family_member_history_resource |
FamilyMemberHistory | Handle family health history |
request_generic_resource |
Any FHIR Resource | Operate on any FHIR resource not covered by specific tools |
Document Management Tools
| Tool | Description |
|---|---|
request_document_reference_resource |
Manage FHIR DocumentReference resources |
add_document_to_pinecone |
Ingests documents into the vector database for semantic search |
search_pinecone |
Performs semantic search across indexed documents using vector embeddings |
LOINC Terminology Tools
| Tool | Description |
|---|---|
get_loinc_codes |
Retrieves 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.
Star History
Repository Owner
Organization
Repository Details
Programming Languages
Tags
Topics
Join Our Newsletter
Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.
Related MCPs
Discover similar Model Context Protocol servers
mcp-pinecone
A Pinecone-backed Model Context Protocol server for semantic search and document management.
mcp-pinecone implements a Model Context Protocol (MCP) server that integrates with Pinecone indexes for use with clients such as Claude Desktop. It provides powerful tools for semantic search, document reading, listing, and processing within a Pinecone vector database. The server supports operations like embedding, chunking, and upserting records, enabling contextual management of large document sets. Designed for ease of installation and interoperability via the MCP standard.
- β 150
- MCP
- sirmews/mcp-pinecone
Flowcore Platform MCP Server
A standardized MCP server for managing and interacting with Flowcore Platform resources.
Flowcore Platform MCP Server provides an implementation of the Model Context Protocol (MCP) for seamless interaction and management of Flowcore resources. It enables AI assistants to query and control the Flowcore Platform using a structured API, allowing for enhanced context handling and data access. The server supports easy deployment with npx, npm, or Bun and requires user authentication using Flowcore credentials.
- β 9
- MCP
- flowcore-io/mcp-flowcore-platform
Firefly MCP Server
Seamless resource discovery and codification for Cloud and SaaS with Model Context Protocol integration.
Firefly MCP Server is a TypeScript-based server implementing the Model Context Protocol to enable integration with the Firefly platform for discovering and managing resources across Cloud and SaaS accounts. It supports secure authentication, resource codification into infrastructure as code, and easy integration with tools such as Claude and Cursor. The server can be configured via environment variables or command line and communicates using standardized MCP interfaces. Its features facilitate automation and codification workflows for cloud resource management.
- β 15
- MCP
- gofireflyio/firefly-mcp
MyMCP Server (All-in-One Model Context Protocol)
Powerful and extensible Model Context Protocol server with developer and productivity integrations.
MyMCP Server is a robust Model Context Protocol (MCP) server implementation that integrates with services like GitLab, Jira, Confluence, YouTube, Google Workspace, and more. It provides AI-powered search, contextual tool execution, and workflow automation for development and productivity tasks. The system supports extensive configuration and enables selective activation of grouped toolsets for various environments. Installation and deployment are streamlined, with both automated and manual setup options available.
- β 93
- MCP
- nguyenvanduocit/all-in-one-model-context-protocol
FastMCP
The fast, Pythonic way to build MCP servers and clients.
FastMCP is a production-ready framework for building Model Context Protocol (MCP) applications in Python. It streamlines the creation of MCP servers and clients, providing advanced features such as enterprise authentication, composable tools, OpenAPI/FastAPI generation, server proxying, deployment tools, and comprehensive client libraries. Designed for ease of use, it offers both standard protocol support and robust utilities for production deployments.
- β 20,201
- MCP
- jlowin/fastmcp
mcp-server-qdrant
Official Model Context Protocol server for seamless integration with Qdrant vector search engine.
mcp-server-qdrant provides an official implementation of the Model Context Protocol for interfacing with the Qdrant vector search engine. It enables storing and retrieving contextual information, acting as a semantic memory layer for LLM-driven applications. Designed for easy integration, it supports environment-based configuration and extensibility via FastMCP. The server standardizes tool interfaces for managing and querying contextual data using Qdrant.
- β 1,054
- MCP
- qdrant/mcp-server-qdrant
Didn't find tool you were looking for?