fix: drop Anthropic provider-defined tools on cross-protocol forward

GU
3mo ago
+231-2

Summary

Follow-up to #2772 (which fixed #2754). That PR made Anthropic server tools carry a parameters field so strict chat-completions providers no longer 400 on a missing field. This PR goes one step further and stops forwarding tools the target can't execute at all.

An Anthropic Messages request routed to a non-Anthropic provider still declared Anthropic provider-defined tools — server tools (web_search_*, bash_*, computer_*, text_editor_*, …), mcp_toolset, and schema-less typed tools — as ordinary functions. The model could emit a tool_call for a tool nobody can run (Manifest doesn't execute provider tools, and the caller never registered them). This drops those tools from the outbound cross-protocol body.

Where it runs

ProviderClient.forward, after the provider is resolved, on the opts.apiMode === 'messages' + needsChatBody path only:

  • Native Anthropic routes are untouched. Their wire body comes from applyAnthropicMessagesMutations directly from the inbound body, and chatBody is undefined, so the drop never runs and server-tool type tags survive (issue #1886).
  • Routing/scoring still sees the full tool set, because chatBody is consumed for scoring before forwarding. Only the wire payload is trimmed.
  • tool_choice pinned to a dropped tool is relaxed to auto; when every tool is dropped the tools array and a required choice are removed rather than forwarded as an empty husk.

This is consistent with the existing cross-protocol philosophy (responses-adapter.ts drops web_search_call and friends because "dropping them is the only safe mapping").

Test plan

  • Unit tests for unsupportedAnthropicToolNames and dropUnsupportedAnthropicTools in anthropic-messages-adapter.spec.ts
  • Integration tests in provider-client.spec.ts: Messages → MiniMax drops server tools but keeps a client tool and relaxes a pinned tool_choice; a request whose tools are all provider-executed emits no tools and tool_choice: auto
  • npx jest routing/proxy — 2435/2435 passing
  • npx eslint on the changed files — 0 errors
  • npx tsc --noEmit — clean
  • Changeset (manifest, patch)

Summary by cubic

Fixes cross-protocol forwarding from Anthropic Messages so Anthropic provider-defined tools are no longer sent to targets that can't execute them.

Previously, server tools (web_search_*, bash_*, computer_*, text_editor_*), mcp_toolset, and schema-less typed tools were translated into ordinary functions and included in the outbound chat-completions body. That let the model emit a tool_call for a tool nobody could run. These tools are now dropped from the wire body after routing and scoring, so routing still sees the full tool set while only executable client tools are forwarded. If tool_choice pins a dropped tool, it is relaxed to auto; if nothing remains, the tools array and a required choice are removed. Native Anthropic routes are unchanged and keep the inbound body's server-tool type tags.