Skip to content

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
juslintek:feat/tool-search-content-blocks
Open

feat(models): add tool_reference, server_tool_use, and tool_search_tool_result content blocks#108
juslintek wants to merge 1 commit intojwadow:mainfrom
juslintek:feat/tool-search-content-blocks

Conversation

@juslintek
Copy link
Copy Markdown

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=true sends tool_reference blocks inside tool_result content. The Anthropic API also returns server_tool_use and tool_search_tool_result blocks for server-side tool search invocations. Without these models, Pydantic rejects requests 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 and 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:

This 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.

…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)
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 21, 2026

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

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)
@juslintek
Copy link
Copy Markdown
Author

I have read the CLA and I accept its terms

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