mcp -and-client-with-spring-ai
MCP (Model Context Protocol) server and client with Spring AI
claude mcp add --transport stdio rafiq15-mcp-server-and-client-with-spring-ai java -jar build/libs/spring-ai-mcp-server.jar \ --env JAVA_HOME="Path to a Java 17+ JDK"
How to use
This MCP server provides a Spring Boot-based implementation of the Model Context Protocol (MCP) for managing medical reports and patient data, with a client application that consumes MCP-enabled APIs. The server exposes REST endpoints for CRUD operations on patients and medical reports and integrates with AI models via Spring AI MCP support to reason over and infer context. To use it, start the server (for example via Gradle bootRun or by running the built jar) and point the client at the server URL. The client uses MCP to structure requests with contextual data and to receive AI-assisted responses, enabling richer, context-aware interactions with medical records and AI models.
Key capabilities include creating and listing patients and reports, and sending context to an AI model through the /api/ai/infer endpoint. The server is designed to be extended with additional MCP-enabled model integrations and supports configuration through application.yaml for ports, DB connections, and other settings.
How to install
Prerequisites:
- Java 17+ JDK
- Gradle 7+
Installation steps:
-
Clone the repository: git clone <repository-url> cd <repository-root>
-
Build both modules (server and client): cd spring-ai-mcp-server ./gradlew build cd ../spring-ai-mcp-client ./gradlew build
-
Run the server (from the server module): cd spring-ai-mcp-server ./gradlew bootRun
or run the built jar directly:
java -jar build/libs/spring-ai-mcp-server.jar
-
Run the client (from the client module): cd spring-ai-mcp-client ./gradlew bootRun
or run the built jar directly:
java -jar build/libs/spring-ai-mcp-client.jar
Notes:
- Ensure environment variables for your database and MCP configuration are set in application.yaml as needed.
- The server and client are built with Gradle and require Java 17+.
- If you prefer a Docker setup, you can containerize the server with a Dockerfile that runs the built jar.
Additional notes
Tips and common issues:
- Ensure Java 17+ is installed and JAVA_HOME is set.
- The MCP endpoints rely on Spring AI’s MCP integration; verify that your dependencies include the appropriate MCP modules.
- If you modify data models (Patient, MedicalReport), refresh the database schema accordingly (e.g., via JPA/Hibernate auto-ddl or migrations).
- The application.yaml/configs control ports, database connections, and MCP behavior; customize to fit your environment.
- When testing AI inference, verify that the /api/ai/infer endpoint receives a properly structured MCP context object.
- For development, running both server and client locally enables end-to-end MCP flows between UI, server, and AI models.
Related MCP Servers
mcp-for-beginners
This open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
xiaozhi-esp32 -java
小智ESP32的Java企业级管理平台,提供设备监控、音色定制、角色切换和对话记录管理的前后端及服务端一体化解决方案
api2mcp4j
This is a revolutionary AI MCP plugin with excellent pluggable and encapsulated features. With just a few lines of configuration, it can easily integrate into your Spring boot web program and give it MCP capabilities,inheriting the powerful engineering capabilities of the Spring series framework
springboot-ai -example
Example Spring AI Model Context Protocol (MCP)
auto -client
基于Spring AI 封装了 mcp-client 服务,目的使web网页智能体也能通过 stdio 和 HTTP SSE(Server-Sent Events) 与 MCP Server 进行交互。项目实现了自动化的连接管理机制,包括自动初始化连接、健康检查、超时关闭以及链接复用等功能
solon-ai-embedded-examples
solon ai(&mcp) embedded examples。支持 MCP_2025_06_18(mcp streamable)。示例项目包括各种框架嵌入:(Solon、SpringBoot、jFinal、Vert.X、Quarkus、Micronaut)