Skip to main content
Glama
fhir-mcp-server
by krlz-dev

fhir-mcp-server

A minimal MCP server over FHIR, built with the official Python SDK v2 (mcp 2.1.1+).

It exposes all three MCP primitives — tool, resource and prompt — against a HAPI FHIR R4 server, and ships with an in-memory test suite.

The interesting problem with agent tooling isn't getting it to run once. It's proving it behaves. So the tests are the point of this repo as much as the server is.

Why v2 matters

Most MCP tutorials and Stack Overflow answers still show the v1 API:

from mcp.server.fastmcp import FastMCP   # v1 — outdated
from mcp.server import MCPServer         # v2 — current

SDK v2 was a major rework released alongside the 2026-07-28 spec revision. Two things bite if you arrive from v1:

  • Result models use snake_case: tool.input_schema, not tool.inputSchema; result.resource_templates, not result.resourceTemplates.

  • FastMCP is gone from the official SDK. (Note: fastmcp on PyPI is a different, third-party package — don't confuse the two.)

Related MCP server: FHIR MCP Server

Requirements

Python 3.10+ and uv.

Install

uv venv .venv
source .venv/bin/activate
uv pip install "mcp[cli]" httpx
uv pip install pytest inline-snapshot   # tests only

Run

uv run mcp dev server.py     # MCP Inspector — try the tools in a form
uv run mcp run server.py     # stdio — for a real host

To connect it to a host (Claude Code, Claude Desktop, an IDE):

uv run --with "mcp[cli]" mcp run /absolute/path/to/server.py

The host launches the server as a subprocess and speaks over stdin/stdout. No port, nothing listening on the network.

Test

pytest -v
test_tools_registrados PASSED
test_prompt_registrado PASSED
test_resource_template PASSED
test_search_patients_contra_servidor_real PASSED

Client(mcp) connects to the server object in memory — no subprocess, no port, no wire. Same idea as FastAPI's TestClient. The last test is an integration test and hits the public sandbox, so it needs network.

What it exposes

Primitive

Name

Who triggers it

Tool

search_patients(family_name, limit=5)

the model

Tool

get_observations(patient_id, limit=10)

the model

Resource

fhir://patient/{patient_id}

the application

Prompt

resumen_clinico(patient_id)

the user

The three primitives differ by who decides to use them, not by what they do. A tool is a POST (acts, has side effects), a resource is a GET (loads data, changes nothing), a prompt is a slash command.

You don't write JSON Schema — the SDK generates it from type hints. A parameter with a default stops being required. It's just Python.

Data

Points at https://hapi.fhir.org/baseR4, the public HAPI FHIR test sandbox.

⚠️ Never put real clinical data in a public repo. Synthetic or sandbox data, always.

License

MIT


If this saved you an afternoon, a coffee helps ☕

Available Tools

2 tools
get_observationsA

Trae las observaciones clínicas de un paciente por su ID FHIR.

Inputs: patient_id (required), limit. Returns: result

search_patientsB

Busca pacientes por apellido en el servidor FHIR.

Inputs: family_name (required), limit. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 2 tools

    Disambiguation5/5

    The two tools have clearly distinct purposes: one searches for patients by last name, the other retrieves clinical observations for a specific patient ID. There is no meaningful overlap or ambiguity between them.

    Naming Consistency5/5

    Both tool names follow the same verb_noun snake_case pattern: search_patients and get_observations. The naming is consistent, predictable, and easy for an agent to navigate.

    Tool Count3/5

    With only two tools, the server feels thin for a FHIR implementation, which typically supports a much broader range of resources and operations. However, the count is not egregiously low and could be acceptable for a narrowly scoped use case.

    Completeness2/5

    The server covers only patient search and observation retrieval, missing foundational FHIR operations like getting a patient by ID, creating or updating resources, and searching observations by clinical criteria. Agents would likely encounter dead ends when trying to perform common FHIR workflows.

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables LLM-based agents and MCP-compatible clients to perform full CRUD operations on FHIR resources and query or manipulate clinical data using natural-language prompts. It also supports document ingestion, semantic search, LOINC terminology lookup, and OAuth2 authentication for FHIR APIs.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables MCP-compatible clients and LLM agents to perform full CRUD operations on FHIR resources, query and manipulate clinical data through natural-language prompts, and use document ingestion, semantic search, and terminology lookup against a FHIR backend.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables LLM-based agents and MCP-compatible clients to interact with a FHIR-compliant backend for full CRUD operations on FHIR resources, document ingestion, semantic search, LOINC terminology lookup, and synthetic data generation through natural-language prompts.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables MCP-compatible clients and LLM-based agents to interact with FHIR-compliant healthcare backends via natural-language prompts, supporting full CRUD operations on FHIR resources, document ingestion, semantic search, and LOINC terminology lookup.
      -