Skip to main content
Glama
Medplum MCP Server

Medplum MCP Server

by rkirkendall

Medplum MCP Server

๐Ÿš€ Project Description

This project implements a complete Model Context Protocol (MCP) server designed to seamlessly interact with a Medplum FHIR server. The MCP server provides a standardized interface, enabling Large Language Models (LLMs) to perform Create, Read, Update, and Search (CRUDS) operations on various FHIR resources through a comprehensive suite of tools. This empowers users to manage healthcare data stored in Medplum using natural language commands through any MCP-compatible client (Claude Desktop, VS Code MCP extensions, etc.).

The server implements the full MCP protocol specification, providing 33 comprehensive FHIR resource management tools that can be discovered and executed by any MCP client. Users can intuitively manage patient information, practitioners, organizations, encounters, observations, and more by conversing with an LLM that leverages the MCP tools to execute requests against the FHIR server.

Related MCP server: Medplum MCP Server

โœจ Current Status

๐ŸŽ‰ MCP Server Implementation Complete! ๐ŸŽ‰

What's Implemented:

  • โœ… Core FHIR resource management tools (Patient, Practitioner, Organization, Encounter, Observation, Medication, etc.)

  • โœ… MCP Server Protocol Implementation - Full Model Context Protocol server with stdio transport

  • โœ… Comprehensive tool schemas for LLM interaction (33 FHIR tools)

  • โœ… Interactive Chat Harness - Full MCP client with natural language interface

  • โœ… Jest integration tests for all tools

  • โœ… Medplum FHIR server connectivity and authentication

  • โœ… MCP Inspector testing and validation

  • โœ… Claude Desktop integration configuration

Ready for Use:

  • ๐Ÿ”„ The MCP server is fully functional and ready for integration with MCP clients

  • โœ… All 33 FHIR tools are properly registered and working

  • ๐Ÿ”„ Server successfully authenticates with Medplum and executes FHIR operations

  • ๐Ÿ”„ Interactive chat harness available - Test all tools with natural language

  • ๐Ÿ”„ Tested with MCP Inspector - all tools discoverable and executable

  • ๐Ÿ”„ Claude Desktop configuration provided for immediate use

Current Capabilities:

  • Full CRUD operations on FHIR resources through natural language

  • Interactive chat interface for testing and development

  • Seamless integration with any MCP-compatible client (Claude Desktop, VS Code MCP extensions, etc.)

  • Comprehensive error handling and logging

  • Production-ready MCP protocol implementation

๐ŸŒŸ Features Implemented

The MCP server currently supports a comprehensive set of 33 tools for managing various FHIR resources:

๐Ÿ‘ฅ Patient Management (4 tools) - src/tools/patientUtils.ts

  • createPatient: Create new patient records with demographics, identifiers, and contact information.

  • getPatientById: Retrieve complete patient details by their unique ID.

  • updatePatient: Modify existing patient information including demographics and contact details.

  • searchPatients: Find patients based on name, birthdate, identifier, or other criteria.

๐Ÿ‘ฉโ€โš•๏ธ Practitioner Management (5 tools) - src/tools/practitionerUtils.ts

  • createPractitioner: Register new healthcare practitioners with their professional details.

  • getPractitionerById: Fetch complete practitioner details by their unique ID.

  • updatePractitioner: Update practitioner information including qualifications and contact details.

  • searchPractitionersByName: Search for practitioners using their first or last name.

  • searchPractitioners: Conduct advanced searches for practitioners based on multiple criteria.

๐Ÿฅ Organization Management (4 tools) - src/tools/organizationUtils.ts

  • createOrganization: Add new healthcare organizations (hospitals, clinics, departments).

  • getOrganizationById: Retrieve complete organization details by their unique ID.

  • updateOrganization: Update organization information including contact details and addresses.

  • searchOrganizations: Search for organizations by name, type, or other attributes.

๐Ÿฅ Encounter Management (4 tools) - src/tools/encounterUtils.ts

  • createEncounter: Create new patient encounters (visits, appointments, hospital stays).

  • getEncounterById: Retrieve complete encounter details by their unique ID.

  • updateEncounter: Update encounter information including status, class, and participants.

  • searchEncounters: Search for encounters by patient, practitioner, date, status, or class.

๐Ÿ”ฌ Observation Management (4 tools) - src/tools/observationUtils.ts

  • createObservation: Record new observations (lab results, vital signs, diagnostic findings).

  • getObservationById: Retrieve complete observation details by their unique ID.

  • updateObservation: Modify existing observations including values, status, and interpretations.

  • searchObservations: Search for observations by patient, code, date, or encounter.

๐Ÿ’Š Medication Request Management (4 tools) - src/tools/medicationRequestUtils.ts

  • createMedicationRequest: Create new medication requests (prescriptions) with dosage and instructions.

  • getMedicationRequestById: Retrieve complete medication request details by their unique ID.

  • updateMedicationRequest: Update prescription information including status, dosage, and instructions.

  • searchMedicationRequests: Search for medication requests by patient, medication, or prescriber.

๐Ÿ’‰ Medication Management (3 tools) - src/tools/medicationUtils.ts

  • createMedication: Create new medication resources with codes, names, and formulations.

  • getMedicationById: Retrieve complete medication details by their unique ID.

  • searchMedications: Search for medications by code, name, or ingredient.

๐Ÿ“‹ Episode of Care Management (4 tools) - src/tools/episodeOfCareUtils.ts

  • createEpisodeOfCare: Create new episodes of care for managing patient care over time.

  • getEpisodeOfCareById: Retrieve complete episode of care details by their unique ID.

  • updateEpisodeOfCare: Update episode information including status, period, and managing organization.

  • searchEpisodesOfCare: Search for episodes of care by patient, status, or managing organization.

๐Ÿ” General FHIR Operations (1 tool)

  • generalFhirSearch: Generic FHIR search with custom parameters for any resource type, enabling advanced queries across all FHIR resources.

Each tool is exposed to the LLM via a well-defined JSON schema and is callable through a dedicated test harness (src/llm-test-harness.ts), facilitating robust testing and integration.

๐Ÿ› ๏ธ Technology Stack

  • Runtime: Node.js

  • Language: TypeScript

  • FHIR Server Interaction: @medplum/core, @medplum/fhirtypes

  • LLM Integration: OpenAI API (specifically gpt-4o in the test harness)

  • Testing: Jest (for integration tests), Manual E2E via test harness

  • Linting & Formatting: ESLint, Prettier

  • Environment Management: dotenv

  • HTTP Client (for Medplum SDK): node-fetch

๐Ÿ“ Project Structure

medplum-mcp/
โ”œโ”€โ”€ src/                  # Source code
โ”‚   โ”œโ”€โ”€ config/           # Medplum client configuration (medplumClient.ts)
โ”‚   โ”œโ”€โ”€ tools/            # FHIR resource utility functions (patientUtils.ts, etc.)
โ”‚   โ”œโ”€โ”€ lib/              # Shared libraries (currently unused)
โ”‚   โ”œโ”€โ”€ index.ts          # Main application entry point
โ”‚   โ”œโ”€โ”€ llm-test-harness.ts # Script for testing LLM tool calling
โ”‚   โ””โ”€โ”€ test-connection.ts  # Script for basic Medplum connection test
โ”œโ”€โ”€ tests/                # Test suites
โ”‚   โ””โ”€โ”€ integration/      # Jest integration tests for tools
โ”œโ”€โ”€ .eslintrc.js
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .prettierrc.js
โ”œโ”€โ”€ .prettierignore
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md

โš™๏ธ Setup and Configuration

  1. Prerequisites:

    • Node.js (refer to package.json for engine specifics; LTS versions recommended)

    • A running Medplum server instance (e.g., local Dockerized instance at http://localhost:8103/)

    • Medplum client credentials (Client ID and Client Secret)

  2. Installation:

    git clone https://github.com/rkirkendall/medplum-mcp.git
    cd medplum-mcp
    npm install
  3. Environment Variables: Create a .env file in the project root with your specific Medplum server details and API keys:

    MEDPLUM_BASE_URL=http://your-medplum-server-url/
    MEDPLUM_CLIENT_ID=your_client_id
    MEDPLUM_CLIENT_SECRET=your_client_secret
    OPENAI_API_KEY=your_openai_api_key # Required for llm-test-harness.ts

๐Ÿš€ Usage

The most user-friendly way to test your MCP server is through the interactive chat interface:

# Build and run the chat harness
npm run chat

# Or in development mode
npx ts-node src/llm-test-harness.ts

Features:

  • ๐Ÿ—ฃ๏ธ Natural language interaction with all 33 FHIR tools

  • ๐Ÿ”ง Automatic tool discovery and execution

  • ๐Ÿ“‹ Built-in help and examples

  • ๐Ÿ”„ Conversation context maintenance

  • โšก Real-time tool execution and results

Example Session:

๐Ÿฅ You: Create a new patient Jane Smith born 1985-03-20
๐Ÿค– Assistant: I'll create a new patient record for Jane Smith...

๐Ÿฅ You: Find all doctors named Stevens
๐Ÿค– Assistant: I found 2 practitioners with the name Stevens...

See CHAT_HARNESS_USAGE.md for detailed usage instructions and IMPLEMENTATION_PLAN.md for development details.

โ–ถ๏ธ Running the MCP Server Directly

npm start # Runs the MCP server with stdio transport
npm run dev # Development mode with live reloading

๐Ÿงช Alternative Testing Methods

# MCP Inspector (web-based tool testing)
npx @modelcontextprotocol/inspector node dist/index.js

# Legacy OpenAI integration (deprecated)
npm run test:harness

โœ… Testing

๐Ÿ”— Integration Tests

Integration tests use Jest and interact with a live Medplum instance (configured via .env).

To run all integration tests:

npx jest tests/integration

To run specific integration test files:

npx jest tests/integration/patient.integration.test.ts
npx jest tests/integration/practitioner.integration.test.ts
npx jest tests/integration/organization.integration.test.ts
# Add other specific test files as needed

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Available Tools

37 tools
createConditionC

Creates a new condition or diagnosis for a patient. Requires a patient ID and a condition code.

Inputs: code (required), patientId (required), clinicalStatus, onsetString, +1 more.

createEncounterC

Creates a new encounter (patient visit). Requires patient ID and status.

Inputs: classCode (required), patientId (required), status (required), organizationId, +1 more.

createEpisodeOfCareC

Creates a new episode of care for a patient. Requires patient ID and status.

Inputs: patientId (required), status (required), managingOrganizationId.

createMedicationC

Creates a new medication resource. Requires medication code or identifier.

Inputs: code (required), display, form.

createMedicationRequestC

Creates a new medication request (prescription). Requires patient ID, medication reference, and prescriber.

Inputs: intent (required), medicationReference (required), patientId (required), practitionerId (required), +1 more.

createObservationB

Creates a new observation (lab result, vital sign, etc.). Requires patient ID and code.

Inputs: code (required), patientId (required), status (required), encounterId, +2 more.

createOrganizationC

Creates a new organization (e.g., hospital, clinic). Requires organization name.

Inputs: name (required), alias.

createPatientB

Creates a new patient resource. Requires first name, last name, and birth date.

Inputs: birthDate (required), firstName (required), lastName (required), gender.

createPractitionerC

Creates a new medical practitioner. Requires given name and family name.

Inputs: familyName (required), givenName (required).

generalFhirSearchC

Performs a generic FHIR search operation on any resource type with custom query parameters.

Inputs: queryParams (required), resourceType (required).

getConditionByIdB

Retrieves a condition resource by its unique ID.

Inputs: conditionId (required).

getEncounterByIdB

Retrieves an encounter by its unique ID.

Inputs: encounterId (required).

getEpisodeOfCareByIdB

Retrieves an episode of care by its unique ID.

Inputs: episodeOfCareId (required).

getMedicationByIdC

Retrieves a medication by its unique ID.

Inputs: medicationId (required).

getMedicationRequestByIdC

Retrieves a medication request by its unique ID.

Inputs: medicationRequestId (required).

getObservationByIdC

Retrieves an observation by its unique ID.

Inputs: observationId (required).

getOrganizationByIdC

Retrieves an organization by its unique ID.

Inputs: organizationId (required).

getPatientByIdB

Retrieves a patient resource by their unique ID.

Inputs: patientId (required).

getPractitionerByIdC

Retrieves a practitioner resource by their unique ID.

Inputs: practitionerId (required).

searchConditionsB

Searches for conditions based on patient and other criteria. Requires a patient ID.

Inputs: patientId (required), category, clinical-status, code.

searchEncountersC

Searches for encounters based on criteria like patient ID or status.

Inputs: patientId, practitionerId, status.

searchEpisodesOfCareB

Searches for episodes of care based on criteria like patient ID or status.

Inputs: managingOrganizationId, patientId, status.

searchMedicationRequestsC

Searches for medication requests based on criteria like patient ID or medication.

Inputs: medicationReference, patientId, practitionerId, status.

searchMedicationsB

Searches for medications based on criteria like code or name.

Inputs: code, form, name.

searchObservationsC

Searches for observations based on criteria like patient ID or code.

Inputs: code, encounterId, patientId, status.

searchOrganizationsB

Searches for organizations based on criteria like name or address. Provide at least one criterion.

Inputs: address, name.

searchPatientsC

Searches for patients based on criteria like name or birth date.

Inputs: birthdate, family, gender, given.

searchPractitionersC

Searches for practitioners based on various criteria like name, specialty, or identifier.

Inputs: family, given, identifier, name, +1 more.

searchPractitionersByNameB

Searches for medical practitioners based on their given name, family name, or a general name string.

Inputs: familyName, givenName, name.

updateConditionB

Updates an existing condition. Requires the condition ID and at least one field to update.

Inputs: conditionId (required), clinicalStatus, onsetString, verificationStatus.

updateEncounterC

Updates an existing encounter. Requires the encounter ID and the fields to update.

Inputs: encounterId (required), status.

updateEpisodeOfCareC

Updates an existing episode of care. Requires the episode ID and fields to update.

Inputs: episodeOfCareId (required), status.

updateMedicationRequestC

Updates an existing medication request. Requires the medication request ID and fields to update.

Inputs: medicationRequestId (required), status.

updateObservationC

Updates an existing observation. Requires the observation ID and the fields to update.

Inputs: observationId (required), status, valueQuantity, valueString.

updateOrganizationC

Updates an existing organization. Requires the organization ID and the fields to update.

Inputs: organizationId (required), alias, name.

updatePatientB

Updates an existing patient's information. Requires the patient's ID and the fields to update.

Inputs: patientId (required), birthDate, firstName, gender, +1 more.

updatePractitionerC

Updates an existing practitioner's information. Requires the practitioner's ID and the fields to update.

Inputs: practitionerId (required), active.

Tool Schema Changelog

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

Loading tool schema changelogโ€ฆ

    TDQS

    B3.4/5.0

    Scored across 37 tools

    Disambiguation5/5

    Every tool has a clearly distinct purpose with no ambiguity. Each tool targets a specific FHIR resource type (e.g., Patient, Condition, Observation) combined with a specific operation (create, get, search, update), making it easy for an agent to select the correct tool. The descriptions reinforce this clarity by specifying required parameters and use cases.

    Naming Consistency5/5

    Tool names follow a highly consistent verb_noun pattern throughout, such as createPatient, getPatientById, searchPatients, updatePatient. This pattern is applied uniformly across all 37 tools, with no deviations in style or convention, making the set predictable and easy to navigate.

    Tool Count3/5

    With 37 tools, the count feels heavy for a typical MCP server, bordering on excessive. While the tools cover multiple FHIR resources comprehensively, such a large number might overwhelm agents or lead to inefficiencies in tool selection, despite the clear organization. A more streamlined set could improve usability without sacrificing functionality.

    Completeness5/5

    The tool surface is complete for the FHIR domain, offering full CRUD/lifecycle coverage (create, get, search, update) for key resources like Patient, Condition, Observation, and others. There are no obvious gaps; agents can perform all essential operations without dead ends, supported by the generalFhirSearch tool for custom queries.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that enables querying FHIR healthcare data using natural language, allowing doctors to retrieve patient information, medications, observations, and other healthcare records.
      1
      -
    • F
      license
      Not graded
      quality
      F
      maintenance
      Enables interaction with Medplum's FHIR data through the Model Context Protocol, allowing LLMs to access and manage healthcare data.
      5
      -
    • A
      license
      A
      quality
      D
      maintenance
      MCP server for FHIR interoperability, enabling natural language querying and manipulation of clinical data with full CRUD operations, semantic search, and RAG capabilities.
      13
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP-compatible clients and LLM agents to query and manipulate FHIR-compliant clinical data through natural-language prompts, including CRUD operations, document ingestion, semantic search, and terminology lookup.
      -