fix: Add null check for session in WebFluxSseServerTransportProvider (#138)

Add error handling to return a 404 NOT_FOUND response when a request
is made with a non-existent session ID. This prevents potential
NullPointerExceptions when processing requests with invalid session IDs.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov 2025-04-10 13:18:55 +02:00 • committed by GitHub
commit 2895d1589a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -306,6 +306,11 @@ public class WebFluxSseServerTransportProvider implements McpServerTransportProv
McpServerSession session = sessions.get(request.queryParam("sessionId").get());
if (session == null) {
return ServerResponse.status(HttpStatus.NOT_FOUND)
.bodyValue(new McpError("Session not found: " + request.queryParam("sessionId").get()));
}
return request.bodyToMono(String.class).flatMap(body -> {
try {
McpSchema.JSONRPCMessage message = McpSchema.deserializeJsonRpcMessage(objectMapper, body);