|
12 | 12 | import java.net.http.HttpResponse.BodyHandler; |
13 | 13 | import java.time.Duration; |
14 | 14 | import java.util.Collections; |
15 | | -import java.util.Comparator; |
16 | 15 | import java.util.List; |
17 | 16 | import java.util.Optional; |
18 | 17 | import java.util.concurrent.CompletionException; |
@@ -142,10 +141,7 @@ private HttpClientStreamableHttpTransport(McpJsonMapper jsonMapper, HttpClient h |
142 | 141 | this.activeSession.set(createTransportSession()); |
143 | 142 | this.httpRequestCustomizer = httpRequestCustomizer; |
144 | 143 | this.supportedProtocolVersions = Collections.unmodifiableList(supportedProtocolVersions); |
145 | | - this.latestSupportedProtocolVersion = this.supportedProtocolVersions.stream() |
146 | | - .sorted(Comparator.reverseOrder()) |
147 | | - .findFirst() |
148 | | - .get(); |
| 144 | + this.latestSupportedProtocolVersion = Collections.max(this.supportedProtocolVersions); |
149 | 145 | } |
150 | 146 |
|
151 | 147 | @Override |
@@ -367,7 +363,7 @@ else if (statusCode == BAD_REQUEST) { |
367 | 363 | }).<McpSchema |
368 | 364 | .JSONRPCMessage>flatMap( |
369 | 365 | jsonrpcMessage -> this.handler.get().apply(Mono.just(jsonrpcMessage))) |
370 | | - .onErrorMap(CompletionException.class, t -> t.getCause()) |
| 366 | + .onErrorMap(CompletionException.class, Throwable::getCause) |
371 | 367 | .onErrorComplete(t -> { |
372 | 368 | this.handleException(t); |
373 | 369 | return true; |
@@ -463,11 +459,11 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) { |
463 | 459 | else { |
464 | 460 | logger.debug("SSE connection established successfully"); |
465 | 461 | } |
466 | | - })).onErrorMap(CompletionException.class, t -> t.getCause()).onErrorComplete().subscribe(); |
| 462 | + })).onErrorMap(CompletionException.class, Throwable::getCause).onErrorComplete().subscribe(); |
467 | 463 |
|
468 | 464 | })).flatMap(responseEvent -> { |
469 | 465 | if (transportSession.markInitialized( |
470 | | - responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElseGet(() -> null))) { |
| 466 | + responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElse(null))) { |
471 | 467 | // Once we have a session, we try to open an async stream for |
472 | 468 | // the server to send notifications and requests out-of-band. |
473 | 469 |
|
@@ -583,7 +579,7 @@ else if (statusCode == BAD_REQUEST) { |
583 | 579 | new RuntimeException("Failed to send message: " + responseEvent)); |
584 | 580 | }) |
585 | 581 | .flatMap(jsonRpcMessage -> this.handler.get().apply(Mono.just(jsonRpcMessage))) |
586 | | - .onErrorMap(CompletionException.class, t -> t.getCause()) |
| 582 | + .onErrorMap(CompletionException.class, Throwable::getCause) |
587 | 583 | .onErrorComplete(t -> { |
588 | 584 | // handle the error first |
589 | 585 | this.handleException(t); |
|
0 commit comments