Content
# Springboot + MCP + JUnit Template Project
<hr/>
> Quickly build an MCP project using Springboot, supporting JUNIT unit testing.
>
> Supported modes: **STDIO** and **SSE**
> **Explanation Video:**
> * First release on the entire network: Building a Springboot+MCP+JUnit project from scratch [with CherryStudio] [BV1qUXkYRE6C](https://www.bilibili.com/video/BV1qUXkYRE6C)
> * First release on the entire network: Springboot+MCP(SSE)+JUnit from setup to deployment [BV1rSXWYGEVz](https://www.bilibili.com/video/BV1rSXWYGEVz)
<hr/>
### Development Environment
- Development IDE: IDEA
- Java version: JAVA17 (Spring official requirement: Java 17+)
- Maven version: 3.8.1 (Choose an appropriate version to avoid import errors)
### Reference Documentation
1. [MCP Official Website - Protocol](https://spec.modelcontextprotocol.io) (Required reading)
2. [MCP Official Website - Coding Guide](https://modelcontextprotocol.io/quickstart/server)
3. [Spring Official Website](https://docs.spring.io/spring-ai/reference/api/mcp/mcp-server-boot-starter-docs.html)
### Client Testing Scheme
#### 1. STDIO Client Configuration:
```text
Command:
java
Arguments:
-jar
-Dfile.encoding=UTF-8
-Dspring.ai.mcp.server.stdio=true
AbsolutePath/**/xxx.jar
Environment:
env1=xxx
env2=yyy
```
The command is `java` (switch to Java 17+ if your local environment doesn't meet the requirement);
The `file.encoding` parameter specifies `System.in` and `System.out` as UTF-8 encoding to avoid encoding issues;
The `spring.ai.mcp.server.stdio` parameter enables the service in STDIO mode;
Environment configuration writes settings to the current system environment for the program to access.
<br/>
#### 2. SSE Client Configuration:
```text
SSE address: http://host:port/sse
```
<hr/>
### Exploring Additional Optional Features
#### 1. Modifying Message Endpoints
See `McpServerProperties` for configuration:
```yaml
spring.ai.mcp.server.sseMessageEndpoint=/mcp/message
```
#### 2. Modifying SSE Endpoints
The original SSE endpoint is `/sse`, but the configuration file doesn't provide an SSE endpoint configuration. To replace the original endpoint, re-inject **ServerMcpTransport**.
Note that both Bean configurations are required because the automatic injection file **MpcWebMvcServerAutoConfiguration** has a condition `@ConditionalOnMissingBean(ServerMcpTransport.class)`, which prevents the two beans from being injected.
```java
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 One Service?
Re-inject multiple **McpSyncServer** instances, see **MpcServerAutoConfiguration**.
Since multiple endpoints may involve many things, interested readers can research this topic themselves.
#### 4. SSE Authorization?
The MCP official protocol document updated an authentication scheme on 2025.03.26, awaiting Spring's updates.
<br/>
<hr/>
Bye.ヾ(•ω•`)o
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
Agent-Reach
Give your AI agent eyes to see the entire internet. Read & search Twitter,...