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:
- β 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
The MCP server currently supports a comprehensive set of 33 tools for managing various FHIR resources:
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.
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.
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.
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.
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.
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.
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.
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.
- Runtime: Node.js
- Language: TypeScript
- FHIR Server Interaction:
@medplum/core,@medplum/fhirtypes - LLM Integration: OpenAI API (specifically
gpt-4oin 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
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:
- Node.js (refer to
package.jsonfor 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)
- Node.js (refer to
-
Installation:
git clone https://github.com/rkirkendall/medplum-mcp.git cd medplum-mcp npm install -
Environment Variables: Create a
.envfile 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.tsFeatures:
- π£οΈ 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.
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:harnessIntegration tests use Jest and interact with a live Medplum instance (configured via .env).
To run all integration tests:
npx jest tests/integrationTo 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 neededThis project is licensed under the MIT License - see the LICENSE file for details.