{"record":{"id":"e647af51c1ec1e3c","repo":"spring-projects/spring-ai","slug":"session-sessionrepresentation-was-not-found-on","errorCode":null,"errorMessage":"Session + sessionRepresentation + was not found on the MCP server","messagePattern":"Session \\+ sessionRepresentation \\+ was not found on the MCP server","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp/transport/mcp-spring-webflux/src/main/java/org/springframework/ai/mcp/client/webflux/transport/WebClientStreamableHttpTransport.java","lineNumber":442,"sourceCode":"\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// inform the caller of sendMessage\n\t\t\t\t\tsink.error(t);\n\t\t\t\t\treturn true;\n\t\t\t\t}).doFinally(s -> {\n\t\t\t\t\t@Nullable Disposable ref = disposableRef.getAndSet(null);\n\t\t\t\t\tif (ref != null) {\n\t\t\t\t\t\ttransportSession.removeConnection(ref);\n\t\t\t\t\t}\n\t\t\t\t}).contextWrite(sink.contextView()).subscribe();\n\t\t\tdisposableRef.set(connection);\n\t\t\ttransportSession.addConnection(connection);\n\t\t});\n\t}\n\n\tprivate static Flux<McpSchema.JSONRPCMessage> mcpSessionNotFoundError(String sessionRepresentation) {\n\t\tif (logger.isWarnEnabled()) {\n\t\t\tlogger.warn(\"Session \" + sessionRepresentation + \" was not found on the MCP server\");\n\t\t}\n\t\t// inform the stream/connection subscriber\n\t\treturn Flux.error(new McpTransportSessionNotFoundException(sessionRepresentation));\n\t}\n\n\tprivate Flux<McpSchema.JSONRPCMessage> extractError(ClientResponse response, String sessionRepresentation) {\n\t\treturn response.<McpSchema.JSONRPCMessage>createError().onErrorResume(e -> {\n\t\t\tWebClientResponseException responseException = (WebClientResponseException) e;\n\t\t\tbyte[] body = responseException.getResponseBodyAsByteArray();\n\t\t\tMcpSchema.JSONRPCResponse.JSONRPCError jsonRpcError = null;\n\t\t\tException toPropagate;\n\t\t\ttry {\n\t\t\t\tMcpSchema.JSONRPCResponse jsonRpcResponse = this.jsonMapper.readValue(body,\n\t\t\t\t\t\tMcpSchema.JSONRPCResponse.class);\n\t\t\t\tjsonRpcError = jsonRpcResponse.error();\n\t\t\t\ttoPropagate = jsonRpcError != null ? new McpError(jsonRpcError)\n\t\t\t\t\t\t: new McpTransportException(\"Can't parse the jsonResponse \" + jsonRpcResponse);\n\t\t\t}","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/transport/mcp-spring-webflux/src/main/java/org/springframework/ai/mcp/client/webflux/transport/WebClientStreamableHttpTransport.java#L424-L460","documentation":"A warning logged by mcpSessionNotFoundError when the MCP server indicates the client's mcp-session-id is unknown. The transport converts this into a McpTransportSessionNotFoundException on the connection flux so subscribers learn the session died and can re-initialize. This is the client-side detection of server-side session loss.","triggerScenarios":"Server restarted or restarted sessions storage; session TTL expired server-side; load balancer routed the request to an instance without the session; sending a stale mcp-session-id header after long idle.","commonSituations":"Kubernetes pod restarts; autoscaling removing the node holding the session; long-lived idle connections exceeding server session timeouts; caching a session id across client restarts.","solutions":["Handle McpTransportSessionNotFoundException in the client by re-running initialize/connect to obtain a new session","Persist session state server-side or enable sticky sessions for multi-instance deployments","Increase server session timeout for long-running workloads","Recreate the client/transport after receiving this error instead of retrying on the dead session"],"exampleFix":"// before\nclient.callTool(request).block(); // dies with McpTransportSessionNotFoundException\n// after\nclient.callTool(request)\n    .onErrorResume(McpTransportSessionNotFoundException.class, e ->\n        reconnectAndInitialize(client).then(client.callTool(request)))","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    client.callTool(req).block();\n} catch (McpTransportSessionNotFoundException e) {\n    // session lost: re-initialize and retry once\n    client.close();\n    McpClient newClient = buildClientAndInitialize();\n    newClient.callTool(req).block();\n}","preventionTips":["Re-initialize the client whenever McpTransportSessionNotFoundException occurs","Never reuse a cached mcp-session-id across process restarts","Use persistent/sticky session storage on the server","Keep sessions active or refresh before server TTL expiry"],"tags":["mcp","session","http","reconnect"],"backgroundTag":"session-not-found","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}