-
-
Notifications
You must be signed in to change notification settings - Fork 210
BE: Handle Flux response bodies in MCP tool call results #1491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi elvis-cai! 👋
Welcome, and thank you for opening your first PR in the repo!
Please wait for triaging by our maintainers.
Please take a look at our contributing guide.
germanosin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contribution. Please check my comment
| return Mono.just(this.callToolResult(response.getBody())); | ||
| Object body = response.getBody(); | ||
| // Handle Flux response bodies by collecting them into a list | ||
| if (body instanceof Flux<?> flux) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to see this trick in the callToolResult method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the quick review, good point, updated
What changes did you make? (Give an overview)
Problem:
When MCP tools return Mono<ResponseEntity<Flux<?>>>, the response body contains a Flux stream that wasn't being properly handled, which
could cause issues when trying to serialize the result for the MCP client.
Solution:
Modified the reponseToCallResult method to detect when the ResponseEntity body is a Flux and automatically collect it into a list before
converting to CallToolResult. This ensures streaming responses are properly materialized before being serialized.
Changes:
This allows MCP tools to return streaming responses (Flux) wrapped in ResponseEntity while ensuring they're properly handled and sent
back to the MCP client as serialized lists.
fix (#1454)
Is there anything you'd like reviewers to focus on?
How Has This Been Tested? (put an "x" (case-sensitive!) next to an item)
Checklist (put an "x" (case-sensitive!) next to all the items, otherwise the build will fail)
Check out Contributing and Code of Conduct
A picture of a cute animal (not mandatory but encouraged)