@@ -2076,28 +2076,32 @@ describe('Task-based execution', () => {
20762076
20772077 await Promise . all ( [ client . connect ( clientTransport ) , server . connect ( serverTransport ) ] ) ;
20782078
2079- // Use callTool to create a task
2080- await client . callTool ( { name : 'test-tool' , arguments : { } } , CallToolResultSchema , {
2079+ // Use callToolStream to create a task and capture the task ID
2080+ let taskId : string | undefined ;
2081+ const stream = client . callToolStream ( { name : 'test-tool' , arguments : { } } , CallToolResultSchema , {
20812082 task : {
20822083 ttl : 60000
20832084 }
20842085 } ) ;
20852086
2087+ for await ( const message of stream ) {
2088+ if ( message . type === 'taskCreated' ) {
2089+ taskId = message . task . taskId ;
2090+ }
2091+ }
2092+
2093+ expect ( taskId ) . toBeDefined ( ) ;
2094+
20862095 // Wait for the task to complete
20872096 await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
20882097
2089- // Get the task ID from the task list since it's generated automatically
2090- const taskList = await client . listTasks ( ) ;
2091- expect ( taskList . tasks . length ) . toBeGreaterThan ( 0 ) ;
2092- const taskId = taskList . tasks [ 0 ] . taskId ;
2093-
20942098 // Verify we can retrieve the task
2095- const task = await client . getTask ( { taskId } ) ;
2099+ const task = await client . getTask ( { taskId : taskId ! } ) ;
20962100 expect ( task ) . toBeDefined ( ) ;
20972101 expect ( task . status ) . toBe ( 'completed' ) ;
20982102
20992103 // Verify we can retrieve the result
2100- const result = await client . getTaskResult ( { taskId } , CallToolResultSchema ) ;
2104+ const result = await client . getTaskResult ( { taskId : taskId ! } , CallToolResultSchema ) ;
21012105 expect ( result . content ) . toEqual ( [ { type : 'text' , text : 'Tool executed successfully!' } ] ) ;
21022106
21032107 // Cleanup
@@ -2299,26 +2303,30 @@ describe('Task-based execution', () => {
22992303
23002304 await Promise . all ( [ client . connect ( clientTransport ) , server . connect ( serverTransport ) ] ) ;
23012305
2302- // Call tool WITH task creation
2303- await client . callTool ( { name : 'collect-info' , arguments : { } } , CallToolResultSchema , {
2306+ // Call tool WITH task creation using callToolStream to capture task ID
2307+ let taskId : string | undefined ;
2308+ const stream = client . callToolStream ( { name : 'collect-info' , arguments : { } } , CallToolResultSchema , {
23042309 task : {
23052310 ttl : 60000
23062311 }
23072312 } ) ;
23082313
2314+ for await ( const message of stream ) {
2315+ if ( message . type === 'taskCreated' ) {
2316+ taskId = message . task . taskId ;
2317+ }
2318+ }
2319+
2320+ expect ( taskId ) . toBeDefined ( ) ;
2321+
23092322 // Wait for completion
23102323 await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
23112324
23122325 // Verify the nested elicitation request was made (related-task metadata is no longer automatically attached)
23132326 expect ( capturedElicitRequest ) . toBeDefined ( ) ;
23142327
2315- // Get the task ID from the task list since it's generated automatically
2316- const taskList = await client . listTasks ( ) ;
2317- expect ( taskList . tasks . length ) . toBeGreaterThan ( 0 ) ;
2318- const taskId = taskList . tasks [ 0 ] . taskId ;
2319-
23202328 // Verify tool result was correct
2321- const result = await client . getTaskResult ( { taskId } , CallToolResultSchema ) ;
2329+ const result = await client . getTaskResult ( { taskId : taskId ! } , CallToolResultSchema ) ;
23222330 expect ( result . content ) . toEqual ( [
23232331 {
23242332 type : 'text' ,
0 commit comments