@@ -514,6 +514,76 @@ test("tracks tool progress", async () => {
514
514
} ) ;
515
515
} ) ;
516
516
517
+ test ( "reports multiple progress updates without buffering" , async ( ) => {
518
+ await runWithTestServer ( {
519
+ run : async ( { client } ) => {
520
+ const progressCalls : Array < { progress : number ; total : number } > = [ ] ;
521
+ const onProgress = vi . fn ( ( data ) => {
522
+ progressCalls . push ( data ) ;
523
+ } ) ;
524
+
525
+ await client . callTool (
526
+ {
527
+ arguments : {
528
+ steps : 3 ,
529
+ } ,
530
+ name : "progress-test" ,
531
+ } ,
532
+ undefined ,
533
+ {
534
+ onprogress : onProgress ,
535
+ } ,
536
+ ) ;
537
+
538
+ expect ( onProgress ) . toHaveBeenCalledTimes ( 4 ) ;
539
+ expect ( progressCalls ) . toEqual ( [
540
+ { progress : 0 , total : 100 } ,
541
+ { progress : 50 , total : 100 } ,
542
+ { progress : 90 , total : 100 } ,
543
+ { progress : 100 , total : 100 } , // This was previously lost due to buffering
544
+ ] ) ;
545
+ } ,
546
+ server : async ( ) => {
547
+ const server = new FastMCP ( {
548
+ name : "Test" ,
549
+ version : "1.0.0" ,
550
+ } ) ;
551
+
552
+ server . addTool ( {
553
+ description : "Test tool for progress buffering fix" ,
554
+ execute : async ( args , { reportProgress } ) => {
555
+ const { steps } = args ;
556
+
557
+ // Initial
558
+ await reportProgress ( { progress : 0 , total : 100 } ) ;
559
+
560
+ for ( let i = 1 ; i <= steps ; i ++ ) {
561
+ await delay ( 50 ) ; // Small delay to simulate work
562
+
563
+ if ( i === 1 ) {
564
+ await reportProgress ( { progress : 50 , total : 100 } ) ;
565
+ } else if ( i === 2 ) {
566
+ await reportProgress ( { progress : 90 , total : 100 } ) ;
567
+ }
568
+ }
569
+
570
+ // This was the critical test case that failed before the fix
571
+ // because there's no await after it, causing it to be buffered
572
+ await reportProgress ( { progress : 100 , total : 100 } ) ;
573
+
574
+ return "Progress test completed" ;
575
+ } ,
576
+ name : "progress-test" ,
577
+ parameters : z . object ( {
578
+ steps : z . number ( ) ,
579
+ } ) ,
580
+ } ) ;
581
+
582
+ return server ;
583
+ } ,
584
+ } ) ;
585
+ } ) ;
586
+
517
587
test ( "sets logging levels" , async ( ) => {
518
588
await runWithTestServer ( {
519
589
run : async ( { client, session } ) => {
0 commit comments