dreamcenter_springboot_mcpserver_junit

dreamcenter_springboot_mcpserver_junit

by dreamcenter
A Springboot-based template project for MCP server development, supporting both STDIO and SSE modes.

Springboot MCP Server Template with JUnit

A template project for building MCP servers using Spring Boot and JUnit. This project supports both STDIO and SSE modes, making it versatile for various use cases.


Overview

This project provides a ready-to-use template for developers looking to build MCP servers with Spring Boot. It includes support for JUnit testing and offers two operational modes: STDIO and SSE. The project is designed to be easy to set up and extend, making it ideal for both beginners and experienced developers.


Development Environment

  • IDE: IntelliJ IDEA
  • Java Version: Java 17 (Spring Boot requires Java 17+)
  • Maven Version: 3.8.1 (Avoid higher versions to prevent build errors)

Reference Documentation

  1. MCP Protocol Specification (Mandatory reading)
  2. MCP Coding Guidelines
  3. Spring Boot Documentation

Client Testing Options

1. STDIO Mode Configuration

Command: java  
Arguments:  
    -jar  
    -Dfile.encoding=UTF-8  
    -Dspring.ai.mcp.server.stdio=true  
    AbsolutePath/**/xxx.jar  
Environments:  
    env1=xxx  
    env2=yyy  

2. SSE Mode Configuration

SSE URL: http://host:port/sse  

Additional Features and Customizations

1. Modify Message Endpoint

Update the configuration file McpServerProperties:

spring.ai.mcp.server.sseMessageEndpoint=/mcp/message

2. Modify SSE Endpoint

Override the default /sse endpoint by redefining the ServerMcpTransport bean:

private final String SSE_ENDPOINT = "/sse";

@Bean
@ConditionalOnMissingBean
public WebMvcSseServerTransport webMvcSseServerTransport(ObjectMapper objectMapper,
        McpServerProperties serverProperties) {
    return new WebMvcSseServerTransport(objectMapper, serverProperties.getSseMessageEndpoint(), SSE_ENDPOINT);
}

@Bean
public RouterFunction<ServerResponse> mvcMcpRouterFunction(WebMvcSseServerTransport transport) {
    return transport.getRouterFunction();
}

3. Multiple Endpoints for a Single Service

Inject multiple instances of McpSyncServer as needed. Refer to the MpcServerAutoConfiguration class for guidance.

4. SSE Authorization

As of March 26, 2025, the MCP protocol includes updated authorization mechanisms. Stay tuned for Spring Boot updates to support this feature.


Tutorial Videos

  • Introduction to Springboot + MCP + JUnit with CherryStudio: BV1qUXkYRE6C
  • Springboot + MCP (SSE) + JUnit: From Setup to Deployment: BV1rSXWYGEVz

Conclusion

This project serves as a robust starting point for building MCP servers with Spring Boot. Its support for both STDIO and SSE modes, along with JUnit testing, makes it a versatile choice for developers. Explore the additional features and customizations to tailor the server to your specific needs.

Bye.ヾ(•ω•`)o

Features & Capabilities

Categories
mcp_server model_context_protocol springboot junit sse stdio java api_integration

Implementation Details

Stats

0 Views
2 GitHub Stars

Repository Info

dreamcenter Organization

Similar MCP Servers

continuedev_continue by continuedev
25049
21423
9300