FHIR MCP Server is a Model Context Protocol (MCP) server that provides seamless integration with FHIR APIs. It is aimed at developers, integrators, and healthcare innovators, serving as a bridge between modern AI/LLM tools and healthcare data, facilitating the search, retrieval, and analysis of clinical information.
Purpose: The main purpose of this project is to expose any FHIR server or API as an MCP server, enabling AI/LLM tools to interact with FHIR healthcare data through the MCP protocol.
Key capabilities:
- MCP-compatible transport: Serve FHIR via stdio, SSE, or streamable HTTP.
- SMART-on-FHIR-based authentication support: Enables secure authentication with FHIR servers and clients.
- Response filtering using FHIRPath: Use custom FHIRPath expressions to filter resources and bundles returned by read and search operations, so as to retrieve only the fields required for the task and reduce payload size.
- Tool integration: Can be integrated with any MCP client, such as VS Code, Claude Desktop, and MCP Inspector.
- Provides the get_capabilities tool: Retrieves metadata for a specified FHIR resource type, including its supported search parameters and custom operations. The parameter type is the FHIR resource type name (for example "Patient", "Observation", "Encounter").
- Provides the search tool: Performs the standard FHIR search interaction for a given resource type, returning a bundle or list of matching resources. The parameter type is the FHIR resource type name (for example "MedicationRequest", "Condition", "Pro... (truncated here in the material).
Usage: Can be installed via the PyPI package, source code, or Docker. Install the PyPI package and run the server: uvx fhir-mcp-server. Install from source: clone the repository, create a virtual environment and install dependencies (uv venv, source .venv/bin/activate, uv pip sync requirements.txt, or use pip install -r requirements.txt), copy .env.example to .env and customize it, run uv run fhir-mcp-server. Install using Docker: build the image docker build -t fhir-mcp-server . or pull the image docker pull wso2/fhir-mcp-server:latest, copy and edit the environment file, run docker run --env-file .env -p 8000:8000 fhir-mcp-server. Use Docker Compose with a HAPI FHIR server: run docker-compose up -d, which will start a PostgreSQL database, a HAPI FHIR server (listening on http://localhost:8080)和 FHIR MCP server (listening on http://localhost:8000,FHIR_SERVER_BASE_URL set to http://hapi-r4-postgresql:8080/fhir)。
Configuration: FHIR_SERVER_BASE_URL must be set. Authorization is enabled by default; to enable authorization, set FHIR_SERVER_BASE_URL, FHIR_SERVER_CLIENT_ID, FHIR_SERVER_CLIENT_SECRET, and FHIR_SERVER_SCOPES. To disable authorization, set FHIR_SERVER_DISABLE_AUTHORIZATION to True. By default, the MCP server runs on http://localhost:8000,可通过 FHIR_MCP_HOST and FHIR_MCP_PORT customize the host and port. They can be set by exporting environment variables or by creating a .env file (see .env.example).
CLI options: --transport specifies the transport protocol, accepting stdio, sse, streamable-http, defaulting to streamable-http; --log-level sets the log verbosity, accepting DEBUG, INFO, WARN, ERROR (case-insensitive), defaulting to INFO; --help displays help information.
Environment variables: FHIR_MCP_HOST, FHIR_MCP_PORT, FHIR_MCP_SERVER_URL, FHIR_MCP_REQUEST_TIMEOUT (default 30 seconds), FHIR_SERVER_CLIENT_ID, FHIR_SERVER_DISABLE_AUTHORIZATION, FHIR_SERVER_CLIENT_SECRET, FHIR_SERVER_BASE_URL, FHIR_SERVER_SCOPES (a space-separated list of OAuth2 scopes; adding fhirUser openid enables the get_user tool to retrieve user context), FHIR_SERVER_ACCESS_TOKEN (used to authenticate requests; once set, it bypasses the OAuth2 authorization flow and uses this token directly; it applies only to local stdio mode deployments and should not be used when the MCP server is exposed over a network or the public internet).
Integrating MCP clients: you can add a JSON block to the MCP configuration file in VS Code (> V1.104); you can configure a local MCP server in Claude Desktop settings, with the configuration file located at macOS: ~/Library/Application Support/Claude/claude_desktop_config.json, Windows: %APPDATA%\Claude\claude_desktop_config.json; you can use MCP Inspector by running npx -y @modelcontextprotocol/inspector, and in the interface select the transport type (Streamable HTTP URL is http://localhost:8000/mcp;STDIO the parameters are --directory /path/to/fhir-mcp-server run fhir-mcp-server --transport stdio; the SSE URL is http://localhost:8000/sse)。
Use cases: for developers, integrators, and healthcare innovators, it can be used to search, retrieve, create, update, and analyze clinical data, and is suitable for scenarios such as connecting to public FHIR servers (no authorization flow required) or the Epic EHR ecosystem (demonstrating the full OAuth 2.0 Authorization Code Grant flow).
Limitations: when running the MCP server locally with Docker or Docker Compose, authorization should be disabled by setting FHIR_SERVER_DISABLE_AUTHORIZATION=True; this issue will be fixed in a future release. FHIR_SERVER_ACCESS_TOKEN applies only to local stdio mode deployments and should not be used when the MCP server is exposed over a network or the public internet. If the two scopes fhirUser openid are not configured, the get_user tool will return empty results.