@@ -63,6 +63,16 @@ export type TaskManagerOptions = {
6363 * If undefined, the queue size is unbounded.
6464 */
6565 maxTaskQueueSize ?: number ;
66+ /**
67+ * Checks if task creation is supported for a given request method.
68+ * Wired by Client/Server to enforce capability negotiation.
69+ */
70+ assertTaskCapability ?: ( method : string ) => void ;
71+ /**
72+ * Checks if task handling is supported for a given request method.
73+ * Wired by Client/Server to enforce capability negotiation.
74+ */
75+ assertTaskHandlerCapability ?: ( method : string ) => void ;
6676} ;
6777
6878/**
@@ -94,6 +104,8 @@ export interface TaskContext {
94104/**
95105 * Internal interface that TaskManager needs from the Protocol host
96106 * for sending outbound requests and notifications.
107+ *
108+ * @internal Not intended for external use. Will be removed from public exports.
97109 */
98110export interface TaskManagerHost {
99111 request < T extends AnySchema > ( request : Request , resultSchema : T , options ?: RequestOptions ) : Promise < SchemaOutput < T > > ;
@@ -136,6 +148,13 @@ export class TaskManager {
136148 this . _host = host ;
137149 }
138150
151+ private get _requireHost ( ) : TaskManagerHost {
152+ if ( ! this . _host ) {
153+ throw new McpError ( ErrorCode . InternalError , 'TaskManager is not bound to a Protocol host — call bind() first' ) ;
154+ }
155+ return this . _host ;
156+ }
157+
139158 get taskStore ( ) : TaskStore | undefined {
140159 return this . _taskStore ;
141160 }
@@ -151,17 +170,13 @@ export class TaskManager {
151170 return this . _taskMessageQueue ;
152171 }
153172
154- /**
155- * Checks if task creation is supported for a given request method.
156- * Set by Client/Server to wire capability checking.
157- */
158- assertTaskCapability ?: ( method : string ) => void ;
173+ get assertTaskCapability ( ) : ( ( method : string ) => void ) | undefined {
174+ return this . _options . assertTaskCapability ;
175+ }
159176
160- /**
161- * Checks if task handling is supported for a given request method.
162- * Set by Client/Server to wire capability checking.
163- */
164- assertTaskHandlerCapability ?: ( method : string ) => void ;
177+ get assertTaskHandlerCapability ( ) : ( ( method : string ) => void ) | undefined {
178+ return this . _options . assertTaskHandlerCapability ;
179+ }
165180
166181 // =========================================================================
167182 // Public API methods (previously protected on Protocol)
@@ -176,7 +191,7 @@ export class TaskManager {
176191 resultSchema : T ,
177192 options ?: RequestOptions
178193 ) : AsyncGenerator < ResponseMessage < SchemaOutput < T > > , void , void > {
179- const host = this . _host ! ;
194+ const host = this . _requireHost ;
180195 const { task } = options ?? { } ;
181196
182197 // For non-task requests, just yield the result
@@ -247,23 +262,23 @@ export class TaskManager {
247262 }
248263
249264 async getTask ( params : GetTaskRequest [ 'params' ] , options ?: RequestOptions ) : Promise < GetTaskResult > {
250- return this . _host ! . request ( { method : 'tasks/get' , params } , GetTaskResultSchema , options ) ;
265+ return this . _requireHost . request ( { method : 'tasks/get' , params } , GetTaskResultSchema , options ) ;
251266 }
252267
253268 async getTaskResult < T extends AnySchema > (
254269 params : GetTaskPayloadRequest [ 'params' ] ,
255270 resultSchema : T ,
256271 options ?: RequestOptions
257272 ) : Promise < SchemaOutput < T > > {
258- return this . _host ! . request ( { method : 'tasks/result' , params } , resultSchema , options ) ;
273+ return this . _requireHost . request ( { method : 'tasks/result' , params } , resultSchema , options ) ;
259274 }
260275
261276 async listTasks ( params ?: { cursor ?: string } , options ?: RequestOptions ) : Promise < SchemaOutput < typeof ListTasksResultSchema > > {
262- return this . _host ! . request ( { method : 'tasks/list' , params } , ListTasksResultSchema , options ) ;
277+ return this . _requireHost . request ( { method : 'tasks/list' , params } , ListTasksResultSchema , options ) ;
263278 }
264279
265280 async cancelTask ( params : { taskId : string } , options ?: RequestOptions ) : Promise < SchemaOutput < typeof CancelTaskResultSchema > > {
266- return this . _host ! . request ( { method : 'tasks/cancel' , params } , CancelTaskResultSchema , options ) ;
281+ return this . _requireHost . request ( { method : 'tasks/cancel' , params } , CancelTaskResultSchema , options ) ;
267282 }
268283
269284 // =========================================================================
0 commit comments