spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

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

Open jorge-trujillo opened this issue 8 months ago • 6 comments
trafficstars

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.

jorge-trujillo avatar Mar 18 '25 19:03 jorge-trujillo