@@ -4624,4 +4624,120 @@ describe("elicitInput()", () => {
4624
4624
text : "Bulk resource 1 content"
4625
4625
} ) ;
4626
4626
} ) ;
4627
+
4628
+ test ( "registerPrompts() should register multiple prompts with single notification" , async ( ) => {
4629
+ const mcpServer = new McpServer ( {
4630
+ name : "test server" ,
4631
+ version : "1.0" ,
4632
+ } ) ;
4633
+ const notifications : Notification [ ] = [ ]
4634
+ const client = new Client ( {
4635
+ name : "test client" ,
4636
+ version : "1.0" ,
4637
+ } ) ;
4638
+ client . fallbackNotificationHandler = async ( notification ) => {
4639
+ notifications . push ( notification )
4640
+ }
4641
+
4642
+ // Register a single prompt first to test notification behavior
4643
+ mcpServer . registerPrompt (
4644
+ "initial" ,
4645
+ {
4646
+ title : "Initial Prompt" ,
4647
+ description : "An initial prompt" ,
4648
+ argsSchema : { input : z . string ( ) }
4649
+ } ,
4650
+ ( { input } ) => ( {
4651
+ messages : [ {
4652
+ role : "user" as const ,
4653
+ content : { type : "text" as const , text : `Initial: ${ input } ` }
4654
+ } ]
4655
+ } )
4656
+ ) ;
4657
+
4658
+ const [ clientTransport , serverTransport ] =
4659
+ InMemoryTransport . createLinkedPair ( ) ;
4660
+
4661
+ await Promise . all ( [
4662
+ client . connect ( clientTransport ) ,
4663
+ mcpServer . connect ( serverTransport ) ,
4664
+ ] ) ;
4665
+
4666
+ // Clear any initial notifications
4667
+ notifications . length = 0 ;
4668
+
4669
+ // Register multiple prompts in bulk
4670
+ const registeredPrompts = mcpServer . registerPrompts ( [
4671
+ {
4672
+ name : "bulk1" ,
4673
+ config : {
4674
+ title : "Bulk Prompt One" ,
4675
+ description : "First bulk prompt" ,
4676
+ argsSchema : { input : z . string ( ) }
4677
+ } ,
4678
+ callback : ( args , _extra ) => ( {
4679
+ messages : [ {
4680
+ role : "user" as const ,
4681
+ content : { type : "text" as const , text : `Bulk 1: ${ args . input } ` }
4682
+ } ]
4683
+ } )
4684
+ } ,
4685
+ {
4686
+ name : "bulk2" ,
4687
+ config : {
4688
+ title : "Bulk Prompt Two" ,
4689
+ description : "Second bulk prompt" ,
4690
+ argsSchema : { value : z . string ( ) }
4691
+ } ,
4692
+ callback : ( args , _extra ) => ( {
4693
+ messages : [ {
4694
+ role : "assistant" as const ,
4695
+ content : { type : "text" as const , text : `Bulk 2: ${ args . value } ` }
4696
+ } ]
4697
+ } )
4698
+ }
4699
+ ] ) ;
4700
+
4701
+ // Yield event loop to let notifications process
4702
+ await new Promise ( process . nextTick ) ;
4703
+
4704
+ // Should return array of registered prompts
4705
+ expect ( registeredPrompts ) . toHaveLength ( 2 ) ;
4706
+ expect ( registeredPrompts [ 0 ] . title ) . toBe ( "Bulk Prompt One" ) ;
4707
+ expect ( registeredPrompts [ 1 ] . title ) . toBe ( "Bulk Prompt Two" ) ;
4708
+
4709
+ // Should have sent exactly ONE notification for all prompts
4710
+ expect ( notifications ) . toHaveLength ( 1 ) ;
4711
+ expect ( notifications [ 0 ] ) . toMatchObject ( {
4712
+ method : "notifications/prompts/list_changed" ,
4713
+ } ) ;
4714
+
4715
+ // Test list prompts shows all prompts
4716
+ const promptsResult = await client . request (
4717
+ {
4718
+ method : "prompts/list" ,
4719
+ params : { }
4720
+ } ,
4721
+ ListPromptsResultSchema ,
4722
+ ) ;
4723
+
4724
+ const promptNames = promptsResult . prompts . map ( p => p . name ) . sort ( ) ;
4725
+ expect ( promptNames ) . toEqual ( [ "bulk1" , "bulk2" , "initial" ] ) ;
4726
+
4727
+ // Test that a prompt actually works
4728
+ const getResult = await client . request (
4729
+ {
4730
+ method : "prompts/get" ,
4731
+ params : {
4732
+ name : "bulk1" ,
4733
+ arguments : { input : "test" }
4734
+ }
4735
+ } ,
4736
+ GetPromptResultSchema ,
4737
+ ) ;
4738
+ expect ( getResult . messages [ 0 ] ) . toMatchObject ( {
4739
+ role : "user" ,
4740
+ content : { type : "text" , text : "Bulk 1: test" }
4741
+ } ) ;
4742
+ } ) ;
4627
4743
} ) ;
0 commit comments