close

DEV Community

Chella Kamina
Chella Kamina

Posted on

Care Transition MCP: Teaching AI to Think Like a Clinician, Not a Stenographer

My sister is a nurse. When I showed her the first version of this tool, she said it felt wrong. That sentence sent me back to the drawing board, and it’s the reason this project exists in its current form.

The Problem

I asked my sister what a real patient handover actually looks like. She described chaos disguised as routine; every ward writes differently. Surgery, paediatrics, adult wards. No standard format, just paper, memory, and whoever happens to be on shift when the patient transfers.

That inconsistency has a cost. The US healthcare system loses an estimated $26 billion a year to preventable readmissions. A quarter of those readmissions happen at a different hospital than the original admission because the information that mattered never travelled with the patient.

What I Built

Care Transition MCP is a five-tool MCP server that pulls real patient FHIR data from the Prompt Opinion platform and generates a structured clinical handover: gaps flagged, medications reconciled, readmission risk assessed. One prompt triggers all five tools. The receiving clinician gets a document they can actually act on, not a wall of raw data they have to interpret themselves.

How It’s Built

FastMCP 1.9.0 with SSE transport, deployed on Google Cloud Run. FHIR data comes from Po’s workspace FHIR R4 endpoint. The LLM is Groq running LLaMA 3.3 70B. Five composable tools, each working independently, any agent on the platform can call any one of them without needing the others.

The Problem That Mattered Most

The first time I ran the tool, it technically worked. But something felt off. The AI was treating “received higher education” as a piece of social history with the same clinical urgency as an active medical emergency. Imagine someone bursting into a room to announce the building is on fire and, in the same breath, mentioning the coffee machine needs descaling. Both delivered with equal weight. That’s what the early output read like to a clinician.

This is what I started calling the SDoH trap: social determinants of health data sitting in the same context window as urgent clinical signals, with nothing distinguishing their importance.

The fix wasn’t a prompt tweak. I went into the FHIR category codes and separated clinical conditions from social history before the data ever reached the model. Social factors were moved into their own dedicated section on discharge barriers. The clinical picture leads every time. That single architectural decision is the difference between a tool a clinician trusts at a glance and one they quietly stop using.

The Infrastructure Problems

The AI logic wasn’t actually the hardest part of this build. The infrastructure was.

BaseHTTPMiddleware is incompatible with SSE streaming. Starlette’s convenience middleware buffers the entire response body before sending it. SSE doesn’t have a body in that sense; it streams indefinitely. The fix was dropping down to raw ASGI middleware.

FHIR headers arrive on a different connection than the tool calls that need them. Po sends patient context headers on the initial SSE handshake, but each tool call runs as a separate async POST request. By the time a tool needed the patient ID, the header that contained it was gone. I solved this with Python ContextVars, threading the context through the async call chain so that every tool call could read it regardless of which request carried it.

Po reads a field that FastMCP doesn’t output correctly. Po expects capabilities.extensions, but FastMCP outputs capabilities.experimental. Fixed by injecting the correct field manually through Pydantic’s __pydantic_extra__.

None of these is an AI problem. They’re the unglamorous plumbing that determines whether an AI system actually works in someone else’s production environment, and they took longer to solve than anything involving the model itself.

What I’m Proud Of

Getting the full FHIR context pipeline working end-to-end, from Po injecting patient headers through SSE, captured by raw ASGI middleware, stored in ContextVars, read inside async tool calls, took the most debugging of anything in this build. But it’s what makes the whole system work cleanly without the caller needing to think about any of it.

Solving the SDoH trap properly. Not by filtering bad output after the fact, but by separating the data at the source, before the model ever has a chance to misjudge it.

Building five genuinely independent tools. Any agent on the Po platform can use the medication reconciliation tool without needing the discharge brief tool, and vice versa. That composability was a deliberate design choice from day one, not an accident of how the code happened to come together.

What I Learned

The hardest part of healthcare AI isn’t the model. It’s teaching the model to think like a clinician, to understand that a missing medication entry on an ICU patient is a safety flag, not just an empty field. The system doesn’t need to be perfect. It needs to be significantly more reliable than a rushed, handwritten note that gets lost somewhere in a hospital hallway during a shift change. That’s a low bar in one sense and a genuinely hard engineering problem in another.

GitHub: Care-Transition-MCP
YouTube:
Care Transition MCP - Fixing the Billion Dollar Hospital Handoff Crisis

Top comments (0)