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.
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.
Command: java
Arguments:
-jar
-Dfile.encoding=UTF-8
-Dspring.ai.mcp.server.stdio=true
AbsolutePath/**/xxx.jar
Environments:
env1=xxx
env2=yyy
SSE URL: http://host:port/sse
Update the configuration file McpServerProperties
:
spring.ai.mcp.server.sseMessageEndpoint=/mcp/message
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();
}
Inject multiple instances of McpSyncServer
as needed. Refer to the MpcServerAutoConfiguration
class for guidance.
As of March 26, 2025, the MCP protocol includes updated authorization mechanisms. Stay tuned for Spring Boot updates to support this feature.
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