wy471x opened a new pull request, #7040: URL: https://github.com/apache/shenyu/pull/7040
Fixes #6640 <!-- Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request. --> Make sure that: - [X] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [X] You submit test cases (unit or integration tests) that back your changes. - [X] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`. ## Summary `ShenyuMcpResponseDecorator.writeWith` completed the response future inside `doOnNext`, so the very first DataBuffer determined the captured result. Any response delivered in more than one chunk was therefore truncated to the first chunk. This PR defers future completion until the whole response body stream has completed (with `setComplete()` kept as the empty/no-body fallback), so tool-call results now contain the full accumulated body. ### Changes: 1. `ShenyuMcpResponseDecorator.writeWith` (ShenyuMcpResponseDecorator.java:57) — `doOnNext` now only appends each chunk to the shared `body`; a `doOnComplete(() -> completeFuture())` was added so the future is completed only after all chunks have been accumulated. 2. Added private `ShenyuMcpResponseDecorator.completeFuture()` (ShenyuMcpResponseDecorator.java:87) — extracts the synchronized, duplicate-completion-safe logic shared by the stream-completion path and `setComplete()`. 3. `ShenyuMcpResponseDecorator.setComplete()` (ShenyuMcpResponseDecorator.java:80) — now delegates to `completeFuture()` before calling the delegate, preserving the no-write/empty-response fallback. ### Test Cases: - `ShenyuMcpResponseDecoratorTest.testWriteWithCompletesFutureWithAllChunks` — feeds two DataBuffers (`part-1,` + `part-2`) through `writeWith` and asserts the future receives the full `part-1,part-2` body, not just the first chunk. - `ShenyuMcpResponseDecoratorTest.testSetCompleteCompletesFutureWithAccumulatedBody` — verifies the `setComplete()` fallback still completes the future. ## Verification - `./mvnw -o -pl shenyu-plugin/shenyu-plugin-mcp-server verify` on JDK 21 passed: checkstyle, RAT, and all module tests (including the new `ShenyuMcpResponseDecoratorTest`). close #6640 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
