From 3b7abdff9609f7bb438c6d79bc91194aeff75a51 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Thu, 11 Dec 2025 15:49:32 -0500 Subject: [PATCH] feat(anthropic): auto-apply mcp beta header (#34301) and update docstring example --- .../langchain_anthropic/chat_models.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py index 29494212bc9..78d5cfa94a6 100644 --- a/libs/partners/anthropic/langchain_anthropic/chat_models.py +++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py @@ -141,6 +141,7 @@ _TOOL_TYPE_TO_BETA: dict[str, str] = { "web_fetch_20250910": "web-fetch-2025-09-10", "code_execution_20250522": "code-execution-2025-05-22", "code_execution_20250825": "code-execution-2025-08-25", + "mcp_toolset": "mcp-client-2025-11-20", "memory_20250818": "context-management-2025-06-27", "computer_20250124": "computer-use-2025-01-24", "computer_20251124": "computer-use-2025-11-24", @@ -1611,14 +1612,20 @@ class ChatAnthropic(BaseChatModel): "type": "url", "url": "https://docs.langchain.com/mcp", "name": "LangChain Docs", - # "tool_configuration": { # optional configuration - # "enabled": True, - # "allowed_tools": ["ask_question"], - # }, # "authorization_token": "PLACEHOLDER", # optional authorization } ] + # Optional: configure which tools are enabled via mcp_toolset + tools = [ + { + "type": "mcp_toolset", + "mcp_server_name": "LangChain Docs", + # "default_config": {"enabled": False}, # disable all by default + # "configs": {"ask_question": {"enabled": True}}, # allowlist + } + ] + model = ChatAnthropic( model="claude-sonnet-4-5-20250929", mcp_servers=mcp_servers, @@ -1626,7 +1633,7 @@ class ChatAnthropic(BaseChatModel): response = model.invoke( "What are LangChain content blocks?", - tools=[{"type": "mcp_toolset", "mcp_server_name": "LangChain Docs"}], + tools=tools, ) ```