@@ -55,6 +55,7 @@ function printHelp(): void {
55
55
console . log ( ' greet [name] - Call the greet tool' ) ;
56
56
console . log ( ' multi-greet [name] - Call the multi-greet tool with notifications' ) ;
57
57
console . log ( ' start-notifications [interval] [count] - Start periodic notifications' ) ;
58
+ console . log ( ' run-notifications-tool-with-resumability [interval] [count] - Run notification tool with resumability' ) ;
58
59
console . log ( ' list-prompts - List available prompts' ) ;
59
60
console . log ( ' get-prompt [name] [args] - Get a prompt with optional JSON arguments' ) ;
60
61
console . log ( ' list-resources - List available resources' ) ;
@@ -121,6 +122,13 @@ function commandLoop(): void {
121
122
break ;
122
123
}
123
124
125
+ case 'run-notifications-tool-with-resumability' : {
126
+ const interval = args [ 1 ] ? parseInt ( args [ 1 ] , 10 ) : 2000 ;
127
+ const count = args [ 2 ] ? parseInt ( args [ 2 ] , 10 ) : 10 ;
128
+ await runNotificationsToolWithResumability ( interval , count ) ;
129
+ break ;
130
+ }
131
+
124
132
case 'list-prompts' :
125
133
await listPrompts ( ) ;
126
134
break ;
@@ -333,12 +341,7 @@ async function callTool(name: string, args: Record<string, unknown>): Promise<vo
333
341
} ;
334
342
335
343
console . log ( `Calling tool '${ name } ' with args:` , args ) ;
336
- const onLastEventIdUpdate = ( event : string ) => {
337
- notificationsToolLastEventId = event ;
338
- } ;
339
- const result = await client . request ( request , CallToolResultSchema , {
340
- resumptionToken : notificationsToolLastEventId , onresumptiontoken : onLastEventIdUpdate
341
- } ) ;
344
+ const result = await client . request ( request , CallToolResultSchema ) ;
342
345
343
346
console . log ( 'Tool result:' ) ;
344
347
result . content . forEach ( item => {
@@ -353,6 +356,7 @@ async function callTool(name: string, args: Record<string, unknown>): Promise<vo
353
356
}
354
357
}
355
358
359
+
356
360
async function callGreetTool ( name : string ) : Promise < void > {
357
361
await callTool ( 'greet' , { name } ) ;
358
362
}
@@ -367,6 +371,47 @@ async function startNotifications(interval: number, count: number): Promise<void
367
371
await callTool ( 'start-notification-stream' , { interval, count } ) ;
368
372
}
369
373
374
+ async function runNotificationsToolWithResumability ( interval : number , count : number ) : Promise < void > {
375
+ if ( ! client ) {
376
+ console . log ( 'Not connected to server.' ) ;
377
+ return ;
378
+ }
379
+
380
+ try {
381
+ console . log ( `Starting notification stream with resumability: interval=${ interval } ms, count=${ count || 'unlimited' } ` ) ;
382
+ console . log ( `Using resumption token: ${ notificationsToolLastEventId || 'none' } ` ) ;
383
+
384
+ const request : CallToolRequest = {
385
+ method : 'tools/call' ,
386
+ params : {
387
+ name : 'start-notification-stream' ,
388
+ arguments : { interval, count }
389
+ }
390
+ } ;
391
+
392
+ const onLastEventIdUpdate = ( event : string ) => {
393
+ notificationsToolLastEventId = event ;
394
+ console . log ( `Updated resumption token: ${ event } ` ) ;
395
+ } ;
396
+
397
+ const result = await client . request ( request , CallToolResultSchema , {
398
+ resumptionToken : notificationsToolLastEventId ,
399
+ onresumptiontoken : onLastEventIdUpdate
400
+ } ) ;
401
+
402
+ console . log ( 'Tool result:' ) ;
403
+ result . content . forEach ( item => {
404
+ if ( item . type === 'text' ) {
405
+ console . log ( ` ${ item . text } ` ) ;
406
+ } else {
407
+ console . log ( ` ${ item . type } content:` , item ) ;
408
+ }
409
+ } ) ;
410
+ } catch ( error ) {
411
+ console . log ( `Error starting notification stream: ${ error } ` ) ;
412
+ }
413
+ }
414
+
370
415
async function listPrompts ( ) : Promise < void > {
371
416
if ( ! client ) {
372
417
console . log ( 'Not connected to server.' ) ;
0 commit comments