[BUG] Re-subscribing the Mono returned by listTools/listResources/listResourceTemplates/listPrompts/listRoots duplicates the results
维护者通常 2 天内回复
评估
调研方向
找到列出的五个方法:McpAsyncServerExchange#listRoots(),以及 McpAsyncClient#listTools()、listResources()、listResourceTemplates() 和 listPrompts()。阅读它们对 reduce(seed, accumulator) 的调用,以及用于返回两个 roots 的模拟会话的现有测试 fixture;验证每次订阅都返回相同的结果。完成标准是五个方法都为每次订阅创建新的累加器,并且测试覆盖重复订阅。
由索引模型根据 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 分钟
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
-
难度 2/5 1-3 小时 新手友好度 72/100
quelea-projection/Quelea#711 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
ShaftHQ/SHAFT_ENGINE#6909 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
mudler/parakeet.cpp#99 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
baomidou/mybatis-plus#7185 ·
-
难度 2/5 1-3 小时 新手友好度 66/100