Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create. If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:
Bug description
When using the MCP Server Starter, one of the supported protocols is SSE. If you are setting a custom context path using the property server.servlet.context-path
, the relevant paths for MCP will change, but the path given when you look at the /sse
endpoint will not. Therefore MCP clients will break. This was tested with Cursor MCP.
Environment JVM: OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS) Spring AI version: "1.0.0-M6" (Used BOM)
Application was written in Kotlin but that shouldn't be relevant here.
Steps to reproduce
- Create any MCP server application that uses SSE
- Connect it to an MCP client, should work fine (I used /sse as the path in Cursor)
- Set the server.servlet.context-path
, say to "/v1"
- Attempt to update your setup in your MCP client, it will always fail
If you look at the output of the /sse endpoint, the reason is that the path provided by the endpoint is incorrect. It will match what you set in spring.ai.mcp.server.sse-message-endpoint
but it will not include the context path.
Expected behavior
In my opinion, this would be fixed if the endpoint that is returned in the call to the /sse
endpoint also prepended the context path.
Minimal Complete Reproducible example Please provide a failing test or a minimal complete verifiable example that reproduces the issue. Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.
Comment From: mlmw92
Same problem
Comment From: rod2k2
same problem, how to solve it if have to add server.servelt.context-path ?
Comment From: HollisChen1
I think there should be an issue of org.springframework.ai.mcp.server.autoconfigure.McpWebMvcServerAutoConfiguration(the same as McpWebFluxServerAutoConfiguration) by adding bean in our config class like below, using another constructor of WebMvcSseServerTransportProvider, make sure your servlet context path was added to spring.ai.mcp.server.base-url
@Bean
public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider(
ObjectProvider<ObjectMapper> objectMapperProvider, McpServerProperties serverProperties) {
ObjectMapper objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new);
return new WebMvcSseServerTransportProvider(objectMapper,serverProperties.getBaseUrl(), serverProperties.getSseMessageEndpoint(), serverProperties.getSseEndpoint());
}
@Bean
public RouterFunction<ServerResponse> mvcMcpRouterFunction(WebMvcSseServerTransportProvider transportProvider) {
return transportProvider.getRouterFunction();
}
Comment From: GregoireW
@HollisChen1 you mention:
make sure your servlet context path was added to spring.ai.mcp.server.base-url
But setting:
spring:
ai:
mcp:
server:
base-url: /myapp/
sse-endpoint: /sse
sse-message-endpoint: /mcp/message
on spring-ai 1.0.0-M7, I get on curl http://localhost:8080/sse
a response containing: data:/mcp/message?sessio...
so the base-url is not taken either I think
Comment From: GregoireW
I will answer myself: those beans are initialized with default configuration (base url and sseEndpoint (the /sse ) ) a small change to add the 2 others parameter should fix the issue
https://github.com/spring-projects/spring-ai/blob/687dea52e0ccf5ffe70dfbf6a7aa248d28c01bdc/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebMvcServerAutoConfiguration.java#L75
https://github.com/spring-projects/spring-ai/blob/687dea52e0ccf5ffe70dfbf6a7aa248d28c01bdc/auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src/main/java/org/springframework/ai/mcp/server/autoconfigure/McpWebFluxServerAutoConfiguration.java#L80
Comment From: GregoireW
looking for this issue, I found a related one: #2841
Comment From: weiwudu
@HollisChen1 you mention:
make sure your servlet context path was added to spring.ai.mcp.server.base-url
But setting:
spring: ai: mcp: server: base-url: /myapp/ sse-endpoint: /sse sse-message-endpoint: /mcp/message
on spring-ai 1.0.0-M7, I get on
curl http://localhost:8080/sse
a response containing:data:/mcp/message?sessio...
so the base-url is not taken either I think
good job! This solution solved my problem
Comment From: mauricio1990silva
has this been fixed? My mcp data endpoint is still going after /mcp/message as supposed to /api/mcp/message even though I have the base-url set to /api/
spring-ai 1.0.0-M7