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

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

Описание и применение

Перевод приложения «Виртуальный AI‑доктор» на модель с вызовами инструментов MCP сократил размер запросов, устранил неустойчивый парсинг текста для экстренных случаев и обеспечил структурированный доступ к данным.

Задача

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