FHIR MCP Server

io.github.wso2由 GitHub 帳號 wso2 發布v0.11.0更新於 Oct 29, 2026

MCP server providing seamless access to FHIR APIs for AI tools and healthcare applications

已驗證STDIO僅桌面資料庫開發者工具

概覽

AI 產生的概覽

把 AI 助理連接到 FHIR 醫療 API,讓它能搜尋、讀取、建立、更新與刪除臨床資源。

可以做什麼
  • 檢視資源類型及其支援的搜尋參數與自訂操作
  • 搜尋並讀取 FHIR 資源,可用 FHIRPath 運算式精簡回傳內容
  • 建立、更新與刪除資源執行個體,並呼叫自訂操作
  • 查詢目前通過驗證使用者所連結的 FHIR 個人資料
適用情境
當你使用 FHIR 伺服器(公開 HAPI、Epic 沙箱、WSO2 FHIR Server 或自建伺服器),並希望助理在開發與整合過程中瀏覽、查詢或維護臨床資源時適用。
執行需求
以本機 Python 套件(Python 3.8+,uv/uvx)或 Docker 執行。需要可存取的 FHIR 伺服器,並設定 FHIR_SERVER_BASE_URL 環境變數。預設啟用授權,需提供 FHIR_SERVER_CLIENT_ID、FHIR_SERVER_CLIENT_SECRET 與 FHIR_SERVER_SCOPES,或在本機 stdio 模式使用 FHIR_SERVER_ACCESS_TOKEN;設定 FHIR_SERVER_DISABLE_AUTHORIZATION=True 可關閉授權。需要能連線至 FHIR 伺服器的網路。
安裝前請注意
此伺服器可建立、更新與刪除 FHIR 資源,助理的操作可能變更或刪除臨床資料。它涉及 OAuth 用戶端憑證(FHIR_SERVER_CLIENT_ID、FHIR_SERVER_CLIENT_SECRET)與存取權杖(FHIR_SERVER_ACCESS_TOKEN);README 提醒不要在伺服器對外暴露於網路時使用存取權杖變數。病患資料會傳送到所設定的 FHIR 伺服器,關閉授權會讓伺服器對任何呼叫方開放。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 FHIR MCP Server,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

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] [Listed on Spark] [Install via Spark]

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

  • Response Filtering using FHIRPath: Filter resources and bundles returned by read and search operations using custom FHIRPath expressions to retrieve only the fields needed for the task, reducing payload sizes.

  • 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.

    • To enable authorization: Set FHIR_SERVER_BASE_URL, FHIR_SERVER_CLIENT_ID, FHIR_SERVER_CLIENT_SECRET, and FHIR_SERVER_SCOPES. Authorization is enabled by default.
    • To disable authorization: Set FHIR_SERVER_DISABLE_AUTHORIZATION to True.

    By default, the MCP server runs on http://localhost:8000, and you can customize the host and port using FHIR_MCP_HOST and FHIR_MCP_PORT.

    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

    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 venvsource .venv/bin/activateuv pip sync requirements.txt

    Or with pip:

    bash
    python -m venv .venvsource .venv/bin/activatepip 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

Installing using Docker

Running the MCP Server with Docker

You can run the MCP server using Docker for a consistent, isolated environment.

Note on Authorization: When running the MCP server locally via Docker or Docker Compose, authorization should be disabled by setting the environment variable, FHIR_SERVER_DISABLE_AUTHORIZATION=True . This would be fixed in the future releases.

  1. Build the Docker Image or pull the docker image from the container registry:

    • Build from source:
      bash
      docker build -t fhir-mcp-server .
    • Pull from GitHub Container Registry:
      bash
      docker pull ghcr.io/wso2/fhir-mcp-server:latest
      latest is built from the main branch. To use a release, pull its version tag instead, for example ghcr.io/wso2/fhir-mcp-server:0.11.0.
  2. Configure Environment Variables

    Copy the example environment file and edit as needed:

    bash
    cp .env.example .env# Edit .env to set your FHIR server, client credentials, etc.

    Alternatively, you can pass environment variables directly with -e flags or use Docker secrets for sensitive values. See the Configuration section for details on available environment variables.

  3. Run the Container

    bash
    docker run --env-file .env -p 8000:8000 ghcr.io/wso2/fhir-mcp-server:latest

    This will start the server and expose it on port 8000. Adjust the port mapping as needed.

Using Docker Compose with WSO2 FHIR Server

For a quick setup that includes both the FHIR MCP server and the WSO2 FHIR Server (with PostgreSQL), use the provided docker-compose.yml. This sets up an instant development environment for testing FHIR operations.

  1. Prerequisites:

    • Docker and Docker Compose installed.
  2. Set the Database Credentials:

    Copy the example environment file and set DB_PASSWORD in .env. If you already have a .env, add the DB_USER, DB_PASSWORD and DB_NAME lines from .env.example to it instead.

    bash
    cp .env.example .env

    Docker Compose reads .env automatically. DB_USER and DB_NAME default to postgres if not set. .env is excluded from Git; use a secrets manager for production deployments.

  3. Run the Stack:

    bash
    docker compose up -d

    This command will:

  4. Access the Services:

    docker compose down removes the database data; use docker compose stop to keep it between runs.

  5. Configure Additional Environment Variables:

    If you need to customize OAuth or other settings, adjust the env variables in the docker-compose.yml. The compose file sets basic configuration; refer to the Configuration section for full options.

Configuring any FHIR Server

To use a different FHIR server, run the FHIR MCP server container with FHIR_SERVER_BASE_URL pointing to that server. The example below uses the HAPI FHIR server. Stop the default stack first if it's already running (docker compose down), as both use ports 8000 and 8080.

  1. Create a network and start the HAPI FHIR server:

    bash
    docker network create fhir-networkdocker run -d --name hapi-fhir-server --network fhir-network -p 127.0.0.1:8080:8080 docker.io/hapiproject/hapi:v8.4.0-2

    HAPI FHIR listens on http://localhost:8080/fhir. This uses its built-in database, so data is lost when the container is removed.

  2. Build and run the FHIR MCP server container:

    bash
    docker build -t fhir-mcp-server .docker run -d --name fhir-mcp-server-hapi --network fhir-network -p 127.0.0.1:8000:8000      -e FHIR_SERVER_BASE_URL=http://hapi-fhir-server:8080/fhir      -e FHIR_MCP_HOST=0.0.0.0      -e FHIR_SERVER_DISABLE_AUTHORIZATION=True      fhir-mcp-server

    The FHIR MCP server listens on http://localhost:8000.

  3. Stop and clean up:

    bash
    docker rm -f fhir-mcp-server-hapi hapi-fhir-serverdocker network rm fhir-network

For any other FHIR server, set FHIR_SERVER_BASE_URL to its base URL. If the FHIR server runs on your host rather than in Docker, use http://host.docker.internal:<port>/... instead of localhost. On Linux, also add --add-host=host.docker.internal:host-gateway to the docker run command, and make sure the FHIR server listens on an address reachable from containers (for example 0.0.0.0, not only 127.0.0.1).

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 MCP configuration file in VS Code (> V1.104). You can do this by pressing Ctrl + Shift + P and typing MCP: Open User Configuration.

Streamable HTTPSTDIOSSE
json
"servers": {    "fhir": {        "type": "http",        "url": "http://localhost:8000/mcp",    }}
json
"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
"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:
Streamable HTTPSTDIOSSE
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:

Streamable HTTPSTDIOSSE
  • 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
  • --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 DEBUGuv 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_DISABLE_AUTHORIZATION: If set to True, disables authorization checks on the MCP server, allowing connections to publicly accessible FHIR servers.
  • 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.

[!NOTE] FHIR_SERVER_ACCESS_TOKEN is intended for local stdio mode deployments only, as a convenience to bypass interactive OAuth authentication. Do not use this variable when the MCP server is exposed over a network or the public internet.

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"}).
    • response_filter_fhirpaths: (Optional) An array of FHIRPath expressions (e.g., ["Patient.name", "Patient.birthDate", "Bundle.link.where(relation='next').url"]) to apply to the resources in the response bundle.
  • 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").
    • response_filter_fhirpaths: (Optional) An array of FHIRPath expressions (e.g., ["Patient.name", "Observation.valueQuantity"]) to filter the returned single resource (or entries when using custom operations like $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 dependenciespip install -e '.[test]'
# Or install from requirements filepip install -r requirements-dev.txt

Using uv:

bash
# Install development dependenciesuv sync --dev

Running Tests

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

bash
# Simple test runnerpython run_tests.py
# Or direct pytest usagePYTHONPATH=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.

來源:README.md,提交 794a669

工具

0
SourceWeft 曾在隔離沙箱中以無憑證方式啟動該軟體包一次,以列出其工具,但未能完成:軟體包安裝失敗。

版本歷史

2
  1. v0.11.0最新Oct 29, 2026
  2. v0.10.0Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分