feat: add document block support in tool results #470
+111
−3
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.
Summary
Add support for document content (e.g., PDFs) in MCP tool results.
Problem
Currently, when a tool returns a document block in its result content, it is silently dropped because the SDK only handles
textandimagecontent types. This causes Claude to hallucinate content instead of reading the actual document.Solution
Use MCP's
EmbeddedResourcewithBlobResourceContentsto transport document data through the MCP layer:1.
__init__.py- Convert document → EmbeddedResource:2.
query.py- Convert EmbeddedResource → Anthropic document format:This enables native PDF support in tool results as documented in the Anthropic API:
https://platform.claude.com/docs/en/build-with-claude/pdf-support
Real-world use case
We encountered this issue in production where a tool fetches PDF attachments from an email system. The tool returned document blocks, but they were silently dropped, causing Claude to hallucinate the PDF content. Our workaround was to render PDFs as images, which works but is suboptimal.
Test Plan
test_document_content_support)🤖 Generated with Claude Code