@@ -300,7 +300,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
300300
301301 // The spec mentions only ACCEPTED, but the existing SDKs can return
302302 // 200 OK for notifications
303- if (response . statusCode (). is2xxSuccessful ( )) {
303+ if (is2xx ( response )) {
304304 Optional <MediaType > contentType = response .headers ().contentType ();
305305 long contentLength = response .headers ().contentLength ().orElse (-1 );
306306 // Existing SDKs consume notifications with no response body nor
@@ -384,14 +384,15 @@ private Flux<McpSchema.JSONRPCMessage> extractError(ClientResponse response, Str
384384 }
385385 catch (IOException ex ) {
386386 toPropagate = new McpTransportException ("Sending request failed, " + e .getMessage (), e );
387- logger .debug ("Received content together with {} HTTP code response: {}" , response .statusCode (), body );
387+ logger .debug ("Received content together with {} HTTP code response: {}" , response .rawStatusCode (),
388+ body );
388389 }
389390
390391 // Some implementations can return 400 when presented with a
391392 // session id that it doesn't know about, so we will
392393 // invalidate the session
393394 // https://github.com/modelcontextprotocol/typescript-sdk/issues/389
394- if (responseException . getStatusCode (). isSameCodeAs ( HttpStatus . BAD_REQUEST )) {
395+ if (isBadRequest ( responseException )) {
395396 if (!sessionRepresentation .equals (MISSING_SESSION_ID )) {
396397 return Mono .error (new McpTransportSessionNotFoundException (sessionRepresentation , toPropagate ));
397398 }
@@ -411,16 +412,8 @@ private Flux<McpSchema.JSONRPCMessage> eventStream(McpTransportStream<Disposable
411412 return Flux .from (sessionStream .consumeSseStream (idWithMessages ));
412413 }
413414
414- private static boolean isNotFound (ClientResponse response ) {
415- return response .statusCode ().isSameCodeAs (HttpStatus .NOT_FOUND );
416- }
417-
418- private static boolean isNotAllowed (ClientResponse response ) {
419- return response .statusCode ().isSameCodeAs (HttpStatus .METHOD_NOT_ALLOWED );
420- }
421-
422415 private static boolean isEventStream (ClientResponse response ) {
423- return response . statusCode (). is2xxSuccessful ( ) && response .headers ().contentType ().isPresent ()
416+ return is2xx ( response ) && response .headers ().contentType ().isPresent ()
424417 && response .headers ().contentType ().get ().isCompatibleWith (MediaType .TEXT_EVENT_STREAM );
425418 }
426419
@@ -572,4 +565,32 @@ public WebClientStreamableHttpTransport build() {
572565
573566 }
574567
568+ /**
569+ * Needed for Spring 5 compatibility
570+ */
571+ private static boolean isBadRequest (final WebClientResponseException responseException ) {
572+ return responseException .getRawStatusCode () == HttpStatus .BAD_REQUEST .value ();
573+ }
574+
575+ /**
576+ * Needed for Spring 5 compatibility
577+ */
578+ private static boolean isNotFound (ClientResponse response ) {
579+ return response .rawStatusCode () == HttpStatus .NOT_FOUND .value ();
580+ }
581+
582+ /**
583+ * Needed for Spring 5 compatibility
584+ */
585+ private static boolean isNotAllowed (ClientResponse response ) {
586+ return response .rawStatusCode () == HttpStatus .METHOD_NOT_ALLOWED .value ();
587+ }
588+
589+ /**
590+ * Needed for Spring 5 compatibility
591+ */
592+ private static boolean is2xx (final ClientResponse response ) {
593+ return response .rawStatusCode () >= 200 && response .rawStatusCode () < 300 ;
594+ }
595+
575596}
0 commit comments