Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How I Rebuilt My AI Doctor App with Spring AI and MCP (and Stopped Stuffing Prompts)

说明与用途

使用Spring AI和MCP重构AI医生应用,取代提示拼接,减少提示大小,消除脆弱的紧急情况文本解析,并实现结构化的按需数据访问。

问题

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.

结果

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.

工作流

  • 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.

证据

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.

来源

  • 记录日期: 2026-10-02T21:41:07.637Z