fix: improve SSE event handling to gracefully ignore unrecognized events (#423)

- Replace McpError exceptions with debug/warning logs for unrecognized SSE event types
- Continue processing instead of failing when encountering unknown SSE events
- Update transport implementations:
  - WebClientStreamableHttpTransport: return empty tuple instead of throwing
  - WebFluxSseClientTransport: complete stream instead of erroring
  - HttpClientSseClientTransport: call sink.success() instead of sink.error()
  - HttpClientStreamableHttpTransport: return empty Flux for unknown events

This improves client resilience when servers send non-standard or future SSE event types.

Resolves #272 , #223 , #93, #421

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov 2025-07-24 15:48:01 +02:00
commit c3a0b1855a
2 changed files with 37 additions and 6 deletions

View file

@ -366,10 +366,8 @@ public class HttpClientSseClientTransport implements McpClientTransport {
return Flux.just(message);
}
else {
logger.error("Received unrecognized SSE event type: {}",
responseEvent.sseEvent().event());
sink.error(new McpError(
"Received unrecognized SSE event type: " + responseEvent.sseEvent().event()));
logger.debug("Received unrecognized SSE event type: {}", responseEvent.sseEvent());
sink.success();
}
}
catch (IOException e) {

View file

@ -264,6 +264,10 @@ public class HttpClientStreamableHttpTransport implements McpClientTransport {
"Error parsing JSON-RPC message: " + responseEvent.sseEvent().data()));
}
}
else {
logger.debug("Received SSE event with type: {}", responseEvent.sseEvent());
return Flux.empty();
}
}
else if (statusCode == METHOD_NOT_ALLOWED) { // NotAllowed
logger.debug("The server does not support SSE streams, using request-response mode.");