Mcp Fhir

io.github.pcmedsinge由 GitHub 帳號 pcmedsinge 發布v1.1.1更新於 Oct 24, 2026

FHIR R4 read/search/validate MCP server — US Core/IPS profiles, SMART-on-FHIR auth (Epic/Cerner).

已驗證STDIO僅桌面安全與監控資料與分析

概覽

AI 產生的概覽

讓助理讀取、搜尋、分頁並依 US Core/IPS 設定檔驗證 FHIR R4 醫療資源,可選向 Epic 或 Cerner 沙箱驗證。

可以做什麼
透過 stdio 提供五個工具:fhir_capabilities 彙整 FHIR 伺服器的 CapabilityStatement,fhir_read 依資源類型與邏輯 ID 讀取單一資源,fhir_search 使用 FHIR 查詢參數並回傳帶 _next_url 的 Bundle,fhir_search_next 在 SSRF 防護下追蹤分頁連結,validate_against_profile 透過 HAPI 驗證器 sidecar 依 US Core 或 IPS 設定檔驗證資源。也可使用 SMART-on-FHIR 後端服務向 Epic 或 Cerner EHR 沙箱驗證。
適用情境
適合助理需要瀏覽或查詢 FHIR R4 臨床資料伺服器、取得病人或觀察資源,或依 US Core 與 IPS 設定檔驗證資源的情境。適用於針對公開展示伺服器或 EHR 沙箱的醫療資料原型與整合工作。
執行需求
以本機 Python 套件執行(需 Python 3.12+ 與 uv,透過 uvx 啟動)。需要 FHIR_BASE_URL 指向 FHIR R4 伺服器,預設使用公開 HAPI 展示伺服器。設定檔驗證需要 HAPI 驗證器 sidecar,由 HAPI_VALIDATOR_URL 設定。SMART 驗證需要 SMART_ENABLED 以及 SMART_CLIENT_ID 和 SMART_CLIENT_SECRET,SMART_TOKEN_URL 為選用。選用的 LangFuse 金鑰可啟用可觀測性。
安裝前請注意
當 SMART_ENABLED=true 時,請求會帶 bearer 權杖,伺服器需要 SMART_CLIENT_ID 和 SMART_CLIENT_SECRET,這些是真實的 EHR 憑證,應避免納入版本控制。查詢會送往 FHIR_BASE_URL 指定的伺服器,臨床資料可能離開本機;預設是公開展示伺服器。選用的 LANGFUSE_PUBLIC_KEY 和 LANGFUSE_SECRET_KEY 會把可觀測性追蹤傳送給第三方。工具為唯讀,但資料屬於敏感健康資訊。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

mcp-fhir

FHIR R4 MCP server — read, search, paginate, validate resources against US Core/IPS profiles, and authenticate against Epic/Cerner EHR sandboxes via SMART-on-FHIR OAuth 2.0.
Part of the fhir-mcp-suite monorepo.

[PyPI] [PyPI - Python Version] [CI] [License]

What it does

mcp-fhir exposes five MCP tools that let any MCP-compatible AI (Claude, GPT-4o, etc.) interact with any FHIR R4 server — and validate resources against US Core and IPS profiles — in a single server process. No other public FHIR MCP server combines search + validation today.

ToolDescription
fhir_capabilitiesCapabilityStatement summary — what the server supports
fhir_readRead a single resource by type + logical ID
fhir_searchSearch a resource type with FHIR query params; returns Bundle with _next_url when paginated
fhir_search_nextFollow a _next_url pagination link (SSRF-guarded)
validate_against_profileValidate a resource via the HAPI validator; supports US Core & IPS aliases

Architecture

Claude Desktop / AI client        │  MCP (stdio or SSE)        ▼┌───────────────────────────────┐│        mcp-fhir  v1.1         ││  ┌───────────────────────────┐││  │  tools/                   │││  │  ├─ fhir_capabilities.py  │││  │  ├─ fhir_read.py          │││  │  ├─ fhir_search.py        ││   ──► FHIR R4 server│  │  └─ validate_profile.py   ││   ──► HAPI validator sidecar│  └───────────────────────────┘││  fhir-mcp-shared               ││  ├─ LangFuse traces (session)  ││  ├─ Pydantic structured output ││  └─ structlog JSON logging     │└───────────────────────────────┘

Quick start

bash
# requires Python 3.12+ and uvuvx mcp-fhir           # stdio transport (Claude Desktop, default)
# SSE transport (HTTP, for API access)MCP_TRANSPORT=sse uvx mcp-fhir

Claude Desktop config (claude_desktop_config.json)

json
{  "mcpServers": {    "mcp-fhir": {      "command": "uvx",      "args": ["mcp-fhir"],      "env": {        "FHIR_BASE_URL": "https://hapi.fhir.org/baseR4",        "HAPI_VALIDATOR_URL": "http://localhost:8082"      }    }  }}

See full installation guide for HAPI validator setup, troubleshooting, and self-hosted FHIR server configuration.

Eval results

Golden query suite — run against the public HAPI demo server (hapi.fhir.org/baseR4):

CategoryCasesPass rate
fhir_capabilities2100 %
fhir_read4100 %
fhir_search6100 %
fhir_search_next2100 %
validate_against_profile6100 %
Total20100 %

CI gate: uv run python evals/mcp-fhir/run_eval.py --ci --threshold 0.9
Validator cases require the HAPI sidecar (docker compose up hapi-validator).

Configuration

All settings via environment variables (see .env.example):

VariableDefaultDescription
FHIR_BASE_URLhttps://hapi.fhir.org/baseR4FHIR server base URL
HAPI_VALIDATOR_URLhttp://localhost:8082HAPI validator sidecar (runs on port 3500 internally; map 8082:3500)
FHIR_TIMEOUT_S30HTTP timeout in seconds
FHIR_MAX_RESULTS20Default _count for searches
MCP_TRANSPORTstdiostdio or sse
MCP_PORT8000Port for SSE transport
LOG_FORMATjsonjson (prod) or console (dev)
LANGFUSE_PUBLIC_KEY(unset)LangFuse observability (optional)
LANGFUSE_SECRET_KEY(unset)LangFuse observability (optional)

SMART-on-FHIR authentication

mcp-fhir v1.1.0 adds SMART-on-FHIR backend services (client_credentials grant, RFC 6749) so the server can authenticate against real Epic / Cerner sandboxes — no browser redirect needed.

When SMART_ENABLED=true, every FHIR request gets an Authorization: Bearer <token> header. Tokens are cached in-process and refreshed automatically 30 s before expiry.

SMART environment variables

VariableDefaultDescription
SMART_ENABLEDfalseSet true to activate SMART auth
SMART_CLIENT_ID""App client ID from EHR registration portal
SMART_CLIENT_SECRET""Client secret (stored as SecretStr, never logged)
SMART_TOKEN_URL""Token endpoint URL; auto-discovered if blank
SMART_SCOPESsystem/*.readSpace-separated OAuth 2.0 scopes
SMART_GRANT_TYPEclient_credentialsOAuth grant type (only client_credentials supported)
SMART_TOKEN_TIMEOUT_S15.0HTTP timeout for token requests

When SMART_TOKEN_URL is blank the server performs SMART auto-discovery:
GET {FHIR_BASE_URL}/.well-known/smart-configuration → token_endpoint.
Falls back to {FHIR_BASE_URL}/oauth2/token if discovery returns a non-200.

Epic sandbox quick-start

  1. Register at https://fhir.epic.com/ → My Apps → create a backend-services app.
  2. Note your Client ID and Client Secret.
  3. Create .env in the monorepo root (already in .gitignore):
dotenv
FHIR_BASE_URL=https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4SMART_ENABLED=trueSMART_CLIENT_ID=your-epic-client-idSMART_CLIENT_SECRET=your-epic-client-secret# SMART_TOKEN_URL is optional — auto-discovered from FHIR_BASE_URL

Cerner sandbox quick-start

  1. Register at https://code.cerner.com/ → create a backend-services app.
  2. Note your Client ID and the token endpoint URL.
  3. Update .env:
dotenv
FHIR_BASE_URL=https://fhir-ehr-code.cerner.com/r4/your-tenant-idSMART_ENABLED=trueSMART_CLIENT_ID=your-cerner-client-idSMART_CLIENT_SECRET=your-cerner-client-secretSMART_TOKEN_URL=https://authorization.cerner.com/tenants/your-tenant-id/protocols/oauth2/profiles/smart-v1/token

Claude Desktop config with SMART auth

json
{  "mcpServers": {    "mcp-fhir": {      "command": "uvx",      "args": ["mcp-fhir"],      "env": {        "FHIR_BASE_URL": "https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4",        "SMART_ENABLED": "true",        "SMART_CLIENT_ID": "your-epic-client-id",        "SMART_CLIENT_SECRET": "your-epic-client-secret"      }    }  }}

Programmatic client (LangGraph / any Python agent)

Use StdioServerParameters to point any Python MCP client at a FHIR server. The same pattern works in LangGraph tool nodes, LangChain agents, or plain asyncio scripts.

python
from mcp import ClientSession, StdioServerParametersfrom mcp.client.stdio import stdio_clientimport asyncio, os
server = StdioServerParameters(    command="uv",    args=["run", "--package", "mcp-fhir", "mcp-fhir"],    env={        **os.environ,        # ── Public HAPI (no auth) ──────────────────────────────────        "FHIR_BASE_URL": "https://hapi.fhir.org/baseR4",        "SMART_ENABLED": "false",
        # ── Epic sandbox (uncomment + fill in) ────────────────────        # "FHIR_BASE_URL":       "https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4",        # "SMART_ENABLED":       "true",        # "SMART_CLIENT_ID":     os.environ["EPIC_CLIENT_ID"],        # "SMART_CLIENT_SECRET": os.environ["EPIC_CLIENT_SECRET"],
        # ── Cerner sandbox (uncomment + fill in) ──────────────────        # "FHIR_BASE_URL":       "https://fhir-myrecord.cerner.com/r4/<tenant-id>",        # "SMART_ENABLED":       "true",        # "SMART_CLIENT_ID":     os.environ["CERNER_CLIENT_ID"],        # "SMART_CLIENT_SECRET": os.environ["CERNER_CLIENT_SECRET"],        # "SMART_TOKEN_URL":     "https://authorization.cerner.com/tenants/<tenant-id>/...",    },)
async def main():    async with stdio_client(server) as (read, write):        async with ClientSession(read, write) as session:            await session.initialize()            result = await session.call_tool(                "fhir_search",                arguments={"resource_type": "Patient", "params": {"_count": "3"}},            )            print(result.content[0].text)
asyncio.run(main())

See demo/fhir_server_configs.py for ready-to-run configs for all supported servers (public HAPI, SMART Health IT, Epic, Cerner, local Docker).

Running SMART integration tests

bash
# Requires real sandbox credentials in .envuv run pytest packages/mcp-fhir/tests -m smart_integration -v

Profile validation

The validate_against_profile tool supports shorthand aliases:

AliasProfile URL
us-core-patienthttp://hl7.org/fhir/us/core/StructureDefinition/us-core-patient
us-core-observationhttp://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-clinical-result
us-core-conditionhttp://hl7.org/fhir/us/core/StructureDefinition/us-core-condition-problems-health-concerns
us-core-medication-requesthttp://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest
us-core-encounterhttp://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter
ips-patienthttp://hl7.org/fhir/uv/ips/StructureDefinition/Patient-uv-ips

Profile validation requires the HAPI validator sidecar (included in docker-compose.yml at repo root).

Development

bash
# From monorepo rootuv syncuv run pytest packages/mcp-fhir/tests -v# Integration tests (requires HAPI public server access)uv run pytest packages/mcp-fhir/tests -m integration

Architecture

Client (Claude / GPT-4o)    │  MCP protocol (stdio or SSE)    ▼mcp-fhir server (Python, anyio)    ├── fhir_read ──────────► FHIR R4 server (configurable)    ├── fhir_search ─────────► FHIR R4 server    └── validate_against_profile              │              ▼        HAPI validator sidecar (markiantorno/validator-wrapper)              │              ▼        LangFuse (optional observability)

License

Apache-2.0

來源:packages/mcp-fhir/README.md,提交 07fc507

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.1.1最新Sep 16, 2026

評分

已滿足適用檢查項的 40%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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

    請在儲存庫或註冊中心條目中宣告授權條款。