Inspiration
Medication errors cause over 250,000 deaths annually in the U.S. alone. At care transitions (admission, transfer, discharge), 50% of patients experience at least one medication discrepancy. Omitted home anticoagulants, missed penicillin-cephalosporin cross-reactivity, and supratherapeutic dosing in renal impairment occur daily despite EHR safety alerts.
Existing clinical decision support tools suffer from three fatal flaws: (1) reliance on slow, rate-limited external APIs, (2) incomplete cross-sensitivity coverage (no API provides HIT or SJS risk patterns), and (3) black-box algorithms clinicians cannot audit.
We built six MCP clinical safety tools that combine FHIR data with curated local knowledge bases extracted directly from FDA labels, KDIGO guidelines, and pediatric formularies. The result: sub‑millisecond response, zero external dependencies for core safety, and fully auditable clinical logic.
What It Does
| Tool | Function | Clinical Impact |
|---|---|---|
| GetPatientMedications | Merges MedicationRequest, MedicationStatement, and MedicationDispense from FHIR into a unified medication list | Prevents missed medications at care transitions |
| Medication Reconciliation | Compares home vs hospital orders; flags omissions, dose/frequency/route changes, duplications | Reduces hospital readmissions by catching discharge discrepancies |
| Allergy Cross‑Checker | Screens orders against 14+ cross‑sensitivity patterns (PCN→cephalosporin, sulfa class, HIT, SJS/TEN risk, opioid pseudoallergy, amide‑ester separation, radiocontrast, vancomycin Red Man Syndrome) | Prevents anaphylaxis and severe cutaneous reactions |
| Dose Range Checker | Evaluates doses against age (pediatric/geriatric/neonatal), weight (mg/kg), and renal function (eGFR) limits | Prevents toxicity and adverse drug events |
| CheckMedicationInteractions | Drug‑drug, drug‑allergy, and drug‑condition checks with severity classification | Catches contraindicated combinations before administration |
| CheckMedicationLabSafety | Evaluates eGFR (renal dosing), ALT/AST (hepatotoxicity), electrolytes (K⁺, Na⁺, Mg²⁺, Ca²⁺), and INR (coagulation) | Prevents inappropriate dosing in organ dysfunction |
How We Built It
Architecture
- Language: Python 3.13 (Alpine Linux container)
- Framework: FastAPI, Uvicorn, FastMCP (stateless HTTP)
- FHIR Integration: Custom
FhirClientwith JWT parsing; context viax-fhir-server-url,x-fhir-access-token,x-patient-idheaders - Deployment: Docker Compose, port 5001
Curated Local Knowledge Bases (No External API Dependency)
We extracted and structured clinical rules from primary sources – not from APIs. This gives us complete control, auditability, and sub‑millisecond latency.
| Knowledge Base | Size | Sources | Clinical Use |
|---|---|---|---|
| Renal Dosing | 40+ drugs with eGFR cutoffs | FDA labels, KDIGO | Metformin, gabapentin, vancomycin, gentamicin, lithium, acyclovir, methotrexate |
| Hepatic Safety | 10+ drugs with hepatotoxicity thresholds | FDA DILIrank | Acetaminophen, isoniazid, valproate, methotrexate, amiodarone |
| Cross‑Sensitivity | 14+ patterns | Peer‑reviewed literature | PCN→cephalosporin (1-10%), HIT cross‑reactivity (UFH↔LMWH 90%), aromatic anticonvulsant SJS risk (HLA‑B*1502) |
| Dose Ranges | 30+ drugs with adult/pediatric/geriatric/neonatal limits | FDA labeling, Lexicomp, Harriet Lane | Acetaminophen (pediatric 15 mg/kg/dose max), ibuprofen (40 mg/kg/day), morphine (renal adjustment) |
| Electrolyte Safety | Full electrolyte panel with medication warnings | Clinical guidelines | ACEi/ARB→hyperkalemia, diuretics→hypokalemia, PPIs→hypomagnesemia |
| Coagulation Safety | INR targets, aPTT, anti‑Xa | ACCP guidelines | Warfarin (INR 2-3), heparin (aPTT 1.5-2.5x), enoxaparin (anti‑Xa 0.5-1.0) |
External APIs (Fallback Only)
- RxNorm – drug name → RxCUI standardization (cached 24h)
- OpenFDA – drug label text for interactions (used only if local rules insufficient)
FHIR Resource Merging Logic
We implemented intelligent merging across three resource types:
- MedicationRequest – prescribed orders (source of truth)
- MedicationStatement – patient‑reported home meds
- MedicationDispense – pharmacy dispensing records
Deduplication uses normalized name matching with generic‑brand mapping (e.g., "lisinopril" ↔ "Prinivil").
JWT Context Auto‑Population
The server extracts patient ID from JWT claims automatically – no manual patient ID entry required by the AI agent.
Challenges We Ran Into
| Challenge | Our Solution |
|---|---|
| No API provides renal dosing tables | Manually extracted eGFR cutoffs for 40+ drugs from FDA labels. Example: gabapentin requires 50% dose reduction at eGFR 30-60, 75% at 15-30, 92% at <15 |
| No API provides cross‑sensitivity patterns | Curated 14+ patterns from literature. Example: aromatic anticonvulsants (carbamazepine, phenytoin, lamotrigine) share HLA‑B*1502‑mediated SJS/TEN risk – no API captures this |
| No API provides pediatric weight‑based dosing | Built mg/kg/day engine using Harriet Lane Handbook standards |
| FHIR medication name extraction is inconsistent | Built parsers handling medicationCodeableConcept.text, medicationCodeableConcept.coding.display, medicationReference.display, code.text, and medication.display across three resource types |
| Frequency parsing (BID, TID, q8h, etc.) | Built natural language parser converting "every 8 hours" → 3 doses/day, "BID" → 2 doses/day |
| MCP context headers are non‑standard | Implemented custom x-fhir-* headers with JWT decoding fallback |
| OpenFDA rate limits (240 requests/min) | Implemented two‑layer cache: RxCUI mappings (24h TTL) + interaction results (24h TTL). Reduced external calls by 95%+ |
Accomplishments We're Proud Of
1. Six Production‑Ready MCP Tools
Fully containerized, documented, and tested. Deployed via Docker Compose on port 5001.
2. Curated Local Knowledge Bases – No API Dependency for Core Safety
| Metric | Achievement |
|---|---|
| Renal dosing rules | 40+ drugs, eGFR-stratified |
| Hepatic safety rules | 10+ drugs, DILIrank-based |
| Cross‑sensitivity patterns | 14+ patterns from literature |
| Dose range rules | 30+ drugs, age/weight adjusted |
| Response time (local checks) | <10 milliseconds |
| External API calls avoided | 95%+ (caching + local rules) |
3. Sophisticated FHIR Integration
- JWT parsing for auto‑patient context
- Merges three medication resource types with deduplication
- Handles dose ranges, complex frequencies, generic/brand mapping
- MCP capability extension advertising required FHIR scopes
4. Clinician‑Validated Logic
Our renal dosing table for metformin matches FDA labeling exactly: eGFR 45-59 → max 1500mg/day, eGFR 30-44 → max 1000mg/day, eGFR <30 → contraindicated. This is not available via any free API.
What We Learned
Technical Insights
- MCP + FHIR + local knowledge bases is a winning combination for clinical safety – offline capability, sub‑millisecond latency, and full auditability are non‑negotiable in healthcare
- External APIs are a trap for critical safety logic – they introduce latency, rate limits, and single points of failure. Core rules must be local.
- Cross‑sensitivity curation is non‑negotiable – no API provides PCN–cephalosporin cross‑reactivity (1-10% risk), HIT cross‑reactivity (90% between UFH and LMWH), or HLA‑associated SJS risk patterns
- FHIR resource merging is harder than expected – MedicationRequest, Statement, and Dispense each have different fields for medication name, dose, and timing. We built unified extractors.
Clinical Insights
- Renal dosing is the most common medication error – 30% of adverse drug events involve inappropriate renal dosing. Our eGFR‑stratified tables directly address this.
- Pediatric dosing cannot rely on adult rules – weight‑based mg/kg limits are mandatory. We implemented Harriet Lane standards.
- Documented allergies often miss cross‑sensitivities – patients with PCN allergy are rarely warned about cephalosporins. Our tool catches this automatically.
Future Directions
- Expand renal dosing to all 200+ FDA‑listed drugs requiring adjustment (currently 40)
- Add pharmacogenomic rules (CYP2D6, CYP2C19, HLA typing) for precision dosing
- Integrate therapeutic drug monitoring (vancomycin, gentamicin, lithium levels)
- Build ML model for dose prediction using patient covariates
- Publish knowledge bases as open source for community validation
Built With
- a2a
- mcp
- python
Log in or sign up for Devpost to join the conversation.