Skip to content
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

Support for separate registration and published endpoint paths in WebMvcSseServerTransportProvider #79

Closed
minguncle opened this issue Mar 27, 2025 · 4 comments
Assignees
Labels
Milestone

Comments

@minguncle
Copy link
Contributor

Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.

Expected Behavior
WebMvcSseServerTransportProvider should support separate configuration for registration paths and published paths. This would allow proper operation in environments with context paths or global URL prefixes. Example usage:
// Registration path: /message (for server routing)
// Published path: /api/v1/message (what clients see/use)
var transportProvider = new WebMvcSseServerTransportProvider(
objectMapper,
"/message", // Server registration path
"/api/v1/message", // Path sent to clients
"/sse"
);
With this enhancement, the server would register handlers at the bare paths, but communicate the full paths to clients through the SSE connection.

Current Behavior

When using WebMvcSseServerTransportProvider in environments with servlet context paths or other global URL prefixes (like Spring Boot's spring.mvc.servlet.path), there's a mismatch between:

  1. The path where handlers are registered with Spring's RouterFunction (e.g., /message)
  2. The full path that needs to be communicated to clients (e.g., /app/message when the context path is /app)

Currently, WebMvcSseServerTransportProvider uses the same path for both registration and client communication, which doesn't work correctly in environments with context paths.
Context

I'm deploying an MCP server in a Spring Boot application with a servlet context path configured via spring.mvc.servlet.path. When registering message endpoints with Spring's RouterFunction, I need to use paths without the context prefix, but when communicating these endpoints to clients, I need to include the full path with context prefix. I've considered workarounds like:

  1. Using a reverse proxy to handle path translation (adds complexity)
  2. Manually modifying paths in client code (error-prone)
  3. Implementing a custom transport provider (duplicates existing code)
    A simple solution would be to enhance WebMvcSseServerTransportProvider to support separate configuration for registration and published paths, which would resolve this issue cleanly.
@aronsemle
Copy link

aronsemle commented Mar 28, 2025

I second this one! I was trying to host using Grizzly on /ai/sse and /ai/mcp/message endpoints and it wouldn't work because of this. I have it working on root /sse and /mcp/message but that's not ideal.

I'd guess I'd only ask if it's worth the endpoint checks in the doGet and doPost handlers? Grizzle gives me control over the routing so why check it again here? Maybe what it's doing now is the best convention but worth asking.

// Example
if (!this.messageEndpoint.equals(pathInfo)) {
response.sendError(404);
} else {

@tzolov tzolov self-assigned this Apr 6, 2025
@tzolov tzolov added the server label Apr 6, 2025
@tzolov tzolov added this to the 0.9.0 milestone Apr 6, 2025
@tzolov
Copy link
Contributor

tzolov commented Apr 6, 2025

@minguncle, this should affect the /sse endpoint as well, right? For example, you would need to access it on /app/sse (if the context is set to app).

How do you resolve this? By setting the sseEndpoint="/app/sse" in the WebMvcSseServerTransportProvider constructor?

Also, I believe this is the same issue but for WebFlux: #102

I kind of like the baseUrl + messageEndpoint approach rather than the publishedMessageEndpoint. I might modify your PR along those lines before merging.

@tzolov
Copy link
Contributor

tzolov commented Apr 6, 2025

@aronsemle I guess you're experiencing this issue but using the core HttpServletSseServerTransportProvider transport? I guess we can apply the same baseUrl + messageEndpoint approach there as well?

tzolov added a commit that referenced this issue Apr 6, 2025
…erver transport

Enhance HttpServletSseServerTransportProvider to support deployment under non-root context paths by:

- Adding baseUrl field and DEFAULT_BASE_URL constant
- Creating new constructor that accepts a baseUrl parameter
- Extending Builder with baseUrl configuration method
- Prepending baseUrl to message endpoint in SSE events
- Add HttpServletSseServerCustomContextPathTests to verify custom context path functionality
- Extract common Tomcat server setup code to TomcatTestUtil for test reuse

Related to #79

Signed-off-by: Christian Tzolov <[email protected]>
@aronsemle
Copy link

@tzolov yes! That would be great if it was also applied to the HttpServletSseServerTransportProvider.

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

Successfully merging a pull request may close this issue.

3 participants