litellm/tests/unit/proxy/mcp_server
jesus-berri 43fc7d5cd3
fix(mcp): keep an MCP server's own Authorization key when the JWT signer is on (#51867)
* fix(mcp): keep an MCP server's own Authorization key when the JWT signer is on

With mcp_jwt_signer enabled, a server whose configured authentication_token is sent in
Authorization (bearer_token, token, authorization, basic) had that key replaced by the
signer's JWT on tools/list and tools/call, so the upstream returned 401. Both signer guards
now also treat the server's own key as occupying Authorization, using the same
to_server_spec mapping that sends the key upstream.

Resolves LIT-10782
Fixes #47988

Co-authored-by: Arvind Kumar <arvindkumar.acad@gmail.com>

* fix(mcp): keep a deferred oauth2-delegate server's own token when the JWT signer is on

Servers that defer to the v1 client, such as oauth2 with delegate_auth_to_upstream,
send their authentication_token in Authorization (or upstream_token_header), but the
signer guard only read the v2 spec and let the gateway JWT overwrite it. The guard
now falls back to v1's own header rule when to_server_spec returns None. BYOK keeps
its existing behavior.

* test(mcp): cover a SigV4 server's token leaving Authorization to the JWT signer

* fix(mcp): only let upstream_token_header claim Authorization for auth types v1 writes a key for

A SigV4 server with a stray authentication_token and upstream_token_header
set to Authorization lost the signer JWT, though v1 never sends that token.
The v1 rule now resolves the header v1 would write the key to, or none, before
applying the override.

* fix(mcp): keep the signer JWT on tools/call when the caller's auth header displaces the server key

A per-request MCP auth header replaces the server's authentication_token, so
the configured key is not what reaches Authorization. The tools/call guard now
only consults the server's configured key when the caller sent none, matching
the tools/list guard, so the upstream no longer ends up with no Authorization.

---------

Co-authored-by: Arvind Kumar <arvindkumar.acad@gmail.com>
2026-11-17 01:47:56 +00:00
..
auth fix(mcp)!: forward the LiteLLM key when the admin configures it (#50604) 2026-11-10 20:51:34 -08: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 fix(mcp): derive MCP bridge and session keys with the FIPS provider's KBKDF (#50032) 2026-11-07 13:33:27 -08:00
__init__.py
conftest.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_byok_credential_cache.py
test_byok_oauth_endpoints.py
test_callback_oauth_error_responses.py
test_capabilities.py
test_catalog.py fix(mcp): challenge a single-server listing whose credential the upstream rejected (#50389) 2026-11-10 15:41:04 -08:00
test_client_allowlist.py
test_contracts.py
test_db_credentials.py
test_discoverable_endpoints.py fix(proxy)!: match the sign-in email fallback to the right user (#51897) 2026-11-15 19:13:38 -08:00
test_gateway_dcr_flow.py fix(mcp): give the MCP client exactly the servers left on in the connect page (#50973) 2026-11-13 16:36:49 -08:00
test_id_jag_grant.py
test_idp_token_exchange.py feat(auth): grant access groups through principal attribute rules (#50455) 2026-11-09 13:59:40 -08:00
test_interactions.py
test_is_tool_name_prefixed.py
test_jwt_mcp_enforcement.py
test_jwt_mcp_simple.py
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 fix(fips): hash MCP advisory-lock keys with SHA-256 in fips_mode and compute the OCI body digest as a security hash (#51165) 2026-11-11 16:22:14 -08: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): keep an MCP server's own Authorization key when the JWT signer is on (#51867) 2026-11-17 01:47:56 +00: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): route aggregate resources/read to the server that lists the URI (#51462) 2026-11-13 12:50:43 -08:00
test_per_user_oauth_cache.py
test_proxy_api_credentials.py
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