Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#1,174 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@kamisheng 已经在做这个了。

开始于 2026年10月12日。

  • #1175 来自 @kamisheng —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
api, backend

调研方向

找到列出的五个方法: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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/java-sdk 的其他 Issue

查看 modelcontextprotocol/java-sdk 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。