@@ -424,6 +424,70 @@ test('should validate elicitation response against requested schema', async () =
424
424
} ) ;
425
425
} ) ;
426
426
427
+ test ( 'should allow custom enum values when allowCustom is true' , async ( ) => {
428
+ const server = new Server (
429
+ {
430
+ name : 'test server' ,
431
+ version : '1.0'
432
+ } ,
433
+ {
434
+ capabilities : {
435
+ prompts : { } ,
436
+ resources : { } ,
437
+ tools : { } ,
438
+ logging : { }
439
+ } ,
440
+ enforceStrictCapabilities : true
441
+ }
442
+ ) ;
443
+
444
+ const client = new Client (
445
+ {
446
+ name : 'test client' ,
447
+ version : '1.0'
448
+ } ,
449
+ {
450
+ capabilities : {
451
+ elicitation : { }
452
+ }
453
+ }
454
+ ) ;
455
+
456
+ client . setRequestHandler ( ElicitRequestSchema , ( ) => ( {
457
+ action : 'accept' ,
458
+ content : {
459
+ priority : 'urgent'
460
+ }
461
+ } ) ) ;
462
+
463
+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
464
+
465
+ await Promise . all ( [ client . connect ( clientTransport ) , server . connect ( serverTransport ) ] ) ;
466
+
467
+ await expect (
468
+ server . elicitInput ( {
469
+ message : 'Select a priority' ,
470
+ requestedSchema : {
471
+ type : 'object' ,
472
+ properties : {
473
+ priority : {
474
+ type : 'string' ,
475
+ enum : [ 'low' , 'medium' , 'high' ] ,
476
+ allowCustom : true ,
477
+ description : 'Choose from presets or enter a custom value'
478
+ }
479
+ } ,
480
+ required : [ 'priority' ]
481
+ }
482
+ } )
483
+ ) . resolves . toEqual ( {
484
+ action : 'accept' ,
485
+ content : {
486
+ priority : 'urgent'
487
+ }
488
+ } ) ;
489
+ } ) ;
490
+
427
491
test ( 'should reject elicitation response with invalid data' , async ( ) => {
428
492
const server = new Server (
429
493
{
@@ -493,6 +557,63 @@ test('should reject elicitation response with invalid data', async () => {
493
557
) . rejects . toThrow ( / d o e s n o t m a t c h r e q u e s t e d s c h e m a / ) ;
494
558
} ) ;
495
559
560
+ test ( 'should reject custom enum values when allowCustom is false' , async ( ) => {
561
+ const server = new Server (
562
+ {
563
+ name : 'test server' ,
564
+ version : '1.0'
565
+ } ,
566
+ {
567
+ capabilities : {
568
+ prompts : { } ,
569
+ resources : { } ,
570
+ tools : { } ,
571
+ logging : { }
572
+ } ,
573
+ enforceStrictCapabilities : true
574
+ }
575
+ ) ;
576
+
577
+ const client = new Client (
578
+ {
579
+ name : 'test client' ,
580
+ version : '1.0'
581
+ } ,
582
+ {
583
+ capabilities : {
584
+ elicitation : { }
585
+ }
586
+ }
587
+ ) ;
588
+
589
+ client . setRequestHandler ( ElicitRequestSchema , ( ) => ( {
590
+ action : 'accept' ,
591
+ content : {
592
+ priority : 'urgent'
593
+ }
594
+ } ) ) ;
595
+
596
+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
597
+
598
+ await Promise . all ( [ client . connect ( clientTransport ) , server . connect ( serverTransport ) ] ) ;
599
+
600
+ await expect (
601
+ server . elicitInput ( {
602
+ message : 'Select a priority' ,
603
+ requestedSchema : {
604
+ type : 'object' ,
605
+ properties : {
606
+ priority : {
607
+ type : 'string' ,
608
+ enum : [ 'low' , 'medium' , 'high' ]
609
+ }
610
+ } ,
611
+ required : [ 'priority' ]
612
+ }
613
+ } )
614
+ ) . rejects . toThrow ( / E l i c i t a t i o n r e s p o n s e c o n t e n t d o e s n o t m a t c h r e q u e s t e d s c h e m a / ) ;
615
+ } ) ;
616
+
496
617
test ( 'should allow elicitation reject and cancel without validation' , async ( ) => {
497
618
const server = new Server (
498
619
{
0 commit comments