Skip to content

feat(rust): support binary tool results#1222

Merged
stephentoub merged 2 commits intogithub:mainfrom
cschleiden:cschleiden/rust-binary-tools
May 8, 2026
Merged

feat(rust): support binary tool results#1222
stephentoub merged 2 commits intogithub:mainfrom
cschleiden:cschleiden/rust-binary-tools

Conversation

@cschleiden
Copy link
Copy Markdown
Member

Rust tool results need to preserve binary payloads from MCP tool calls so callers can return images and binary resources to the LLM without collapsing structured results into text.

This updates the Rust SDK coverage around binary tool results by ensuring resource blobs default to application/octet-stream when mimeType is missing or empty, and by adding focused tests for the public binaryResultsForLlm wire shape plus MCP image, resource blob, mixed text/binary, and no-binary conversion behavior.

Validation:

  • cd rust && cargo test --all-features
  • cargo +nightly-2026-04-14 fmt --check
  • cargo clippy --all-features --all-targets -- -D warnings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 7, 2026 04:01
@cschleiden cschleiden requested a review from a team as a code owner May 7, 2026 04:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Rust SDK’s handling of MCP tool results that include binary payloads, ensuring binary resources are preserved for LLM consumption (instead of being forced into text-only results).

Changes:

  • Default MCP resource.blob mimeType to application/octet-stream when mimeType is missing or an empty string.
  • Add Rust type-level serialization tests to confirm the binaryResultsForLlm wire shape is emitted correctly (and omitted when None).
  • Expand MCP conversion tests to cover image content, resource blob content, mixed text/binary, and no-binary cases.
Show a summary per file
File Description
rust/src/types.rs Adds focused serialization tests for ToolResultExpanded.binaryResultsForLlm wire output.
rust/src/tool.rs Treats empty mimeType as missing (defaults to application/octet-stream) and adds targeted MCP conversion tests for binary content.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@stephentoub
Copy link
Copy Markdown
Collaborator

Thanks, @cschleiden. I think the Python and Node.js SDKs have the same bug. Would you mind fixing those in this PR as well?

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub merged commit b0d1c8e into github:main May 8, 2026
23 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants