Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[BUG] Re-subscribing the Mono returned by listTools/listResources/listResourceTemplates/listPrompts/listRoots duplicates the results

オープン 初心者向け
#1,174 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@kamisheng がすでに取り組んでいます。

2026年10月12日 から。

  • #1175 @kamisheng による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
api, backend

調査の方向性

列挙された5つのメソッド、McpAsyncServerExchange#listRoots() と McpAsyncClient#listTools()、listResources()、listResourceTemplates()、listPrompts() を見つけてください。それらの reduce(seed, accumulator) の呼び出しと、2つのrootsを返すモックセッション用の既存のテストfixtureを読み、各購読が同じ結果を返すことを確認してください。5つすべてのメソッドが購読ごとに新しいアキュムレーターを作成し、テストが繰り返しの購読をカバーすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Bug description

The Mono returned by these methods is not safe to subscribe more than once: each
subscription appends to the same mutable accumulator created when the method was called,
so the results grow on every subscription.

Mono<McpSchema.ListRootsResult> listRoots = exchange.listRoots();
listRoots.block().roots().size();   // 2
listRoots.block().roots().size();   // 4  <- duplicated
listRoots.block().roots().size();   // 6

Affected methods (all use reduce(seed, accumulator) with a seed created at assembly
time):

  • McpAsyncServerExchange#listRoots()
  • McpAsyncClient#listTools()
  • McpAsyncClient#listResources()
  • McpAsyncClient#listResourceTemplates()
  • McpAsyncClient#listPrompts()
Steps to reproduce

Using the existing test fixture (McpAsyncServerExchange with a mocked session that
returns a single page of 2 roots):

Mono<McpSchema.ListRootsResult> listRoots = exchange.listRoots();

System.out.println(listRoots.block().roots().size());   // 2
System.out.println(listRoots.block().roots().size());   // 4
System.out.println(listRoots.block().roots().size());   // 6
Expected behavior

Every subscription starts from an empty accumulator and returns the same result (2 / 2 /
2). Re-subscribing a Mono is a supported Reactor pattern (retry, repeat, cache, reusing
the Mono in several downstream branches), and concurrent subscriptions currently race on
the shared ArrayList too.

Suggested fix

Flux#reduceWith(Supplier, BiFunction) creates the seed per subscription:

.reduceWith(() -> McpSchema.ListRootsResult.builder(new ArrayList<>()).build(),
        (allRootsResult, result) -> { ... })

.reduceWith(ArrayList<McpSchema.Tool>::new, (accumulated, result) -> { ... })

Happy to open a PR with the five call sites updated and tests if you agree with the
approach.

主要言語
Java
スター
3.7k
フォーク
1.2k
平均マージ
3時間 38分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/java-sdk のほかの issue

modelcontextprotocol/java-sdk の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。