@@ -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 (response . statusCode (). is2xxSuccessful ( )) {
316+ if (is2xx ( response )) {
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,14 +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 . statusCode ( ), body );
400+ logger .debug ("Received content together with {} HTTP code response: {}" , getStatusCode ( response ), body );
401401 }
402402
403403 // Some implementations can return 400 when presented with a
404404 // session id that it doesn't know about, so we will
405405 // invalidate the session
406406 // https://github.com/modelcontextprotocol/typescript-sdk/issues/389
407- if (responseException . getStatusCode (). isSameCodeAs ( HttpStatus . BAD_REQUEST )) {
407+ if (isBadRequest ( responseException )) {
408408 if (!sessionRepresentation .equals (MISSING_SESSION_ID )) {
409409 return Mono .error (new McpTransportSessionNotFoundException (sessionRepresentation , toPropagate ));
410410 }
@@ -424,16 +424,8 @@ private Flux<McpSchema.JSONRPCMessage> eventStream(McpTransportStream<Disposable
424424 return Flux .from (sessionStream .consumeSseStream (idWithMessages ));
425425 }
426426
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-
435427 private static boolean isEventStream (ClientResponse response ) {
436- return response . statusCode (). is2xxSuccessful ( ) && response .headers ().contentType ().isPresent ()
428+ return is2xx ( response ) && response .headers ().contentType ().isPresent ()
437429 && response .headers ().contentType ().get ().isCompatibleWith (MediaType .TEXT_EVENT_STREAM );
438430 }
439431
@@ -612,4 +604,39 @@ public WebClientStreamableHttpTransport build() {
612604
613605 }
614606
607+ /**
608+ * Needed for Spring 5 compatibility, user can extend and override this method
609+ */
610+ protected int getStatusCode (final ClientResponse response ) {
611+ return response .statusCode ().value ();
612+ }
613+
614+ /**
615+ * Needed for Spring 5 compatibility, user can extend and override this method
616+ */
617+ protected boolean isBadRequest (final WebClientResponseException responseException ) {
618+ return responseException .getStatusCode ().isSameCodeAs (HttpStatus .BAD_REQUEST );
619+ }
620+
621+ /**
622+ * Needed for Spring 5 compatibility, user can extend and override this method
623+ */
624+ protected boolean isNotFound (ClientResponse response ) {
625+ return response .statusCode ().isSameCodeAs (HttpStatus .NOT_FOUND );
626+ }
627+
628+ /**
629+ * Needed for Spring 5 compatibility, user can extend and override this method
630+ */
631+ protected boolean isNotAllowed (ClientResponse response ) {
632+ return response .statusCode ().isSameCodeAs (HttpStatus .NOT_FOUND );
633+ }
634+
635+ /**
636+ * Needed for Spring 5 compatibility, user can extend and override this method
637+ */
638+ private static boolean is2xx (final ClientResponse response ) {
639+ return response .statusCode ().is2xxSuccessful ();
640+ }
641+
615642}
0 commit comments