feat(models): add tool_reference, server_tool_use, and tool_search_tool_result content blocks#108
Open
juslintek wants to merge 1 commit intojwadow:mainfrom
Open
Conversation
…ol_result content blocks Claude Code v2.1.69+ sends tool_reference blocks inside tool_result content when using the deferred tool search feature (ENABLE_TOOL_SEARCH=true). The Anthropic API also returns server_tool_use and tool_search_tool_result blocks for server-side tool search invocations. Without these models, Pydantic validation rejects requests containing these block types with 422 errors. Changes: - Add ToolReferenceContentBlock model (type='tool_reference') - Add ServerToolUseContentBlock model (type='server_tool_use') - Add ToolSearchResultContentBlock model (type='tool_search_tool_result') - Add ToolReferenceContentBlock to ToolResultContentBlock.content union - Add all three to ContentBlock union - Add model_config extra=allow to ToolResultContentBlock for cache_control Related: jwadow#90, jwadow#96, jwadow#82 (different approaches to the same 422 issue)
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
juslintek
added a commit
to juslintek/kiro-gateway
that referenced
this pull request
Mar 21, 2026
When Claude Code sends tools with defer_loading=true (ENABLE_TOOL_SEARCH), the gateway now: 1. Separates deferred tools from active tools 2. Only sends active tools to Kiro API (reducing token usage) 3. Scans messages for tool_reference blocks 4. Expands referenced deferred tools into the active set This enables Claude Code's MCP Tool Search feature to work through the gateway, where the model requests tools on-demand instead of sending all MCP tools in every request. Also skips Anthropic built-in server tools (no input_schema) that the Kiro API cannot handle. Depends on: jwadow#108 (tool search content block models)
Author
|
I have read the CLA and I accept its terms |
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.
What
Adds Pydantic models for three content block types used by Anthropic's tool search feature, preventing 422 validation errors.
Why
Claude Code v2.1.69+ with
ENABLE_TOOL_SEARCH=truesendstool_referenceblocks insidetool_resultcontent. The Anthropic API also returnsserver_tool_useandtool_search_tool_resultblocks for server-side tool search invocations. Without these models, Pydantic rejects requests with 422 errors.Changes
ToolReferenceContentBlockmodel (type='tool_reference')ServerToolUseContentBlockmodel (type='server_tool_use')ToolSearchResultContentBlockmodel (type='tool_search_tool_result')ToolReferenceContentBlocktoToolResultContentBlock.contentunionContentBlockunionmodel_config = {"extra": "allow"}toToolResultContentBlock(forcache_controland future fields)All models use
extra="allow"for forward compatibility with new fields.Related
Overlaps with #90, #96, #82 which address the same 422 issue with different approaches:
ToolReferenceContentBlockonly (subset of this PR)tool_referenceto text markers inextract_text_contentmodel_validatorto sanitize all unknown blocks to textThis PR takes a typed-model approach covering all three tool search block types, preserving type information for downstream processing.
Testing
All 1413 existing tests pass. No behavioral changes — only model acceptance is expanded.