fhir-mcp-oauth2-demo
Integrates with Keycloak as the OAuth2 authorization server, obtaining client-credentials tokens and validating JWTs against Keycloak's JWKS while enforcing SMART-style scopes for FHIR requests.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
FHIR + MCP: OAuth2 Client Credentials and Scope Enforcement
A small, runnable demo of how an AI agent's MCP server gets a token for a FHIR server, and how the token (not the prompt) limits what the agent can read.

Three containers: Keycloak (authorization server), HAPI FHIR, and a small
Python gateway that validates JWTs against Keycloak's JWKS and checks
SMART-style system/ scopes.
Prerequisites
Docker and Docker Compose
Python 3.12+
Related MCP server: Secure Clinical LLM Access via MCP
Run
# 1. Python dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 2. Start the stack and wait for Keycloak to be healthy (~30-60s)
docker compose up -d
docker compose ps # keycloak should show "healthy"
# 3. Seed HAPI with synthetic data (direct to HAPI on :8084, no auth)
python seed.py
# 4. Run the three cases
python demo.pyWhat the demo shows
Valid token: client credentials grant with
system-Observation.rsscope, Observation search returns 200.Wrong scope: the same client searches Patients, the gateway returns 403.
Token near expiry: the token lives 60s;
TokenClientrefreshes it inside a 30s cache margin, before it expires, and the next call returns 200.
demo.py drives TokenClient and the gateway directly. mcp_server.py
exposes the same calls as an MCP tool (search_observations) over STDIO.
Scope naming
Keycloak does not allow / in client scope names. The demo uses
system-Observation.rs (dash) in Keycloak. The gateway normalizes this to
system/Observation.rs when checking. A SMART-native FHIR server would use
the canonical / format directly.
Ports
Service | Port | Purpose |
Gateway | 8083 | FHIR requests (scope-enforced) |
HAPI | 8084 | Direct FHIR (no auth, for seed) |
Keycloak | 8085 | Token endpoint, JWKS (admin/admin) |
Credentials are demo-only
The client secret demo-secret-not-for-production and the Keycloak
admin/admin login exist only for this local stack. All ports bind to
127.0.0.1. Never reuse these values, and in a real deployment load
credentials from the environment or a secret manager.
Recording
recording/record-video.sh records a live run with asciinema and renders a
GIF with agg. See recording/README.md.
Related
LangCare FHIR MCP server, generic OAuth2 client credentials: PR #10 (under review)
Cleanup
docker compose down -vLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
The Remote MCP server acts as a standardized bridge between LLM applications (like Claude, ChatGPT, and Cursor) and external services, enabling AI agents to access external tools and resources. Its primary capability is providing a centralized search tool to discover other MCP servers and their respective tools. Unlike local implementations, it runs remotely with OAuth authentication and permission controls for security.
Find, vet, and run MCP tools through a secure audited gateway with prompt-injection risk scoring
One OAuth connector for your team's remote MCP servers, with Tool Packs, guardrails and logs.
Query, browse, and automate OmegaAI workspaces from any MCP client. Streamable HTTP with OAuth 2.0.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI applications to query and retrieve healthcare data (patients, conditions, observations, medications) from a public FHIR R4 server via MCP tools.MIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables LLMs to securely query synthetic clinical data through validated, scoped tools (patient summaries, conditions, medications, lab trends, encounters) while maintaining audit logs and access controls.-
- AlicenseAqualityCmaintenanceEnables MCP clients to search FHIR R4 patients and observations, access patient data as resources, and generate clinical summaries through prompts, using a public HAPI FHIR sandbox.2MIT
- FlicenseNot gradedqualityAmaintenanceEnables LLM-based agents and MCP-compatible clients to query and manipulate clinical data on a FHIR-compliant backend through CRUD resource tools, document ingestion, semantic search, and terminology lookup.-