Skip to content

Commit 12e3883

Browse files
committed
Revert "WebClientStreamableHttpTransport: use Spring-5 compatible methods (modelcontextprotocol#649)"
This reverts commit 67f8eab.
1 parent e6045f7 commit 12e3883

File tree

1 file changed

+12
-37
lines changed

1 file changed

+12
-37
lines changed

mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
313313

314314
// The spec mentions only ACCEPTED, but the existing SDKs can return
315315
// 200 OK for notifications
316-
if (is2xx(response)) {
316+
if (response.statusCode().is2xxSuccessful()) {
317317
Optional<MediaType> contentType = response.headers().contentType();
318318
long contentLength = response.headers().contentLength().orElse(-1);
319319
// Existing SDKs consume notifications with no response body nor
@@ -397,15 +397,14 @@ private Flux<McpSchema.JSONRPCMessage> extractError(ClientResponse response, Str
397397
}
398398
catch (IOException ex) {
399399
toPropagate = new McpTransportException("Sending request failed, " + e.getMessage(), e);
400-
logger.debug("Received content together with {} HTTP code response: {}", response.rawStatusCode(),
401-
body);
400+
logger.debug("Received content together with {} HTTP code response: {}", response.statusCode(), body);
402401
}
403402

404403
// Some implementations can return 400 when presented with a
405404
// session id that it doesn't know about, so we will
406405
// invalidate the session
407406
// https://github.com/modelcontextprotocol/typescript-sdk/issues/389
408-
if (isBadRequest(responseException)) {
407+
if (responseException.getStatusCode().isSameCodeAs(HttpStatus.BAD_REQUEST)) {
409408
if (!sessionRepresentation.equals(MISSING_SESSION_ID)) {
410409
return Mono.error(new McpTransportSessionNotFoundException(sessionRepresentation, toPropagate));
411410
}
@@ -425,8 +424,16 @@ private Flux<McpSchema.JSONRPCMessage> eventStream(McpTransportStream<Disposable
425424
return Flux.from(sessionStream.consumeSseStream(idWithMessages));
426425
}
427426

427+
private static boolean isNotFound(ClientResponse response) {
428+
return response.statusCode().isSameCodeAs(HttpStatus.NOT_FOUND);
429+
}
430+
431+
private static boolean isNotAllowed(ClientResponse response) {
432+
return response.statusCode().isSameCodeAs(HttpStatus.METHOD_NOT_ALLOWED);
433+
}
434+
428435
private static boolean isEventStream(ClientResponse response) {
429-
return is2xx(response) && response.headers().contentType().isPresent()
436+
return response.statusCode().is2xxSuccessful() && response.headers().contentType().isPresent()
430437
&& response.headers().contentType().get().isCompatibleWith(MediaType.TEXT_EVENT_STREAM);
431438
}
432439

@@ -605,36 +612,4 @@ public WebClientStreamableHttpTransport build() {
605612

606613
}
607614

608-
/**
609-
* Needed for Spring 5 compatibility
610-
*/
611-
@SuppressWarnings("deprecation")
612-
private static boolean isBadRequest(final WebClientResponseException responseException) {
613-
return responseException.getRawStatusCode() == HttpStatus.BAD_REQUEST.value();
614-
}
615-
616-
/**
617-
* Needed for Spring 5 compatibility
618-
*/
619-
@SuppressWarnings("deprecation")
620-
private static boolean isNotFound(ClientResponse response) {
621-
return response.rawStatusCode() == HttpStatus.NOT_FOUND.value();
622-
}
623-
624-
/**
625-
* Needed for Spring 5 compatibility
626-
*/
627-
@SuppressWarnings("deprecation")
628-
private static boolean isNotAllowed(ClientResponse response) {
629-
return response.rawStatusCode() == HttpStatus.METHOD_NOT_ALLOWED.value();
630-
}
631-
632-
/**
633-
* Needed for Spring 5 compatibility
634-
*/
635-
@SuppressWarnings("deprecation")
636-
private static boolean is2xx(final ClientResponse response) {
637-
return response.rawStatusCode() >= 200 && response.rawStatusCode() < 300;
638-
}
639-
640615
}

0 commit comments

Comments
 (0)