Thanks to visit codestin.com
Credit goes to github.com

Skip to content

HTTP transport's client should use context path without the "/sse" prefix #48

@bkowal

Description

@bkowal

Disclaimer: I haven't found clear explanation of the expected behavior in the MCP spec. However, what I described below (address without the "/sse" infix) seems to be expected by both Spring AI MCP server and FastMCP server.

Currently, when HTTP transport in MCP Tool receives message address, it adds the "/sse" prefix to the context path:
https://github.com/f/mcptools/blob/master/pkg/transport/http.go#L83

This caused communication with the server to fail. I think this line should read:
address: address + messageAddress,

If the "/sse" infix is used (as it done now in ), on the MCP Tools side I get:

../mcptools/bin/mcp tools http://localhost:8081 DEBUG: Received SSE: id:4d82fd24-3739-4c65-bf30-942700bc818c DEBUG: Received SSE: event:endpoint DEBUG: Received SSE: data:/mcp/message?sessionId=4d82fd24-3739-4c65-bf30-942700bc818c DEBUG: Received SSE: DEBUG: Connecting to server: http://localhost:8081/sse/mcp/message?sessionId=4d82fd24-3739-4c65-bf30-942700bc818c DEBUG: Sending request: {"params":{"capabilities":{},"clientInfo":{"name":"mcp-client","version":"0.1.0"},"protocolVersion":"2024-11-05"},"jsonrpc":"2.0","method":"initialize","id":1} DEBUG: Sent request to server DEBUG: Read from server: {"timestamp":"2025-04-28T22:04:34.290+00:00","status":404,"error":"Not Found","path":"/sse/mcp/message"} Error creating HTTP transport: error sending initialize request: timeout waiting for SSE response

On the Spring AI MCP Server side I get:

2025-04-29T00:04:34.221+02:00 DEBUG 6481 --- [] [nio-8081-exec-1] o.s.w.s.f.support.RouterFunctionMapping : Mapped to io.modelcontextprotocol.server.transport.WebMvcSseServerTransportProvider$$Lambda$852/0x00007f7244416a68@1d50a7ca 2025-04-29T00:04:34.226+02:00 DEBUG 6481 --- [] [nio-8081-exec-1] i.m.s.t.WebMvcSseServerTransportProvider : Creating new SSE connection for session: 4d82fd24-3739-4c65-bf30-942700bc818c 2025-04-29T00:04:34.236+02:00 DEBUG 6481 --- [] [nio-8081-exec-1] o.s.w.c.request.async.WebAsyncManager : Started async request for "/sse" 2025-04-29T00:04:34.241+02:00 DEBUG 6481 --- [] [nio-8081-exec-1] i.m.s.t.WebMvcSseServerTransportProvider : Session transport 4d82fd24-3739-4c65-bf30-942700bc818c initialized with SSE builder 2025-04-29T00:04:34.252+02:00 DEBUG 6481 --- [] [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Exiting but response remains open for further handling 2025-04-29T00:04:34.255+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.web.servlet.DispatcherServlet : POST "/sse/mcp/message?sessionId=4d82fd24-3739-4c65-bf30-942700bc818c", parameters={masked} 2025-04-29T00:04:34.259+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]] 2025-04-29T00:04:34.262+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] org.apache.catalina.webresources.Cache : Increased cache size by [531] for item [org.apache.catalina.webresources.CachedResource@67c32a31] at [/sse/mcp/message] making total cache size [2084] 2025-04-29T00:04:34.262+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found 2025-04-29T00:04:34.265+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.servlet.resource.NoResourceFoundException: No static resource sse/mcp/message.] 2025-04-29T00:04:34.266+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND 2025-04-29T00:04:34.273+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error?sessionId=4d82fd24-3739-4c65-bf30-942700bc818c", parameters={masked} 2025-04-29T00:04:34.276+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest) 2025-04-29T00:04:34.299+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json] 2025-04-29T00:04:34.300+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Tue Apr 29 00:04:34 CEST 2025, status=404, error=Not Found, path=/sse/mcp/message}] 2025-04-29T00:04:34.317+02:00 DEBUG 6481 --- [] [nio-8081-exec-2] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 404

If I remove "/sse", rebuild mcp tools and test again, the HTTP 404 error goes away and I observe the issue described in #47.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions