Bug Report
Bug description
I have a MCP Server and the MCP client built. First, I spin up the MCP Server and then the MCP client. My client app interacts with the MCP server and works fine.
However, when I restart or redeploy the MCP Server, the client app interacts with the MCP server, and I observe the following error:
2025-04-17T11:02:40.637-05:00 ERROR 14929 --- [onPool-worker-3] i.m.c.t.HttpClientSseClientTransport : Error sending message: 404
Detailed Error
2025-04-17T11:02:39.088-05:00 INFO 14929 --- [nio-8086-exec-4] com.llm.controller.ChatsController : userInput message : UserInput(prompt=Find me all the phones ?) 2025-04-17T11:02:39.088-05:00 INFO 14929 --- [nio-8086-exec-4]
com.llm.controller.ChatsController : requestSpec : org.springframework.ai.chat.client.DefaultChatClient$DefaultChatClientRequestSpec@2f15ab7e 2025-04-17T11:02:39.088-05:00 INFO 14929 --- [nio-8086-exec-4] com.llm.controller.ChatsController : responseSpec1 : org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec@21d250ec 2025-04-17T11:02:40.132-05:00 DEBUG 14929 --- [nio-8086-exec-4] o.s.a.m.tool.DefaultToolCallingManager : Executing tool call: spring_ai_mcp_client_person_mcp_server_getAllProducts
2025-04-17T11:02:40.637-05:00 ERROR 14929 --- [onPool-worker-3] i.m.c.t.HttpClientSseClientTransport : Error sending message: 404
2025-04-17T11:06:40.155-05:00 ERROR 14929 --- [nio-8086-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: reactor.core.Exceptions$ReactiveException: java.util.concurrent.TimeoutException: Did not observe any item or terminal signal within 240000ms in 'source(MonoCreate)' (and no fallback has been configured)] with root cause
Environment
- Spring AI version: 1.0.0-M7
- Java version: 21
- Vector Store: [Provide details if used, or leave blank]
Steps to reproduce
- Spin up the MCP Server.
- Spin up the MCP client and interact with the MCP Server (this works fine).
- Restart or redeploy the MCP Server.
- Have the MCP client interact with the MCP server again.
- Observe the error.
Expected behavior
I expected the MCP client to interact with the MCP server successfully after the server restart, without any errors.
Minimal Complete Reproducible example
You can view the complete example in my GitHub repository.
Comment From: yangtuooc
After the server restarts, it loses all session states, but the client is still using its old session ID. This causes ‘session not found’ errors. Here is the relevant code snippet from the source:
private final ConcurrentHashMap<String, McpServerSession> sessions = new ConcurrentHashMap<>();
// ...
private ServerResponse handleMessage(ServerRequest request) {
// ...
String sessionId = request.param("sessionId").get();
McpServerSession session = sessions.get(sessionId);
if (session == null) {
return ServerResponse.status(HttpStatus.NOT_FOUND).body(new McpError("Session not found: " + sessionId));
}
// ...
}
Source: WebMvcSseServerTransportProvider.java
Comment From: dilipsundarraj1
@yangtuooc Yep I also noticed the same thing. The reason for creating this issue is to bring it to everyone's attention. Ideally I would expect the server to enable the new connection using the passed in id or create a brand new connection .
Comment From: jakubmalek
According to https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#session-management
When a client receives HTTP 404 in response to a request containing an Mcp-Session-Id, it MUST start a new session by sending a new InitializeRequest without a session ID attached.
So the problem is related to MCP client, not the server.
Comment From: lbhkobe
My MCP server is deployed in Kubernetes and has multiple pods. When the MCP client starts, it may GET /sse from podA to obtain a sessionId, but then POST to /mcp/message?sessionId=xx on podB, resulting in a 404 error... because podB didn't save this sessionId
Comment From: zhuchuanjie001
我的 MCP 服务器部署在 Kubernetes 中,有多个 Pod。MCP 客户端启动时,可能会从 PodA GET /sse 获取 sessionId,然后 POST 到 PodB 的 /mcp/message?sessionId=xx,导致 404 错误……因为 PodB 没有保存这个 sessionId。
这个问题可以解决吗,目前我们也遇到了同样问题
Comment From: 734839030
sessionId not found for multiple pods; This issue prevents the use of Spring AI.