Virtual AI Doctor: a Spring AI & MCP health assistant
An AI-powered virtual doctor built with Java, Spring Boot, Spring AI and the Model Context Protocol, where the model fetches patient context and flags emergencies through tool calls.
Overview
Virtual AI Doctor lets users describe their symptoms in Hindi or English and get medical guidance in the same language. It is a learning and portfolio project and does not replace a real doctor.
The design change that mattered
The first version built one large prompt for every message: instructions, the full health profile, the conversation so far and the new symptoms. Every request carried data it often didn't need, prompts kept growing, and detecting emergencies meant parsing a severity tag out of plain text.
I re-architected the AI layer around Spring AI's Model Context Protocol (MCP) server/client integration, built on the official MCP Java SDK, so the model can call tools only when it needs them:
- getPatientProfile fetches age, blood group, allergies and history on demand.
- flagHighSeverity is called by the model itself when it judges a consultation to be an emergency, which replaces fragile text parsing.
Features
- AI symptom analysis with Groq (LLaMA 3.1) through Spring AI
- Automatic Hindi / English detection and replies
- Persistent multi-turn memory with Spring AI ChatMemory (JDBC, MySQL)
- JWT-secured signup, login and APIs
- Email alerts and downloadable PDF reports for high-severity cases
- Nearby pharmacy finder using OpenStreetMap and the Overpass API
- Consultation history, health profile, dark / light mode
Tech stack
| Layer | Technology |
|---|---|
| Backend | Java 17, Spring Boot 3.5, Spring Security, Spring Data JPA, Hibernate |
| AI | Spring AI, MCP, Groq API (LLaMA 3.1) |
| Database | MySQL (Railway) |
| Alerts | Spring Mail, Brevo API |
| Frontend / hosting | HTML, CSS, JavaScript on Vercel; backend on Render |
What's next
A MEDIUM-severity MCP tool, a React frontend, real-time chat with WebSockets and voice input for symptoms.
Read more
I wrote about this redesign on Dev.to: How I Rebuilt My AI Doctor App with Spring AI and MCP.
About the developer
Built by Swayam Verma, a Java & Spring Boot backend developer and B.Tech CSE student from Bhopal, India. See my portfolio, GitHub and LinkedIn.