@@ -206,6 +206,26 @@ void testListAllTools() {
206206 });
207207 }
208208
209+ @ Test
210+ void testListAllToolsCanBeResubscribed () {
211+ withClient (createMcpTransport (), mcpAsyncClient -> {
212+ Mono <McpSchema .ListToolsResult > listTools = mcpAsyncClient .listTools ();
213+
214+ AtomicInteger firstSubscriptionSize = new AtomicInteger ();
215+ StepVerifier .create (mcpAsyncClient .initialize ().then (listTools )).consumeNextWith (result -> {
216+ firstSubscriptionSize .set (result .tools ().size ());
217+ assertThat (result .tools ()).isNotEmpty ();
218+ }).verifyComplete ();
219+
220+ // The same Mono must be safe to subscribe again: every subscription has to
221+ // start from an empty accumulator instead of appending to the previous
222+ // result.
223+ StepVerifier .create (listTools )
224+ .consumeNextWith (result -> assertThat (result .tools ()).hasSize (firstSubscriptionSize .get ()))
225+ .verifyComplete ();
226+ });
227+ }
228+
209229 @ Test
210230 void testListAllToolsReturnsImmutableList () {
211231 withClient (createMcpTransport (), mcpAsyncClient -> {
@@ -378,6 +398,26 @@ void testListAllResources() {
378398 });
379399 }
380400
401+ @ Test
402+ void testListAllResourcesCanBeResubscribed () {
403+ withClient (createMcpTransport (), mcpAsyncClient -> {
404+ Mono <McpSchema .ListResourcesResult > listResources = mcpAsyncClient .listResources ();
405+
406+ AtomicInteger firstSubscriptionSize = new AtomicInteger ();
407+ StepVerifier .create (mcpAsyncClient .initialize ().then (listResources )).consumeNextWith (result -> {
408+ firstSubscriptionSize .set (result .resources ().size ());
409+ assertThat (result .resources ()).isNotEmpty ();
410+ }).verifyComplete ();
411+
412+ // The same Mono must be safe to subscribe again: every subscription has to
413+ // start from an empty accumulator instead of appending to the previous
414+ // result.
415+ StepVerifier .create (listResources )
416+ .consumeNextWith (result -> assertThat (result .resources ()).hasSize (firstSubscriptionSize .get ()))
417+ .verifyComplete ();
418+ });
419+ }
420+
381421 @ Test
382422 void testListAllResourcesReturnsImmutableList () {
383423 withClient (createMcpTransport (), mcpAsyncClient -> {
@@ -443,6 +483,26 @@ void testListAllPrompts() {
443483 });
444484 }
445485
486+ @ Test
487+ void testListAllPromptsCanBeResubscribed () {
488+ withClient (createMcpTransport (), mcpAsyncClient -> {
489+ Mono <McpSchema .ListPromptsResult > listPrompts = mcpAsyncClient .listPrompts ();
490+
491+ AtomicInteger firstSubscriptionSize = new AtomicInteger ();
492+ StepVerifier .create (mcpAsyncClient .initialize ().then (listPrompts )).consumeNextWith (result -> {
493+ firstSubscriptionSize .set (result .prompts ().size ());
494+ assertThat (result .prompts ()).isNotEmpty ();
495+ }).verifyComplete ();
496+
497+ // The same Mono must be safe to subscribe again: every subscription has to
498+ // start from an empty accumulator instead of appending to the previous
499+ // result.
500+ StepVerifier .create (listPrompts )
501+ .consumeNextWith (result -> assertThat (result .prompts ()).hasSize (firstSubscriptionSize .get ()))
502+ .verifyComplete ();
503+ });
504+ }
505+
446506 @ Test
447507 void testListAllPromptsReturnsImmutableList () {
448508 withClient (createMcpTransport (), mcpAsyncClient -> {
@@ -636,6 +696,26 @@ void testListAllResourceTemplates() {
636696 });
637697 }
638698
699+ @ Test
700+ void testListAllResourceTemplatesCanBeResubscribed () {
701+ withClient (createMcpTransport (), mcpAsyncClient -> {
702+ Mono <McpSchema .ListResourceTemplatesResult > listResourceTemplates = mcpAsyncClient .listResourceTemplates ();
703+
704+ AtomicInteger firstSubscriptionSize = new AtomicInteger ();
705+ StepVerifier .create (mcpAsyncClient .initialize ().then (listResourceTemplates )).consumeNextWith (result -> {
706+ firstSubscriptionSize .set (result .resourceTemplates ().size ());
707+ assertThat (result .resourceTemplates ()).isNotEmpty ();
708+ }).verifyComplete ();
709+
710+ // The same Mono must be safe to subscribe again: every subscription has to
711+ // start from an empty accumulator instead of appending to the previous
712+ // result.
713+ StepVerifier .create (listResourceTemplates )
714+ .consumeNextWith (result -> assertThat (result .resourceTemplates ()).hasSize (firstSubscriptionSize .get ()))
715+ .verifyComplete ();
716+ });
717+ }
718+
639719 @ Test
640720 void testListAllResourceTemplatesReturnsImmutableList () {
641721 withClient (createMcpTransport (), mcpAsyncClient -> {
0 commit comments