litellm/tests/unit/proxy/mcp_server
jesus-berri 3e0bcc508e
fix(mcp): return an upstream -32042 URL elicitation error from /mcp as a JSON-RPC error (#52384)
* test(mcp): add red /mcp contract for an upstream -32042 URL elicitation error

A tools/call that the upstream answers with -32042 must reach the /mcp
client as a JSON-RPC error with code and data.elicitations intact. The
stub provider moves to a shared factory so the existing REST case and
the new /mcp case script the same peer.

* fix(mcp): return an upstream -32042 URL elicitation error from /mcp as a JSON-RPC error

An upstream tools/call answered with JSON-RPC error -32042 was flattened into an isError text result, so the client never saw data.elicitations[].url. The four catches that built that result now re-raise it and the MCP SDK serializes it with code, message and data intact. /mcp-rest/tools/call keeps its HTTP 200 isError text result, and every other error keeps its current path.

Co-Authored-By: bot_apk <apk@cognition.ai>

* fix(mcp): keep the REST virtual mcp_tool_call result for an upstream -32042

The virtual mcp_tool_call branch of /mcp-rest/tools/call had no guard, so the re-raised -32042 became an HTTP 500. Both REST branches now share one guard that renders it as the HTTP 200 isError text result, while /mcp still relays it as a JSON-RPC error on its virtual path. The MCP client also re-raises -32042 before its error-level log, since it is an expected consent signal.

Co-Authored-By: bot_apk <apk@cognition.ai>

* test(mcp): add integration cells for upstream -32042 URL elicitation across entry points, auth paths and chaos

Covers every /mcp entry point, the official SDK client, SDK-built upstreams over http, sse and stdio,
token exchange, delegated and per-user OAuth servers, the REST error result, unusual error payloads,
spend log rows, a two-proxy burst, a killed worker, an upstream outage and a held reply.

The LLM auto-execute cell pins the tool result text and spend status that the merge base produces.

* test(mcp): assert the auto-executed -32042 tool call hands the model the error and logs a failure

Co-Authored-By: bot_apk <apk@cognition.ai>

* fix(mcp): run post_mcp_call guardrails over a relayed -32042 URL elicitation's message text

Co-Authored-By: bot_apk <apk@cognition.ai>

* fix(mcp): keep the LLM auto-execute path unchanged for -32042 and drop the unmasked cause from the relayed error

Co-Authored-By: bot_apk <apk@cognition.ai>

* fix(mcp): let a during-call guardrail block outrank a relayed -32042 and run the post tool call hook on its messages

Co-Authored-By: bot_apk <apk@cognition.ai>

* fix(mcp): flatten a -32042 for REST before the shared post-call path so guardrails and the tool call hook run once

Co-Authored-By: bot_apk <apk@cognition.ai>

* fix(mcp): run the -32042 guardrails and tool call hook outside the except block so a block cannot chain the upstream error

Co-Authored-By: bot_apk <apk@cognition.ai>

* test(mcp): drive the -32042 relay unit test through a real post_mcp_call guardrail

Co-Authored-By: bot_apk <apk@cognition.ai>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: bot_apk <apk@cognition.ai>
2026-11-19 08:56:01 -08:00
..
auth feat(auth): read projects, tags, access groups and object permissions through rust repositories (#52178) 2026-11-18 22:32:06 +00:00
faults feat(mcp): cache upstream tool lists with an admin-set lifetime (#51160) 2026-11-12 08:48:04 -08:00
guardrail_translation
outbound_credentials feat(proxy)!: require a LITELLM_SALT_KEY of at least 112 bits to start in fips_mode (#52099) 2026-11-17 12:58:59 -08:00
__init__.py
conftest.py fix(mcp): decide connected from the provider's scope refusal, not from scope names (#51788) 2026-11-17 18:23:34 -08:00
test_byok_credential_cache.py
test_byok_oauth_endpoints.py
test_callback_oauth_error_responses.py
test_capabilities.py
test_catalog.py feat(auth): read projects, tags, access groups and object permissions through rust repositories (#52178) 2026-11-18 22:32:06 +00:00
test_client_allowlist.py
test_contracts.py
test_db_credentials.py fix(mcp): decide connected from the provider's scope refusal, not from scope names (#51788) 2026-11-17 18:23:34 -08:00
test_discoverable_endpoints.py feat(auth): read teams, team memberships and organizations through rust repositories (#52176) 2026-11-18 22:32:05 +00:00
test_gateway_dcr_flow.py fix(mcp): decide connected from the provider's scope refusal, not from scope names (#51788) 2026-11-17 18:23:34 -08:00
test_id_jag_grant.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_idp_token_exchange.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_interactions.py
test_is_tool_name_prefixed.py
test_jwt_mcp_enforcement.py fix(auth): check a mapped JWT's end-user claim and keep the error classes of refused keys and JWTs (#52397) 2026-11-18 03:36:46 +00:00
test_jwt_mcp_simple.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00
test_mcp_auth_header_extraction.py
test_mcp_auth_priority.py
test_mcp_block_recording.py
test_mcp_chat_completions.py
test_mcp_client_unit.py feat(mcp): cache upstream tool lists with an admin-set lifetime (#51160) 2026-11-12 08:48:04 -08:00
test_mcp_cost_calculator.py
test_mcp_custom_fields.py
test_mcp_debug.py
test_mcp_discovery.py feat(mcp): add Parallel to the MCP discovery registry (#52141) 2026-11-16 16:30:58 -08:00
test_mcp_elicitation_handler.py
test_mcp_env_vars.py feat(fips): encrypt stored secrets with the FIPS provider's AES-256-GCM in fips_mode (#51429) 2026-11-18 03:22:53 +00:00
test_mcp_guardrail_usage_monitor.py fix(mcp): refuse calls to guardrail-hidden tools (#48669) 2026-10-27 17:13:40 -07:00
test_mcp_header_alias_utils.py
test_mcp_hook_extra_headers.py fix(mcp): refuse calls to guardrail-hidden tools (#48669) 2026-10-27 17:13:40 -07:00
test_mcp_logging.py fix(mcp): log SDK request rejections (#49184) 2026-10-30 20:08:59 -07:00
test_mcp_max_concurrent_requests.py
test_mcp_metadata_preservation.py
test_mcp_oauth_passthrough.py
test_mcp_oauth_passthrough_cold_start.py
test_mcp_oauth_passthrough_tools.py test: drop the unit tests that flaked on main this week (#51488) 2026-11-12 17:32:49 -08:00
test_mcp_partial_update.py
test_mcp_proxy_mode.py feat(mcp): cache upstream tool lists with an admin-set lifetime (#51160) 2026-11-12 08:48:04 -08:00
test_mcp_sampling_completion_flow.py
test_mcp_sampling_model_access.py
test_mcp_sampling_model_resolution.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_mcp_sampling_priority_selection.py
test_mcp_sampling_request_builder.py
test_mcp_sampling_response_conversion.py
test_mcp_sampling_tool_conversion.py
test_mcp_server.py feat(mcp): cache upstream tool lists with an admin-set lifetime (#51160) 2026-11-12 08:48:04 -08:00
test_mcp_server_identity_env.py
test_mcp_server_manager.py fix(mcp): return an upstream -32042 URL elicitation error from /mcp as a JSON-RPC error (#52384) 2026-11-19 08:56:01 -08:00
test_mcp_server_tool_calls_and_headers.py fix(mcp): let zero-budget users call MCP tools that cost nothing (#52130) 2026-11-16 17:44:44 -08:00
test_mcp_session_logging.py
test_mcp_sigv4_auth.py
test_mcp_stale_session.py
test_mcp_tool_search.py feat(mcp): cache upstream tool lists with an admin-set lifetime (#51160) 2026-11-12 08:48:04 -08:00
test_mcp_toolset_scope.py fix(proxy)!: bind admin-owned team keys to their team's MCP servers (#49161) 2026-10-30 22:07:32 -07:00
test_oauth2_flow_backfill.py
test_oauth2_mcp_config.yaml
test_oauth2_token_cache.py
test_oauth_identity_binding.py
test_oauth_issuer_stamp_backfill.py
test_openapi_spec_path_url.py fix(mcp): accept YAML OpenAPI documents (#48622) 2026-10-27 14:46:15 -07:00
test_openapi_to_mcp_generator.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_openapi_tool_auth.py
test_operations.py fix(mcp): return an upstream -32042 URL elicitation error from /mcp as a JSON-RPC error (#52384) 2026-11-19 08:56:01 -08:00
test_per_user_oauth_cache.py
test_proxy_api_credentials.py feat(db): rust repositories for user, end user and budget auth objects (#52170) 2026-11-18 22:32:05 +00:00
test_rest_endpoints.py fix(mcp)!: forward the LiteLLM key when the admin configures it (#50604) 2026-11-10 20:51:34 -08:00
test_result_conversion.py
test_semantic_tool_filter.py refactor(mcp): let the semantic filter take its MCP tool loader as a parameter (#50483) 2026-11-13 16:34:00 -08:00
test_server_resolution.py
test_short_mcp_tool_prefix.py
test_state_tokens.py
test_subscriptions.py
test_tool_registry.py
test_ui_session_utils.py
test_upstream.py feat(mcp): add an opt-in per-server setting to skip MCP tool output validation (#49961) 2026-11-03 20:42:10 -08:00
test_utils.py feat(auth): decide key and JWT authentication in a Rust core (#51374) 2026-11-17 14:07:47 +09:00