fix: pass through unknown MCP content block types#590
Open
dotuananh0712 wants to merge 2 commits intoanthropics:mainfrom
Open
fix: pass through unknown MCP content block types#590dotuananh0712 wants to merge 2 commits intoanthropics:mainfrom
dotuananh0712 wants to merge 2 commits intoanthropics:mainfrom
Conversation
Add RateLimitEvent dataclass and parser support for rate_limit_event messages from Claude Code CLI. This prevents MessageParseError from crashing the receive_messages() generator when rate limit events occur. The fix adds: 1. RateLimitEvent type to types.py 2. Handler for 'rate_limit_event' case in message_parser.py Fixes anthropics#583
The MCP tool result handler in query.py only handled 'text' and 'image' content blocks, silently dropping other block types like 'search_result'. This fix adds a fallback that uses model_dump() to pass through unknown block types, enabling RAG applications to use search_result blocks for structured citations. Fixes anthropics#574
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.
Summary
The MCP tool result handler in
query.pyonly handledtextandimagecontent blocks, silently dropping other block types likesearch_result. This prevented using native citations with custom RAG tools.Problem
When a custom
@toolreturns asearch_resultcontent block, the SDK silently dropped it because the handler only checked for:hasattr(item, "text")→ text blockshasattr(item, "data")andhasattr(item, "mimeType")→ image blocksThe
search_resultblock has neither, so it fell through both checks.Solution
Add a fallback using
model_dump()to pass through unknown block types, enabling:search_resultblocks for RAG citationsChanges
In
_internal/query.py, added:Fixes
Fixes #574
This PR was contributed by an AI assistant (OpenCode).