Fix Streamable HTTP WebClient GET SSE handling
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
This commit is contained in:
parent
9a63538840
commit
8e9857f181
1 changed files with 75 additions and 14 deletions
|
|
@ -125,13 +125,14 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
|
|||
}
|
||||
|
||||
private DefaultMcpTransportSession createTransportSession() {
|
||||
Supplier<Publisher<Void>> onClose = () -> {
|
||||
DefaultMcpTransportSession transportSession = this.activeSession.get();
|
||||
return transportSession.sessionId().isEmpty() ? Mono.empty()
|
||||
: webClient.delete().uri(this.endpoint).headers(httpHeaders -> {
|
||||
httpHeaders.add("mcp-session-id", transportSession.sessionId().get());
|
||||
}).retrieve().toBodilessEntity().doOnError(e -> logger.info("Got response {}", e)).then();
|
||||
};
|
||||
Function<String, Publisher<Void>> onClose = sessionId -> sessionId == null ? Mono.empty()
|
||||
: webClient.delete().uri(this.endpoint).headers(httpHeaders -> {
|
||||
httpHeaders.add("mcp-session-id", sessionId);
|
||||
})
|
||||
.retrieve()
|
||||
.toBodilessEntity()
|
||||
.doOnError(e -> logger.warn("Got error when closing transport", e))
|
||||
.then();
|
||||
return new DefaultMcpTransportSession(onClose);
|
||||
}
|
||||
|
||||
|
|
@ -192,6 +193,7 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
|
|||
})
|
||||
.exchangeToFlux(response -> {
|
||||
if (isEventStream(response)) {
|
||||
logger.debug("Established SSE stream via GET");
|
||||
return eventStream(stream, response);
|
||||
}
|
||||
else if (isNotAllowed(response)) {
|
||||
|
|
@ -208,6 +210,7 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
|
|||
}).flux();
|
||||
}
|
||||
})
|
||||
.flatMap(jsonrpcMessage -> this.handler.get().apply(Mono.just(jsonrpcMessage)))
|
||||
.onErrorComplete(t -> {
|
||||
this.handleException(t);
|
||||
return true;
|
||||
|
|
@ -274,6 +277,7 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
|
|||
else {
|
||||
MediaType mediaType = contentType.get();
|
||||
if (mediaType.isCompatibleWith(MediaType.TEXT_EVENT_STREAM)) {
|
||||
logger.debug("Established SSE stream via POST");
|
||||
// communicate to caller that the message was delivered
|
||||
sink.success();
|
||||
// starting a stream
|
||||
|
|
|
|||
Loading…
Reference in a new issue