spring-demo -sse
A Spring Boot demo project for implementing Server-Sent Events (SSE) with an MCP (Message Control Protocol) server. Explore real-time data streaming and event-driven architecture in Java using this hands-on example.
claude mcp add --transport stdio kaifcoder-spring-demo-mcp-server-sse docker run -i kaifcoder/spring-demo-mcp-server-sse
How to use
This MCP server demonstrates exposing a Spring Boot application as both a REST API and an MCP tool. The UserService is registered as an MCP tool so that clients such as VS Code Copilot can discover and invoke it through the MCP framework using SSE for sessions and JSON-RPC for tool calls. You can also use the REST endpoints to fetch user details, while the MCP interface provides a language-model-friendly way to query the same data via tools like getUserDetailsMcp.
To use the MCP server, first ensure the server is running and accessible at the configured port (default 8080). Create an SSE session by opening the /mcp/sse endpoint, then send JSON-RPC messages to /mcp/messages?sessionId=<your-session-id> to initialize, list tools, and invoke the getUserDetailsMcp tool with appropriate arguments (e.g., a userId). The server will return results asynchronously through the SSE channel as JSON-RPC responses.
How to install
Prerequisites:
- Java 17+ with JDK installed
- Maven 3.8+ (wrapper available as mvnw)
- Docker (optional, if using the provided docker-based run command)
- Clone the repository and navigate to the project directory:
git clone <your-repo-url>
cd mcpdemo
- Build the project (uses the Maven wrapper):
./mvnw clean install
- Run the application (local run, via Maven):
./mvnw spring-boot:run
The application starts on http://localhost:8080 by default. If you prefer Docker, you can run the prebuilt image (see mcp_config for the exact image) and expose port 8080 as needed:
docker run -p 8080:8080 kaifcoder/spring-demo-mcp-server-sse
- Verify REST endpoints (optional):
curl http://localhost:8080/api/users/123
Additional notes
Notes and tips:
- The MCP server exposes the UserService as an MCP tool. Use the SSE endpoint at /mcp/sse to start a session, then send JSON-RPC requests to /mcp/messages?sessionId=<session-id> to initialize, list tools (tools/list), and invoke tools (tools/call).
- Ensure the MCP server port does not conflict with other services. If needed, update application.yaml to change the server.port.
- For debugging MCP messages, enable TRACE logging in application.yaml.
- If you encounter a “Tool not visible” error in your IDE, confirm the server is running and the your client URL matches http://localhost:8080/mcp/sse.
- The REST API and MCP tools operate against the same UserService data source; prefer the MCP tool for integration with LM/AI copilots, and use REST for quick manual checks.
Related MCP Servers
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
spring-ai
From Java Dev to AI Engineer: Spring AI Fast Track
mcp-zap
A Spring Boot application exposing OWASP ZAP as an MCP (Model Context Protocol) server. It lets any MCP‑compatible AI agent (e.g., Claude Desktop, Cursor) orchestrate ZAP actions—spider, active scan, import OpenAPI specs, and generate reports.
mcp_mediator
Automatically generate an MCP Server from existing source code, service classes, helper methods, and external MCP tools. The MCP Mediator aggregates various sources and tools into a unified system, enabling seamless automatic generation of a complete MCP Server.
solon-ai-embedded-examples
solon ai(&mcp) embedded examples。支持 MCP_2025_06_18(mcp streamable)。示例项目包括各种框架嵌入:(Solon、SpringBoot、jFinal、Vert.X、Quarkus、Micronaut)
slack
Spring AI를 활용한 Slack MCP 서버입니다.