Skip to content

server.servlet.context-path not properly factoring into SSE MCP server path #2512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jorge-trujillo opened this issue Mar 18, 2025 · 6 comments
Labels

Comments

@jorge-trujillo
Copy link

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.

@mlmw92
Copy link

mlmw92 commented Apr 3, 2025

Same problem

@rod2k2
Copy link

rod2k2 commented Apr 11, 2025

same problem, how to solve it if have to add server.servelt.context-path ?

@HollisChen1
Copy link

HollisChen1 commented Apr 14, 2025

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();
}

@GregoireW
Copy link

GregoireW commented Apr 24, 2025

@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

@GregoireW
Copy link

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

@GregoireW
Copy link

looking for this issue, I found a related one: #2841

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants