Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.net.http.HttpResponse.BodyHandler;
import java.time.Duration;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -142,10 +141,7 @@ private HttpClientStreamableHttpTransport(McpJsonMapper jsonMapper, HttpClient h
this.activeSession.set(createTransportSession());
this.httpRequestCustomizer = httpRequestCustomizer;
this.supportedProtocolVersions = Collections.unmodifiableList(supportedProtocolVersions);
this.latestSupportedProtocolVersion = this.supportedProtocolVersions.stream()
.sorted(Comparator.reverseOrder())
.findFirst()
.get();
this.latestSupportedProtocolVersion = Collections.max(this.supportedProtocolVersions);
}

@Override
Expand Down Expand Up @@ -367,7 +363,7 @@ else if (statusCode == BAD_REQUEST) {
}).<McpSchema
.JSONRPCMessage>flatMap(
jsonrpcMessage -> this.handler.get().apply(Mono.just(jsonrpcMessage)))
.onErrorMap(CompletionException.class, t -> t.getCause())
.onErrorMap(CompletionException.class, Throwable::getCause)
.onErrorComplete(t -> {
this.handleException(t);
return true;
Expand Down Expand Up @@ -463,11 +459,11 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) {
else {
logger.debug("SSE connection established successfully");
}
})).onErrorMap(CompletionException.class, t -> t.getCause()).onErrorComplete().subscribe();
})).onErrorMap(CompletionException.class, Throwable::getCause).onErrorComplete().subscribe();

})).flatMap(responseEvent -> {
if (transportSession.markInitialized(
responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElseGet(() -> null))) {
responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElse(null))) {
// Once we have a session, we try to open an async stream for
// the server to send notifications and requests out-of-band.

Expand Down Expand Up @@ -583,7 +579,7 @@ else if (statusCode == BAD_REQUEST) {
new RuntimeException("Failed to send message: " + responseEvent));
})
.flatMap(jsonRpcMessage -> this.handler.get().apply(Mono.just(jsonRpcMessage)))
.onErrorMap(CompletionException.class, t -> t.getCause())
.onErrorMap(CompletionException.class, Throwable::getCause)
.onErrorComplete(t -> {
// handle the error first
this.handleException(t);
Expand Down