Repository navigation
fix: return binary HTTP tool responses as MCP content - #128
Merged
Merged
Conversation
A generic HTTP tool such as whatsapp__api-call answers tools/call with the upstream body. WAHA's GET /api/files/avelino/<id>.jpeg is image/jpeg. The HTTP transport read every body with Response::text, which decodes as UTF-8 and replaces bytes it cannot represent with U+FFFD, so the image that came back was not the image that was fetched. Text, JSON and SSE still go through Response::text and the JSON-RPC parser. image/* becomes an image block (mimeType + base64 data). Every other non-text type becomes an embedded resource with mimeType and a base64 blob, the tool-result shapes in the 2025-06-18 and 2026-07-28 specs. The CLI's typed Content keeps the nested resource, so a PDF is not dropped on the way to JSON output. Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
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.
A generic HTTP tool such as
whatsapp__api-callanswerstools/callwith the upstream HTTP body. WAHA'sGET /api/files/avelino/<id>.jpegcomes backContent-Type: image/jpegand the file itself. The HTTP transport read every body withResponse::text, which decodes as UTF-8 and replaces bytes it cannot represent with U+FFFD. The image that came back was not the image that was fetched.Text, JSON and SSE still go through
Response::textand the JSON-RPC parser, including charset handling.image/*becomes an image block (mimeType+ base64data). Every other non-text type becomes an embedded resource withmimeTypeand a base64blob. Those are the tool-result shapes in the 2025-06-18 schema (ImageContent.data/mimeType,BlobResourceContents.blob/mimeType) and the same blocks in the 2026-07-28 tools page. Audio stays an embedded resource: the split here is image versus everything else, not a third content type.The CLI's typed
Contentkeeps the nestedresource, so a PDF is not dropped when a direct call is printed as JSON. The proxy already relays the raw result, sowhatsapp__api-callthroughmcp servewas never going through that struct.How it was tested
cargo test: 989 passed, 0 failed.The fixture is
src/transport/fixtures/waha-8x8.jpeg, a real baseline JPEG (JFIF, 8x8, 225 bytes, sha2564f1093edc44e2aff91909bd7a6cb4b09b9b92b8cbc9158a82db68b06a7c49cb9). It is not valid UTF-8.String::from_utf8_lossyon it contains U+FFFD, which is the old bug.transport::body::tests::jpeg_round_trips_as_image_contentdecodes the image block's base64 and checks the bytes and the sha256 against the fixture.transport::http::tests::jpeg_tool_response_round_tripsserves that file asContent-Type: image/jpegontools/callforGET /api/files/avelino/abc.jpegand checks the same sha256 throughHttpTransport.transport::http::tests::pdf_tool_response_is_an_embedded_resourcedoes the same forapplication/pdf(embedded resourceblob, sha256 match,mimeTypeset).transport::http::tests::json_and_text_tool_responses_are_unchangedchecksapplication/jsonandtext/plainstill parse as JSON-RPC text content, not base64.transport::http::tests::non_json_text_is_still_a_parse_errorchecks a non-JSON text body is still a parse error.protocol::tests::test_content_embedded_resource_blob_round_tripschecks the blob survives a typedContentround trip.Not tested
No WAHA instance and no API key here, so this was not run against a live
GET /api/files/avelino/<id>.jpeg. The local stub returns the same content type and a real JPEG body.The content types follow the published spec: the 2025-06-18 schema (
ImageContent,EmbeddedResource,BlobResourceContents) and the 2026-07-28 tools page.Checklist