Skip to content

ai-anthropic: modelOptions.mcp_servers is forwarded without the mcp-client beta header #1424

Description

@changbaebang

TanStack AI version

@tanstack/ai 0.56.0, @tanstack/ai-anthropic 0.18.8 (current main, bffdd18)

Framework/Library version

Any (server-side, framework-independent). @anthropic-ai/sdk 0.112.4.

Describe the bug and the steps to reproduce it

modelOptions.mcp_servers is forwarded to the Messages API body, but the required beta header is never sent. This is the same shape as #1074 (context_management forwarded without context-management-2025-06-27), which #1080 fixed.

  • mcp_servers is in the validKeys allowlist in packages/ai-anthropic/src/adapters/text.ts, so it reaches the request body.
  • computeAnthropicBetas in the same file only looks at thinking, context_management, and the code-execution / skills tools. It never adds mcp-client-2025-11-20.
  • The SDK does not inject it either: client.beta.messages.create sends exactly the betas it is given (resources/beta/messages/messages.js, 'anthropic-beta': betas?.toString()).
  • The existing test forwards container, mcp_servers, service_tier, ... to the beta client asserts the body but not payload.betas, so nothing catches it.

Anthropic's MCP connector docs require the header: https://platform.claude.com/docs/en/agents-and-tools/mcp-connector (anthropic-beta: mcp-client-2025-11-20).

Steps to reproduce (no API key needed):

  1. chat({ adapter: anthropicText('claude-sonnet-4-5'), messages, modelOptions: { mcp_servers: [{ type: 'url', name: 'x', url: 'https://mcp.example.com' }] } })
  2. Inspect the betaMessagesCreate payload (or the outgoing request): mcp_servers is present, betas is undefined.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

Reproduces in the package's own test suite — add expect(payload.betas).toContain('mcp-client-2025-11-20') to the mcp_servers test in packages/ai-anthropic/tests/anthropic-adapter.test.ts and it fails on main.

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Yes — PR incoming: add the beta in computeAnthropicBetas when mcp_servers is a non-empty array, assert payload.betas in the test, patch changeset.

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

has-prAn open PR references this issuewaiting-on: maintainerThe ball is in the maintainers’ court

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions