How I Rebuilt My AI Doctor App with Spring AI and MCP (and Stopped Stuffing Prompts)
Description and use
Rebuilding the AI Doctor app with Spring AI and MCP replaced prompt concatenation with tool calling, reducing prompt size, eliminating fragile emergency parsing, and enabling structured, on‑demand data access.
Problem
The original design concatenated the entire patient profile and conversation into a single prompt for each request, causing unnecessary data transfer, growing prompt size, and fragile emergency detection.
Outcome
Switching from prompt concatenation to MCP tool calling reduced prompt size, eliminated fragile text parsing for emergencies, and enabled structured, on‑demand data access, improving performance and reliability.
Workflow
- 1. User submits symptoms via frontend.
- 2. Backend receives request and creates a request‑scoped ConsultationContext.
- 3. Spring AI ChatClient sends the user’s message to the LLM without the full profile.
- 4. LLM decides to call getPatientProfile or flagHighSeverity as needed.
- 5. getPatientProfile retrieves the patient profile from MySQL and returns it to the LLM.
- 6. flagHighSeverity triggers an email alert via Brevo API and generates a PDF report.
- 7. LLM generates the final response and returns it to the frontend.
- 8. Spring AI ChatMemory stores the conversation turn for future turns.
Evidence
For every message, the backend built one big prompt: instructions, the user's health profile (age, blood group, allergies, medical history), the conversation so far, and the new symptoms.
Spring AI supports an MCP server/client architecture, built on the official MCP Java SDK.
I turned two parts of the app into tools the model can call when it decides it needs them: getPatientProfile and flagHighSeverity.
When a high‑severity flag comes in, the backend sends an email alert through the Brevo API and the user can download a PDF report of the consultation.
- Record date: 2026-10-02T21:41:07.637Z