litellm/tests/unit/responses/mcp
edvinsq d473d742d2
fix(proxy): keep a request's slot, TPM and budget holds while it runs MCP tools (#54469)
* fix(proxy): keep a request's parallel slot when an MCP tool call inside it fails

* fix(proxy): keep the request's budget hold when a tool call inside it fails on the Rust spend logger

The Rust spend logger replaces the Python budget logger whenever the spend
logs ledger is on, which is the default with a database. Its failure path
released the request's budget reservation for every failure, so a failed MCP
tool call still freed the hold while the request ran. The failure document now
says whether the failure was reported inside a tool call, and the logger keeps
the reservation for those while still writing the failure row

The MCP tool loop again passes empty request data for a failure before the
server lookup, as before this branch, so failure hooks see no new fields.
Test signatures gain their return and Final annotations

* fix(proxy): keep the request's rate limit headers when a tool call inside it runs

A tool call's limit check replaced the request's stored rate limit response, so an MCP tool request answered without its x-ratelimit-api_key-* headers. The tool call now leaves the request's stored response alone, so the headers and the logged statuses come from the request's own check, as on a request without tools

* fix(proxy): check a tool call inside a request against TPM and project IO limits, and keep the request's budget hold and slot through its tool calls

A tool call inside a request reserves TPM and project IO on a scratch limiter state, so an exhausted limit still refuses it as before, then gives that reservation straight back so the request's own reservation settles once at its end. The tool call's own spend log no longer carries the request's budget reservation, which it used to settle at the tool call's cost. The MCP loop stamps the request's slot as reused when its tool calls start, so a round logged before them, such as streaming /v1/messages round 1, leaves the slot held

* fix(mcp): keep the request's budget hold through the MCP tool listing inside it

The tool listing's own spend log carried the request's budget reservation and finalized it before the request ended, so the listing now logs with the reservation stripped, as the tool call already does

* fix(proxy): refund a tool call's TPM hold before the tool runs

The scratch reservation a nested MCP tool call takes for its TPM and IO
check now goes back to Redis at once instead of waiting on the request's
post-call batch, so other requests on the key no longer see the tool
call's tokens while the request runs

The slot test now uses fixed end times, and the budget tests read the
spend log metadata through the real logging path

* test(proxy): move the tool call TPM refund test into the integration suite

It starts a Redis server, which tests/unit does not allow. It now runs the proxy's own pre-call hook
against the integration lane's Redis, and fails on base with the tool call's tokens still held

* test(mcp): run the budget hold tests through the real MCP manager and tool registry

The tool call test now calls a registered in-process OpenAPI tool through the real server
manager and proxy logging, and the listing test uses the real manager with no servers, so
neither doubles our own code. Removing either budget reservation strip fails its test

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-26 08:11:44 +00:00
..
__init__.py ci: move provider-independent MCP tests into tests/unit and run mcp-integration from litellm-tests (#42904) 2026-09-24 23:07:48 +00:00
conftest.py refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
test_aresponses_api_with_mcp.py feat(responses): store each bridged turn's path to the root so a fork replays only its ancestors (#49519) 2026-11-23 12:43:11 -08:00
test_chat_completions_handler.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
test_litellm_proxy_mcp_handler.py fix(proxy): keep a request's slot, TPM and budget holds while it runs MCP tools (#54469) 2026-11-26 08:11:44 +00:00
test_mcp_streaming_iterator.py feat(guardrails): add mcp_block_behavior to raise 400 on MCP tool blocks (#50284) 2026-11-06 12:31:00 -08:00
test_parked_stream_dispatch.py fix(mcp): bill both calls of a streamed chat completions MCP auto-execute (#48899) 2026-10-30 07:34:10 -07:00
test_round_billing.py fix(responses): bill the provider-reported input on a cut bridged stream (#53394) 2026-11-23 06:20:25 +00:00
test_tool_precheck.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00