@@ -10,7 +10,6 @@ import type {
1010 JSONRPCResponse ,
1111 JSONRPCResultResponse ,
1212 Notification ,
13- RelatedTaskMetadata ,
1413 Request ,
1514 RequestId ,
1615 Result ,
@@ -33,8 +32,8 @@ import {
3332 TaskStatusNotificationSchema
3433} from '../types/types.js' ;
3534import type { AnySchema , SchemaOutput } from '../util/zodCompat.js' ;
36- import type { ResponseMessage } from './responseMessage.js' ;
3735import type { NotificationOptions , RequestOptions } from './protocol.js' ;
36+ import type { ResponseMessage } from './responseMessage.js' ;
3837
3938// ============================================================================
4039// Types
@@ -217,12 +216,14 @@ export class TaskManager {
217216 yield { type : 'result' , result } ;
218217 break ;
219218 }
220- case 'failed' :
219+ case 'failed' : {
221220 yield { type : 'error' , error : new McpError ( ErrorCode . InternalError , `Task ${ taskId } failed` ) } ;
222221 break ;
223- case 'cancelled' :
222+ }
223+ case 'cancelled' : {
224224 yield { type : 'error' , error : new McpError ( ErrorCode . InternalError , `Task ${ taskId } was cancelled` ) } ;
225225 break ;
226+ }
226227 }
227228 return ;
228229 }
@@ -299,11 +300,7 @@ export class TaskManager {
299300 resolver ( message as JSONRPCResultResponse ) ;
300301 } else {
301302 const errorMessage = message as JSONRPCErrorResponse ;
302- resolver ( new McpError (
303- errorMessage . error . code ,
304- errorMessage . error . message ,
305- errorMessage . error . data
306- ) ) ;
303+ resolver ( new McpError ( errorMessage . error . code , errorMessage . error . message , errorMessage . error . data ) ) ;
307304 }
308305 } else {
309306 const messageType = queuedMessage . type === 'response' ? 'Response' : 'Error' ;
@@ -345,15 +342,15 @@ export class TaskManager {
345342 return await handleTaskResult ( ) ;
346343 }
347344
348- async handleListTasks ( cursor : string | undefined , sessionId ?: string ) : Promise < { tasks : Task [ ] ; nextCursor ?: string ; _meta : Record < string , unknown > } > {
345+ async handleListTasks (
346+ cursor : string | undefined ,
347+ sessionId ?: string
348+ ) : Promise < { tasks : Task [ ] ; nextCursor ?: string ; _meta : Record < string , unknown > } > {
349349 try {
350350 const { tasks, nextCursor } = await this . _requireTaskStore . listTasks ( cursor , sessionId ) ;
351351 return { tasks, nextCursor, _meta : { } } ;
352352 } catch ( error ) {
353- throw new McpError (
354- ErrorCode . InvalidParams ,
355- `Failed to list tasks: ${ error instanceof Error ? error . message : String ( error ) } `
356- ) ;
353+ throw new McpError ( ErrorCode . InvalidParams , `Failed to list tasks: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
357354 }
358355 }
359356
@@ -445,7 +442,10 @@ export class TaskManager {
445442 /**
446443 * Extracts task-related context from an inbound request.
447444 */
448- extractInboundTaskContext ( request : JSONRPCRequest , sessionId ?: string ) : {
445+ extractInboundTaskContext (
446+ request : JSONRPCRequest ,
447+ sessionId ?: string
448+ ) : {
449449 relatedTaskId ?: string ;
450450 taskCreationParams ?: TaskCreationParams ;
451451 taskContext ?: TaskContext ;
@@ -484,8 +484,7 @@ export class TaskManager {
484484 originalSendNotification : ( notification : Notification , options ?: NotificationOptions ) => Promise < void >
485485 ) : ( notification : Notification ) => Promise < void > {
486486 return async ( notification : Notification ) => {
487- const notificationOptions : NotificationOptions = { } ;
488- notificationOptions . relatedTask = { taskId : relatedTaskId } ;
487+ const notificationOptions : NotificationOptions = { relatedTask : { taskId : relatedTaskId } } ;
489488 await originalSendNotification ( notification , notificationOptions ) ;
490489 } ;
491490 }
@@ -590,19 +589,13 @@ export class TaskManager {
590589 ) : Promise < boolean > {
591590 if ( ! relatedTaskId || ! this . _taskMessageQueue ) return false ;
592591
593- if ( isJSONRPCErrorResponse ( message ) ) {
594- await this . _enqueueTaskMessage (
595- relatedTaskId ,
596- { type : 'error' , message, timestamp : Date . now ( ) } ,
597- sessionId
598- ) ;
599- } else {
600- await this . _enqueueTaskMessage (
601- relatedTaskId ,
602- { type : 'response' , message : message as JSONRPCResultResponse , timestamp : Date . now ( ) } ,
603- sessionId
604- ) ;
605- }
592+ await ( isJSONRPCErrorResponse ( message )
593+ ? this . _enqueueTaskMessage ( relatedTaskId , { type : 'error' , message, timestamp : Date . now ( ) } , sessionId )
594+ : this . _enqueueTaskMessage (
595+ relatedTaskId ,
596+ { type : 'response' , message : message as JSONRPCResultResponse , timestamp : Date . now ( ) } ,
597+ sessionId
598+ ) ) ;
606599 return true ;
607600 }
608601
@@ -616,9 +609,7 @@ export class TaskManager {
616609 return {
617610 createTask : async taskParams => {
618611 if ( ! request ) throw new Error ( 'No request provided' ) ;
619- return await taskStore . createTask (
620- taskParams , request . id , { method : request . method , params : request . params } , sessionId
621- ) ;
612+ return await taskStore . createTask ( taskParams , request . id , { method : request . method , params : request . params } , sessionId ) ;
622613 } ,
623614 getTask : async taskId => {
624615 const task = await taskStore . getTask ( taskId , sessionId ) ;
@@ -630,7 +621,8 @@ export class TaskManager {
630621 const task = await taskStore . getTask ( taskId , sessionId ) ;
631622 if ( task ) {
632623 const notification : TaskStatusNotification = TaskStatusNotificationSchema . parse ( {
633- method : 'notifications/tasks/status' , params : task
624+ method : 'notifications/tasks/status' ,
625+ params : task
634626 } ) ;
635627 await host ?. notification ( notification as Notification ) ;
636628 if ( isTerminal ( task . status ) ) {
@@ -654,7 +646,8 @@ export class TaskManager {
654646 const updatedTask = await taskStore . getTask ( taskId , sessionId ) ;
655647 if ( updatedTask ) {
656648 const notification : TaskStatusNotification = TaskStatusNotificationSchema . parse ( {
657- method : 'notifications/tasks/status' , params : updatedTask
649+ method : 'notifications/tasks/status' ,
650+ params : updatedTask
658651 } ) ;
659652 await host ?. notification ( notification as Notification ) ;
660653 if ( isTerminal ( updatedTask . status ) ) {
@@ -714,10 +707,14 @@ export class TaskManager {
714707 return ;
715708 }
716709 const timeoutId = setTimeout ( resolve , interval ) ;
717- signal . addEventListener ( 'abort' , ( ) => {
718- clearTimeout ( timeoutId ) ;
719- reject ( new McpError ( ErrorCode . InvalidRequest , 'Request cancelled' ) ) ;
720- } , { once : true } ) ;
710+ signal . addEventListener (
711+ 'abort' ,
712+ ( ) => {
713+ clearTimeout ( timeoutId ) ;
714+ reject ( new McpError ( ErrorCode . InvalidRequest , 'Request cancelled' ) ) ;
715+ } ,
716+ { once : true }
717+ ) ;
721718 } ) ;
722719 }
723720
0 commit comments