
Medplum
STDIOComplete MCP server for Medplum FHIR healthcare data management with natural language interface
Complete MCP server for Medplum FHIR healthcare data management with natural language interface
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.
🎉 MCP Server Implementation Complete! 🎉
What's Implemented:
Ready for Use:
Current Capabilities:
The MCP server currently supports a comprehensive set of 33 tools for managing various FHIR resources:
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.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.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.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.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.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.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.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.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.
@medplum/core
, @medplum/fhirtypes
gpt-4o
in the test harness)dotenv
node-fetch
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
Prerequisites:
package.json
for engine specifics; LTS versions recommended)http://localhost:8103/
)Installation:
git clone https://github.com/rkirkendall/medplum-mcp.git cd medplum-mcp npm install
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
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:
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.
npm start # Runs the MCP server with stdio transport npm run dev # Development mode with live reloading
# MCP Inspector (web-based tool testing) npx @modelcontextprotocol/inspector node dist/index.js # Legacy OpenAI integration (deprecated) npm run test:harness
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
This project is licensed under the MIT License - see the LICENSE file for details.