@@ -308,7 +308,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
308308
309309 // The spec mentions only ACCEPTED, but the existing SDKs can return
310310 // 200 OK for notifications
311- if (response . statusCode (). is2xxSuccessful ( )) {
311+ if (is2xx ( response )) {
312312 Optional <MediaType > contentType = response .headers ().contentType ();
313313 long contentLength = response .headers ().contentLength ().orElse (-1 );
314314 // Existing SDKs consume notifications with no response body nor
@@ -392,14 +392,15 @@ private Flux<McpSchema.JSONRPCMessage> extractError(ClientResponse response, Str
392392 }
393393 catch (IOException ex ) {
394394 toPropagate = new McpTransportException ("Sending request failed, " + e .getMessage (), e );
395- logger .debug ("Received content together with {} HTTP code response: {}" , response .statusCode (), body );
395+ logger .debug ("Received content together with {} HTTP code response: {}" , response .rawStatusCode (),
396+ body );
396397 }
397398
398399 // Some implementations can return 400 when presented with a
399400 // session id that it doesn't know about, so we will
400401 // invalidate the session
401402 // https://github.com/modelcontextprotocol/typescript-sdk/issues/389
402- if (responseException . getStatusCode (). isSameCodeAs ( HttpStatus . BAD_REQUEST )) {
403+ if (isBadRequest ( responseException )) {
403404 if (!sessionRepresentation .equals (MISSING_SESSION_ID )) {
404405 return Mono .error (new McpTransportSessionNotFoundException (sessionRepresentation , toPropagate ));
405406 }
@@ -419,16 +420,8 @@ private Flux<McpSchema.JSONRPCMessage> eventStream(McpTransportStream<Disposable
419420 return Flux .from (sessionStream .consumeSseStream (idWithMessages ));
420421 }
421422
422- private static boolean isNotFound (ClientResponse response ) {
423- return response .statusCode ().isSameCodeAs (HttpStatus .NOT_FOUND );
424- }
425-
426- private static boolean isNotAllowed (ClientResponse response ) {
427- return response .statusCode ().isSameCodeAs (HttpStatus .METHOD_NOT_ALLOWED );
428- }
429-
430423 private static boolean isEventStream (ClientResponse response ) {
431- return response . statusCode (). is2xxSuccessful ( ) && response .headers ().contentType ().isPresent ()
424+ return is2xx ( response ) && response .headers ().contentType ().isPresent ()
432425 && response .headers ().contentType ().get ().isCompatibleWith (MediaType .TEXT_EVENT_STREAM );
433426 }
434427
@@ -607,4 +600,36 @@ public WebClientStreamableHttpTransport build() {
607600
608601 }
609602
603+ /**
604+ * Needed for Spring 5 compatibility
605+ */
606+ @ SuppressWarnings ("deprecation" )
607+ private static boolean isBadRequest (final WebClientResponseException responseException ) {
608+ return responseException .getRawStatusCode () == HttpStatus .BAD_REQUEST .value ();
609+ }
610+
611+ /**
612+ * Needed for Spring 5 compatibility
613+ */
614+ @ SuppressWarnings ("deprecation" )
615+ private static boolean isNotFound (ClientResponse response ) {
616+ return response .rawStatusCode () == HttpStatus .NOT_FOUND .value ();
617+ }
618+
619+ /**
620+ * Needed for Spring 5 compatibility
621+ */
622+ @ SuppressWarnings ("deprecation" )
623+ private static boolean isNotAllowed (ClientResponse response ) {
624+ return response .rawStatusCode () == HttpStatus .METHOD_NOT_ALLOWED .value ();
625+ }
626+
627+ /**
628+ * Needed for Spring 5 compatibility
629+ */
630+ @ SuppressWarnings ("deprecation" )
631+ private static boolean is2xx (final ClientResponse response ) {
632+ return response .rawStatusCode () >= 200 && response .rawStatusCode () < 300 ;
633+ }
634+
610635}
0 commit comments