fix: reassemble server-streaming google.api.HttpBody tool results instead of returning the last chunk - #11
Draft
hanxiaop wants to merge 1 commit into
Draft
fix: reassemble server-streaming google.api.HttpBody tool results instead of returning the last chunk#11hanxiaop wants to merge 1 commit into
hanxiaop wants to merge 1 commit into
Conversation
…of returning the last chunk
hanxiaop
marked this pull request as draft
August 11, 2026 07:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Server-streaming tools return a summary result whose payload is the last message received, which is right for watch-style streams but wrong for google.api.HttpBody, where the stream is one document split into chunks. The generator now detects an RPC that streams HttpBody and emits a handler that stitches the chunks back together, in order, into a single tool result. The first chunk's content type picks the shape: image and audio become MCP media content, everything else must be valid UTF-8 and comes back as text, and a binary payload fails the call instead of returning mangled bytes. These tools advertise no output schema, and their progress events report cumulative bytes rather than a message count.
Reassembly is capped at 4 MiB by default so one call can't buffer unbounded data. The cap is tunable per server with protomcp.WithHTTPBodyDocumentLimit, and a document over the limit fails the call rather than being truncated. The greeter example adds a DownloadTranscript RPC with end-to-end tests covering the text, image, audio, binary-rejection, and size-limit paths.