[BUG] Re-subscribing the Mono returned by listTools/listResources/listResourceTemplates/listPrompts/listRoots duplicates the results
メンテナーはふだん 2 日以内に返信
評価
調査の方向性
列挙された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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/java-sdk のほかの issue
-
HttpServletStreamableServerTransportProvider: GET stream sends no status or headers until the first event対応中かも @karthiksenv が 9 日前に担当しました。 オープンarea/server area/transport P3
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
modelcontextprotocol/java-sdk#1155 ·
メンテナーはふだん 2 日以内に返信
-
Client request handlers that complete empty send no JSON-RPC response対応中かも @1fanwang が 39 日前に担当しました。 オープンarea/client bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/java-sdk#1124 · コメント 5 件 ·
メンテナーはふだん 2 日以内に返信
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities対応中かも @1yuxiangJ が 54 日前に担当しました。 オープンbug P2 ready for work
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
modelcontextprotocol/java-sdk#1086 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Reject listRoots if not supported by client, without sending any request対応中かも @nikita-kibitkin が 78 日前に担当しました。 オープンenhancement good first issue P3
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/java-sdk#1067 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
StdioClientTransport missing explicit UTF-8 charset in InputStreamReader (same issue as #295, but on client side)対応中かも @suryateja-g13 が 149 日前に担当しました。 オープンbug P2 ready for work
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/java-sdk#898 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
modelcontextprotocol/java-sdk の issue をすべて見る
似ている issue
-
needs-area-label
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
quelea-projection/Quelea#711 ·
-
bug pdd
難易度 2/5 1時間未満 初心者へのやさしさ 67/100
objectionary/eo#9450 ·
メンテナーはふだん 1 日以内に返信
-
[EC2] DescribeAvailabilityZones should return real AWS error for unknown zone name対応中かも @omatheusmesmo が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
area: core good first issue type: enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100