Skip to main content
Glama

Medplum MCP Server

by rkirkendall
CHAT_HARNESS_USAGE.mdβ€’6 kB
# MCP Chat Test Harness Usage Guide ## Overview The MCP Chat Test Harness provides an interactive command-line interface to test your Medplum MCP server. It acts as an MCP client that connects to your server and allows you to interact with your 22 FHIR tools using natural language. ## Prerequisites 1. **Environment Setup**: Ensure your `.env` file contains: ``` MEDPLUM_BASE_URL=http://localhost:8103/ MEDPLUM_CLIENT_ID=your_client_id MEDPLUM_CLIENT_SECRET=your_client_secret OPENAI_API_KEY=your_openai_api_key ``` 2. **Medplum Server**: Have your Medplum server running (e.g., at `http://localhost:8103/`) 3. **Build the Project**: ```bash npm run build ``` ## Running the Chat Harness ### Option 1: Using the npm script (recommended) ```bash npm run chat ``` ### Option 2: Direct execution ```bash node dist/llm-test-harness.js ``` ### Option 3: Development mode ```bash npx ts-node src/llm-test-harness.ts ``` ## How It Works 1. **MCP Client Connection**: The harness starts your MCP server and connects to it as a client 2. **Tool Discovery**: It automatically discovers all 22 available FHIR tools 3. **Natural Language Processing**: Uses OpenAI GPT-4o to interpret your requests 4. **Tool Execution**: Calls the appropriate MCP tools and displays results 5. **Conversation Flow**: Maintains context across the conversation ## Available Commands ### Chat Commands - **Natural language queries**: Ask questions about healthcare data management - **`help`**: Show detailed examples of what you can ask - **`tools`**: Display all available MCP tools - **`clear`**: Clear conversation history - **`quit`** or **`exit`**: End the chat session ### Example Queries #### Patient Management ``` πŸ₯ You: Create a new patient Jane Smith born 1985-03-20 πŸ₯ You: Find all patients with last name Johnson πŸ₯ You: Get patient details for ID abc123 πŸ₯ You: Update patient ID xyz789 to mark as inactive ``` #### Practitioner Management ``` πŸ₯ You: Find all doctors named Stevens πŸ₯ You: Create a new practitioner Dr. Emily Wilson πŸ₯ You: Search for cardiologists πŸ₯ You: Get practitioner details for ID prac456 ``` #### Organization Management ``` πŸ₯ You: Create a new hospital called City General πŸ₯ You: Find organizations in downtown area πŸ₯ You: Get organization details for ID org789 ``` #### Clinical Data ``` πŸ₯ You: Create a blood pressure observation for patient ID pat123 πŸ₯ You: Find all lab results for patient ID pat456 πŸ₯ You: Create a new encounter for patient visit πŸ₯ You: Search for diabetes-related observations ``` #### Medications ``` πŸ₯ You: Create a new medication for hypertension πŸ₯ You: Find all medications containing aspirin πŸ₯ You: Create a prescription for patient ID pat789 ``` #### General Searches ``` πŸ₯ You: Search for all encounters this month πŸ₯ You: Find all active episodes of care πŸ₯ You: Search FHIR resources of type Condition ``` ## What You'll See ### Successful Tool Execution ``` πŸ€– Processing: "Find all patients named Smith" πŸ”§ LLM wants to call 1 tool(s): πŸ“ž Calling searchPatients with args: { "family": "Smith" } βœ… Result: { "content": [ { "resourceType": "Patient", "id": "patient-123", "name": [ { "family": "Smith", "given": ["John"] } ] } ] } πŸ€– Assistant: I found 1 patient with the last name Smith. Here are the details: **Patient ID:** patient-123 **Name:** John Smith ``` ### Error Handling ``` πŸ”§ LLM wants to call 1 tool(s): πŸ“ž Calling getPatientById with args: { "patientId": "invalid-id" } ❌ Error: Patient not found πŸ€– Assistant: I couldn't find a patient with ID "invalid-id". Please check the ID and try again. ``` ## Troubleshooting ### Common Issues 1. **Connection Failed**: - Ensure Medplum server is running - Check your `.env` file configuration - Verify client credentials 2. **OpenAI API Errors**: - Verify `OPENAI_API_KEY` is set correctly - Check your OpenAI account has sufficient credits 3. **Tool Execution Errors**: - Review the tool arguments being passed - Check if required FHIR resources exist - Verify proper resource relationships ### Debug Mode Add `console.log` statements in the harness or use the MCP Inspector for detailed debugging: ```bash npx @modelcontextprotocol/inspector node dist/index.js ``` ## Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Chat Harness │───▢│ OpenAI API │───▢│ Tool Selection β”‚ β”‚ (MCP Client) β”‚ β”‚ (GPT-4o) β”‚ β”‚ & Execution β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ MCP Server │◀───────────────────────────│ FHIR Tools β”‚ β”‚ (Your Server) β”‚ β”‚ (22 tools) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Medplum FHIR β”‚ β”‚ Server β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` This harness provides a complete testing environment for your MCP server, allowing you to verify that all tools work correctly and can be accessed through natural language interactions.

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rkirkendall/medplum-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server