litellm/tests/unit/llms/deepseek/chat
chaznm a25d09613f
fix(mcp): drop hosted MCP tool_choice under drop_params and honor drop_params in Bedrock batch rows (#53697)
* fix(mcp): drop a tool_choice naming a dropped hosted MCP tool, honor deployment drop_params in Bedrock batch, and survive a failed toolset read in mcp_security

When drop_params drops a hosted MCP tool, a function tool_choice that names its server_label is now removed too, unless a kept tool or legacy function has that name, so the provider no longer rejects a forced choice for a tool that is gone.

Bedrock batch rows now resolve drop_params from the row first and the deployment second, and the Converse and Anthropic branches drop hosted MCP tools up front. Bedrock and Vertex batch rows that keep a hosted MCP tool get a 400 whose advice a batch row can follow, in place of the MCP gateway advice.

The mcp_security guardrail now reads saved toolsets through saved_toolset_exists, so a failed read blocks with the policy's 400 in block mode and passes through with a warning in alert mode, in place of a raw 500.

* fix(mcp): refuse a batch upload when the toolset read fails instead of dropping its row

* fix(mcp): drop a Responses mcp tool_choice for a dropped hosted MCP server

A tool_choice of {"type": "mcp", "server_label": X} survived when the gateway dropped server X, so a Bedrock
batch row uploaded an empty toolChoice name that Bedrock rejects, where before the upload answered a clear 400.

* fix(mcp): drop any mcp tool_choice once the hosted MCP tools are dropped

Every type: mcp tool is dropped together, so an mcp tool_choice left behind names a server the request no longer carries, whatever its label. A choice naming an unsent server or carrying no label was kept and reached Nova as a forced tool with an empty name.

* fix(mcp): drop a Responses mcp tool_choice and Bedrock passthrough batch MCP tools under drop_params

A Responses `{"type": "mcp", "server_label": X}` tool_choice now becomes a function
choice naming X on the chat bridge, so the hosted MCP drop removes it with its tool
instead of the validator answering 400. Bedrock passthrough batch rows (gpt-oss,
Llama, qwen, deepseek) now drop hosted MCP tools and the choice that forces them
when the row or deployment sets drop_params, and never send drop_params to Bedrock.

* fix(mcp): map a Responses mcp tool_choice only when the request sends that server

Mapping every mcp choice to a function choice turned a choice naming an unsent
server into a forced function the hosted MCP drop could not recognize, so a Bedrock
batch row kept it. The bridge now maps the choice only when the request carries an
mcp tool with that label, and every other mcp choice keeps its shape for the drop.

* fix(bedrock): refuse a passthrough batch row with a hosted MCP tool unless drop_params is set

* fix(responses): drop an mcp tool_choice under drop_params instead of mapping it to a function choice

* test(mcp): type the toolset read failure test and fix its blank lines

* test(responses): check a function tool_choice under drop_params is still forced

* fix(batch): honor the router default and a Responses row's drop_params in batch uploads

A batch upload now prefers router_settings.default_litellm_params drop_params over the
deployment's, the same order chat uses. The Responses batch bridge keeps a row's own
drop_params, and Bedrock passes the effective drop_params into it, so an mcp tool_choice
with no MCP tool is dropped instead of reaching Bedrock

* fix(batch): narrow an allowed_tools choice around dropped hosted MCP tools and treat a null drop_params as unset

* test(tools): cover malformed legacy functions when dropping MCP tools

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(mcp): drop a forced MCP tool_choice only with the hosted MCP tool it names

The Responses bridge no longer clears every mcp tool_choice under drop_params. A choice that names a gateway server or a server the request did not send keeps the 400 it got before this PR

An allowed_tools choice that names only dropped MCP servers now keeps the function tools and drops only the choice, the same in batch and real time

litellm.completion drops an mcp tool_choice together with the hosted MCP tool it names under drop_params, and keeps the 400 when drop_params is off. The 400 text now says when drop_params can drop the choice

Vertex batch passes the resolved drop_params to the Responses bridge, batch refusals give advice that matches the row's own drop_params, and the MCP security guardrail says a server's toolset could not be verified when the read fails

* fix(mcp): drop a forced hosted MCP choice and its tool on every route under drop_params

Under drop_params, completion() now drops an mcp tool_choice together with the hosted MCP tool it names before any provider config sees them, on every provider outside openai, azure and litellm_proxy. Before, xAI, OpenRouter, Groq and similar routes got both the tool and the choice, and Mistral, Fireworks, DeepInfra and Azure AI dropped the choice but still sent the tool. A provider that runs hosted MCP itself, a gateway server, a server the request did not send, and drop_params off all stay a 400

A batch row's mcp tool_choice is now dropped only when it names a hosted MCP server the row sends and drop_params drops. Any other mcp choice, including one in a row with no MCP tool, gets the same 400 as a real-time call, so Vertex Gemini and Claude and Bedrock Nova, Claude Invoke and gpt-oss no longer store a broken row

The batch refusal advice now says the router default and the deployment apply only when the upload names a model

* fix(mcp): let a forced hosted MCP choice follow its tool under drop_params

A forced `mcp` tool_choice under drop_params is now dropped only on routes whose config drops hosted MCP tools, and it is dropped together with that tool. Each chat config reports this through `hosted_mcp_tool_handling(model)` as "drops", "runs" or "forwards", and the drop helper reads the same value, so the two cannot drift apart. Routes that forward hosted MCP tools, such as OpenRouter, xAI, Groq and Mistral, keep the merge base's 400 whatever drop_params says, so nothing reaches the provider. OCI and Ollama now report "drops", which matches how their transformations already treat the tools. On OCI a forced `mcp` choice used to fail with an OCIError and now drops with its tool

The 400 now names the one cause that applies: drop_params is off, the request sent no tool for that server, the tool_choice names no server, the provider runs hosted MCP itself, or the route forwards hosted MCP tools. A forced LiteLLM MCP gateway server now gets its own 400 on every route, before any tool listing or model call. Batch rows and real-time calls use the same text

When the saved toolset read fails in block mode, the mcp_security guardrail now answers 503 with a try-again message and keeps `unverified_servers`. A server that is known to be unregistered still gets the policy 400. Alert mode is unchanged

Uploads that name no model now apply `router_settings.default_litellm_params.drop_params`, with the batch row value and a `files_settings` drop_params still winning. The batch remedy no longer limits the router default to uploads that name a model, and its row wording is now true for any value that does not turn dropping on, such as "no" or 0

* fix(mcp): keep OCI's all-tools-dropped 400 for MCP-only requests and reword the forced-MCP 400

* fix(files): let a null upload drop_params take the router default

* fix(files): pass one drop_params to a model-less upload

A files_settings entry with drop_params: null plus a router default made
acreate_file receive drop_params twice and answer 500. The upload now merges
the request and the router default into one mapping before the call.

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-23 08:51:59 -08:00
..
__init__.py test(unit): make every tests/unit directory a package so pytest collection is unique 2026-09-20 11:50:59 +00:00
test_deepseek_chat_transformation.py fix(mcp): drop hosted MCP tool_choice under drop_params and honor drop_params in Bedrock batch rows (#53697) 2026-11-23 08:51:59 -08:00