Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,174 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
api, backend

Hướng nghiên cứu

Tìm năm phương thức được liệt kê: McpAsyncServerExchange#listRoots() và McpAsyncClient#listTools(), listResources(), listResourceTemplates(), listPrompts(). Đọc các lời gọi reduce(seed, accumulator) của chúng và fixture kiểm thử hiện có cho một phiên được mô phỏng trả về hai roots; xác minh mỗi lần đăng ký đều trả về cùng kết quả. Hoàn tất khi cả năm phương thức tạo một bộ tích lũy mới cho mỗi lần đăng ký và các kiểm thử bao phủ những lần đăng ký lặp lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Java
Star
3.7k
Fork
1.2k
Merge trung bình
3 giờ 38 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/java-sdk

Tất cả issue của modelcontextprotocol/java-sdk

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.