@@ -184,6 +184,7 @@ export class HttpClientTransport implements Transport {
184
184
async send ( message : JSONRPCMessage ) : Promise < void > {
185
185
// Create a new abort controller for this request
186
186
this . _abortController = new AbortController ( ) ;
187
+ let response : Response | undefined ;
187
188
188
189
try {
189
190
const commonHeaders = await this . _commonHeaders ( ) ;
@@ -201,7 +202,7 @@ export class HttpClientTransport implements Transport {
201
202
signal : this . _abortController . signal ,
202
203
} ;
203
204
204
- const response = await fetch ( this . _url , init ) ;
205
+ response = await fetch ( this . _url , init ) ;
205
206
206
207
if ( ! response . ok ) {
207
208
if ( response . status === 401 && this . _authProvider ) {
@@ -220,7 +221,8 @@ export class HttpClientTransport implements Transport {
220
221
// Handle streaming responses
221
222
const contentType = response . headers . get ( "content-type" ) ;
222
223
if ( contentType ?. includes ( "text/event-stream" ) ) {
223
- await this . _handleStreamingResponse ( response ) ;
224
+ // Don't await streaming response handling - it will continue in the background
225
+ this . _handleStreamingResponse ( response ) ;
224
226
return ;
225
227
}
226
228
@@ -236,8 +238,10 @@ export class HttpClientTransport implements Transport {
236
238
this . onerror ?.( error as Error ) ;
237
239
throw error ;
238
240
} finally {
239
- // Clean up the abort controller if it wasn't used
240
- if ( this . _abortController ) {
241
+ // Only clean up the abort controller for non-streaming responses
242
+ if (
243
+ ! response ?. headers . get ( "content-type" ) ?. includes ( "text/event-stream" )
244
+ ) {
241
245
this . _abortController = undefined ;
242
246
}
243
247
}
0 commit comments