Skip to content

fix(streaming): fire BetaInputJsonEvent for server_tool_use blocks#1446

Open
abhicris wants to merge 1 commit intoanthropics:mainfrom
abhicris:fix/server-tool-use-input-json-event
Open

fix(streaming): fire BetaInputJsonEvent for server_tool_use blocks#1446
abhicris wants to merge 1 commit intoanthropics:mainfrom
abhicris:fix/server-tool-use-input-json-event

Conversation

@abhicris
Copy link
Copy Markdown

Closes #1421.

Bug

`lib/streaming/_beta_messages.py` fires `BetaInputJsonEvent` for `tool_use` and `mcp_tool_use` content blocks but not for `server_tool_use`, even though the API streams `input_json_delta` events for server-side tools the same way.

This was inconsistent with the accumulator's own `TRACKS_TOOL_INPUT` tuple in the same file, which does include `BetaServerToolUseBlock` — so the SDK accumulates the streamed input into `content_block.input` correctly, but never fires the parsed event to consumers. Forces consumers to bypass `BetaInputJsonEvent` and match on the raw `BetaRawContentBlockDeltaEvent` with a `BetaInputJSONDelta` delta.

Fix

Add `"server_tool_use"` to the content-block type check on line 368:

```diff
elif event.delta.type == "input_json_delta":

  •    if content_block.type == "tool_use" or content_block.type == "mcp_tool_use":
    
  •    if content_block.type in ("tool_use", "mcp_tool_use", "server_tool_use"):
           events_to_fire.append(
               build(
                   BetaInputJsonEvent,
                   type="input_json",
                   partial_json=event.delta.partial_json,
                   snapshot=content_block.input,
               )
           )
    

```

(Plus a comment explaining the consistency with `TRACKS_TOOL_INPUT`.)

`+8 / -1`. Affects only the parsed event surface — the accumulator's state already tracks server_tool_use correctly. Now `tool_search_tool_regex` / `web_search` / future server-side tools' input streams will surface as `BetaInputJsonEvent` to consumers using the stream helpers.


Contributed by kcolbchain.

…loses anthropics#1421)

`lib/streaming/_beta_messages.py` fired `BetaInputJsonEvent` for `tool_use`
and `mcp_tool_use` content blocks but not for `server_tool_use`, even though
the API streams `input_json_delta` events for server-side tools the same way.

This was inconsistent with the accumulator's own `TRACKS_TOOL_INPUT` tuple
which already includes `BetaServerToolUseBlock` — so the SDK accumulates
streamed input into `content_block.input` correctly, but never fires the
parsed event to consumers. Forces consumers to bypass `BetaInputJsonEvent`
and match on the raw `BetaRawContentBlockDeltaEvent` with a
`BetaInputJSONDelta` delta.

Add `"server_tool_use"` to the content-block type check so the parsed event
fires for server-side tool input streaming (e.g. `tool_search_tool_regex`,
`web_search`).
@abhicris abhicris requested a review from a team as a code owner April 25, 2026 09:53
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.

BetaInputJsonEvent not fired for server_tool_use blocks during streaming

1 participant