FHIR MCP server

Integrates FHIR data into workflows, enabling seamless access and search of healthcare resources for dynamic querying and analysis.
Back to servers
Setup instructions
Provider
Flexpa
Release date
Jan 08, 2025
Language
TypeScript
Stats
43 stars

This MCP server implementation connects to FHIR servers, providing a bridge between LLMs and healthcare data. It enables access to FHIR resources through a standardized interface, allowing AI assistants to search and retrieve healthcare information in a structured way.

Installation

Prerequisites

Before installing the MCP FHIR server, ensure you have:

  • Node.js installed
  • A FHIR server with a valid access token
  • Claude Desktop (if using with Claude)

Setup

  1. Install the package using npm:
npm install @flexpa/mcp-fhir
  1. Configure the server by setting the following environment variables:
FHIR_BASE_URL="https://your-fhir-server.com"
FHIR_ACCESS_TOKEN="your-access-token"

Claude Desktop Integration

To use the MCP FHIR server with Claude Desktop:

  1. Create or modify the Claude Desktop config file:

MacOS:

nano ~/Library/Application\ Support/Claude/claude_desktop_config.json

Windows:

notepad %APPDATA%/Claude/claude_desktop_config.json
  1. Add the server configuration:
{
  "mcpServers": {
    "fhir": {
      "command": "/path/to/@flexpa/mcp-fhir/build/index.js"
    },
    "env": {
      "FHIR_BASE_URL": "<FHIR_BASE_URL>",
      "FHIR_ACCESS_TOKEN": "<FHIR_ACCESS_TOKEN>"
    }
  }
}
  1. Restart Claude Desktop for the changes to take effect.

Usage

Accessing FHIR Resources

The server provides access to FHIR resources through URI-based identifiers. Resources are addressed using the fhir:// protocol.

To retrieve a specific FHIR resource, use the read_fhir tool with a URI in the format:

fhir://{resourceType}/{id}

For example:

  • fhir://Patient/123
  • fhir://Observation/456
  • fhir://MedicationRequest/789

Searching FHIR Resources

The server supports searching FHIR resources using the standard FHIR search parameters. Use the search_fhir tool with:

  • resourceType: The type of FHIR resource to search for
  • searchParams: A map of search parameters corresponding to FHIR search parameters

Example search parameters:

  • Patients with a specific name: { "name": "Smith" }
  • Observations for a specific patient: { "patient": "Patient/123", "code": "8480-6" }
  • Medication requests within a date range: { "patient": "Patient/123", "date": "ge2023-01-01" }

Available Tools

search_fhir

Searches for FHIR resources based on resource type and search parameters.

Parameters:

  • resourceType: The FHIR resource type to search
  • searchParams: Object containing search parameters

Returns FHIR search results in JSON format.

read_fhir

Retrieves a specific FHIR resource by URI.

Parameters:

  • uri: The FHIR resource URI (e.g., fhir://Patient/123)

Returns the complete FHIR resource in JSON format.

Debugging

The MCP Inspector can help debug communication between Claude and the MCP server:

npm run inspector

This will provide a URL to access debugging tools in your browser, allowing you to monitor the requests and responses between Claude and the MCP FHIR server.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "fhir" '{"command":"/path/to/@flexpa/mcp-fhir/build/index.js","env":{"FHIR_BASE_URL":"<FHIR_BASE_URL>","FHIR_ACCESS_TOKEN":"<FHIR_ACCESS_TOKEN>"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "fhir": {
            "command": "/path/to/@flexpa/mcp-fhir/build/index.js",
            "env": {
                "FHIR_BASE_URL": "<FHIR_BASE_URL>",
                "FHIR_ACCESS_TOKEN": "<FHIR_ACCESS_TOKEN>"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "fhir": {
            "command": "/path/to/@flexpa/mcp-fhir/build/index.js",
            "env": {
                "FHIR_BASE_URL": "<FHIR_BASE_URL>",
                "FHIR_ACCESS_TOKEN": "<FHIR_ACCESS_TOKEN>"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later