Skip to content

Fix binary resource blob encoding - #3098

Merged
SamMorrowDrums merged 1 commit into
mainfrom
sammorrowdrums-fix-resource-blob-encoding
Aug 19, 2026
Merged

Fix binary resource blob encoding#3098
SamMorrowDrums merged 1 commit into
mainfrom
sammorrowdrums-fix-resource-blob-encoding

Conversation

@SamMorrowDrums

Copy link
Copy Markdown
Collaborator

Summary

Returns raw binary bytes through MCP resource blobs so the Go SDK performs exactly one base64 encoding. The same migration bug is fixed in both get_file_contents and repository resource reads.

Why

Fixes #3097.

Binary resources were manually base64-encoded before being assigned to mcp.ResourceContents.Blob []byte, causing encoding/json to encode the base64 text a second time. Images were corrupted after a spec-compliant single decode and could poison subsequent client conversation turns.

What changed

  • Pass decoded file bytes directly to ResourceContents.Blob in get_file_contents.
  • Pass raw response bytes directly to ResourceContents.Blob in repository resource reads, the only other affected production construction found by the audit.
  • Marshal actual MCP results in regression tests, decode wire blobs once, and assert exact PNG/PDF bytes and PNG magic.
  • Verify unencoded text content remains text while base64-encoded binary content follows the SDK-supported decode path.

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

Binary resource behavior is corrected to the MCP wire contract. Tool names, descriptions, input schemas, and response shapes are unchanged.

Prompts tested (tool changes only)

  • Fetch a PNG with get_file_contents and consume it as an image.
  • Fetch a plain-text repository file with get_file_contents.
  • Read an image through a repository resource URI.

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

The change removes the extra base64 layer and its persistent invalid payload growth; existing 1 MiB resource-link behavior and data exposure are unchanged.

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@SamMorrowDrums
SamMorrowDrums requested a review from a team as a code owner August 19, 2026 09:20
Copilot AI balanced review requested due to automatic review settings August 19, 2026 09:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes double-base64 encoding of binary MCP resources.

Changes:

  • Pass raw binary bytes to MCP resource blobs.
  • Add PNG/PDF wire-format regression coverage.
  • Preserve text-resource behavior.
Show a summary per file
File Description
pkg/github/repository_resource.go Returns raw response bytes as blobs.
pkg/github/repository_resource_test.go Verifies single-encoded PNG resources.
pkg/github/repositories.go Removes manual blob encoding.
pkg/github/repositories_test.go Tests text and binary wire serialization.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@SamMorrowDrums
SamMorrowDrums merged commit 3000061 into main Aug 19, 2026
20 checks passed
@SamMorrowDrums
SamMorrowDrums deleted the sammorrowdrums-fix-resource-blob-encoding branch August 19, 2026 09:32
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.

get_file_contents double-base64-encodes binary files, corrupting all images

2 participants