@@ -250,7 +250,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
250250 const totalElapsed = Date . now ( ) - info . startTime ;
251251 if ( info . maxTotalTimeout && totalElapsed >= info . maxTotalTimeout ) {
252252 this . _timeoutInfo . delete ( messageId ) ;
253- throw new McpError ( ErrorCode . RequestTimeout , 'Maximum total timeout exceeded' , {
253+ throw McpError . fromError ( ErrorCode . RequestTimeout , 'Maximum total timeout exceeded' , {
254254 maxTotalTimeout : info . maxTotalTimeout ,
255255 totalElapsed
256256 } ) ;
@@ -313,7 +313,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
313313 this . _transport = undefined ;
314314 this . onclose ?.( ) ;
315315
316- const error = new McpError ( ErrorCode . ConnectionClosed , 'Connection closed' ) ;
316+ const error = McpError . fromError ( ErrorCode . ConnectionClosed , 'Connection closed' ) ;
317317 for ( const handler of responseHandlers . values ( ) ) {
318318 handler ( error ) ;
319319 }
@@ -567,7 +567,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
567567 } ) ;
568568
569569 const timeout = options ?. timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC ;
570- const timeoutHandler = ( ) => cancel ( new McpError ( ErrorCode . RequestTimeout , 'Request timed out' , { timeout } ) ) ;
570+ const timeoutHandler = ( ) => cancel ( McpError . fromError ( ErrorCode . RequestTimeout , 'Request timed out' , { timeout } ) ) ;
571571
572572 this . _setupTimeout ( messageId , timeout , options ?. maxTotalTimeout , timeoutHandler , options ?. resetTimeoutOnProgress ?? false ) ;
573573
0 commit comments