Skip to content

Handle MCP blob resources without MIME types safely - #1836

Open
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/mcp-unknown-mime-blob
Open

Handle MCP blob resources without MIME types safely#1836
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/mcp-unknown-mime-blob

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Prevent MCP binary blob resources with no MIME type from being treated as UTF-8 text.

mcp_resource_to_content() currently considers mime_type=None supported for every MCP resource. For a BlobResourceContents, that causes arbitrary binary bytes to be base64-decoded and then decoded as UTF-8, which can raise UnicodeDecodeError. It can also cause an unknown binary blob to be selected ahead of a later supported resource in the same ReadResourceResult.

Fix

  • treat missing MIME as text only for TextResourceContents;
  • skip no-MIME blob resources while selecting the first representable resource;
  • raise UnsupportedMCPValueError for a directly embedded no-MIME blob instead of leaking a Unicode decoding exception;
  • preserve explicitly typed text/*, PDF, and supported image behavior;
  • include <missing> in the unsupported-resource diagnostic when MIME metadata is absent.

Regression coverage

Adds offline tests covering:

  • an isolated no-MIME binary blob;
  • a no-MIME blob followed by a usable text resource;
  • an embedded no-MIME binary resource;
  • unchanged support for an explicitly text/plain blob.

The change is confined to the hand-maintained MCP conversion helper and its tests.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 16, 2026 22:45
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.

1 participant