Get the FREE Ultimate OpenClaw Setup Guide →

mcp -and-client-with-spring-ai

MCP (Model Context Protocol) server and client with Spring AI

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Clone the repository: git clone <repository-url> cd <repository-root>

  2. Build both modules (server and client): cd spring-ai-mcp-server ./gradlew build cd ../spring-ai-mcp-client ./gradlew build

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

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

Sponsor this space

Reach thousands of developers