99 isJSONRPCResultResponse ,
1010 JSONRPCMessageSchema ,
1111 normalizeHeaders ,
12- SdkError ,
13- SdkErrorCode
12+ SdkErrorCode ,
13+ StreamableHTTPError
1414} from '@modelcontextprotocol/core' ;
1515import { EventSourceParserStream } from 'eventsource-parser/stream' ;
1616
@@ -273,9 +273,13 @@ export class StreamableHTTPClientTransport implements Transport {
273273 }
274274 await response . text ?.( ) . catch ( ( ) => { } ) ;
275275 if ( isAuthRetry ) {
276- throw new SdkError ( SdkErrorCode . ClientHttpAuthentication , 'Server returned 401 after re-authentication' , {
277- status : 401
278- } ) ;
276+ throw new StreamableHTTPError (
277+ SdkErrorCode . ClientHttpAuthentication ,
278+ 'Server returned 401 after re-authentication' ,
279+ {
280+ status : 401
281+ }
282+ ) ;
279283 }
280284 throw new UnauthorizedError ( ) ;
281285 }
@@ -288,10 +292,14 @@ export class StreamableHTTPClientTransport implements Transport {
288292 return ;
289293 }
290294
291- throw new SdkError ( SdkErrorCode . ClientHttpFailedToOpenStream , `Failed to open SSE stream: ${ response . statusText } ` , {
292- status : response . status ,
293- statusText : response . statusText
294- } ) ;
295+ throw new StreamableHTTPError (
296+ SdkErrorCode . ClientHttpFailedToOpenStream ,
297+ `Failed to open SSE stream: ${ response . statusText } ` ,
298+ {
299+ status : response . status ,
300+ statusText : response . statusText
301+ }
302+ ) ;
295303 }
296304
297305 this . _handleSseStream ( response . body , options , true ) ;
@@ -581,9 +589,13 @@ export class StreamableHTTPClientTransport implements Transport {
581589 }
582590 await response . text ?.( ) . catch ( ( ) => { } ) ;
583591 if ( isAuthRetry ) {
584- throw new SdkError ( SdkErrorCode . ClientHttpAuthentication , 'Server returned 401 after re-authentication' , {
585- status : 401
586- } ) ;
592+ throw new StreamableHTTPError (
593+ SdkErrorCode . ClientHttpAuthentication ,
594+ 'Server returned 401 after re-authentication' ,
595+ {
596+ status : 401
597+ }
598+ ) ;
587599 }
588600 throw new UnauthorizedError ( ) ;
589601 }
@@ -598,7 +610,7 @@ export class StreamableHTTPClientTransport implements Transport {
598610
599611 // Check if we've already tried upscoping with this header to prevent infinite loops.
600612 if ( this . _lastUpscopingHeader === wwwAuthHeader ) {
601- throw new SdkError ( SdkErrorCode . ClientHttpForbidden , 'Server returned 403 after trying upscoping' , {
613+ throw new StreamableHTTPError ( SdkErrorCode . ClientHttpForbidden , 'Server returned 403 after trying upscoping' , {
602614 status : 403 ,
603615 text
604616 } ) ;
@@ -629,7 +641,7 @@ export class StreamableHTTPClientTransport implements Transport {
629641 }
630642 }
631643
632- throw new SdkError ( SdkErrorCode . ClientHttpNotImplemented , `Error POSTing to endpoint: ${ text } ` , {
644+ throw new StreamableHTTPError ( SdkErrorCode . ClientHttpNotImplemented , `Error POSTing to endpoint: ${ text } ` , {
633645 status : response . status ,
634646 text
635647 } ) ;
@@ -675,7 +687,7 @@ export class StreamableHTTPClientTransport implements Transport {
675687 }
676688 } else {
677689 await response . text ?.( ) . catch ( ( ) => { } ) ;
678- throw new SdkError ( SdkErrorCode . ClientHttpUnexpectedContent , `Unexpected content type: ${ contentType } ` , {
690+ throw new StreamableHTTPError ( SdkErrorCode . ClientHttpUnexpectedContent , `Unexpected content type: ${ contentType } ` , {
679691 contentType
680692 } ) ;
681693 }
@@ -725,10 +737,14 @@ export class StreamableHTTPClientTransport implements Transport {
725737 // We specifically handle 405 as a valid response according to the spec,
726738 // meaning the server does not support explicit session termination
727739 if ( ! response . ok && response . status !== 405 ) {
728- throw new SdkError ( SdkErrorCode . ClientHttpFailedToTerminateSession , `Failed to terminate session: ${ response . statusText } ` , {
729- status : response . status ,
730- statusText : response . statusText
731- } ) ;
740+ throw new StreamableHTTPError (
741+ SdkErrorCode . ClientHttpFailedToTerminateSession ,
742+ `Failed to terminate session: ${ response . statusText } ` ,
743+ {
744+ status : response . status ,
745+ statusText : response . statusText
746+ }
747+ ) ;
732748 }
733749
734750 this . _sessionId = undefined ;
0 commit comments