GH-4542: Collect all Flux elements in async MCP tool callbacks
Summary
- Fixes
AbstractAsyncMcpToolMethodCallback.convertToCallToolResult()which was calling.next()onFluxreturn types, silently discarding all elements except the first - When an async MCP tool method returns
Flux<T>, all emitted elements are now collected and returned as separateCallToolResultcontent entries - This affects both
AsyncMcpToolMethodCallback(stateful) andAsyncStatelessMcpToolMethodCallback(stateless) because both extendAbstractAsyncMcpToolMethodCallback - Updated existing tests that asserted the broken one-element behavior to verify all elements are returned
Before: Flux.just("a", "b", "c") → CallToolResult with 1 content item ("a")
After: Flux.just("a", "b", "c") → CallToolResult with 3 content items ("a", "b", "c")
Fixes: #4542
Test plan
- [ ]
./mvnw -pl mcp/mcp-annotations test— all 1349 tests pass - [ ]
testMultipleFluxToolnow asserts 3 content items instead of 1 - [ ]
testGetToolSpecificationsWithFluxHandlingnow asserts 3 content items in bothAsyncMcpToolProviderTestsandAsyncStatelessMcpToolProviderTests - [ ]
testToolWithFluxReturnTypeinAsyncMcpToolProviderTestsnow asserts all 3 items
The failing "MCP transport integration tests" check is unrelated to this PR's changes. The failures are in WebClientStreamableHttpTransportIT.testCloseInitialized and testCloseUninitialized within the mcp/mcp-transport-webflux module — a module this PR does not modify.
This PR only changes files in mcp/mcp-annotations. The same "MCP transport integration tests" workflow passed successfully on main a few hours ago (run 26394342907), so this appears to be a pre-existing intermittent failure in the transport layer.
Thank you for taking the time to migrate and build on this — really appreciate it!