java -client
This repository contains a minimalist example of setting up MCP with Spring AI:- an MCP server that exposes "tools" via SSE/WebMVC- an MCP client.
claude mcp add --transport stdio duocrafters-java-mcp-client-server java -jar path/to/mcp-server.jar \ --env JAVA_OPTS="-Xms256m -Xmx512m" \ --env SPRING_PROFILES_ACTIVE="prod"
How to use
This MCP server provides a minimal Spring AI-based implementation of the Model Context Protocol. The server exposes domain-specific tools via a Spring MVC endpoint and streams tool results through SSE, enabling a client (Mistral-based) to orchestrate tool usage dynamically. The MCP Client component consumes user queries, delegates reasoning to the Mistral LLM, and directly calls the MCP Server tools exposed over HTTP/SSE to fulfill user intents. The end-to-end setup is designed to be lightweight yet expressive enough to illustrate tool invocation, reasoning, and response streaming in real time. You can use the client to compose complex calls by chaining tool usage, and observe how the server surfaces results through the SSE stream for robust, interactive sessions.
How to install
Prerequisites:
- Java 25 or newer
- Maven 3.8+ (or your preferred build tool for Maven projects)
Installation steps:
-
Clone the repository: git clone <repository-url> cd <repository-directory>
-
Build the project (all modules) without running tests: mvn clean install -DskipTests
-
Run the MCP server (example for the server module): mvn -pl server spring-boot:run
-
Run the MCP client (example for the client module): mvn -pl client spring-boot:run
-
Start the frontend (if present) to interact with the MCP setup: mvn -pl frontend spring-boot:run
Notes:
- The MCP Server exposes tools at /mcp/sse on port 8082 by default (adjust via Spring properties).
- Ensure the server and client can communicate over the network; adjust URLs if you run modules on different hosts or containers.
Additional notes
Tips and caveats:
- Default ports: Server 8082, Client 8080, Frontend 8081. If running locally, ensure these ports are not in use or configure alternative ports in application properties.
- The MCP Server streams tool results via SSE. Ensure your client handles streaming data to interpret tool outputs incrementally.
- If you modify tool definitions, update the MCP client’s tool expectations accordingly.
- For production, consider containerizing the server and client (e.g., Docker) and configuring health checks, resource limits, and proper security (HTTPS, authentication).
- Environment variables like SPRING_PROFILES_ACTIVE can be used to toggle configurations (dev/prod).