From 0a1dbc0fb4f6b52aec97700dddb457adf91d1cbd Mon Sep 17 00:00:00 2001 From: Mateo Wang <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 27 Oct 2026 10:47:50 -0700 Subject: [PATCH] refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) * refactor(mcp): drop the experimental label from the MCP server and client paths Move litellm/proxy/_experimental/mcp_server to litellm/proxy/mcp_server and litellm/experimental_mcp_client to litellm/mcp_client, with the mirrored tests moved under tests/unit/proxy/mcp_server and tests/unit/mcp_client. Both old packages stay as shims that warn with DeprecationWarning, re-export the new package's public names and alias every submodule in sys.modules so deep imports keep resolving to the same objects. The OpenAPI docs gate now puts the merge base's enterprise package on PYTHONPATH so its base counts do not mix the checked-out enterprise code with the base litellm tree Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci(mcp): keep tests/unit/proxy/_experimental as a sharded root for the shim tests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(mcp): alias namespace subpackages and bind attributes in the deprecated MCP shims pkgutil.walk_packages skipped mcp_server/auth because it has no __init__.py, so old imports of litellm.proxy._experimental.mcp_server.auth.* failed, and sys.modules entries alone left litellm.experimental_mcp_client.tools unreachable as an attribute. Walk the package on disk and setattr each alias on its old parent. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .github/workflows/test-unit.yml | 54 +- .gitignore | 2 +- Makefile | 4 +- README.md | 4 +- .../litellm_enterprise/proxy/liteadmin.py | 4 +- litellm/cost_calculator.py | 2 +- litellm/experimental_mcp_client/__init__.py | 11 +- .../litellm_core_utils/deprecated_package.py | 53 + litellm/llms/__init__.py | 2 +- .../anthropic/messages/native/mcp_handler.py | 6 +- .../Readme.md | 6 +- litellm/mcp_client/__init__.py | 8 + .../client.py | 20 +- .../tools.py | 0 .../_experimental/mcp_server/__init__.py | 4 + litellm/proxy/_lazy_features.py | 8 +- litellm/proxy/_types.py | 2 +- .../auth/agent_permission_handler.py | 6 +- .../anthropic_endpoints/gateway_endpoints.py | 26 +- .../ui_discovery_endpoints.py | 2 +- .../guardrails/guardrail_hooks/akto/akto.py | 2 +- .../mcp_end_user_permission.py | 2 +- .../mcp_security/mcp_security_guardrail.py | 2 +- .../panw_prisma_airs/panw_prisma_airs.py | 2 +- .../proxy/hooks/mcp_semantic_filter/hook.py | 8 +- litellm/proxy/litellm_pre_call_utils.py | 2 +- .../access_group_endpoints.py | 2 +- .../key_management_endpoints.py | 16 +- .../mcp_management_endpoints.py | 182 +- .../management_endpoints/sso/saml_sso.py | 8 +- litellm/proxy/management_endpoints/ui_sso.py | 22 +- .../object_permission_utils.py | 8 +- .../{_experimental => }/mcp_server/AGENTS.md | 4 +- .../{_experimental => }/mcp_server/README.md | 0 .../mcp_server/auth/litellm_auth_handler.py | 0 .../mcp_server/auth/managed_agent_access.py | 8 +- .../mcp_server/auth/token_endpoint_auth.py | 0 .../mcp_server/auth/user_api_key_auth_mcp.py | 142 +- .../mcp_server/bridge_token_flow.py | 54 +- .../mcp_server/byok_credential_cache.py | 0 .../mcp_server/byok_oauth_endpoints.py | 12 +- .../mcp_server/capabilities.py | 0 .../{_experimental => }/mcp_server/catalog.py | 92 +- .../mcp_server/client_allowlist.py | 0 .../mcp_server/contracts.py | 4 +- .../mcp_server/cost_calculator.py | 0 .../{_experimental => }/mcp_server/db.py | 22 +- .../mcp_server/discoverable_endpoints.py | 90 +- .../mcp_server/elicitation_handler.py | 0 .../mcp_server/exceptions.py | 2 +- .../mcp_server/faults/__init__.py | 8 +- .../mcp_server/faults/classify.py | 2 +- .../mcp_server/faults/list_outcomes.py | 6 +- .../mcp_server/faults/render_oauth.py | 4 +- .../mcp_server/faults/traversal.py | 0 .../mcp_server/faults/types.py | 0 .../mcp_server/gateway_dcr_flow.py | 28 +- .../guardrail_translation/__init__.py | 2 +- .../guardrail_translation/handler.py | 6 +- .../mcp_server/id_jag_grant.py | 14 +- .../mcp_server/idp_token_exchange.py | 2 +- .../mcp_server/interactions.py | 6 +- .../mcp_server/legacy_callbacks.py | 16 +- .../mcp_server/mcp_context.py | 0 .../mcp_server/mcp_debug.py | 18 +- .../mcp_server/mcp_server_manager.py | 140 +- .../mcp_server/oauth2_flow_backfill.py | 2 +- .../mcp_server/oauth2_token_cache.py | 14 +- .../mcp_server/oauth_identity_binding.py | 4 +- .../mcp_server/oauth_issuer_stamp_backfill.py | 2 +- .../mcp_server/oauth_utils.py | 6 +- .../mcp_server/openapi_to_mcp_generator.py | 12 +- .../mcp_server/operations.py | 104 +- .../outbound_credentials/__init__.py | 8 +- .../outbound_credentials/adapter.py | 10 +- .../authz_code_refresher.py | 8 +- .../bridge_credentials.py | 2 +- .../client_credentials.py | 10 +- .../dual_cache_token_backend.py | 6 +- .../outbound_credentials/envelope.py | 0 .../outbound_credentials/httpx_auth.py | 0 .../login_assertion_exchange.py | 20 +- .../outbound_credentials/oauth_token_store.py | 0 .../per_user_oauth_store.py | 18 +- .../presented_token_store.py | 2 +- .../redis_distributed_lock.py | 2 +- .../redis_refresh_coordinator.py | 2 +- .../outbound_credentials/resolver.py | 18 +- .../mcp_server/outbound_credentials/result.py | 0 .../runtime_refresh_coordinator.py | 6 +- .../session_credentials.py | 2 +- .../outbound_credentials/session_token.py | 0 .../sso_assertion_refresher.py | 10 +- .../sso_assertion_store.py | 2 +- .../outbound_credentials/token_cache_codec.py | 2 +- .../outbound_credentials/token_endpoint.py | 4 +- .../token_exchange_provider.py | 4 +- .../outbound_credentials/token_exchanger.py | 8 +- .../mcp_server/outbound_credentials/types.py | 2 +- .../outbound_credentials/v2_token_store.py | 2 +- .../mcp_server/proxy_api_credentials.py | 14 +- .../mcp_server/rest_endpoints.py | 106 +- .../mcp_server/result_conversion.py | 2 +- .../mcp_server/sampling_handler.py | 2 +- .../mcp_server/scope_challenge.py | 2 +- .../mcp_server/semantic_tool_filter.py | 8 +- .../{_experimental => }/mcp_server/server.py | 66 +- .../mcp_server/server_resolution.py | 4 +- .../mcp_server/sse_transport.py | 0 .../mcp_server/state_tokens.py | 2 +- .../mcp_server/stdio_gate.py | 0 .../mcp_server/subscriptions.py | 18 +- .../mcp_server/tool_catalog_guard.py | 2 +- .../mcp_server/tool_outcome.py | 0 .../mcp_server/tool_registry.py | 0 .../mcp_server/tool_search.py | 8 +- .../mcp_server/toolset_db.py | 2 +- .../mcp_server/ui_session_utils.py | 6 +- .../mcp_server/upstream.py | 20 +- .../{_experimental => }/mcp_server/utils.py | 0 litellm/proxy/proxy_server.py | 50 +- .../public_endpoints/public_endpoints.py | 2 +- .../proxy_setting_endpoints.py | 2 +- litellm/proxy/vector_store_endpoints/utils.py | 8 +- .../mcp/litellm_proxy_mcp_handler.py | 28 +- .../responses/mcp/mcp_streaming_iterator.py | 2 +- litellm/responses/mcp/tool_precheck.py | 2 +- litellm/responses/utils.py | 2 +- scripts/check_mcp_operation_boundary.py | 2 +- scripts/check_mcp_sdk_install.py | 12 +- scripts/openapi_docs_gate.py | 5 +- scripts/pre_commit_lint.sh | 2 +- .../base_sdk_tests/check_base_sdk_install.py | 4 +- tests/benchmarks/test_mcp_benchmarks.py | 4 +- .../ensure_async_clients_test.py | 4 +- .../unbounded_in_baseline.txt | 12 +- tests/e2e/coverage_registry/mcp.yaml | 2 +- tests/integration/mcp/test_interactions.py | 18 +- .../mcp/test_mcp_protocol_errors.py | 6 +- tests/integration/mcp/test_mcp_transports.py | 15 +- tests/integration/mcp/test_pagination.py | 15 +- tests/integration/mcp/test_proxy_mcp_e2e.py | 12 +- tests/integration/mcp_coverage.toml | 4 +- .../unit/experimental_mcp_client/test_init.py | 29 + .../litellm_proxy/skills/test_skill_search.py | 4 +- .../auth => mcp_client}/__init__.py | 0 .../test_mcp_client.py | 83 +- .../test_tools.py | 22 +- .../_experimental/mcp_server/test_init.py | 30 + .../test_gateway_endpoints.py | 30 +- tests/unit/proxy/auth/test_login_utils.py | 6 +- .../unit/proxy/auth/test_mcp_ip_filtering.py | 2 +- tests/unit/proxy/db/mcp_server/test_db.py | 3 +- .../guardrail_hooks/akto/test_akto.py | 5 +- .../guardrail_hooks/test_mcp_security.py | 11 +- .../guardrail_hooks/test_panw_prisma_airs.py | 2 +- .../guardrail_hooks/test_presidio.py | 10 +- .../test_unified_guardrail.py | 6 +- .../hooks/test_parallel_request_limiter_v3.py | 6 +- .../test_key_management_endpoints.py | 58 +- .../test_mcp_management_endpoints.py | 212 ++- .../management_endpoints/test_mcp_servers.py | 4 +- .../management_endpoints/test_saml_sso.py | 2 +- .../proxy/management_endpoints/test_ui_sso.py | 20 +- .../test_object_permission_utils.py | 104 +- .../faults => mcp_server}/__init__.py | 0 .../auth}/__init__.py | 0 .../auth/test_managed_agent_access.py | 16 +- .../auth/test_token_endpoint_auth.py | 2 +- .../auth/test_user_api_key_auth_mcp.py | 570 +++---- .../mcp_server/conftest.py | 10 +- .../faults}/__init__.py | 0 .../mcp_server/faults/test_classify.py | 8 +- .../mcp_server/faults/test_list_outcomes.py | 40 +- .../mcp_server/faults/test_render_oauth.py | 6 +- .../mcp_server/faults/test_traversal.py | 2 +- .../guardrail_translation}/__init__.py | 0 .../test_mcp_guardrail_handler.py | 10 +- .../outbound_credentials}/__init__.py | 0 .../outbound_credentials/test_adapter.py | 20 +- .../test_authz_code_refresher.py | 6 +- .../test_bridge_credentials.py | 6 +- .../test_client_credentials.py | 11 +- .../test_dual_cache_token_backend.py | 6 +- .../outbound_credentials/test_envelope.py | 8 +- .../outbound_credentials/test_httpx_auth.py | 2 +- .../test_login_assertion_exchange.py | 14 +- .../test_oauth_token_store.py | 2 +- .../test_per_user_oauth_store.py | 20 +- .../test_presented_token_store.py | 4 +- .../test_redis_distributed_lock.py | 4 +- .../test_redis_refresh_coordinator.py | 4 +- .../outbound_credentials/test_resolver.py | 20 +- .../outbound_credentials/test_result.py | 2 +- .../test_session_credentials.py | 6 +- .../test_session_token.py | 2 +- .../test_sso_assertion_refresher.py | 8 +- .../test_sso_assertion_store.py | 20 +- .../test_token_cache_codec.py | 4 +- .../test_token_endpoint.py | 12 +- .../test_token_exchange_provider.py | 4 +- .../test_token_exchanger.py | 14 +- .../outbound_credentials/test_types.py | 2 +- .../test_v2_token_store.py | 2 +- .../mcp_server/test_byok_credential_cache.py | 6 +- .../mcp_server/test_byok_oauth_endpoints.py | 159 +- .../test_callback_oauth_error_responses.py | 10 +- .../mcp_server/test_capabilities.py | 10 +- .../mcp_server/test_catalog.py | 40 +- .../mcp_server/test_client_allowlist.py | 2 +- .../mcp_server/test_contracts.py | 2 +- .../mcp_server/test_db_credentials.py | 99 +- .../mcp_server/test_discoverable_endpoints.py | 1518 ++++++++--------- .../mcp_server/test_gateway_dcr_flow.py | 52 +- .../mcp_server/test_id_jag_grant.py | 20 +- .../mcp_server/test_idp_token_exchange.py | 8 +- .../mcp_server/test_interactions.py | 22 +- .../mcp_server/test_is_tool_name_prefixed.py | 3 +- .../mcp_server/test_jwt_mcp_enforcement.py | 9 +- .../mcp_server/test_jwt_mcp_simple.py | 15 +- .../test_mcp_auth_header_extraction.py | 7 +- .../mcp_server/test_mcp_auth_priority.py | 7 +- .../mcp_server/test_mcp_block_recording.py | 7 +- .../mcp_server/test_mcp_chat_completions.py | 32 +- .../mcp_server/test_mcp_client_unit.py | 16 +- .../mcp_server/test_mcp_cost_calculator.py | 3 +- .../mcp_server/test_mcp_custom_fields.py | 11 +- .../mcp_server/test_mcp_debug.py | 17 +- .../mcp_server/test_mcp_discovery.py | 2 - .../test_mcp_elicitation_handler.py | 11 +- .../mcp_server/test_mcp_env_vars.py | 139 +- .../test_mcp_guardrail_usage_monitor.py | 2 +- .../mcp_server/test_mcp_header_alias_utils.py | 2 +- .../mcp_server/test_mcp_hook_extra_headers.py | 46 +- .../mcp_server/test_mcp_logging.py | 24 +- .../test_mcp_max_concurrent_requests.py | 10 +- .../test_mcp_metadata_preservation.py | 3 +- .../mcp_server/test_mcp_oauth_passthrough.py | 24 +- .../test_mcp_oauth_passthrough_cold_start.py | 13 +- .../test_mcp_oauth_passthrough_tools.py | 59 +- .../mcp_server/test_mcp_partial_update.py | 23 +- .../mcp_server/test_mcp_proxy_mode.py | 12 +- .../test_mcp_sampling_completion_flow.py | 29 +- .../test_mcp_sampling_model_access.py | 24 +- .../test_mcp_sampling_model_resolution.py | 2 +- .../test_mcp_sampling_priority_selection.py | 2 +- .../test_mcp_sampling_request_builder.py | 2 +- .../test_mcp_sampling_response_conversion.py | 2 +- .../test_mcp_sampling_tool_conversion.py | 3 +- .../mcp_server/test_mcp_server.py | 320 ++-- .../test_mcp_server_identity_env.py | 4 +- .../mcp_server/test_mcp_server_manager.py | 746 ++++---- .../test_mcp_server_tool_calls_and_headers.py | 1075 ++++++------ .../mcp_server/test_mcp_session_logging.py | 2 +- .../mcp_server/test_mcp_sigv4_auth.py | 84 +- .../mcp_server/test_mcp_stale_session.py | 256 +-- .../mcp_server/test_mcp_tool_search.py | 147 +- .../mcp_server/test_mcp_toolset_scope.py | 112 +- .../mcp_server/test_oauth2_flow_backfill.py | 2 +- .../mcp_server/test_oauth2_mcp_config.yaml | 0 .../mcp_server/test_oauth2_token_cache.py | 42 +- .../mcp_server/test_oauth_identity_binding.py | 16 +- .../test_oauth_issuer_stamp_backfill.py | 4 +- .../mcp_server/test_openapi_spec_path_url.py | 2 +- .../test_openapi_to_mcp_generator.py | 52 +- .../mcp_server/test_openapi_tool_auth.py | 83 +- .../mcp_server/test_operations.py | 154 +- .../mcp_server/test_per_user_oauth_cache.py | 40 +- .../mcp_server/test_proxy_api_credentials.py | 16 +- .../mcp_server/test_rest_endpoints.py | 105 +- .../mcp_server/test_result_conversion.py | 8 +- .../mcp_server/test_semantic_tool_filter.py | 75 +- .../mcp_server/test_server_resolution.py | 17 +- .../mcp_server/test_short_mcp_tool_prefix.py | 10 +- .../mcp_server/test_state_tokens.py | 4 +- .../mcp_server/test_subscriptions.py | 28 +- .../mcp_server/test_tool_registry.py | 5 +- .../mcp_server/test_ui_session_utils.py | 38 +- .../mcp_server/test_utils.py | 10 +- .../public_endpoints/test_public_endpoints.py | 8 +- tests/unit/proxy/test_dynamic_mcp_route.py | 13 +- .../unit/proxy/test_litellm_pre_call_utils.py | 6 +- ...test_proxy_server_endpoints_and_startup.py | 19 +- .../test_get_instance_fn_runtime_gate.py | 2 +- tests/unit/responses/mcp/conftest.py | 2 +- .../mcp/test_aresponses_api_with_mcp.py | 21 +- .../mcp/test_chat_completions_handler.py | 43 +- .../mcp/test_litellm_proxy_mcp_handler.py | 52 +- .../mcp/test_mcp_streaming_iterator.py | 2 +- .../unit/responses/mcp/test_tool_precheck.py | 2 +- .../unit/test_check_mcp_operation_boundary.py | 8 +- tests/unit/test_circleci_path_filter.py | 2 +- tests/unit/test_internal_context.py | 14 +- tests/unit/test_private_usage_aliases.py | 146 +- .../src/utils/mcpHeaderUtils.ts | 2 +- 295 files changed, 4954 insertions(+), 4799 deletions(-) create mode 100644 litellm/litellm_core_utils/deprecated_package.py rename litellm/{experimental_mcp_client => mcp_client}/Readme.md (89%) create mode 100644 litellm/mcp_client/__init__.py rename litellm/{experimental_mcp_client => mcp_client}/client.py (98%) rename litellm/{experimental_mcp_client => mcp_client}/tools.py (100%) create mode 100644 litellm/proxy/_experimental/mcp_server/__init__.py rename litellm/proxy/{_experimental => }/mcp_server/AGENTS.md (98%) rename litellm/proxy/{_experimental => }/mcp_server/README.md (100%) rename litellm/proxy/{_experimental => }/mcp_server/auth/litellm_auth_handler.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/auth/managed_agent_access.py (89%) rename litellm/proxy/{_experimental => }/mcp_server/auth/token_endpoint_auth.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/auth/user_api_key_auth_mcp.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/bridge_token_flow.py (95%) rename litellm/proxy/{_experimental => }/mcp_server/byok_credential_cache.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/byok_oauth_endpoints.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/capabilities.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/catalog.py (93%) rename litellm/proxy/{_experimental => }/mcp_server/client_allowlist.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/contracts.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/cost_calculator.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/db.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/discoverable_endpoints.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/elicitation_handler.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/exceptions.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/faults/__init__.py (81%) rename litellm/proxy/{_experimental => }/mcp_server/faults/classify.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/faults/list_outcomes.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/faults/render_oauth.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/faults/traversal.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/faults/types.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/gateway_dcr_flow.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/guardrail_translation/__init__.py (88%) rename litellm/proxy/{_experimental => }/mcp_server/guardrail_translation/handler.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/id_jag_grant.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/idp_token_exchange.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/interactions.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/legacy_callbacks.py (87%) rename litellm/proxy/{_experimental => }/mcp_server/mcp_context.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/mcp_debug.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/mcp_server_manager.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/oauth2_flow_backfill.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/oauth2_token_cache.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/oauth_identity_binding.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/oauth_issuer_stamp_backfill.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/oauth_utils.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/openapi_to_mcp_generator.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/operations.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/__init__.py (85%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/adapter.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/authz_code_refresher.py (94%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/bridge_credentials.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/client_credentials.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/dual_cache_token_backend.py (92%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/envelope.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/httpx_auth.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/login_assertion_exchange.py (92%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/oauth_token_store.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/per_user_oauth_store.py (92%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/presented_token_store.py (90%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/redis_distributed_lock.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/redis_refresh_coordinator.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/resolver.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/result.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/runtime_refresh_coordinator.py (85%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/session_credentials.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/session_token.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/sso_assertion_refresher.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/sso_assertion_store.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/token_cache_codec.py (95%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/token_endpoint.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/token_exchange_provider.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/token_exchanger.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/types.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/outbound_credentials/v2_token_store.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/proxy_api_credentials.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/rest_endpoints.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/result_conversion.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/sampling_handler.py (99%) rename litellm/proxy/{_experimental => }/mcp_server/scope_challenge.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/semantic_tool_filter.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/server.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/server_resolution.py (96%) rename litellm/proxy/{_experimental => }/mcp_server/sse_transport.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/state_tokens.py (97%) rename litellm/proxy/{_experimental => }/mcp_server/stdio_gate.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/subscriptions.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/tool_catalog_guard.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/tool_outcome.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/tool_registry.py (100%) rename litellm/proxy/{_experimental => }/mcp_server/tool_search.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/toolset_db.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/ui_session_utils.py (98%) rename litellm/proxy/{_experimental => }/mcp_server/upstream.py (94%) rename litellm/proxy/{_experimental => }/mcp_server/utils.py (100%) create mode 100644 tests/unit/experimental_mcp_client/test_init.py rename tests/unit/{proxy/_experimental/mcp_server/auth => mcp_client}/__init__.py (100%) rename tests/unit/{experimental_mcp_client => mcp_client}/test_mcp_client.py (98%) rename tests/unit/{experimental_mcp_client => mcp_client}/test_tools.py (96%) create mode 100644 tests/unit/proxy/_experimental/mcp_server/test_init.py rename tests/unit/proxy/{_experimental/mcp_server/faults => mcp_server}/__init__.py (100%) rename tests/unit/proxy/{_experimental/mcp_server/guardrail_translation => mcp_server/auth}/__init__.py (100%) rename tests/unit/proxy/{_experimental => }/mcp_server/auth/test_managed_agent_access.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/auth/test_token_endpoint_auth.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/auth/test_user_api_key_auth_mcp.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/conftest.py (93%) rename tests/unit/proxy/{_experimental/mcp_server/outbound_credentials => mcp_server/faults}/__init__.py (100%) rename tests/unit/proxy/{_experimental => }/mcp_server/faults/test_classify.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/faults/test_list_outcomes.py (93%) rename tests/unit/proxy/{_experimental => }/mcp_server/faults/test_render_oauth.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/faults/test_traversal.py (95%) rename tests/unit/proxy/{experimental => mcp_server/guardrail_translation}/__init__.py (100%) rename tests/unit/proxy/{_experimental => }/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py (99%) rename tests/unit/proxy/{experimental/mcp_server => mcp_server/outbound_credentials}/__init__.py (100%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_adapter.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_authz_code_refresher.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_bridge_credentials.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_client_credentials.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_dual_cache_token_backend.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_envelope.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_httpx_auth.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_login_assertion_exchange.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_oauth_token_store.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_per_user_oauth_store.py (92%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_presented_token_store.py (73%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_redis_distributed_lock.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_resolver.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_result.py (90%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_session_credentials.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_session_token.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_sso_assertion_refresher.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_sso_assertion_store.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_token_cache_codec.py (93%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_token_endpoint.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_token_exchange_provider.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_token_exchanger.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_types.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/outbound_credentials/test_v2_token_store.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_byok_credential_cache.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_byok_oauth_endpoints.py (92%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_callback_oauth_error_responses.py (94%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_capabilities.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_catalog.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_client_allowlist.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_contracts.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_db_credentials.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_discoverable_endpoints.py (90%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_gateway_dcr_flow.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_id_jag_grant.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_idp_token_exchange.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_interactions.py (94%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_is_tool_name_prefixed.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_jwt_mcp_enforcement.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_jwt_mcp_simple.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_auth_header_extraction.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_auth_priority.py (91%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_block_recording.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_chat_completions.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_client_unit.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_cost_calculator.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_custom_fields.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_debug.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_discovery.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_elicitation_handler.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_env_vars.py (93%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_guardrail_usage_monitor.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_header_alias_utils.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_hook_extra_headers.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_logging.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_max_concurrent_requests.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_metadata_preservation.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_oauth_passthrough.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_oauth_passthrough_cold_start.py (90%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_oauth_passthrough_tools.py (93%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_partial_update.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_proxy_mode.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sampling_completion_flow.py (85%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sampling_model_access.py (92%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sampling_model_resolution.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sampling_priority_selection.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sampling_request_builder.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sampling_response_conversion.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sampling_tool_conversion.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_server.py (92%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_server_identity_env.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_server_manager.py (96%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_server_tool_calls_and_headers.py (91%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_session_logging.py (91%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_sigv4_auth.py (93%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_stale_session.py (84%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_tool_search.py (90%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_mcp_toolset_scope.py (88%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_oauth2_flow_backfill.py (99%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_oauth2_mcp_config.yaml (100%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_oauth2_token_cache.py (90%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_oauth_identity_binding.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_oauth_issuer_stamp_backfill.py (98%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_openapi_spec_path_url.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_openapi_to_mcp_generator.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_openapi_tool_auth.py (91%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_operations.py (94%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_per_user_oauth_cache.py (91%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_proxy_api_credentials.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_rest_endpoints.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_result_conversion.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_semantic_tool_filter.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_server_resolution.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_short_mcp_tool_prefix.py (97%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_state_tokens.py (95%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_subscriptions.py (95%) rename tests/unit/proxy/{experimental => }/mcp_server/test_tool_registry.py (92%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_ui_session_utils.py (91%) rename tests/unit/proxy/{_experimental => }/mcp_server/test_utils.py (98%) diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 76af64c8ccd..9658e834c42 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -579,13 +579,13 @@ jobs: - shard: mcp-elicitation test-path: |- - tests/unit/experimental_mcp_client/test_mcp_client.py - tests/unit/proxy/_experimental/mcp_server/test_capabilities.py - tests/unit/proxy/_experimental/mcp_server/test_interactions.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py - tests/unit/proxy/_experimental/mcp_server/test_operations.py + tests/unit/mcp_client/test_mcp_client.py + tests/unit/proxy/mcp_server/test_capabilities.py + tests/unit/proxy/mcp_server/test_interactions.py + tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py + tests/unit/proxy/mcp_server/test_mcp_server_manager.py + tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py + tests/unit/proxy/mcp_server/test_operations.py python-version: "3.12" workers: 4 reruns: 0 @@ -603,7 +603,7 @@ jobs: tests/unit/proxy/spend_tracking --ignore=tests/unit/proxy/spend_tracking/test_search_api_logging.py tests/unit/proxy/pass_through_endpoints - tests/unit/proxy/experimental + tests/unit/proxy/mcp_server/test_tool_registry.py tests/unit/proxy/common_utils --ignore=tests/unit/proxy/common_utils/test_cache_aware_routing.py --ignore=tests/unit/proxy/common_utils/test_check_batch_cost.py @@ -811,14 +811,14 @@ jobs: - shard: mcp-oauth test-path: |- - tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py - tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py - tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py - tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py - tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py - tests/unit/proxy/_experimental/mcp_server/outbound_credentials + tests/unit/proxy/mcp_server/test_discoverable_endpoints.py + tests/unit/proxy/mcp_server/test_mcp_server_manager.py + tests/unit/proxy/mcp_server/test_db_credentials.py + tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py + tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py + tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py + tests/unit/proxy/mcp_server/faults/test_list_outcomes.py + tests/unit/proxy/mcp_server/outbound_credentials python-version: "3.12" workers: 4 reruns: 2 @@ -828,19 +828,21 @@ jobs: - shard: mcp-server test-path: |- + tests/unit/mcp_client tests/unit/experimental_mcp_client + tests/unit/proxy/mcp_server tests/unit/proxy/_experimental/mcp_server tests/unit/responses/mcp - --ignore=tests/unit/experimental_mcp_client/test_mcp_client.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_capabilities.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_interactions.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_operations.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py - --ignore=tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py - --ignore=tests/unit/proxy/_experimental/mcp_server/outbound_credentials + --ignore=tests/unit/mcp_client/test_mcp_client.py + --ignore=tests/unit/proxy/mcp_server/test_capabilities.py + --ignore=tests/unit/proxy/mcp_server/test_interactions.py + --ignore=tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py + --ignore=tests/unit/proxy/mcp_server/test_mcp_server_manager.py + --ignore=tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py + --ignore=tests/unit/proxy/mcp_server/test_operations.py + --ignore=tests/unit/proxy/mcp_server/test_discoverable_endpoints.py + --ignore=tests/unit/proxy/mcp_server/test_db_credentials.py + --ignore=tests/unit/proxy/mcp_server/outbound_credentials python-version: "3.12" workers: 4 reruns: 0 diff --git a/.gitignore b/.gitignore index 5ca20f02274..b08ee92d6af 100644 --- a/.gitignore +++ b/.gitignore @@ -105,7 +105,7 @@ litellm_config.yaml .cursor litellm/proxy/to_delete_loadtest_work/* update_model_cost_map.py -tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py +tests/unit/proxy/mcp_server/test_mcp_server_manager.py scripts/test_vertex_ai_search.py LAZY_LOADING_IMPROVEMENTS.md STABILIZATION_TODO.md diff --git a/Makefile b/Makefile index dec853515b9..937873f8835 100644 --- a/Makefile +++ b/Makefile @@ -313,7 +313,7 @@ test-unit-proxy-core: install-test-deps $(UV_RUN) pytest tests/unit/proxy/auth tests/unit/proxy/client tests/unit/proxy/db tests/unit/proxy/hooks tests/unit/proxy/policy_engine --ignore=tests/unit/proxy/db/db_transaction_queue/test_e2e_pod_lock_manager.py --ignore=tests/unit/proxy/db/test_update_daily_tag_spend.py --tb=short -vv -n 4 --durations=20 test-unit-proxy-misc: install-test-deps - $(UV_RUN) pytest tests/unit/proxy/agent_endpoints tests/unit/proxy/anthropic_endpoints tests/unit/proxy/common_utils --ignore=tests/unit/proxy/common_utils/test_cache_aware_routing.py --ignore=tests/unit/proxy/common_utils/test_check_batch_cost.py --ignore=tests/unit/proxy/common_utils/test_check_responses_cost.py --ignore=tests/unit/proxy/common_utils/test_proxy_encrypt_decrypt.py --ignore=tests/unit/proxy/common_utils/test_realtime_cache.py tests/unit/proxy/discovery_endpoints tests/unit/proxy/experimental tests/unit/proxy/google_endpoints tests/unit/proxy/health_endpoints tests/unit/proxy/image_endpoints tests/unit/proxy/middleware --ignore=tests/unit/proxy/middleware/test_request_size_limit_middleware.py tests/unit/proxy/openai_files_endpoint tests/unit/proxy/pass_through_endpoints tests/unit/proxy/prompts tests/unit/proxy/public_endpoints tests/unit/proxy/response_api_endpoints tests/unit/proxy/shutdown tests/unit/proxy/spend_tracking --ignore=tests/unit/proxy/spend_tracking/test_search_api_logging.py tests/unit/proxy/ui_crud_endpoints tests/unit/proxy/vector_store_endpoints tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py --ignore=tests/unit/proxy/google_endpoints/test_gemini_agents_endpoints.py --ignore=tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py --ignore=tests/unit/proxy/google_endpoints/test_google_gemini_proxy_request.py --ignore=tests/unit/proxy/public_endpoints/test_blog_posts_endpoint.py --tb=short -vv -n 4 --durations=20 + $(UV_RUN) pytest tests/unit/proxy/agent_endpoints tests/unit/proxy/anthropic_endpoints tests/unit/proxy/common_utils --ignore=tests/unit/proxy/common_utils/test_cache_aware_routing.py --ignore=tests/unit/proxy/common_utils/test_check_batch_cost.py --ignore=tests/unit/proxy/common_utils/test_check_responses_cost.py --ignore=tests/unit/proxy/common_utils/test_proxy_encrypt_decrypt.py --ignore=tests/unit/proxy/common_utils/test_realtime_cache.py tests/unit/proxy/discovery_endpoints tests/unit/proxy/mcp_server/test_tool_registry.py tests/unit/proxy/google_endpoints tests/unit/proxy/health_endpoints tests/unit/proxy/image_endpoints tests/unit/proxy/middleware --ignore=tests/unit/proxy/middleware/test_request_size_limit_middleware.py tests/unit/proxy/openai_files_endpoint tests/unit/proxy/pass_through_endpoints tests/unit/proxy/prompts tests/unit/proxy/public_endpoints tests/unit/proxy/response_api_endpoints tests/unit/proxy/shutdown tests/unit/proxy/spend_tracking --ignore=tests/unit/proxy/spend_tracking/test_search_api_logging.py tests/unit/proxy/ui_crud_endpoints tests/unit/proxy/vector_store_endpoints tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py --ignore=tests/unit/proxy/google_endpoints/test_gemini_agents_endpoints.py --ignore=tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py --ignore=tests/unit/proxy/google_endpoints/test_google_gemini_proxy_request.py --ignore=tests/unit/proxy/public_endpoints/test_blog_posts_endpoint.py --tb=short -vv -n 4 --durations=20 test-unit-proxy-root: install-test-deps $(UV_RUN) pytest tests/unit/proxy/test_*.py --ignore=tests/unit/proxy/test_aproxy_startup.py --ignore=tests/unit/proxy/test_credential_slot_registry.py --ignore=tests/unit/proxy/test_custom_callback_input.py --ignore=tests/unit/proxy/test_custom_logger_s3_gcs.py --ignore=tests/unit/proxy/test_custom_tokenizer_bug.py --ignore=tests/unit/proxy/test_db_schema_changes.py --ignore=tests/unit/proxy/test_deprecated_key_grace_period.py --ignore=tests/unit/proxy/test_get_favicon.py --ignore=tests/unit/proxy/test_get_image.py --ignore=tests/unit/proxy/test_prisma_client_backoff_retry.py --ignore=tests/unit/proxy/test_prompt_test_endpoint.py --ignore=tests/unit/proxy/test_proxy_config_unit_test.py --ignore=tests/unit/proxy/test_proxy_custom_auth.py --ignore=tests/unit/proxy/test_proxy_reject_logging.py --ignore=tests/unit/proxy/test_proxy_server.py --ignore=tests/unit/proxy/test_proxy_setting_guardrails.py --ignore=tests/unit/proxy/test_proxy_token_counter.py --ignore=tests/unit/proxy/test_proxy_utils.py --ignore=tests/unit/proxy/test_reducto_ocr_route.py --ignore=tests/unit/proxy/test_response_polling_pre_call_checks.py --ignore=tests/unit/proxy/test_server_root_path.py --ignore=tests/unit/proxy/test_ui_path_detection.py --ignore=tests/unit/proxy/test_unit_test_proxy_hooks.py --ignore=tests/unit/proxy/test_update_spend.py --ignore=tests/unit/proxy/test_zero_cost_model_budget_bypass.py --tb=short -vv -n 4 --durations=20 @@ -325,7 +325,7 @@ test-unit-core-utils: install-test-deps $(UV_RUN) pytest tests/unit/litellm_core_utils --tb=short -vv -n 2 --durations=20 test-unit-other: install-test-deps - $(UV_RUN) pytest tests/unit/caching tests/unit/responses tests/unit/secret_managers tests/unit/vector_stores tests/unit/a2a_protocol tests/unit/completion_extras tests/unit/containers tests/unit/enterprise tests/unit/experimental_mcp_client tests/unit/google_genai tests/unit/images tests/unit/interactions tests/unit/router_strategy tests/unit/router_utils tests/unit/types --tb=short -vv -n 4 --durations=20 + $(UV_RUN) pytest tests/unit/caching tests/unit/responses tests/unit/secret_managers tests/unit/vector_stores tests/unit/a2a_protocol tests/unit/completion_extras tests/unit/containers tests/unit/enterprise tests/unit/mcp_client tests/unit/google_genai tests/unit/images tests/unit/interactions tests/unit/router_strategy tests/unit/router_utils tests/unit/types --tb=short -vv -n 4 --durations=20 test-unit-root: install-test-deps $(UV_RUN) pytest tests/unit/test_*.py --tb=short -vv -n 4 --durations=20 diff --git a/README.md b/README.md index 4feb6e00ffa..5dfa8d01fc4 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,7 @@ async with httpx.AsyncClient(headers=headers, timeout=60.0) as http_client: ```python from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client -from litellm import experimental_mcp_client +from litellm import mcp_client import litellm server_params = StdioServerParameters(command="python", args=["mcp_server.py"]) @@ -233,7 +233,7 @@ async with stdio_client(server_params) as (read, write): await session.initialize() # Load MCP tools in OpenAI format - tools = await experimental_mcp_client.load_mcp_tools(session=session, format="openai") + tools = await mcp_client.load_mcp_tools(session=session, format="openai") # Use with any LiteLLM model response = await litellm.acompletion( diff --git a/enterprise/litellm_enterprise/proxy/liteadmin.py b/enterprise/litellm_enterprise/proxy/liteadmin.py index e89bf11bd6e..bbf42829f47 100644 --- a/enterprise/litellm_enterprise/proxy/liteadmin.py +++ b/enterprise/litellm_enterprise/proxy/liteadmin.py @@ -18,8 +18,8 @@ from fastapi.responses import HTMLResponse, RedirectResponse, Response from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.oauth_utils import get_request_base_url from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.mcp_server.oauth_utils import get_request_base_url from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.auth.auth_checks import UserNotFoundError @@ -122,7 +122,7 @@ def _cookie_name(token: str) -> str: async def _session_user(request: Request) -> str | None: - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( get_authenticated_browser_user_id, ) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 8331c68fe24..86b22069a39 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -1980,7 +1980,7 @@ def completion_cost( base_pricing_model=(selected_model if base_model is not None and not custom_pricing else None), ) elif call_type == _MCP_CALL_TYPE: - from litellm.proxy._experimental.mcp_server.cost_calculator import ( + from litellm.proxy.mcp_server.cost_calculator import ( MCPCostCalculator, ) diff --git a/litellm/experimental_mcp_client/__init__.py b/litellm/experimental_mcp_client/__init__.py index 7a3917a50ea..f2905c0f95c 100644 --- a/litellm/experimental_mcp_client/__init__.py +++ b/litellm/experimental_mcp_client/__init__.py @@ -1,8 +1,7 @@ -try: - from .tools import call_openai_tool, load_mcp_tools -except ModuleNotFoundError as exc: - if exc.name not in ("mcp", "httpx2"): - raise - raise ImportError("MCP client dependencies are missing. Install them with: pip install 'litellm[mcp]'") from exc +import litellm.mcp_client as _mcp_client +from litellm.litellm_core_utils.deprecated_package import alias_deprecated_package +from litellm.mcp_client import call_openai_tool, load_mcp_tools + +alias_deprecated_package(__name__, _mcp_client) __all__ = ["call_openai_tool", "load_mcp_tools"] diff --git a/litellm/litellm_core_utils/deprecated_package.py b/litellm/litellm_core_utils/deprecated_package.py new file mode 100644 index 00000000000..542686ecf19 --- /dev/null +++ b/litellm/litellm_core_utils/deprecated_package.py @@ -0,0 +1,53 @@ +import importlib +import sys +import warnings +from itertools import chain +from pathlib import Path +from types import ModuleType +from typing import Final + + +def _dotted_name(root: Path, path: Path, package_name: str) -> str: + parts: Final = path.relative_to(root).with_suffix("").parts + return ".".join((package_name, *parts)).removesuffix(".__init__") + + +def _parents_and_self(dotted: str, package_name: str) -> tuple[str, ...]: + parts: Final = dotted.removeprefix(f"{package_name}.").split(".") + return tuple(f"{package_name}.{'.'.join(parts[:depth])}" for depth in range(1, len(parts) + 1)) + + +def _module_names(package: ModuleType) -> tuple[str, ...]: + roots: Final = tuple(Path(root) for root in package.__path__) + files: Final = tuple( + (root, path) for root in roots for path in root.rglob("*.py") + ) # comprehension-ok: nested walk over each package root + leaves: Final = tuple( + name + for name in (_dotted_name(root, path, package.__name__) for root, path in files) + if name != package.__name__ + ) + return tuple( + sorted( + set(chain.from_iterable(_parents_and_self(leaf, package.__name__) for leaf in leaves)) - {package.__name__} + ) + ) + + +def _alias(old_name: str, new_package_name: str, new_dotted: str) -> None: + module: Final = importlib.import_module(new_dotted) + old_dotted: Final = f"{old_name}{new_dotted.removeprefix(new_package_name)}" + old_parent, _, child = old_dotted.rpartition(".") + sys.modules[old_dotted] = module + setattr(sys.modules[old_parent], child, module) + + +def alias_deprecated_package(old_name: str, new_package: ModuleType) -> None: + """Make every module under ``new_package`` importable and attribute-reachable under ``old_name`` and warn once.""" + warnings.warn( + f"{old_name} is deprecated, import {new_package.__name__} instead", + DeprecationWarning, + stacklevel=3, + ) + for new_dotted in _module_names(new_package): + _alias(old_name, new_package.__name__, new_dotted) diff --git a/litellm/llms/__init__.py b/litellm/llms/__init__.py index 91f33635658..c18ce8cea68 100644 --- a/litellm/llms/__init__.py +++ b/litellm/llms/__init__.py @@ -144,7 +144,7 @@ def discover_guardrail_translation_mappings() -> dict[CallTypes, type["BaseTrans continue try: - from litellm.proxy._experimental.mcp_server.guardrail_translation import ( + from litellm.proxy.mcp_server.guardrail_translation import ( guardrail_translation_mappings as mcp_guardrail_translation_mappings, ) diff --git a/litellm/llms/anthropic/messages/native/mcp_handler.py b/litellm/llms/anthropic/messages/native/mcp_handler.py index 9df3c2c32e5..8fe18d79f24 100644 --- a/litellm/llms/anthropic/messages/native/mcp_handler.py +++ b/litellm/llms/anthropic/messages/native/mcp_handler.py @@ -76,12 +76,12 @@ async def anthropic_messages_with_mcp( upstream provider as a url it cannot reach. """ import litellm - from litellm.experimental_mcp_client.tools import ( - transform_mcp_tool_to_anthropic_tool, - ) from litellm.llms.anthropic.messages.adapters.handler import request_safeguards_evaluator from litellm.llms.anthropic.messages.native.handler import proxy_classifies_tool_uses from litellm.llms.anthropic.messages.safeguards import with_safeguard_results + from litellm.mcp_client.tools import ( + transform_mcp_tool_to_anthropic_tool, + ) from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) diff --git a/litellm/experimental_mcp_client/Readme.md b/litellm/mcp_client/Readme.md similarity index 89% rename from litellm/experimental_mcp_client/Readme.md rename to litellm/mcp_client/Readme.md index 3385a37cf69..b6008591dd7 100644 --- a/litellm/experimental_mcp_client/Readme.md +++ b/litellm/mcp_client/Readme.md @@ -5,13 +5,13 @@ LiteLLM MCP Client allows you to use MCP tools with LiteLLM Install the optional dependencies with `pip install 'litellm[mcp]'`, then use the existing public imports: ```python -from litellm.experimental_mcp_client import call_openai_tool, load_mcp_tools -from litellm.experimental_mcp_client.client import MCPClient +from litellm.mcp_client import call_openai_tool, load_mcp_tools +from litellm.mcp_client.client import MCPClient client = MCPClient(server_url="https://mcp.example.com/mcp") ``` -Core `import litellm` works without the MCP extra. Importing the experimental MCP client without its MCP or HTTPX2 dependency raises an error with this installation command +`litellm.experimental_mcp_client` is a deprecated alias of `litellm.mcp_client` that warns on import. Core `import litellm` works without the MCP extra. Importing the MCP client without its MCP or HTTPX2 dependency raises an error with this installation command ## MCP Python SDK compatibility diff --git a/litellm/mcp_client/__init__.py b/litellm/mcp_client/__init__.py new file mode 100644 index 00000000000..7a3917a50ea --- /dev/null +++ b/litellm/mcp_client/__init__.py @@ -0,0 +1,8 @@ +try: + from .tools import call_openai_tool, load_mcp_tools +except ModuleNotFoundError as exc: + if exc.name not in ("mcp", "httpx2"): + raise + raise ImportError("MCP client dependencies are missing. Install them with: pip install 'litellm[mcp]'") from exc + +__all__ = ["call_openai_tool", "load_mcp_tools"] diff --git a/litellm/experimental_mcp_client/client.py b/litellm/mcp_client/client.py similarity index 98% rename from litellm/experimental_mcp_client/client.py rename to litellm/mcp_client/client.py index 79887e4ab99..107b7155303 100644 --- a/litellm/experimental_mcp_client/client.py +++ b/litellm/mcp_client/client.py @@ -100,11 +100,11 @@ from litellm.constants import ( MCP_TOOL_LISTING_MAX_PAGES, MCP_TOOL_LISTING_TIMEOUT, ) -from litellm.experimental_mcp_client.tools import list_tools_with_pagination from litellm.llms.custom_httpx.http_handler import get_ssl_configuration -from litellm.proxy._experimental.mcp_server.mcp_context import get_active_mcp_request_ctx -from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.mcp_client.tools import list_tools_with_pagination +from litellm.proxy.mcp_server.mcp_context import get_active_mcp_request_ctx +from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response +from litellm.proxy.mcp_server.result_conversion import ( age_freshness, aggregate_freshness, error_text_result, @@ -125,14 +125,14 @@ from litellm.types.mcp import ( ) if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult - from litellm.proxy._experimental.mcp_server.legacy_callbacks import ElicitationCallback + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult + from litellm.proxy.mcp_server.legacy_callbacks import ElicitationCallback def _mcp_response_hooks() -> tuple[Callable[[httpx2.Response], Awaitable[None]], ...]: if get_active_mcp_request_ctx() is None: return (capture_upstream_error_response,) - from litellm.proxy._experimental.mcp_server.legacy_callbacks import ( + from litellm.proxy.mcp_server.legacy_callbacks import ( get_scope_response, record_upstream_tool_authorization, ) @@ -564,7 +564,7 @@ class MCPClient: return self._hash_discovery_auth(await self.prepare_request_auth(), self._aws_identity()) async def subscription_auth_fingerprint(self) -> str: - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) @@ -1125,8 +1125,8 @@ class MCPClient: request_state: str | None, allow_input_required: bool, ) -> TSessionResult | InputRequiredResult: - from litellm.proxy._experimental.mcp_server.contracts import ClientInteraction - from litellm.proxy._experimental.mcp_server.interactions import LegacyClientInteraction, ModernClientInteraction + from litellm.proxy.mcp_server.contracts import ClientInteraction + from litellm.proxy.mcp_server.interactions import LegacyClientInteraction, ModernClientInteraction with anyio.fail_after(self.timeout): first: Final = await request(input_responses, request_state) diff --git a/litellm/experimental_mcp_client/tools.py b/litellm/mcp_client/tools.py similarity index 100% rename from litellm/experimental_mcp_client/tools.py rename to litellm/mcp_client/tools.py diff --git a/litellm/proxy/_experimental/mcp_server/__init__.py b/litellm/proxy/_experimental/mcp_server/__init__.py new file mode 100644 index 00000000000..cf217531dc4 --- /dev/null +++ b/litellm/proxy/_experimental/mcp_server/__init__.py @@ -0,0 +1,4 @@ +import litellm.proxy.mcp_server as _mcp_server +from litellm.litellm_core_utils.deprecated_package import alias_deprecated_package + +alias_deprecated_package(__name__, _mcp_server) diff --git a/litellm/proxy/_lazy_features.py b/litellm/proxy/_lazy_features.py index 4e54d6ac733..db01475154b 100644 --- a/litellm/proxy/_lazy_features.py +++ b/litellm/proxy/_lazy_features.py @@ -163,7 +163,7 @@ LAZY_FEATURES: Final[tuple[LazyFeature, ...]] = ( # /.well-known/oauth-authorization-server: the root document is the # gateway's own authorization server metadata (token endpoint /token). name="mcp_discoverable", - module_path="litellm.proxy._experimental.mcp_server.discoverable_endpoints", + module_path="litellm.proxy.mcp_server.discoverable_endpoints", path_prefixes=( "/oauth/client-metadata.json", "/.well-known/oauth-", @@ -185,19 +185,19 @@ LAZY_FEATURES: Final[tuple[LazyFeature, ...]] = ( # No /mcp/oauth prefix here: the mounted /mcp sub-app would # shadow it, and there are no actual routes there anyway. name="mcp_byok_oauth", - module_path="litellm.proxy._experimental.mcp_server.byok_oauth_endpoints", + module_path="litellm.proxy.mcp_server.byok_oauth_endpoints", path_prefixes=("/v1/mcp/oauth", "/.well-known/oauth-"), ), LazyFeature( name="mcp_rest", - module_path="litellm.proxy._experimental.mcp_server.rest_endpoints", + module_path="litellm.proxy.mcp_server.rest_endpoints", path_prefixes=("/mcp-rest",), ), LazyFeature( # Hardcoded /mcp matches BASE_MCP_ROUTE; importing the constant # here would defeat lazy loading. name="mcp_app", - module_path="litellm.proxy._experimental.mcp_server.server", + module_path="litellm.proxy.mcp_server.server", path_prefixes=("/mcp",), register_fn=_mount_app("/mcp", attr_name="app"), persistent_swagger_stub=True, diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 49d23d82aa9..dd91bb6eef3 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -37,7 +37,7 @@ from litellm.litellm_core_utils.initialize_dynamic_callback_params import ( validate_langfuse_span_scope_value, validate_no_callback_env_reference, ) -from litellm.proxy._experimental.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled +from litellm.proxy.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled from litellm.types.agents import ( AgentCaller as AgentCaller, # noqa: PLC0414 # public re-export ) diff --git a/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py b/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py index dd002a2763e..9be9d4c7121 100644 --- a/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py +++ b/litellm/proxy/agent_endpoints/auth/agent_permission_handler.py @@ -16,7 +16,6 @@ from fastapi import HTTPException from pydantic import TypeAdapter, ValidationError from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.ui_session_utils import build_effective_auth_contexts from litellm.proxy._types import ( UI_TEAM_ID, LiteLLM_ObjectPermissionTable, @@ -30,6 +29,7 @@ from litellm.proxy.agent_endpoints.auth.agent_access_groups import ( ) from litellm.proxy.agent_endpoints.auth.agent_caller import agent_caller_auth from litellm.proxy.agent_endpoints.auth.managed_authorization import managed_agent_policy +from litellm.proxy.mcp_server.ui_session_utils import build_effective_auth_contexts from litellm.repositories.table_repositories import AgentsRepository from litellm.types.agents import AgentResponse @@ -244,7 +244,7 @@ class AgentRequestHandler: or user_api_key_auth is None ): return False - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler key_hash: Final = user_api_key_auth.api_key or user_api_key_auth.token authority: Final = ( @@ -905,7 +905,7 @@ async def _managed_actor_agent_access(auth: UserAPIKeyAuth) -> AgentAccess: async def _verified_human_agent_sources( user_id: str | None, *, allowed_team_ids: frozenset[str] | None = None ) -> tuple[tuple[str | None, frozenset[str]], ...]: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler if user_id is None: return () diff --git a/litellm/proxy/anthropic_endpoints/gateway_endpoints.py b/litellm/proxy/anthropic_endpoints/gateway_endpoints.py index ba3307bc1ad..1911cb574ef 100644 --- a/litellm/proxy/anthropic_endpoints/gateway_endpoints.py +++ b/litellm/proxy/anthropic_endpoints/gateway_endpoints.py @@ -37,18 +37,6 @@ from litellm.constants import ( CLI_SSO_SESSION_TTL_SECONDS, LITELLM_CLI_SOURCE_IDENTIFIER, ) -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( - PROXY_API_AUDIENCE, - MintedProxyCredential, - MintProxyCredential, - SessionSigning, - proxy_credential_response, - refresh_proxy_credential, - resolve_session_signing, - revoke_session_refresh_token, -) -from litellm.proxy._experimental.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import SessionPrincipal from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRoles from litellm.proxy.anthropic_endpoints.endpoints import anthropic_response, count_tokens from litellm.proxy.auth.user_api_key_auth import user_api_key_auth @@ -58,6 +46,18 @@ from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # leg ) from litellm.proxy.management_endpoints.sso_helper_utils import CLI_SSO_SESSIONS_TARGET from litellm.proxy.management_endpoints.ui_sso import CliSsoTeamDetail +from litellm.proxy.mcp_server.gateway_dcr_flow import ( + PROXY_API_AUDIENCE, + MintedProxyCredential, + MintProxyCredential, + SessionSigning, + proxy_credential_response, + refresh_proxy_credential, + resolve_session_signing, + revoke_session_refresh_token, +) +from litellm.proxy.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS +from litellm.proxy.mcp_server.outbound_credentials.session_token import SessionPrincipal from litellm.proxy.proxy_server import model_list from litellm.types.llms.base import LiteLLMBaseModel @@ -340,7 +340,7 @@ async def _claim_device_code(login_id: str, cache: DualCache) -> bool: def _proxy_credential_minter() -> MintProxyCredential: - from litellm.proxy._experimental.mcp_server.proxy_api_credentials import mint_proxy_credential + from litellm.proxy.mcp_server.proxy_api_credentials import mint_proxy_credential return mint_proxy_credential diff --git a/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py b/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py index 86e77596e70..8225984a964 100644 --- a/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py +++ b/litellm/proxy/discovery_endpoints/ui_discovery_endpoints.py @@ -4,8 +4,8 @@ from typing import Final from fastapi import APIRouter -from litellm.proxy._experimental.mcp_server.stdio_gate import is_mcp_stdio_enabled from litellm.proxy.common_utils.html_forms.default_credentials_hint import should_hide_default_credentials_hint +from litellm.proxy.mcp_server.stdio_gate import is_mcp_stdio_enabled from litellm.types.proxy.discovery_endpoints.ui_discovery_endpoints import ( UiDiscoveryEndpoints, ) diff --git a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py index 224f1f78270..da131931aec 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py +++ b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py @@ -38,9 +38,9 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.utils import JSONLeafPath, json_string_leaves from litellm.proxy._types import SpecialHeaders from litellm.proxy.litellm_pre_call_utils import get_chain_id_from_headers +from litellm.proxy.mcp_server.utils import JSONLeafPath, json_string_leaves from litellm.types.guardrails import GuardrailEventHooks, LitellmParams, Mode from litellm.types.proxy.guardrails.guardrail_hooks.akto import AktoGuardrailConfigModelOptionalParams from litellm.types.utils import CallTypes, GenericGuardrailAPIInputs diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py index d7ce3438fca..ab35ead03c7 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_end_user_permission/mcp_end_user_permission.py @@ -189,7 +189,7 @@ class MCPEndUserPermissionGuardrail(CustomGuardrail): if not direct_mcp_servers and not mcp_access_groups: return None # Both empty → no restrictions - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py index 3cb20a00e2f..9c0a574ae3b 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_security/mcp_security_guardrail.py @@ -104,7 +104,7 @@ class MCPSecurityGuardrail(CustomGuardrail): if not requested_servers: return frozenset() - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py index 6426bfb8788..d50001ba636 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py +++ b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py @@ -577,7 +577,7 @@ class PanwPrismaAirsHandler(CustomGuardrail): if request_data.get("server_name"): return request_data["server_name"] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/hooks/mcp_semantic_filter/hook.py b/litellm/proxy/hooks/mcp_semantic_filter/hook.py index d33811d3dea..c6e26999766 100644 --- a/litellm/proxy/hooks/mcp_semantic_filter/hook.py +++ b/litellm/proxy/hooks/mcp_semantic_filter/hook.py @@ -18,16 +18,16 @@ from litellm.constants import ( DEFAULT_MCP_SEMANTIC_FILTER_TOP_K, ) from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( +from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) if TYPE_CHECKING: from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.router import Router @@ -487,7 +487,7 @@ class SemanticToolFilterHook(CustomLogger): Returns: SemanticToolFilterHook instance if enabled, None otherwise """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index 5f1948d1c1c..baa150efc86 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -2525,7 +2525,7 @@ async def add_litellm_data_to_request( _headers, allow_client_message_redaction_opt_out=_allow_client_message_redaction_opt_out, ) - from litellm.proxy._experimental.mcp_server.utils import upstream_credential_headers + from litellm.proxy.mcp_server.utils import upstream_credential_headers _mcp_credential_headers: Final = upstream_credential_headers(_headers) _logging_safe_headers: Final = redact_credential_headers( diff --git a/litellm/proxy/management_endpoints/access_group_endpoints.py b/litellm/proxy/management_endpoints/access_group_endpoints.py index a87455e5a60..6558c82f80c 100644 --- a/litellm/proxy/management_endpoints/access_group_endpoints.py +++ b/litellm/proxy/management_endpoints/access_group_endpoints.py @@ -10,7 +10,6 @@ from typing_extensions import ReadOnly, TypedDict from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger from litellm.litellm_core_utils.core_helpers import iter_items -from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import ( CommonProxyErrors, LiteLLM_AccessGroupTable, @@ -37,6 +36,7 @@ from litellm.proxy.management_helpers.resource_display_names import ( key_display_names, mcp_server_display_names, ) +from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.utils import PrismaClient, get_prisma_client_or_throw from litellm.repositories.table_repositories import AccessGroupRepository, TeamRepository from litellm.types.access_group import ( diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 0ad4258fb04..b97d409a6c3 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -44,14 +44,6 @@ from litellm.litellm_core_utils.duration_parser import duration_in_seconds from litellm.litellm_core_utils.safe_json_dumps import safe_dumps from litellm.models.credentials import CredentialItem from litellm.models.project import LiteLLM_ProjectTable -from litellm.proxy._experimental.mcp_server.db import ( - rotate_mcp_server_credentials_master_key, - rotate_mcp_user_credentials_master_key, - rotate_mcp_user_env_vars_master_key, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - rotate_sso_identity_assertions_master_key, -) from litellm.proxy._types import * from litellm.proxy._types import Litellm_EntityType, LiteLLM_VerificationToken, hash_token from litellm.proxy.auth.auth_checks import ( # noqa: F401 # legacy module exports @@ -153,6 +145,14 @@ from litellm.proxy.management_helpers.team_member_permission_checks import ( TeamMemberPermissionChecks, ) from litellm.proxy.management_helpers.utils import management_endpoint_wrapper +from litellm.proxy.mcp_server.db import ( + rotate_mcp_server_credentials_master_key, + rotate_mcp_user_credentials_master_key, + rotate_mcp_user_env_vars_master_key, +) +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + rotate_sso_identity_assertions_master_key, +) from litellm.proxy.search_endpoints.search_tool_registry import rotate_search_tools_master_key from litellm.proxy.spend_tracking.budget_reservation import get_budget_window_start from litellm.proxy.spend_tracking.spend_counter_batch import SPEND_COUNTERS_TARGET diff --git a/litellm/proxy/management_endpoints/mcp_management_endpoints.py b/litellm/proxy/management_endpoints/mcp_management_endpoints.py index 776072c69be..f6b836bc4be 100644 --- a/litellm/proxy/management_endpoints/mcp_management_endpoints.py +++ b/litellm/proxy/management_endpoints/mcp_management_endpoints.py @@ -49,7 +49,7 @@ from fastapi.responses import JSONResponse from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, public_catalog_operation +from litellm.proxy.mcp_server.catalog import catalog_operation, public_catalog_operation try: from prisma.errors import RecordNotFoundError, UniqueViolationError @@ -63,19 +63,6 @@ from litellm._logging import verbose_logger, verbose_proxy_logger from litellm._uuid import uuid from litellm.constants import LITELLM_PROXY_ADMIN_NAME, MCP_GATEWAY_SESSION_ID_PREFIX_LENGTH from litellm.litellm_core_utils.core_helpers import as_str_mapping -from litellm.proxy._experimental.mcp_server.utils import ( - LITELLM_MCP_SERVER_DESCRIPTION, - LITELLM_MCP_SERVER_NAME, - MCP_SERVERS_TARGET, - McpServerPayloadLike, - build_env_var_setup_url, - collect_env_var_references, - get_server_prefix, - parse_admin_env_vars, -) -from litellm.proxy._experimental.mcp_server.utils import ( - validate_and_normalize_mcp_server_payload as _base_validate_and_normalize_mcp_server_payload, -) from litellm.proxy.common_utils.encrypt_decrypt_utils import ( decrypt_value_helper, encrypt_value_helper, @@ -87,6 +74,19 @@ from litellm.proxy.management_helpers.audit_logs import ( get_audit_log_changed_by, is_audit_logging_enabled, ) +from litellm.proxy.mcp_server.utils import ( + LITELLM_MCP_SERVER_DESCRIPTION, + LITELLM_MCP_SERVER_NAME, + MCP_SERVERS_TARGET, + McpServerPayloadLike, + build_env_var_setup_url, + collect_env_var_references, + get_server_prefix, + parse_admin_env_vars, +) +from litellm.proxy.mcp_server.utils import ( + validate_and_normalize_mcp_server_payload as _base_validate_and_normalize_mcp_server_payload, +) from litellm.repositories.table_repositories import ( MCPServerRepository, MCPUserCredentialsRepository, @@ -159,63 +159,6 @@ if MCP_AVAILABLE: def validate_tool_name(name: str) -> _ToolNameValidationResult: return _ToolNameValidationResult() - from litellm.proxy._experimental.mcp_server.contracts import TargetCatalog - from litellm.proxy._experimental.mcp_server.db import ( - McpIdentifierConflict, - approve_mcp_server, - create_draft_mcp_server, - create_mcp_server_if_identifier_free, - delete_mcp_server, - delete_user_credential, - delete_user_env_vars, - get_all_mcp_servers, - get_draft_mcp_server, - get_mcp_server, - get_mcp_servers, - get_mcp_submissions, - get_user_env_vars, - get_user_env_vars_bulk, - get_user_oauth_credential, - is_resubmitted_oauth_client, - list_server_user_credentials, - list_user_oauth_credentials, - mcp_oauth_token_identity, - merge_user_env_vars, - oauth_credentials_for_upstream_edit, - purge_user_oauth_credentials_for_server, - reject_mcp_server, - set_mcp_server_pinned_tools, - stale_mcp_auth_fields, - store_user_credential, - store_user_oauth_credential, - update_mcp_server, - ) - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( # noqa: F401 # legacy module exports - _raise_if_not_oauth2, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export - authorize_with_server, - client_supplied_application_type, - client_supplied_redirect_uris, - exchange_token_with_server, - get_request_base_url, - raise_if_not_oauth2, - redeem_passthrough_authorization_code, - register_client_with_server, - resolve_ephemeral_dcr_client, - ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) - from litellm.proxy._experimental.mcp_server.server_resolution import ( - MCPServerTargetCatalog, - authorize_mcp_server, - resolve_mcp_server, - ) - from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - admitted_user_context, - build_effective_auth_contexts, - granted_toolset_ids, - is_ui_session_credential, - ) from litellm.proxy._types import ( LiteLLM_MCPServerTable, LiteLLM_ObjectPermissionTable, @@ -266,6 +209,63 @@ if MCP_AVAILABLE: convert_connector_entries, ) from litellm.proxy.management_helpers.utils import management_endpoint_wrapper + from litellm.proxy.mcp_server.contracts import TargetCatalog + from litellm.proxy.mcp_server.db import ( + McpIdentifierConflict, + approve_mcp_server, + create_draft_mcp_server, + create_mcp_server_if_identifier_free, + delete_mcp_server, + delete_user_credential, + delete_user_env_vars, + get_all_mcp_servers, + get_draft_mcp_server, + get_mcp_server, + get_mcp_servers, + get_mcp_submissions, + get_user_env_vars, + get_user_env_vars_bulk, + get_user_oauth_credential, + is_resubmitted_oauth_client, + list_server_user_credentials, + list_user_oauth_credentials, + mcp_oauth_token_identity, + merge_user_env_vars, + oauth_credentials_for_upstream_edit, + purge_user_oauth_credentials_for_server, + reject_mcp_server, + set_mcp_server_pinned_tools, + stale_mcp_auth_fields, + store_user_credential, + store_user_oauth_credential, + update_mcp_server, + ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( # noqa: F401 # legacy module exports + _raise_if_not_oauth2, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export + authorize_with_server, + client_supplied_application_type, + client_supplied_redirect_uris, + exchange_token_with_server, + get_request_base_url, + raise_if_not_oauth2, + redeem_passthrough_authorization_code, + register_client_with_server, + resolve_ephemeral_dcr_client, + ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) + from litellm.proxy.mcp_server.server_resolution import ( + MCPServerTargetCatalog, + authorize_mcp_server, + resolve_mcp_server, + ) + from litellm.proxy.mcp_server.ui_session_utils import ( + admitted_user_context, + build_effective_auth_contexts, + granted_toolset_ids, + is_ui_session_credential, + ) from litellm.types.mcp import ( MCP_ADMIN_CONFIG_CREDENTIAL_KEYS, MCPAuth, @@ -1097,7 +1097,7 @@ if MCP_AVAILABLE: """ Get all MCP tools available for the current key, including those from access groups """ - from litellm.proxy._experimental.mcp_server.server import _list_mcp_tools + from litellm.proxy.mcp_server.server import _list_mcp_tools listing: Final = await _list_mcp_tools( user_api_key_auth=user_api_key_dict, @@ -1122,7 +1122,7 @@ if MCP_AVAILABLE: """ Get all available MCP access groups from the database AND config """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client @@ -1678,7 +1678,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_403_FORBIDDEN, detail={"error": "Admin access required to view MCP gateway sessions."}, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( get_mcp_gateway_sessions_report, ) @@ -1713,7 +1713,7 @@ if MCP_AVAILABLE: "error": "Provide session_id_prefix and/or user_id to select the sessions to terminate.", }, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( terminate_mcp_gateway_sessions, ) @@ -1777,7 +1777,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_404_NOT_FOUND, detail={"error": f"MCP server '{server_id}' not found in the database."}, ) - from litellm.proxy._experimental.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog + from litellm.proxy.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog snapshot: Final = await fetch_pinnable_tool_catalog(server, request, user_api_key_dict) if not snapshot: @@ -2342,12 +2342,12 @@ if MCP_AVAILABLE: # issued to this client could mint fresh upstream access tokens through # us. Require normal LiteLLM auth for those. if not api_key: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 - global_mcp_server_manager, - ) from litellm.proxy.auth.auth_utils import ( # noqa: PLC0415 get_request_route, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + global_mcp_server_manager, + ) server_id: Final[str] = request.path_params.get("server_id", "") if server_id: @@ -2677,7 +2677,7 @@ if MCP_AVAILABLE: ) if payload.save: await store_user_credential(prisma_client, user_id, server_id, payload.credential) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _invalidate_byok_cred_cache, ) @@ -2708,7 +2708,7 @@ if MCP_AVAILABLE: await delete_user_credential(prisma_client, target_user_id, server_id) except RecordNotFoundError: pass # Already deleted or didn't exist - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _invalidate_byok_cred_cache, ) @@ -2732,7 +2732,7 @@ if MCP_AVAILABLE: """Persist the OAuth2 access token obtained by the calling user.""" prisma_client: Final = get_prisma_client_or_throw("Database not connected. Connect a database to your proxy") await _authorize_and_fetch_mcp_server(prisma_client, user_api_key_dict, server_id) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # keep manager import lazy + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # keep manager import lazy global_mcp_server_manager as _manager, ) @@ -2769,7 +2769,7 @@ if MCP_AVAILABLE: expires_in=payload.expires_in, scopes=payload.scopes, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) @@ -2813,7 +2813,7 @@ if MCP_AVAILABLE: await delete_user_credential(prisma_client, target_user_id, server_id) except RecordNotFoundError: pass # Already gone — treat as a successful delete - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) @@ -3107,7 +3107,7 @@ if MCP_AVAILABLE: allowed_names: Final = {spec["name"] for spec in user_specs} updates: Final = {k: v for k, v in payload.values.items() if k in allowed_names and v != ""} merged: Final = await merge_user_env_vars(prisma_client, user_id, server_id, updates, allowed_names) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( invalidate_user_env_vars_cache, ) @@ -3134,7 +3134,7 @@ if MCP_AVAILABLE: ) server: Final = await _authorize_and_fetch_mcp_server(prisma_client, user_api_key_dict, server_id) await delete_user_env_vars(prisma_client, user_id, server_id) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( invalidate_user_env_vars_cache, ) @@ -3369,7 +3369,7 @@ if MCP_AVAILABLE: try: # Update the public model groups import litellm - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import proxy_config @@ -3532,7 +3532,7 @@ if MCP_AVAILABLE: # MCP Toolset endpoints # --------------------------------------------------------------------------- - from litellm.proxy._experimental.mcp_server.toolset_db import ( + from litellm.proxy.mcp_server.toolset_db import ( create_mcp_toolset, delete_mcp_toolset, get_mcp_toolset, @@ -3577,7 +3577,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_409_CONFLICT, detail={"error": f"A toolset named '{payload.toolset_name}' already exists."}, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3673,7 +3673,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_404_NOT_FOUND, detail={"error": f"Toolset '{payload.toolset_id}' not found."}, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3703,7 +3703,7 @@ if MCP_AVAILABLE: status_code=status.HTTP_404_NOT_FOUND, detail={"error": f"Toolset '{toolset_id}' not found."}, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/management_endpoints/sso/saml_sso.py b/litellm/proxy/management_endpoints/sso/saml_sso.py index ba265acfe4a..d9fe9fcf8f4 100644 --- a/litellm/proxy/management_endpoints/sso/saml_sso.py +++ b/litellm/proxy/management_endpoints/sso/saml_sso.py @@ -38,13 +38,13 @@ from pydantic import ValidationError from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger from litellm.caching.dual_cache import DualCache -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - SSOIdentityAssertion, - assertion_from_saml_login, -) from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.proxy.management_endpoints.sso_helper_utils import SSO_SESSIONS_TARGET from litellm.proxy.management_endpoints.types import CustomOpenID, get_litellm_user_role +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + SSOIdentityAssertion, + assertion_from_saml_login, +) from litellm.proxy.utils import get_custom_url try: diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.py index 02494de8c87..22c4f27d94a 100644 --- a/litellm/proxy/management_endpoints/ui_sso.py +++ b/litellm/proxy/management_endpoints/ui_sso.py @@ -72,17 +72,6 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.login_assertion_exchange import ( - exchange_login_assertion_if_configured, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - GOOGLE_REFRESH_TOKEN_PARAMS, - MICROSOFT_REFRESH_TOKEN_SCOPE, - SSOIdentityAssertion, - assertion_from_sso_login, - ema_assertion_retention_enabled, - retain_sso_identity_assertion_for_ema, -) from litellm.proxy._types import ( CommonProxyErrors, LiteLLM_UserTable, @@ -143,6 +132,17 @@ from litellm.proxy.management_endpoints.types import ( get_litellm_user_role, is_valid_litellm_user_role, ) +from litellm.proxy.mcp_server.outbound_credentials.login_assertion_exchange import ( + exchange_login_assertion_if_configured, +) +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + GOOGLE_REFRESH_TOKEN_PARAMS, + MICROSOFT_REFRESH_TOKEN_SCOPE, + SSOIdentityAssertion, + assertion_from_sso_login, + ema_assertion_retention_enabled, + retain_sso_identity_assertion_for_ema, +) from litellm.proxy.utils import ( PrismaClient, ProxyLogging, diff --git a/litellm/proxy/management_helpers/object_permission_utils.py b/litellm/proxy/management_helpers/object_permission_utils.py index 920970427ba..a719a5c67d4 100644 --- a/litellm/proxy/management_helpers/object_permission_utils.py +++ b/litellm/proxy/management_helpers/object_permission_utils.py @@ -300,7 +300,7 @@ async def _resolve_mcp_server_identifiers_to_ids( if not identifiers: return {} - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -450,7 +450,7 @@ async def _resolve_team_allowed_mcp_servers( - Servers from mcp_access_groups - Server IDs referenced in mcp_tool_permissions keys """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -475,7 +475,7 @@ async def _resolve_team_allowed_mcp_servers( def get_allow_all_keys_server_ids() -> set[str]: """Return the set of MCP server IDs marked with allow_all_keys=True.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -487,7 +487,7 @@ _get_allow_all_keys_server_ids: Final = get_allow_all_keys_server_ids def _get_all_mcp_server_ids() -> set[str]: """Return every MCP server id registered on the proxy (config + DB union).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/_experimental/mcp_server/AGENTS.md b/litellm/proxy/mcp_server/AGENTS.md similarity index 98% rename from litellm/proxy/_experimental/mcp_server/AGENTS.md rename to litellm/proxy/mcp_server/AGENTS.md index 8c53216f77a..25150c11f1d 100644 --- a/litellm/proxy/_experimental/mcp_server/AGENTS.md +++ b/litellm/proxy/mcp_server/AGENTS.md @@ -12,7 +12,7 @@ wiring must change with it. Respect the current package boundaries: ```text -litellm/proxy/_experimental/mcp_server/ +litellm/proxy/mcp_server/ AGENTS.md server.py # ASGI/MCP route handling, sessions, tool calls [PR7: 7-arm only — move BYOK/OAuth pre-fetch into resolver] mcp_server_manager.py # upstream server registry, clients, tool routing [PR7: _create_mcp_client swaps resolve_mcp_auth -> resolve_credentials] @@ -89,7 +89,7 @@ module materially harder to understand. ## Tests -Mirror this package under `tests/unit/proxy/_experimental/mcp_server/`. +Mirror this package under `tests/unit/proxy/mcp_server/`. For regressions, extend the existing mapped test file instead of creating a new one. Use subdirectories that match the implementation path, such as `auth/test_token_endpoint_auth.py` for `auth/token_endpoint_auth.py` and diff --git a/litellm/proxy/_experimental/mcp_server/README.md b/litellm/proxy/mcp_server/README.md similarity index 100% rename from litellm/proxy/_experimental/mcp_server/README.md rename to litellm/proxy/mcp_server/README.md diff --git a/litellm/proxy/_experimental/mcp_server/auth/litellm_auth_handler.py b/litellm/proxy/mcp_server/auth/litellm_auth_handler.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/auth/litellm_auth_handler.py rename to litellm/proxy/mcp_server/auth/litellm_auth_handler.py diff --git a/litellm/proxy/_experimental/mcp_server/auth/managed_agent_access.py b/litellm/proxy/mcp_server/auth/managed_agent_access.py similarity index 89% rename from litellm/proxy/_experimental/mcp_server/auth/managed_agent_access.py rename to litellm/proxy/mcp_server/auth/managed_agent_access.py index 096b7eb3c77..a01db0db6d8 100644 --- a/litellm/proxy/_experimental/mcp_server/auth/managed_agent_access.py +++ b/litellm/proxy/mcp_server/auth/managed_agent_access.py @@ -8,15 +8,15 @@ from litellm.types.proxy.agent_identity import AgentIdentityFailure async def _delegated_resource_subject(user_id: str) -> UserAPIKeyAuth: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler human: Final = await MCPRequestHandler.reload_admitted_user(user_id, requires_fresh_policy=True) return human.model_copy(update=MappingProxyType({"mcp_explicit_grants_only": True})) async def managed_agent_servers(auth: UserAPIKeyAuth) -> tuple[str, ...]: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager agent: Final = auth.managed_agent_policy if agent is None: @@ -49,7 +49,7 @@ async def managed_agent_servers(auth: UserAPIKeyAuth) -> tuple[str, ...]: async def managed_agent_tools(server_id: str, auth: UserAPIKeyAuth) -> list[str] | None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler if server_id not in await managed_agent_servers(auth): return [] diff --git a/litellm/proxy/_experimental/mcp_server/auth/token_endpoint_auth.py b/litellm/proxy/mcp_server/auth/token_endpoint_auth.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/auth/token_endpoint_auth.py rename to litellm/proxy/mcp_server/auth/token_endpoint_auth.py diff --git a/litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py b/litellm/proxy/mcp_server/auth/user_api_key_auth_mcp.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py rename to litellm/proxy/mcp_server/auth/user_api_key_auth_mcp.py index f883031a529..cc7080738d0 100644 --- a/litellm/proxy/_experimental/mcp_server/auth/user_api_key_auth_mcp.py +++ b/litellm/proxy/mcp_server/auth/user_api_key_auth_mcp.py @@ -21,33 +21,7 @@ import litellm from litellm._internal_context import with_service_target from litellm._logging import verbose_logger from litellm.constants import MCP_ALL_TOOLS_WILDCARD, MCP_PEEKED_BODY_SCOPE_KEY -from litellm.experimental_mcp_client.client import strip_auth_scheme -from litellm.proxy._experimental.mcp_server.catalog import global_manager -from litellm.proxy._experimental.mcp_server.oauth_utils import ( - get_passthrough_resource_metadata_url, - get_passthrough_www_authenticate, - get_request_base_url, - get_route_relative_request_path, - well_known_root_suffix, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( - BridgeEnvelopeAdmitted, - BridgeEnvelopeInvalid, - NotBridgeEnvelope, - envelope_keys_from_master_key, - is_bridge_envelope_shaped, - resolve_bridge_envelope, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( - EnvelopeIdentity, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( - is_session_bearer_shaped, -) -from litellm.proxy._experimental.mcp_server.utils import ( - asgi_scope_fields, - strip_known_server_prefix, -) +from litellm.mcp_client.client import strip_auth_scheme from litellm.proxy._types import ( UI_TEAM_ID, LiteLLM_AccessGroupTable, @@ -87,6 +61,32 @@ from litellm.proxy.common_utils.user_api_key_cache import ( get_management_object_ttl, user_object_permission_id_cache_key, ) +from litellm.proxy.mcp_server.catalog import global_manager +from litellm.proxy.mcp_server.oauth_utils import ( + get_passthrough_resource_metadata_url, + get_passthrough_www_authenticate, + get_request_base_url, + get_route_relative_request_path, + well_known_root_suffix, +) +from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( + BridgeEnvelopeAdmitted, + BridgeEnvelopeInvalid, + NotBridgeEnvelope, + envelope_keys_from_master_key, + is_bridge_envelope_shaped, + resolve_bridge_envelope, +) +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( + EnvelopeIdentity, +) +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( + is_session_bearer_shaped, +) +from litellm.proxy.mcp_server.utils import ( + asgi_scope_fields, + strip_known_server_prefix, +) from litellm.repositories.table_repositories import ( AgentsRepository, MCPServerRepository, @@ -201,7 +201,7 @@ def _is_mcp_passthrough_cold_start(mcp_servers: list[str] | None, client_ip: str cannot be resolved.""" if not mcp_servers: return False - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -216,7 +216,7 @@ def _is_legacy_delegate_cold_start(mcp_servers: list[str] | None, client_ip: str """Allow only credential-free legacy delegates to reach the route's OAuth challenge.""" if not mcp_servers: return False - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, global_mcp_server_manager, ) @@ -308,7 +308,7 @@ def _gateway_dcr_challenge_target( client_ip: str | None, ) -> str | None: """Resolve a single path target whose sign-in metadata advertises the gateway.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -328,8 +328,8 @@ def gateway_dcr_challenge_scope( ) -> str | None: if MCPRequestHandler.extract_target_server_names_from_path(route) or not mcp_servers: return None - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import gateway_server_scope - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.gateway_dcr_flow import gateway_server_scope + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -919,7 +919,7 @@ class MCPRequestHandler: transparent proxy and the caller's ``Authorization`` is an upstream token, never a LiteLLM key. A mixed-target request keeps normal auth. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPAuth @@ -946,7 +946,7 @@ class MCPRequestHandler: envelope admission arm never fires for an aggregate scope or a server that did not opt into the bridge. Mirrors :meth:`_target_servers_are_true_passthrough`. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -1163,7 +1163,7 @@ class MCPRequestHandler: mint-time snapshot. Pre-DB gates (size, IP, route allowlist) run first, mirroring the standard pipeline. Fails closed with the requested scope's ``invalid_token`` challenge on an expired, tampered, foreign, or refresh token, or a missing/deactivated/policy-rejected user.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( NotSessionBearer, SessionBearerAdmitted, SessionBearerInvalid, @@ -1332,7 +1332,7 @@ class MCPRequestHandler: so each is resolved to an id via ``expand_permission_list`` before the membership check. Returns None (no descriptors) when nothing applies; a lookup failure narrows to None rather than raising, since rate limiting must not deny a request authorization already allowed.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -1394,7 +1394,7 @@ class MCPRequestHandler: else: return refreshed if refreshed.mcp_toolset_id is not None: - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope return await apply_toolset_scope(refreshed, refreshed.mcp_toolset_id) return refreshed @@ -1416,10 +1416,10 @@ class MCPRequestHandler: project, org, and budget state are NOT re-checked here; the caller runs the admitted identity through ``_enforce_admitted_live_policy`` for those. """ - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.auth.auth_checks import get_key_object + from litellm.proxy.mcp_server.bridge_token_flow import ( master_key_admin_auth, # noqa: PLC0415 # inline import avoids a module-load circular import ) - from litellm.proxy.auth.auth_checks import get_key_object from litellm.proxy.proxy_server import prisma_client, user_api_key_cache admin: Final = master_key_admin_auth(key_hash) @@ -1661,7 +1661,7 @@ class MCPRequestHandler: @staticmethod def get_guardrail_bearer_token(headers: Headers, auth: UserAPIKeyAuth) -> SecretStr | None: - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( _custom_litellm_key_header_name, # pyright: ignore[reportPrivateUsage] # reuse the shared credential-header setting ) @@ -1884,7 +1884,7 @@ class MCPRequestHandler: from litellm.proxy.proxy_server import general_settings if managed_agent_policy(user_api_key_auth) is not None: - from litellm.proxy._experimental.mcp_server.auth.managed_agent_access import managed_agent_servers + from litellm.proxy.mcp_server.auth.managed_agent_access import managed_agent_servers return MCPServerAccess(server_ids=await managed_agent_servers(user_api_key_auth), scope="scoped") @@ -2257,7 +2257,7 @@ class MCPRequestHandler: intersected with it, so the route narrows a team grant exactly as it narrows the user's own.""" if auth.mcp_toolset_id is None: return None - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2308,8 +2308,8 @@ class MCPRequestHandler: if not is_mcp_admitted_user_subject(auth) and not personal_key_inherits_team_grants(auth): return auth try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.operations import ( _get_allowed_mcp_servers, _resolve_display_name_to_original, resolve_scoped_mcp_server, @@ -2473,7 +2473,7 @@ class MCPRequestHandler: onto a server reached through a different source. A source that grants the server with no tool restriction means the user can use every tool on it, so allow-all wins the union. When no source grants the server the result is ``[]`` — deny all, fail closed.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2620,8 +2620,8 @@ class MCPRequestHandler: async def personal_key_team_rpm_limits( auth: UserAPIKeyAuth, server: MCPServer, tool_name: str ) -> Mapping[str, Mapping[str, int]] | None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth.auth_checks import get_team_object + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.proxy_server import prisma_client, proxy_logging_obj, user_api_key_cache try: @@ -2672,7 +2672,7 @@ class MCPRequestHandler: then carries the key's OWN tool rules, never a team's; otherwise nothing is allowed. Each team resolves through the raising ``_single_credential_tools`` so one team's fault reaches the caller's fail-closed handler instead of becoming an allow-all ``None`` in the union.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2773,7 +2773,7 @@ class MCPRequestHandler: nothing (deleted or unknown ids, a swallowed DB fault, or a toolset with no tools): that is a KNOWN restriction with unknown contents, and every caller already turns this error into deny rather than letting the level read as unrestricted.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2827,7 +2827,7 @@ class MCPRequestHandler: ``mcp_tool_permissions`` entry for it. A granting group with no entry grants every tool, so ``None`` wins. A group that does not grant the server contributes nothing, and an explicit ``[]`` entry on a granting group grants no tools. ``None`` when no group grants the server.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2848,7 +2848,7 @@ class MCPRequestHandler: @staticmethod def _group_grants_server(group: LiteLLM_AccessGroupTable, server_id: str) -> bool: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2892,7 +2892,7 @@ class MCPRequestHandler: """Servers the key's object permission grants on its own: ``mcp_servers`` by id, name or alias and legacy ``mcp_access_groups`` by the tag the server carries, exactly as server admission resolves them. A tag never doubles as a server name, so a tag that collides with one grants nothing by itself.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager if key_obj_perm is None: return frozenset() @@ -3054,7 +3054,7 @@ class MCPRequestHandler: return None if managed_agent_policy(user_api_key_auth) is not None: - from litellm.proxy._experimental.mcp_server.auth.managed_agent_access import managed_agent_tools + from litellm.proxy.mcp_server.auth.managed_agent_access import managed_agent_tools return await managed_agent_tools(server_id, user_api_key_auth) @@ -3111,7 +3111,7 @@ class MCPRequestHandler: # server_ids OR names/aliases; normalize to server_id-keyed form # before lookup so a name-based key does not silently drop its # tool restrictions when server_id is the resolved uuid. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3203,7 +3203,7 @@ class MCPRequestHandler: fail-open (skip the org step, keep the key/team/agent restrictions; letting the raise escape would collapse them to allow-all, WIDER than before the fault), while a keyless source re-raises so the outer handler denies that one source (its only org bound is this ceiling).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3317,12 +3317,12 @@ class MCPRequestHandler: if user_api_key_auth is None: return [] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy.auth.auth_checks import ( get_mcp_server_ids_from_access_groups, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.proxy.proxy_server import ( prisma_client, proxy_logging_obj, @@ -3374,12 +3374,12 @@ class MCPRequestHandler: if user_api_key_auth is None: return [] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy.auth.auth_checks import ( get_object_permission, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.proxy.proxy_server import ( prisma_client, proxy_logging_obj, @@ -3538,7 +3538,7 @@ class MCPRequestHandler: ``mcp_servers``, the ``all_proxy_servers`` sentinel → the full registry, legacy access groups, tool-perm-referenced servers, toolset-referenced servers) unioned with its unified ``access_group_ids`` servers.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3750,7 +3750,7 @@ class MCPRequestHandler: if object_permissions is None: return [] - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3855,7 +3855,7 @@ class MCPRequestHandler: try: # Permission entries may be server_ids OR names/aliases — expand to ids. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -3990,7 +3990,7 @@ class MCPRequestHandler: ``mcp_tool_permissions`` or reached through ``mcp_toolsets`` count as entitled, exactly as they do for a key or a team, so granting one tool never requires naming its server twice. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4130,7 +4130,7 @@ class MCPRequestHandler: restriction. Returns ``[]`` (deny every tool on this server) when the entitlement cannot be resolved, because the caller's own except-handler treats a raise as allow-all for key auth. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4173,7 +4173,7 @@ class MCPRequestHandler: axis twin of ``apply_agent_caller_ceiling``, so the headers only ever narrow. Denies every tool on the server when the caller's team cannot be loaded, since a caller we cannot resolve must not read as unrestricted.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4217,7 +4217,7 @@ class MCPRequestHandler: user_api_key_auth: UserAPIKeyAuth | None = None, ) -> Sequence[str] | None: """Narrow a key/team tool allowlist by the end user's (customer's) tool entitlement.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client @@ -4353,7 +4353,7 @@ class MCPRequestHandler: return [] try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4390,7 +4390,7 @@ class MCPRequestHandler: allow, or None when the agent has none attached. Unlike the object_permission path above, an attached group set that names no servers is an empty ceiling and denies every server. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4469,7 +4469,7 @@ class MCPRequestHandler: ) try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4545,7 +4545,7 @@ class MCPRequestHandler: try: # Import here to avoid circular import - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/_experimental/mcp_server/bridge_token_flow.py b/litellm/proxy/mcp_server/bridge_token_flow.py similarity index 95% rename from litellm/proxy/_experimental/mcp_server/bridge_token_flow.py rename to litellm/proxy/mcp_server/bridge_token_flow.py index 9f393f25e49..63428dfb28a 100644 --- a/litellm/proxy/_experimental/mcp_server/bridge_token_flow.py +++ b/litellm/proxy/mcp_server/bridge_token_flow.py @@ -13,24 +13,24 @@ from pydantic import SecretStr from typing_extensions import assert_never from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS from litellm.proxy.common_utils.encrypt_decrypt_utils import ( # noqa: F401 # legacy module exports _V2_GCM_PREFIX, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export V2_GCM_PREFIX, # pyright: ignore[reportPrivateUsage] # reuse the encrypted credential's format discriminator ) +from litellm.proxy.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS from litellm.types.mcp_server.mcp_server_manager import MCPServer if TYPE_CHECKING: from litellm.models.user import LiteLLM_UserTable - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _BridgeAuthorizationCode - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.handle_jwt import JWTIdentity + from litellm.proxy.mcp_server.discoverable_endpoints import _BridgeAuthorizationCode + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( EnvelopeIdentity, EnvelopeKeys, RefreshCredential, UpstreamTokenGrant, ) - from litellm.proxy._types import UserAPIKeyAuth - from litellm.proxy.auth.handle_jwt import JWTIdentity def _litellm_key_from_request(request: Request) -> str | None: @@ -87,14 +87,14 @@ async def oauth_authorization_uses_gateway_credential(request: Request) -> bool: async def _opaque_bearer_is_gateway_credential(token: str) -> bool: - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # envelope imports bridge types - is_envelope, - is_refresh_envelope, - ) from litellm.proxy._types import hash_token # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.resolvers.exceptions import KeyNotFoundError # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.resolvers.store import IdentityStore # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # envelope imports bridge types + is_envelope, + is_refresh_envelope, + ) from litellm.proxy.proxy_server import ( # noqa: PLC0415 # startup owns the identity store dependencies prisma_client, user_api_key_cache, @@ -447,16 +447,16 @@ async def _resolve_request_auth( async def can_store_oauth_credential(request: Request, auth: "UserAPIKeyAuth", server_id: str) -> bool: """Apply the same write policy to request credentials and verified signed-callback users.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # registry imports auth helpers - global_mcp_server_manager, - ) - from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - can_access_mcp_server, # noqa: PLC0415 # proxy import cycle - ) from litellm.proxy.auth.route_checks import RouteChecks # noqa: PLC0415 # proxy import cycle from litellm.proxy.auth.user_api_key_auth import ( # noqa: PLC0415 # proxy import cycle run_centralized_common_checks, # pyright: ignore[reportPrivateUsage] # reuse admission policy for the credential-write action ) + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # registry imports auth helpers + global_mcp_server_manager, + ) + from litellm.proxy.mcp_server.ui_session_utils import ( + can_access_mcp_server, # noqa: PLC0415 # proxy import cycle + ) write_route: Final = f"/v1/mcp/server/{server_id}/oauth-user-credential" try: @@ -584,7 +584,7 @@ def _bridge_grant_from_token_response(token_response: object) -> "UpstreamTokenG lifetime leaves the grant ``expires_in`` ``None`` for the envelope fallback, a positive value is honoured, and an explicit already-elapsed value is a rejection rather than a silent fall-through to the cap.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import UpstreamTokenGrant, ) @@ -790,18 +790,18 @@ async def prepare_bridge_mint( presented key keeps its resolution origin so the mapper statuses it truthfully; neither source present is ``no_identity``. The refresh_token grant has its own phase-1 (:func:`_prepare_bridge_refresh`), which recovers identity from the presented refresh envelope.""" - from litellm.proxy._experimental.mcp_server.client_allowlist import ( # noqa: PLC0415 # keep mint policy dependencies local + from litellm.proxy._types import UserAPIKeyAuth # noqa: PLC0415 # proxy import cycle + from litellm.proxy.auth.handle_jwt import JWTHandler # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.client_allowlist import ( # noqa: PLC0415 # keep mint policy dependencies local load_mcp_client_allowlist, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import key_hash_identity, user_identity, ) - from litellm.proxy._types import UserAPIKeyAuth # noqa: PLC0415 # proxy import cycle - from litellm.proxy.auth.handle_jwt import JWTHandler # noqa: PLC0415 # proxy import cycle from litellm.proxy.proxy_server import ( # noqa: PLC0415 # inline import avoids a module-load circular import general_settings, master_key, @@ -877,7 +877,7 @@ async def prepare_bridge_refresh( never a raw upstream refresh token, so a missing value, a non-envelope, an unopenable envelope, or one minted for another server is ``invalid_grant``. Running before the exchange means a rejected refresh never consumes or rotates the upstream refresh token.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import BridgeRefreshOpened, envelope_keys_from_master_key, open_bridge_refresh_envelope, @@ -917,10 +917,10 @@ def finish_bridge_mint( fresh refresh envelope. The only hard failures here are properties of the upstream access token (no usable token, an already-expired lifetime, or a token too large to seal); a refresh token that cannot be sealed degrades to an access-only response rather than failing the whole exchange.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import build_bridge_token_response, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import EnvelopeLifetimeUnrepresentable, SealedEnvelope, UpstreamTokenGrant, @@ -961,7 +961,7 @@ def _upstream_refresh_credential(token_response: object) -> "RefreshCredential | token would hand the client a full-TTL-capped envelope the IdP will reject, so the exchange degrades to an access-only response (the client re-authenticates at access expiry), mirroring how :func:`_bridge_grant_from_token_response` refuses an already-elapsed access token instead of capping it.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import RefreshCredential, ) @@ -988,10 +988,10 @@ def _mint_refresh_envelope_value( ``None`` when the upstream returned no refresh token or the refresh token is too large to seal. A too-large refresh token degrades to an access-only response (logged) rather than failing an exchange that already succeeded upstream: the client simply re-authenticates when the access envelope expires.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( # noqa: PLC0415 # inline import avoids a module-load circular import build_bridge_refresh_token_response, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( # noqa: PLC0415 # inline import avoids a module-load circular import SealedEnvelope, ) diff --git a/litellm/proxy/_experimental/mcp_server/byok_credential_cache.py b/litellm/proxy/mcp_server/byok_credential_cache.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/byok_credential_cache.py rename to litellm/proxy/mcp_server/byok_credential_cache.py diff --git a/litellm/proxy/_experimental/mcp_server/byok_oauth_endpoints.py b/litellm/proxy/mcp_server/byok_oauth_endpoints.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/byok_oauth_endpoints.py rename to litellm/proxy/mcp_server/byok_oauth_endpoints.py index 2181e92baa9..868b73e39f1 100644 --- a/litellm/proxy/_experimental/mcp_server/byok_oauth_endpoints.py +++ b/litellm/proxy/mcp_server/byok_oauth_endpoints.py @@ -25,16 +25,16 @@ from fastapi import APIRouter, Depends, Form, HTTPException, Request from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.catalog import public_catalog_operation -from litellm.proxy._experimental.mcp_server.db import store_user_credential -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.catalog import public_catalog_operation +from litellm.proxy.mcp_server.db import store_user_credential +from litellm.proxy.mcp_server.oauth_utils import ( BYOK_RESOURCE_METADATA_PATH, TOKEN_NO_CACHE_HEADERS, get_request_base_url, validate_loopback_redirect_uri, well_known_root_suffix, ) -from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.middleware.per_request_root_path_middleware import get_server_root_paths # --------------------------------------------------------------------------- @@ -779,7 +779,7 @@ async def byok_authorize_get( help_url = "" if server_id: try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -955,7 +955,7 @@ async def byok_token( ) # Invalidate any cached negative result so the user isn't blocked # for up to the TTL period after completing the OAuth flow. - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _invalidate_byok_cred_cache, ) diff --git a/litellm/proxy/_experimental/mcp_server/capabilities.py b/litellm/proxy/mcp_server/capabilities.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/capabilities.py rename to litellm/proxy/mcp_server/capabilities.py diff --git a/litellm/proxy/_experimental/mcp_server/catalog.py b/litellm/proxy/mcp_server/catalog.py similarity index 93% rename from litellm/proxy/_experimental/mcp_server/catalog.py rename to litellm/proxy/mcp_server/catalog.py index 2db548f5863..cfa620c978e 100644 --- a/litellm/proxy/_experimental/mcp_server/catalog.py +++ b/litellm/proxy/mcp_server/catalog.py @@ -23,15 +23,15 @@ from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter from litellm._logging import verbose_logger from litellm.caching.in_memory_cache import InMemoryCache -from litellm.proxy._experimental.mcp_server.result_conversion import age_freshness, aggregate_freshness +from litellm.proxy.mcp_server.result_conversion import age_freshness, aggregate_freshness if TYPE_CHECKING: from mcp.types import ListToolsResult, PaginatedRequestParams, PaginatedResult - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext - from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing, ServerOutcome - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext + from litellm.proxy.mcp_server.db import OAuthCredentialPayload + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing, ServerOutcome + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer from litellm.types.mcp_server.tool_registry import MCPTool @@ -90,7 +90,7 @@ def _check_oauth_revision(selected: MCPServer, candidate: MCPServer | None) -> N def _snapshot(manager: MCPServerManager, database_identity: str) -> CatalogSnapshot: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry servers: Final = manager.config_mcp_servers | manager.registry detached: Final = MappingProxyType({key: value.model_copy(deep=True) for key, value in servers.items()}) @@ -154,7 +154,7 @@ class CatalogSnapshots: if not should_load_db_object("mcp"): return _snapshot(self.manager, self._database_identity) - from litellm.proxy._experimental.mcp_server.db import get_mcp_catalog_revision + from litellm.proxy.mcp_server.db import get_mcp_catalog_revision try: revision: Final = await get_mcp_catalog_revision(prisma_client) @@ -198,7 +198,7 @@ class CatalogSnapshots: if current is not None: yield current return - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry shared: Final = await self._fresh_snapshot() initial_routing: Final = self._unchanged_routing(shared.servers, self.manager.published_tool_routes) @@ -227,7 +227,7 @@ class CatalogSnapshots: def _unchanged_routing( self, servers: Mapping[str, MCPServer], routing: Mapping[str, str] ) -> MappingProxyType[str, str]: - from litellm.proxy._experimental.mcp_server.utils import normalize_server_name + from litellm.proxy.mcp_server.utils import normalize_server_name current: Final = self.manager.config_mcp_servers | self.manager.registry unchanged: Final = ( @@ -252,7 +252,7 @@ class CatalogSnapshots: server: MCPServer, resolve: Callable[[MCPServer], Awaitable[MCPServer]], ) -> MCPServer: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import oauth_endpoints_unresolved + from litellm.proxy.mcp_server.mcp_server_manager import oauth_endpoints_unresolved snapshot: Final = self.current() selected: Final = snapshot.servers.get(server.server_id) if snapshot is not None else None @@ -270,7 +270,7 @@ class CatalogSnapshots: return resolved async def reload(self) -> None: - from litellm.proxy._experimental.mcp_server.db import get_mcp_catalog_revision + from litellm.proxy.mcp_server.db import get_mcp_catalog_revision from litellm.proxy.proxy_server import prisma_client revision: Final = await get_mcp_catalog_revision(prisma_client) if prisma_client is not None else None @@ -294,8 +294,8 @@ class CatalogSnapshots: self._operation.reset(token) async def _reload_and_publish(self, *, reuse_unchanged: bool) -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry - from litellm.proxy._experimental.mcp_server.utils import normalize_server_name + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.utils import normalize_server_name previous_config: Final = MappingProxyType( {key: value.model_copy(deep=True) for key, value in self.manager.config_mcp_servers.items()} @@ -399,8 +399,8 @@ class CatalogSnapshots: async def _stage_servers( self, rows: Sequence[BaseModel], *, reuse_unchanged: bool ) -> dict[str, MCPServer]: # mutable-ok: assign_unique_short_prefix requires a dict registry - from litellm.proxy._experimental.mcp_server.db import LiteLLM_MCPServerTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.db import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, oauth_endpoints_unresolved, warn_on_server_name_fields, @@ -464,20 +464,20 @@ class CatalogSnapshots: return new_registry async def _reload(self, *, reuse_unchanged: bool) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - config_ids_capturing_db_identifiers, - warn_on_shared_identifier_prefixes, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( get_prisma_client_or_throw, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + config_ids_capturing_db_identifiers, + warn_on_shared_identifier_prefixes, + ) verbose_logger.debug("Loading MCP servers from database into registry...") prisma_client: Final = get_prisma_client_or_throw("Database not connected. Connect a database to your proxy") # Load only "active", legacy "approved", and NULL (no approval workflow) rows. # Pending/rejected servers are excluded at the DB level so we never load them. - from litellm.proxy._experimental.mcp_server.db import get_runtime_mcp_server_rows + from litellm.proxy.mcp_server.db import get_runtime_mcp_server_rows raw_rows: Final[Sequence[BaseModel]] = await get_runtime_mcp_server_rows(prisma_client) database_identity: Final = hashlib.sha256( @@ -584,7 +584,7 @@ def catalog_operation( def global_manager() -> MCPServerManager: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager return global_mcp_server_manager @@ -608,8 +608,8 @@ async def paginate_catalog( from pydantic import ValidationError from litellm.constants import MCP_TOOL_LISTING_MAX_PAGES - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.state_tokens import open_state, seal_state + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.state_tokens import open_state, seal_state ordered: Final = tuple(sorted(server_ids)) purpose: Final = "mcp.catalog.list.v1:" + method @@ -673,7 +673,7 @@ async def paginate_catalog( for task in tasks: task.cancel() await asyncio.gather(*tasks, return_exceptions=True) - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY elapsed: Final = time.monotonic() - started pages: Final = tuple( @@ -719,7 +719,7 @@ async def list_tools_page( ) -> ListToolsResult: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY pages, next_cursor, outcomes = await paginate_catalog( method="tools/list", @@ -773,9 +773,9 @@ async def get_filtered_server_tools( ) -> tuple[ListToolsResult, ServerOutcome]: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception + from litellm.proxy.mcp_server.operations import ( _get_byok_credential, _get_user_oauth_extra_headers_from_db, _prepare_mcp_server_headers, @@ -806,7 +806,7 @@ async def get_filtered_server_tools( # Prefer server-stored per-user OAuth when configured, so a stale # Authorization header from the MCP client cannot override Redis/DB # (same issue as call_tool in mcp_server_manager: VS Code caches tokens). - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 to_server_spec, ) @@ -885,8 +885,8 @@ async def get_filtered_server_tools( user_api_key_auth=user_api_key_auth, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller - from litellm.proxy._experimental.mcp_server.utils import strip_known_server_prefix + from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller + from litellm.proxy.mcp_server.utils import strip_known_server_prefix record: Final = partial( global_mcp_server_manager.record_listed_tools, @@ -908,7 +908,7 @@ async def get_filtered_server_tools( listing_updates.callback(record) if mcp_proxy_mode: - from litellm.proxy._experimental.mcp_server.tool_search import with_mcp_proxy_identity + from litellm.proxy.mcp_server.tool_search import with_mcp_proxy_identity filtered_tools = [with_mcp_proxy_identity(tool, server.server_id) for tool in filtered_tools] else: @@ -936,7 +936,7 @@ async def get_filtered_server_tools( def _caller_scope(context: OperationContext, servers: Sequence[MCPServer]) -> str: - from litellm.proxy._experimental.mcp_server.utils import upstream_credential_headers + from litellm.proxy.mcp_server.utils import upstream_credential_headers caller: Final = context.user_api_key_auth headers: Final = context.raw_headers or {} @@ -975,18 +975,18 @@ async def aggregate_gateway_tools( from mcp.types import ListToolsResult, PaginatedRequestParams from pydantic import TypeAdapter - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerOutcome, classify_list_exception, ) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _aggregate_server_key, _mcp_server_rate_limit_rejection, global_mcp_server_manager, ) - from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError async with global_mcp_server_manager.catalog.operation() as snapshot: servers: Final = {server.server_id: server for server in allowed} @@ -1065,12 +1065,12 @@ async def list_gateway_tools( ) -> ListToolsResult: from mcp.types import INTERNAL_ERROR, ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, listing_failed_outright, outcome_wire_value, ) - from litellm.proxy._experimental.mcp_server.operations import _list_mcp_tools + from litellm.proxy.mcp_server.operations import _list_mcp_tools caller, auth, servers, server_headers, oauth_headers, headers, client_ip = context.legacy_auth() listing: Final = await _list_mcp_tools( @@ -1115,13 +1115,13 @@ async def list_gateway_catalog( PaginatedRequestParams, ) - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.operations import ( _get_allowed_mcp_servers, global_mcp_server_manager, raise_denied_scoped_mcp_access, ) - from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError context = replace(context, _caller=await MCPRequestHandler.refresh_catalog_authority(context.user_api_key_auth)) params: Final = request.params or PaginatedRequestParams() @@ -1146,11 +1146,11 @@ async def list_gateway_catalog( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, classify_list_exception, ) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _aggregate_server_key, _mcp_server_rate_limit_rejection, ) @@ -1204,7 +1204,7 @@ async def list_gateway_catalog( ) if params.cursor is None and servers and len(rejections) == len(servers): raise rejections[0] - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, ServerOutcome, outcome_wire_value, @@ -1232,7 +1232,7 @@ async def fetch_optional_catalog_page( ) -> CatalogListResult: from mcp.types import PaginatedRequestParams - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers, global_mcp_server_manager + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers, global_mcp_server_manager caller, auth, _, server_headers, oauth_headers, raw_headers, client_ip = context.legacy_auth() auth_header, extra_headers = _prepare_mcp_server_headers( @@ -1269,7 +1269,7 @@ def combine_optional_catalog( ListResourceTemplatesResult, ) - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY outcomes: Final = (meta or {}).get(SERVER_OUTCOMES_META_KEY) incomplete: Final = isinstance(outcomes, dict) and any( diff --git a/litellm/proxy/_experimental/mcp_server/client_allowlist.py b/litellm/proxy/mcp_server/client_allowlist.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/client_allowlist.py rename to litellm/proxy/mcp_server/client_allowlist.py diff --git a/litellm/proxy/_experimental/mcp_server/contracts.py b/litellm/proxy/mcp_server/contracts.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/contracts.py rename to litellm/proxy/mcp_server/contracts.py index 84cd2751444..43c42d3b0df 100644 --- a/litellm/proxy/_experimental/mcp_server/contracts.py +++ b/litellm/proxy/mcp_server/contracts.py @@ -10,8 +10,8 @@ from typing import TYPE_CHECKING, Final, Literal, Protocol, TypeAlias from mcp.types import ErrorData, InputRequest, InputResponse, InputResponses from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.tool_outcome import WireCompat from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.tool_outcome import WireCompat from litellm.types.mcp_server.mcp_server_manager import MCPServer if TYPE_CHECKING: @@ -33,7 +33,7 @@ if TYPE_CHECKING: ListToolsResult | ListPromptsResult | ListResourcesResult | ListResourceTemplatesResult ) - from litellm.proxy._experimental.mcp_server.server_resolution import ResolvedMCPServer + from litellm.proxy.mcp_server.server_resolution import ResolvedMCPServer class TargetCatalog(Protocol): diff --git a/litellm/proxy/_experimental/mcp_server/cost_calculator.py b/litellm/proxy/mcp_server/cost_calculator.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/cost_calculator.py rename to litellm/proxy/mcp_server/cost_calculator.py diff --git a/litellm/proxy/_experimental/mcp_server/db.py b/litellm/proxy/mcp_server/db.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/db.py rename to litellm/proxy/mcp_server/db.py index 0666cc7e6c0..27f8b90a586 100644 --- a/litellm/proxy/_experimental/mcp_server/db.py +++ b/litellm/proxy/mcp_server/db.py @@ -15,14 +15,6 @@ from litellm._logging import verbose_proxy_logger from litellm._uuid import uuid from litellm.constants import MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( - RefreshTokenPresented, - credential_binding_matches, - enforce_oauth_identity_binding, -) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( - build_upstream_oauth2_token_request, -) from litellm.proxy._types import ( LiteLLM_MCPServerTable, MCPApprovalStatus, @@ -42,6 +34,14 @@ from litellm.proxy.common_utils.encrypt_decrypt_utils import ( # noqa: F401 # encrypt_value_helper, get_salt_key, ) +from litellm.proxy.mcp_server.oauth_identity_binding import ( + RefreshTokenPresented, + credential_binding_matches, + enforce_oauth_identity_binding, +) +from litellm.proxy.mcp_server.oauth_utils import ( + build_upstream_oauth2_token_request, +) from litellm.proxy.utils import PrismaClient from litellm.repositories.config_repository import ConfigRepository from litellm.repositories.object_permission_repository import ObjectPermissionRepository @@ -1066,7 +1066,7 @@ async def delete_mcp_server( ) if credential_user_ids: if invalidate_token_cache is None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2031,7 +2031,7 @@ async def purge_user_oauth_credentials_for_server( where={"server_id": server_id, "user_id": {"in": [row.user_id for row in oauth_rows]}} ) if invalidate_token_cache is None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -2238,7 +2238,7 @@ async def resolve_user_oauth_access_token( if not user_id or not server_id: return None try: - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, mcp_per_user_token_cache, ) diff --git a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py b/litellm/proxy/mcp_server/discoverable_endpoints.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py rename to litellm/proxy/mcp_server/discoverable_endpoints.py index ca7ad9e3384..eb12b15cdae 100644 --- a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py +++ b/litellm/proxy/mcp_server/discoverable_endpoints.py @@ -22,11 +22,21 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.proxy.common_utils.encrypt_decrypt_utils import ( + decrypt_value_helper, + encrypt_value_helper, +) +from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # legacy module exports + _read_request_body, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export + read_request_body, +) +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointAuthConfigError, normalize_token_endpoint_auth_method, ) -from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.bridge_token_flow import ( # noqa: F401 # legacy module exports _bridge_mint_error_response, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _BridgeMintReady, _BridgeRefreshReady, @@ -45,8 +55,8 @@ from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( # noqa: prepare_bridge_refresh, reload_active_user_by_id, ) -from litellm.proxy._experimental.mcp_server.catalog import public_catalog_operation -from litellm.proxy._experimental.mcp_server.faults import ( +from litellm.proxy.mcp_server.catalog import public_catalog_operation +from litellm.proxy.mcp_server.faults import ( CallerRejected, CredentialSource, UpstreamProtocolFault, @@ -55,7 +65,7 @@ from litellm.proxy._experimental.mcp_server.faults import ( dcr_fault_detail, render_token_fault, ) -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy.mcp_server.gateway_dcr_flow import ( JWT_BEARER_GRANT_TYPE, VendorCredentialState, aggregate_authorize, @@ -72,21 +82,21 @@ from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( revoke_refresh_token, supported_grant_types, ) -from litellm.proxy._experimental.mcp_server.id_jag_grant import ( +from litellm.proxy.mcp_server.id_jag_grant import ( basic_client_id, jwt_bearer_available, redeem_id_jag_assertion, ) -from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( +from litellm.proxy.mcp_server.idp_token_exchange import ( exchange_idp_subject_token, token_exchange_available, ) -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( +from litellm.proxy.mcp_server.oauth_identity_binding import ( RefreshOwnershipProven, RefreshTokenPresented, enforce_oauth_identity_binding, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy.mcp_server.oauth_utils import ( CIMD_METADATA_PATH, TOKEN_NO_CACHE_HEADERS, build_upstream_authorize_url, @@ -101,27 +111,17 @@ from litellm.proxy._experimental.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, well_known_root_suffix, ) -from litellm.proxy._experimental.mcp_server.proxy_api_credentials import ( +from litellm.proxy.mcp_server.proxy_api_credentials import ( lookup_consent_teams, mint_proxy_credential, ) -from litellm.proxy.auth.ip_address_utils import IPAddressUtils -from litellm.proxy.auth.user_api_key_auth import user_api_key_auth -from litellm.proxy.common_utils.encrypt_decrypt_utils import ( - decrypt_value_helper, - encrypt_value_helper, -) -from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # legacy module exports - _read_request_body, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export - read_request_body, -) from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp import MCPAuth, MCPCredentials from litellm.types.mcp_server.mcp_server_manager import MCPServer, MCPTokenEndpointAuthMethod if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server.db import OAuthCredentialPayload # TTL cache for upstream OAuth metadata fetched from pass-through MCP servers. # Keeps us from hammering the upstream IdP on each discovery request. @@ -476,7 +476,7 @@ async def _session_cookie_user_id(request: Request) -> str | None: """The signed-in litellm user for a browser request, or ``None``. Thin wrapper so the aggregate DCR flow's verbs receive the identity as a plain value instead of parsing cookies themselves.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( # noqa: PLC0415 # circular import at module load + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( # noqa: PLC0415 # circular import at module load get_authenticated_browser_user_id, ) @@ -578,7 +578,7 @@ def _append_query_params(url: str, params: dict[str, str]) -> str: def _resolve_mcp_server_by_name_or_id(lookup: str, client_ip: str | None) -> MCPServer | None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -598,7 +598,7 @@ def _resolve_oauth2_server_for_root_endpoints( without a server name prefix, we try to find the right server automatically. Returns the server if exactly one OAuth2 server is configured, else None. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -684,7 +684,7 @@ async def _store_per_user_token_server_side( Errors are logged but NOT re-raised — the token is always returned to the client even when server-side storage fails. """ - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.oauth2_token_cache import ( # noqa: PLC0415 compute_per_user_token_ttl, mcp_per_user_token_cache, ) @@ -706,7 +706,7 @@ async def _store_per_user_token_server_side( try: prisma_client: Final = get_prisma_client_or_throw("Database not connected. Cannot store per-user OAuth token.") - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 store_user_oauth_credential, ) @@ -735,7 +735,7 @@ async def _store_per_user_token_server_side( ) return # Don't warm Redis if DB write failed - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) @@ -762,7 +762,7 @@ def raise_if_not_oauth2(mcp_server: MCPServer) -> None: modes (``_persist_dcr_client_registration`` skips them unconditionally, so even the admin Authorize path with ``replace_stale_client`` enabled writes nothing to the server row). """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES, ) @@ -825,7 +825,7 @@ async def _server_with_oauth_endpoints( """ if needed_endpoint(mcp_server) is not None and not needs_cimd_discovery(mcp_server): return mcp_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # circular import with mcp_server_manager at module load global_mcp_server_manager, ) @@ -972,10 +972,10 @@ def _bridge_access_denied_redirect(redirect_uri: str, state: str, mcp_server: MC async def _user_can_reach_mcp_server(user_id: str, server_id: str) -> bool: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -1013,7 +1013,7 @@ async def _resolve_oauth_authorization_user( async def _managed_authorization_scope( request: Request, server: MCPServer, scope: str | None, authorized_user_id: str | None ) -> tuple[str | None, str | None]: - from litellm.proxy._experimental.mcp_server.db import get_user_oauth_credential + from litellm.proxy.mcp_server.db import get_user_oauth_credential from litellm.proxy.proxy_server import prisma_client gateway_credential: Final = authorized_user_id is None and await oauth_authorization_uses_gateway_credential( @@ -1214,7 +1214,7 @@ async def _saved_refresh_credential( if not user_id or not refresh_token or not server.needs_user_oauth_token or server.auth_type != MCPAuth.oauth2: return None from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.db import get_user_oauth_credential + from litellm.proxy.mcp_server.db import get_user_oauth_credential if proxy_server.prisma_client is None: return None @@ -1524,7 +1524,7 @@ async def exchange_token_with_server( try: # Identity binding above must retain the verified caller even when a write is # denied. Authorize persistence separately, immediately before its side effect. - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler # A sealed code delegates a verified user for this authorized server. Raw # request credentials retain their own JWT/key restrictions during resolution. @@ -1683,7 +1683,7 @@ async def _load_store_dcr_credentials( (which has no LiteLLM_MCPServerTable row). Returns None when the store has no usable client_id or the DB is unreachable. Registration writes request strict reads so a failed lookup cannot be mistaken for an absent client.""" - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # avoids circular import get_mcp_server_oauth_client_credentials, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 # avoids circular import @@ -1737,8 +1737,8 @@ async def _resolve_persisted_dcr_client( the server-scoped store, while a rowless non-config server is a throwaway temp/session server with no persisted client. Returns (row_or_None, credentials_or_None); the row is only needed by the reuse path to refresh the registry for a DB-declared server.""" - from litellm.proxy._experimental.mcp_server.db import get_mcp_server # noqa: PLC0415 # avoids circular import - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.db import get_mcp_server # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import global_mcp_server_manager, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 # avoids circular import @@ -1793,7 +1793,7 @@ async def _reuse_persisted_dcr_client_if_available( async def _refresh_persisted_dcr_server(persisted_server: Optional["LiteLLM_MCPServerTable"]) -> None: if persisted_server is not None and persisted_server.approval_status != "draft": - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids circular import global_mcp_server_manager, ) @@ -1910,16 +1910,16 @@ async def _persist_dcr_client_registration( "dcr_server_url": mcp_server.url, } - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # avoids circular import + from litellm.proxy._types import UpdateMCPServerRequest # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # avoids circular import McpIdentifierConflict, create_mcp_server_oauth_client_credentials_if_absent, update_mcp_server, upsert_mcp_server_oauth_client_credentials, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 global_mcp_server_manager, ) - from litellm.proxy._types import UpdateMCPServerRequest # noqa: PLC0415 from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 try: @@ -2403,7 +2403,7 @@ async def authorize( scope=scope, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager lookup_name: Final[str | None] = mcp_server_name or client_id client_ip: Final = IPAddressUtils.get_mcp_client_ip(request) @@ -2532,7 +2532,7 @@ async def _vendor_credential_state( The one reading of "authorized" the connect page displays and the finish step enforces, so the button a user sees and the grant they get cannot disagree. A read fault is neither, and fails the scoped grant closed.""" - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # circular import at module load + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # circular import at module load get_user_oauth_credential, oauth_grant_state, ) @@ -3184,7 +3184,7 @@ def _aggregate_header_scopes(request: Request) -> tuple[str, ...]: discovery request, so a client that skips the 401 challenge (Claude Code re-authenticating a server it already knows needs auth) still carries the selection to ``/authorize`` through ``scopes_supported``. Empty when the header is absent or any entry does not resolve.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle MCPRequestHandler, gateway_dcr_challenge_scope, ) @@ -3489,7 +3489,7 @@ async def register_client(request: Request, mcp_server_name: str | None = None): request=request, request_body=data, token_exchange_available=token_exchange_available() ) client_application_type: Final = client_supplied_application_type(data.get("application_type")) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async with global_mcp_server_manager.catalog.operation(): dummy_return: Final = { diff --git a/litellm/proxy/_experimental/mcp_server/elicitation_handler.py b/litellm/proxy/mcp_server/elicitation_handler.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/elicitation_handler.py rename to litellm/proxy/mcp_server/elicitation_handler.py diff --git a/litellm/proxy/_experimental/mcp_server/exceptions.py b/litellm/proxy/mcp_server/exceptions.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/exceptions.py rename to litellm/proxy/mcp_server/exceptions.py index ca2f04bb96a..8be3ae78d15 100644 --- a/litellm/proxy/_experimental/mcp_server/exceptions.py +++ b/litellm/proxy/mcp_server/exceptions.py @@ -4,7 +4,7 @@ from typing import Final from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope +from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope TOKEN_EXCHANGE_SUBJECT_ERROR: Final = ( "Missing or invalid subject token. Authenticate with your identity provider and send its token " diff --git a/litellm/proxy/_experimental/mcp_server/faults/__init__.py b/litellm/proxy/mcp_server/faults/__init__.py similarity index 81% rename from litellm/proxy/_experimental/mcp_server/faults/__init__.py rename to litellm/proxy/mcp_server/faults/__init__.py index de7ee5c866a..bcaa6314869 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/__init__.py +++ b/litellm/proxy/mcp_server/faults/__init__.py @@ -7,16 +7,16 @@ a server-fault status) unrepresentable, and gives the trust-boundary rule one en spec-defined machine fields may cross to callers, upstream prose and raw bodies go to server logs. """ -from litellm.proxy._experimental.mcp_server.faults.classify import ( +from litellm.proxy.mcp_server.faults.classify import ( classify_upstream_dcr_rejection, classify_upstream_token_rejection, ) -from litellm.proxy._experimental.mcp_server.faults.render_oauth import ( +from litellm.proxy.mcp_server.faults.render_oauth import ( dcr_fault_detail, render_token_fault, ) -from litellm.proxy._experimental.mcp_server.faults.traversal import iter_exception_tree -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.traversal import iter_exception_tree +from litellm.proxy.mcp_server.faults.types import ( CallerRejected, CredentialSource, GatewayRejected, diff --git a/litellm/proxy/_experimental/mcp_server/faults/classify.py b/litellm/proxy/mcp_server/faults/classify.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/faults/classify.py rename to litellm/proxy/mcp_server/faults/classify.py index 7826fc34eac..b5e5cbcd27d 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/classify.py +++ b/litellm/proxy/mcp_server/faults/classify.py @@ -13,7 +13,7 @@ import httpx from pydantic import TypeAdapter from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.types import ( GATEWAY_CAPABILITY_CODES, GATEWAY_CREDENTIAL_CODES, MAX_WIRE_FIELD_CHARS, diff --git a/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py b/litellm/proxy/mcp_server/faults/list_outcomes.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py rename to litellm/proxy/mcp_server/faults/list_outcomes.py index e148e28e826..b8af3ead8fb 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py +++ b/litellm/proxy/mcp_server/faults/list_outcomes.py @@ -33,12 +33,12 @@ from litellm.constants import ( MCP_UPSTREAM_RATE_LIMIT_MAX_DELAY_SECONDS, MCP_UPSTREAM_RATE_LIMIT_MAX_RETRIES, ) -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.traversal import iter_exception_tree -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.faults.traversal import iter_exception_tree from litellm.types.llms.base import LiteLLMBaseModel ListFaultCategory: TypeAlias = Literal[ diff --git a/litellm/proxy/_experimental/mcp_server/faults/render_oauth.py b/litellm/proxy/mcp_server/faults/render_oauth.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/faults/render_oauth.py rename to litellm/proxy/mcp_server/faults/render_oauth.py index 3ecf5310482..92fa457e476 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/render_oauth.py +++ b/litellm/proxy/mcp_server/faults/render_oauth.py @@ -11,8 +11,8 @@ from typing import Final from fastapi.responses import JSONResponse from typing_extensions import assert_never -from litellm.proxy._experimental.mcp_server.faults.types import CallerRejected, UpstreamOAuthFault -from litellm.proxy._experimental.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS +from litellm.proxy.mcp_server.faults.types import CallerRejected, UpstreamOAuthFault +from litellm.proxy.mcp_server.oauth_utils import TOKEN_NO_CACHE_HEADERS def _gateway_rejected_description(code: str) -> str: diff --git a/litellm/proxy/_experimental/mcp_server/faults/traversal.py b/litellm/proxy/mcp_server/faults/traversal.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/faults/traversal.py rename to litellm/proxy/mcp_server/faults/traversal.py diff --git a/litellm/proxy/_experimental/mcp_server/faults/types.py b/litellm/proxy/mcp_server/faults/types.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/faults/types.py rename to litellm/proxy/mcp_server/faults/types.py diff --git a/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py b/litellm/proxy/mcp_server/gateway_dcr_flow.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py rename to litellm/proxy/mcp_server/gateway_dcr_flow.py index 70e4bac01b5..ae74d878b36 100644 --- a/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py +++ b/litellm/proxy/mcp_server/gateway_dcr_flow.py @@ -58,8 +58,15 @@ from typing_extensions import NotRequired, ReadOnly, TypedDict, assert_never from litellm._internal_context import with_service_target from litellm._logging import verbose_logger from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import ( + decrypt_value_helper, + encrypt_value_helper, +) +from litellm.proxy.common_utils.html_forms.native_client_consent import ( + render_native_client_consent_page, +) +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.oauth_utils import ( TOKEN_NO_CACHE_HEADERS, UPSTREAM_SCOPE_PREFIX, UpstreamScope, @@ -70,13 +77,13 @@ from litellm.proxy._experimental.mcp_server.oauth_utils import ( is_loopback_redirect_host, validate_redirect_uri_shape, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( SessionRefreshOpened, SessionSigningConfigError, active_session_signing_keys, open_session_refresh_bearer, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SESSION_ISSUER, SESSION_REFRESH_TTL_SECONDS, MintedSessionToken, @@ -91,13 +98,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token i open_session_refresh_token, open_session_token, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import ( - decrypt_value_helper, - encrypt_value_helper, -) -from litellm.proxy.common_utils.html_forms.native_client_consent import ( - render_native_client_consent_page, -) from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -624,7 +624,7 @@ def _is_aggregate_resource(request: Request, resource: str) -> bool: def _gateway_flow_server(name: str) -> MCPServer | None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # proxy import cycle global_mcp_server_manager, ) @@ -656,7 +656,7 @@ def resolve_scoped_resource_server(request: Request, resource: str | None) -> MC base: Final = canonicalize_url_identity(get_request_base_url(request)) if _is_aggregate_resource(request, resource) or not canonical.startswith(f"{base}/"): return None - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: PLC0415 # proxy import cycle MCPRequestHandler, ) @@ -992,7 +992,7 @@ async def _flow_target( ) -> tuple[Literal["unscoped", "interactive", "m2m", "stale"], MCPServer | None]: if server_id is None: return "unscoped", None - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # import cycle MCPServerManager, global_mcp_server_manager, ) diff --git a/litellm/proxy/_experimental/mcp_server/guardrail_translation/__init__.py b/litellm/proxy/mcp_server/guardrail_translation/__init__.py similarity index 88% rename from litellm/proxy/_experimental/mcp_server/guardrail_translation/__init__.py rename to litellm/proxy/mcp_server/guardrail_translation/__init__.py index ac06aa93c96..c4b52b745a3 100644 --- a/litellm/proxy/_experimental/mcp_server/guardrail_translation/__init__.py +++ b/litellm/proxy/mcp_server/guardrail_translation/__init__.py @@ -2,7 +2,7 @@ from typing import Final -from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import ( +from litellm.proxy.mcp_server.guardrail_translation.handler import ( MCPGuardrailTranslationHandler, ) from litellm.types.utils import CallTypes diff --git a/litellm/proxy/_experimental/mcp_server/guardrail_translation/handler.py b/litellm/proxy/mcp_server/guardrail_translation/handler.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/guardrail_translation/handler.py rename to litellm/proxy/mcp_server/guardrail_translation/handler.py index d1a8084f4b2..28c51148da5 100644 --- a/litellm/proxy/_experimental/mcp_server/guardrail_translation/handler.py +++ b/litellm/proxy/mcp_server/guardrail_translation/handler.py @@ -13,7 +13,7 @@ every ``description`` string in the schema lead ``texts``, so a guardrail that blocks or masks them decides what the client gets to see in ``tools/list``. Note: For MCP tool definitions (schema) -> OpenAI tools=[], see -litellm.experimental_mcp_client.tools.transform_mcp_tool_to_openai_tool +litellm.mcp_client.tools.transform_mcp_tool_to_openai_tool when you have a full MCP Tool from list_tools. Here we only have the call payload (name + arguments) so we just build the tool definition. """ @@ -25,9 +25,9 @@ from fastapi import HTTPException from mcp.types import Tool as MCPTool from litellm._logging import verbose_proxy_logger -from litellm.experimental_mcp_client.tools import transform_mcp_tool_to_openai_tool from litellm.llms.base_llm.guardrail_translation.base_translation import BaseTranslation -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.mcp_client.tools import transform_mcp_tool_to_openai_tool +from litellm.proxy.mcp_server.utils import ( MAX_STRUCTURED_CONTENT_SCAN_DEPTH, JSONLeafPath, json_string_leaves, diff --git a/litellm/proxy/_experimental/mcp_server/id_jag_grant.py b/litellm/proxy/mcp_server/id_jag_grant.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/id_jag_grant.py rename to litellm/proxy/mcp_server/id_jag_grant.py index f2177df5a26..96f212e3bd7 100644 --- a/litellm/proxy/_experimental/mcp_server/id_jag_grant.py +++ b/litellm/proxy/mcp_server/id_jag_grant.py @@ -27,20 +27,20 @@ from pydantic import TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger from litellm.models.user import LiteLLM_UserTable -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy._types import IdJagRequestingApp +from litellm.proxy.auth.handle_jwt import ID_JAG_TYP, AssertionRejection, JWTHandler +from litellm.proxy.mcp_server.gateway_dcr_flow import ( AssertionIdentity, ConsentTeam, SubjectIdentity, SubjectTokenRefusal, ) -from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( +from litellm.proxy.mcp_server.idp_token_exchange import ( gateway_outage_refusal, log_line, read_token_exchange_prerequisites, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import proxy_base_url_from_env -from litellm.proxy._types import IdJagRequestingApp -from litellm.proxy.auth.handle_jwt import ID_JAG_TYP, AssertionRejection, JWTHandler +from litellm.proxy.mcp_server.oauth_utils import proxy_base_url_from_env ID_JAG_REQUIRED_CLAIMS: Final = ("iss", "sub", "aud", "exp", "iat", "jti", "client_id") REJECTED_ASSERTION: Final = "assertion was rejected" @@ -395,10 +395,10 @@ class AssertionRedemption: async def redeem_id_jag_assertion( assertion: str, client_id: str, client_secret: str | None, request: Request ) -> AssertionIdentity | SubjectTokenRefusal: - from litellm.proxy._experimental.mcp_server.proxy_api_credentials import ( # noqa: PLC0415 # circular import at module load + from litellm.proxy.auth.auth_checks import get_user_object # noqa: PLC0415 # circular import at module load + from litellm.proxy.mcp_server.proxy_api_credentials import ( # noqa: PLC0415 # circular import at module load lookup_consent_teams_from_database, ) - from litellm.proxy.auth.auth_checks import get_user_object # noqa: PLC0415 # circular import at module load from litellm.proxy.proxy_server import ( # noqa: PLC0415 # rebound after startup, so read them per call jwt_handler, prisma_client, diff --git a/litellm/proxy/_experimental/mcp_server/idp_token_exchange.py b/litellm/proxy/mcp_server/idp_token_exchange.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/idp_token_exchange.py rename to litellm/proxy/mcp_server/idp_token_exchange.py index 5044a5bd3dc..c8ccdc9bca6 100644 --- a/litellm/proxy/_experimental/mcp_server/idp_token_exchange.py +++ b/litellm/proxy/mcp_server/idp_token_exchange.py @@ -13,10 +13,10 @@ from fastapi import HTTPException, Request from typing_extensions import assert_never from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal from litellm.proxy._types import JWTAuthBuilderResult, ProxyException from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler +from litellm.proxy.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal EXCHANGE_ROUTE: Final = "/token" REJECTED_SUBJECT_TOKEN: Final = "subject_token was rejected by the gateway's JWT auth" diff --git a/litellm/proxy/_experimental/mcp_server/interactions.py b/litellm/proxy/mcp_server/interactions.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/interactions.py rename to litellm/proxy/mcp_server/interactions.py index 42addcfb65b..24cedb57ef8 100644 --- a/litellm/proxy/_experimental/mcp_server/interactions.py +++ b/litellm/proxy/mcp_server/interactions.py @@ -25,9 +25,9 @@ from mcp.types import ( ) from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, ValidationError -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error -from litellm.proxy._experimental.mcp_server.state_tokens import StateTokenError, open_state, seal_state +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.outbound_credentials.result import Error +from litellm.proxy.mcp_server.state_tokens import StateTokenError, open_state, seal_state from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/litellm/proxy/_experimental/mcp_server/legacy_callbacks.py b/litellm/proxy/mcp_server/legacy_callbacks.py similarity index 87% rename from litellm/proxy/_experimental/mcp_server/legacy_callbacks.py rename to litellm/proxy/mcp_server/legacy_callbacks.py index 440b184e6ee..3d2f97492bb 100644 --- a/litellm/proxy/_experimental/mcp_server/legacy_callbacks.py +++ b/litellm/proxy/mcp_server/legacy_callbacks.py @@ -13,14 +13,14 @@ from mcp.types import ( ) from litellm.constants import MCP_CLIENT_TIMEOUT -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.mcp_context import get_active_mcp_request_ctx -from litellm.proxy._experimental.mcp_server.scope_challenge import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.mcp_context import get_active_mcp_request_ctx +from litellm.proxy.mcp_server.scope_challenge import ( OAuthScopeResponse, is_tool_call_request, scope_response_from_request, ) -from litellm.proxy._types import UserAPIKeyAuth class SamplingCallback(Protocol): @@ -43,7 +43,7 @@ def create_sampling_callback( client_ip: str | None = None, operation_context: OperationContext | None = None, ) -> SamplingCallback: - from litellm.proxy._experimental.mcp_server.server import get_active_auth_context + from litellm.proxy.mcp_server.server import get_active_auth_context auth: Final = get_active_auth_context() if operation_context is None and user_api_key_auth is None else None captured: Final = ( @@ -60,7 +60,7 @@ def create_sampling_callback( context: ClientRequestContext, params: CreateMessageRequestParams ) -> CreateMessageResult | CreateMessageResultWithTools | ErrorData: import litellm - from litellm.proxy._experimental.mcp_server.sampling_handler import handle_sampling_create_message + from litellm.proxy.mcp_server.sampling_handler import handle_sampling_create_message return await handle_sampling_create_message( context=context, @@ -75,7 +75,7 @@ def create_sampling_callback( def create_elicitation_callback(timeout: float | None = None) -> ElicitationCallback: - from litellm.proxy._experimental.mcp_server.server import get_active_mcp_session + from litellm.proxy.mcp_server.server import get_active_mcp_session downstream_session: Final = get_active_mcp_session() request: Final = get_active_mcp_request_ctx() @@ -94,7 +94,7 @@ def create_elicitation_callback(timeout: float | None = None) -> ElicitationCall code=-32602, message="A legacy upstream cannot resume input for a modern client; the operation may have partially completed", ) - from litellm.proxy._experimental.mcp_server.elicitation_handler import handle_elicitation_request + from litellm.proxy.mcp_server.elicitation_handler import handle_elicitation_request return await handle_elicitation_request( context=context, diff --git a/litellm/proxy/_experimental/mcp_server/mcp_context.py b/litellm/proxy/mcp_server/mcp_context.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/mcp_context.py rename to litellm/proxy/mcp_server/mcp_context.py diff --git a/litellm/proxy/_experimental/mcp_server/mcp_debug.py b/litellm/proxy/mcp_server/mcp_debug.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/mcp_debug.py rename to litellm/proxy/mcp_server/mcp_debug.py index bf74ea99e55..94b3d96a359 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_debug.py +++ b/litellm/proxy/mcp_server/mcp_debug.py @@ -124,7 +124,7 @@ from litellm.litellm_core_utils.secret_redaction import REDACTED, redact_string from litellm.litellm_core_utils.sensitive_data_masker import SensitiveDataMasker if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution # Header the client sends to opt into debug mode MCP_DEBUG_REQUEST_HEADER: Final = "x-litellm-mcp-debug" @@ -137,7 +137,7 @@ MCP_AUTH_DIAGNOSTICS_SCOPE_KEY: Final = "litellm.mcp.auth_diagnostics" def record_auth_resolution(server_id: str, source: AuthResolution) -> None: - from litellm.proxy._experimental.mcp_server.mcp_context import get_active_mcp_request_ctx + from litellm.proxy.mcp_server.mcp_context import get_active_mcp_request_ctx context: Final[object] = get_active_mcp_request_ctx() request: Final[object] = getattr(context, "request", None) @@ -155,7 +155,7 @@ class MCPAuthDiagnostics: self._outcomes = tuple(item for item in self._outcomes if item[0] != server_id) + ((server_id, resolution),) def resolution(self) -> str: - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution match self._outcomes: case (): @@ -166,7 +166,7 @@ class MCPAuthDiagnostics: return AuthResolution.multiple.value def headers(self) -> Mapping[str, str]: - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution if len(self._outcomes) <= 1: return MappingProxyType({"x-mcp-debug-auth-resolution": self.resolution()}) @@ -370,16 +370,16 @@ class MCPDebug: if not raw_headers or not MCPDebug.is_debug_enabled(raw_headers): return {} - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) server_url: str | None = None server_auth_type: str | None = None - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution auth_resolution: Final = AuthResolution.unresolved.value @@ -471,7 +471,7 @@ def _body_secret_values(request: httpx.Request | httpx2.Request) -> tuple[str, . body: Final = _JSON_BODY.validate_json(raw) except ValueError: return None - from litellm.proxy._experimental.mcp_server.utils import ( # noqa: PLC0415 # MCP utils imports clients; inspect bodies only after initialization + from litellm.proxy.mcp_server.utils import ( # noqa: PLC0415 # MCP utils imports clients; inspect bodies only after initialization json_string_leaves, ) @@ -613,7 +613,7 @@ def describe_upstream_response(response: httpx.Response | httpx2.Response) -> st def describe_upstream_http_failure(exc: BaseException) -> str | None: - from litellm.proxy._experimental.mcp_server.faults.traversal import ( # noqa: PLC0415 # fault package initialization imports the credential resolver + from litellm.proxy.mcp_server.faults.traversal import ( # noqa: PLC0415 # fault package initialization imports the credential resolver iter_exception_tree, ) diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/mcp_server/mcp_server_manager.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/mcp_server_manager.py rename to litellm/proxy/mcp_server/mcp_server_manager.py index db70c7d77de..8e613a8a6e8 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/mcp_server/mcp_server_manager.py @@ -73,7 +73,12 @@ from litellm.constants import ( MCP_UPSTREAM_SESSION_SHUTDOWN_TIMEOUT_SECONDS, ) from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException -from litellm.experimental_mcp_client.client import ( +from litellm.integrations.custom_guardrail import ( + _sync_guardrail_info_to_logging_obj, # pyright: ignore[reportPrivateUsage] - the same bridge @log_guardrail_information uses; reimplementing it here would fork the metadata-key logic +) +from litellm.litellm_core_utils.url_utils import SSRFError, async_safe_get +from litellm.llms.custom_httpx.http_handler import get_async_httpx_client +from litellm.mcp_client.client import ( SESSION_CLEANUP_TIMEOUT_MESSAGE, MCPClient, PersistentMCPSession, @@ -81,102 +86,114 @@ from litellm.experimental_mcp_client.client import ( strip_auth_scheme, to_basic_credentials, ) -from litellm.integrations.custom_guardrail import ( - _sync_guardrail_info_to_logging_obj, # pyright: ignore[reportPrivateUsage] - the same bridge @log_guardrail_information uses; reimplementing it here would fork the metadata-key logic +from litellm.proxy._types import ( + LiteLLM_MCPServerTable, + MCPAuthType, + MCPEnvVar, + MCPTransport, + MCPTransportType, + SpecialMCPServerNames, + UserAPIKeyAuth, + is_per_server_oauth_discovery_eligible, ) -from litellm.litellm_core_utils.url_utils import SSRFError, async_safe_get -from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports +from litellm.proxy.agent_endpoints.auth.managed_authorization import managed_agent_policy +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper +from litellm.proxy.common_utils.user_api_key_cache import get_management_object_ttl +from litellm.proxy.management_endpoints.sso.id_jag_assertion_capture import ( + id_jag_assertion_capture_gap_at_startup, +) +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports MCPRequestHandler, MCPServerAccess, _is_mcp_admitted_user_subject, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export is_mcp_admitted_user_subject, ) -from litellm.proxy._experimental.mcp_server.catalog import _configuration_identity, _DiscoveryCache, _DiscoveryKey -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.elicitation_handler import ( +from litellm.proxy.mcp_server.catalog import _configuration_identity, _DiscoveryCache, _DiscoveryKey +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.elicitation_handler import ( MCP_ELICITATION_AVAILABLE, ) -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, raise_classified_list_failure, retry_upstream_rate_limit, upstream_auth_challenge, upstream_insufficient_scope, ) -from litellm.proxy._experimental.mcp_server.interactions import bind_target -from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response, has_active_mcp_request_context -from litellm.proxy._experimental.mcp_server.mcp_debug import describe_upstream_http_failure, record_auth_resolution -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( +from litellm.proxy.mcp_server.interactions import bind_target +from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response, has_active_mcp_request_context +from litellm.proxy.mcp_server.mcp_debug import describe_upstream_http_failure, record_auth_resolution +from litellm.proxy.mcp_server.oauth2_token_cache import ( MCPPerUserTokenCache, mcp_per_user_token_cache, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export canonicalize_url_identity, get_byok_www_authenticate, needs_cimd_discovery, redact_mcp_resource_url, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Error, Ok, UpstreamCredentialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( +from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_public, raise_token_exchange_challenge, to_server_spec, to_subject, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InvalidatableOAuthTokenStore, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( +from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchange_provider import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchange_provider import ( build_token_exchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, AuthResolution, IdJagConfig, PassthroughConfig, TokenExchangeConfig, ) -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.proxy.mcp_server.result_conversion import ( WireCompat, complete_call_tool_result, handler_outcome, to_gateway_tool, ) -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( MCP_SAMPLING_AVAILABLE, ) -from litellm.proxy._experimental.mcp_server.stdio_gate import ( +from litellm.proxy.mcp_server.stdio_gate import ( MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_blocked, warn_if_mcp_stdio_blocked, ) -from litellm.proxy._experimental.mcp_server.tool_catalog_guard import ( +from litellm.proxy.mcp_server.tool_catalog_guard import ( CatalogAlert, apply_description_overrides, pin_tool_catalog, scan_tool_descriptions, ) -from litellm.proxy._experimental.mcp_server.upstream import ( +from litellm.proxy.mcp_server.upstream import ( passthrough_token_from_mcp_auth_header, prepare_upstream_client, resolve_upstream_auth, take_forwarded_authorization, to_server_spec_fail_closed, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( MCP_SERVERS_TARGET, MCP_TOOL_PREFIX_SEPARATOR, MCPMissingUserEnvVarsError, @@ -201,23 +218,6 @@ from litellm.proxy._experimental.mcp_server.utils import ( strip_known_server_prefix, validate_mcp_server_name, ) -from litellm.proxy._types import ( - LiteLLM_MCPServerTable, - MCPAuthType, - MCPEnvVar, - MCPTransport, - MCPTransportType, - SpecialMCPServerNames, - UserAPIKeyAuth, - is_per_server_oauth_discovery_eligible, -) -from litellm.proxy.agent_endpoints.auth.managed_authorization import managed_agent_policy -from litellm.proxy.auth.ip_address_utils import IPAddressUtils -from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper -from litellm.proxy.common_utils.user_api_key_cache import get_management_object_ttl -from litellm.proxy.management_endpoints.sso.id_jag_assertion_capture import ( - id_jag_assertion_capture_gap_at_startup, -) from litellm.proxy.middleware.per_request_root_path_middleware import ( get_request_root_path, ) @@ -242,7 +242,7 @@ from litellm.types.utils import CallTypes if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult from litellm.types.mcp_server.mcp_toolset import MCPToolset try: @@ -1032,7 +1032,7 @@ async def _openapi_spec_health( ) -> tuple[Literal["healthy", "unhealthy", "unknown"], str | None]: """Check specification availability, not upstream operations or user credentials.""" from litellm.llms.custom_httpx.http_handler import HTTPResponseLimitError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async + from litellm.proxy.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async if not spec_path.startswith(("http://", "https://")): return "unknown", "OpenAPI servers have no protocol-level health probe" @@ -1464,7 +1464,7 @@ async def _resolve_byok_mcp_auth_header( if not mcp_server.is_byok: return mcp_auth_header - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _check_byok_credential, _get_byok_credential, ) @@ -1835,7 +1835,7 @@ def _create_sampling_callback( ): if not MCP_SAMPLING_AVAILABLE: return None - from litellm.proxy._experimental.mcp_server.legacy_callbacks import create_sampling_callback + from litellm.proxy.mcp_server.legacy_callbacks import create_sampling_callback return create_sampling_callback(user_api_key_auth, raw_headers, client_ip, operation_context) @@ -1843,7 +1843,7 @@ def _create_sampling_callback( def _create_elicitation_callback(timeout: float | None = None): if not MCP_ELICITATION_AVAILABLE: return None - from litellm.proxy._experimental.mcp_server.legacy_callbacks import create_elicitation_callback + from litellm.proxy.mcp_server.legacy_callbacks import create_elicitation_callback return create_elicitation_callback(timeout=timeout) @@ -2035,7 +2035,7 @@ class MCPServerManager: self._template_discovery_cache = _DiscoveryCache[ListResourceTemplatesResult]( discovery_ttl, discovery_clock, TypeAdapter(ListResourceTemplatesResult) ) - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.catalog import CatalogSnapshots self.catalog = CatalogSnapshots(self) self.registry: dict[str, MCPServer] = {} @@ -2887,7 +2887,7 @@ class MCPServerManager: """Overlay each config-declared server's persisted DCR client (from the server-scoped store) onto its in-memory object so token refresh authenticates after a restart. A best-effort no-op when the DB is unreachable at config-load time.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # circular import + from litellm.proxy.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # circular import hydrate_config_server_dcr_client, ) @@ -2919,16 +2919,16 @@ class MCPServerManager: server: The MCPServer instance to register tools for base_url: Base URL for API calls """ - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( build_input_schema, create_tool_function, load_openapi_spec_async, resolve_operation_params, ) - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( get_base_url as get_openapi_base_url, ) - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -3061,7 +3061,7 @@ class MCPServerManager: self.remove_server_tool_routing(server) def remove_server_tool_routing(self, server: MCPServer) -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry prefix_root: Final = normalize_server_name(get_server_prefix(server)) if server.spec_path and prefix_root: @@ -3128,7 +3128,7 @@ class MCPServerManager: ) -> _EnvVarList | None: env_vars_list: Final = _deserialize_json_list(getattr(mcp_server, "env_vars", None)) if env_vars_are_encrypted: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 decrypt_global_env_var_values, ) @@ -3578,7 +3578,7 @@ class MCPServerManager: return [] try: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 get_active_submitted_mcp_server_ids_for_user, ) from litellm.proxy.proxy_server import prisma_client, user_api_key_cache @@ -3835,7 +3835,7 @@ class MCPServerManager: one silently renames the tool when a native name happens to begin with it (``greyhound_internal_events`` on a server prefixed ``greyhound``). """ - from litellm.proxy._experimental.mcp_server.toolset_db import list_mcp_toolsets + from litellm.proxy.mcp_server.toolset_db import list_mcp_toolsets from litellm.proxy.proxy_server import prisma_client, user_api_key_cache if not toolset_ids or prisma_client is None: @@ -3933,7 +3933,7 @@ class MCPServerManager: return MCPToolset(**cached) return cached - from litellm.proxy._experimental.mcp_server.toolset_db import ( + from litellm.proxy.mcp_server.toolset_db import ( get_mcp_toolset_by_name, ) @@ -4291,7 +4291,7 @@ class MCPServerManager: "is configured. Connect a database to your proxy to use per-user " "MCP env vars." ) - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 get_user_env_vars, ) @@ -4455,7 +4455,7 @@ class MCPServerManager: record_listing: bool = False, listing_updates: ExitStack | None = None, ) -> ListToolsResult: - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -4662,7 +4662,7 @@ class MCPServerManager: self._template_discovery_cache.invalidate(server_id) def invalidate_server_definition_caches(self, server_id: str) -> None: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # lazy: discoverable_endpoints lazily imports this module's manager singleton + from litellm.proxy.mcp_server.discoverable_endpoints import ( # noqa: PLC0415 # lazy: discoverable_endpoints lazily imports this module's manager singleton invalidate_oauth_metadata_cache, ) @@ -5830,7 +5830,7 @@ class MCPServerManager: Returns: List of tools with prefixed names """ - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry if register_bare_names and listing_updates is not None: listing_updates.callback(self._create_prefixed_tools, tools, server, add_prefix=add_prefix) @@ -5942,7 +5942,7 @@ class MCPServerManager: deriving the spellings routing accepts, never by stripping the entry, which would cut a second boundary out of a native name that opens with the server prefix. """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( server_applies_tool_allowlist, ) @@ -6005,7 +6005,7 @@ class MCPServerManager: Raises: HTTPException: If tool is not allowed for this key/team """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -6050,7 +6050,7 @@ class MCPServerManager: """ from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -6868,7 +6868,7 @@ class MCPServerManager: return oauth2_headers try: - from litellm.proxy._experimental.mcp_server.operations import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.operations import ( # noqa: PLC0415 _get_user_oauth_extra_headers_from_db, ) @@ -7108,7 +7108,7 @@ class MCPServerManager: ) async def _call_openapi_via_handler(): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_auth_header, request_extra_headers, request_resolved_auth_headers, @@ -7207,7 +7207,7 @@ class MCPServerManager: Returns: MCPServer if found, None otherwise """ - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry registered_tool: Final = global_mcp_tool_registry.get_tool(tool_name) if registered_tool is not None: diff --git a/litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py b/litellm/proxy/mcp_server/oauth2_flow_backfill.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py rename to litellm/proxy/mcp_server/oauth2_flow_backfill.py index 71281b276fa..1ef67df498f 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py +++ b/litellm/proxy/mcp_server/oauth2_flow_backfill.py @@ -42,7 +42,7 @@ from typing import Final, Literal, Protocol from pydantic import JsonValue from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.db import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.db import ( # noqa: F401 # legacy module exports _decode_oauth_payload, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export decode_oauth_payload, decrypt_credentials, diff --git a/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py b/litellm/proxy/mcp_server/oauth2_token_cache.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py rename to litellm/proxy/mcp_server/oauth2_token_cache.py index cc92b8cce9b..1e6e83c0f4b 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth2_token_cache.py +++ b/litellm/proxy/mcp_server/oauth2_token_cache.py @@ -26,17 +26,17 @@ from litellm.constants import ( MCP_PER_USER_TOKEN_REDIS_KEY_PREFIX, ) from litellm.llms.custom_httpx.http_handler import get_async_httpx_client -from litellm.proxy._experimental.mcp_server.oauth_utils import ( - build_upstream_oauth2_token_request, - resolve_upstream_resource, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import OAuthToken -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import OAuthTokenCacheCodec -from litellm.proxy._experimental.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET from litellm.proxy.common_utils.encrypt_decrypt_utils import ( decrypt_value_helper, encrypt_value_helper, ) +from litellm.proxy.mcp_server.oauth_utils import ( + build_upstream_oauth2_token_request, + resolve_upstream_resource, +) +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import OAuthToken +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import OAuthTokenCacheCodec +from litellm.proxy.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET from litellm.types.llms.custom_http import httpxSpecialProvider if TYPE_CHECKING: diff --git a/litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py b/litellm/proxy/mcp_server/oauth_identity_binding.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py rename to litellm/proxy/mcp_server/oauth_identity_binding.py index b3aa040c507..6fdda498d50 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py +++ b/litellm/proxy/mcp_server/oauth_identity_binding.py @@ -184,7 +184,7 @@ def _upstream_principal( async def _load_caller_principal(litellm_user_id: str, binding: MCPOAuthIdentityBinding) -> str | None: if binding.caller_field == "user_id": return litellm_user_id - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( # noqa: PLC0415 # inline import avoids a module-load circular import + from litellm.proxy.mcp_server.bridge_token_flow import ( # noqa: PLC0415 # inline import avoids a module-load circular import load_active_user_by_id, ) @@ -198,7 +198,7 @@ async def _load_stored_refresh_token( litellm_user_id: str, server_id: str, binding: MCPOAuthIdentityBinding ) -> VerifiedRefreshToken | None: try: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 # keep database imports lazy + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 # keep database imports lazy get_user_oauth_credential, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 # keep database imports lazy diff --git a/litellm/proxy/_experimental/mcp_server/oauth_issuer_stamp_backfill.py b/litellm/proxy/mcp_server/oauth_issuer_stamp_backfill.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/oauth_issuer_stamp_backfill.py rename to litellm/proxy/mcp_server/oauth_issuer_stamp_backfill.py index eb02ed64e91..c417187396f 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth_issuer_stamp_backfill.py +++ b/litellm/proxy/mcp_server/oauth_issuer_stamp_backfill.py @@ -40,8 +40,8 @@ from typing import Final, Protocol from urllib.parse import urlparse from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.oauth_utils import canonicalize_url_identity from litellm.proxy.db.db_span import db_span +from litellm.proxy.mcp_server.oauth_utils import canonicalize_url_identity from litellm.proxy.utils import PrismaClient # The actor the removed discovery write-back stamped rows with. diff --git a/litellm/proxy/_experimental/mcp_server/oauth_utils.py b/litellm/proxy/mcp_server/oauth_utils.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/oauth_utils.py rename to litellm/proxy/mcp_server/oauth_utils.py index 133bad780bf..76343f77e32 100644 --- a/litellm/proxy/_experimental/mcp_server/oauth_utils.py +++ b/litellm/proxy/mcp_server/oauth_utils.py @@ -14,15 +14,15 @@ from fastapi import HTTPException, Request from starlette.types import Scope from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointClientAuth, build_token_endpoint_client_auth, normalize_token_endpoint_auth_method, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( GOOGLE_REFRESH_TOKEN_PARAMS, ) -from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.proxy.middleware.per_request_root_path_middleware import get_request_root_path if TYPE_CHECKING: diff --git a/litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py b/litellm/proxy/mcp_server/openapi_to_mcp_generator.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py rename to litellm/proxy/mcp_server/openapi_to_mcp_generator.py index f0353f309a9..96d178dbeb1 100644 --- a/litellm/proxy/_experimental/mcp_server/openapi_to_mcp_generator.py +++ b/litellm/proxy/mcp_server/openapi_to_mcp_generator.py @@ -16,7 +16,7 @@ import httpx from typing_extensions import ReadOnly, Required from litellm.llms.custom_httpx.http_handler import MaskedHTTPStatusError -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.exceptions import ( MCPOpenApiUpstreamError, MCPUpstreamAuthError, ) @@ -54,8 +54,8 @@ from litellm.llms.custom_httpx.http_handler import ( header_value, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.tool_outcome import JsonResult, TextResult, parse_http_body -from litellm.proxy._experimental.mcp_server.tool_registry import ( +from litellm.proxy.mcp_server.tool_outcome import JsonResult, TextResult, parse_http_body +from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) from litellm.types.mcp import MCPAuthType, credential_redirect_hook, custom_credential_slot @@ -442,7 +442,7 @@ def _merge_openapi_tool_request_headers( the MCP caller (allowlisted by ``MCPServer.extra_headers``) This matches the existing MCP invariant in - :func:`litellm.proxy._experimental.mcp_server.utils.merge_mcp_headers` + :func:`litellm.proxy.mcp_server.utils.merge_mcp_headers` and the managed MCP path, where ``static_headers`` always wins over caller-forwarded headers. Keeping the same precedence here prevents an authenticated caller from overriding an operator-configured value @@ -542,11 +542,11 @@ def create_tool_function( """ effective_headers: Final = _merge_openapi_tool_request_headers(headers) if auth_type is not None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_public, validate_static_credential, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok match validate_static_credential(auth_type, effective_headers, upstream_token_header, headers or ()): case Error(error): diff --git a/litellm/proxy/_experimental/mcp_server/operations.py b/litellm/proxy/mcp_server/operations.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/operations.py rename to litellm/proxy/mcp_server/operations.py index 39e882fcab0..763e3578a96 100644 --- a/litellm/proxy/_experimental/mcp_server/operations.py +++ b/litellm/proxy/mcp_server/operations.py @@ -56,40 +56,51 @@ from litellm.constants import ( MCP_TOOL_LISTING_TIMEOUT, ) from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( +from litellm.proxy._types import ( + UserAPIKeyAuth, +) +from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import ( + publish_auth_cache_invalidation, +) +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.litellm_pre_call_utils import ( + LiteLLMProxyRequestSetup, + get_chain_id_from_headers, +) +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) -from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( +from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache, byok_credential_cache_key, cache_byok_credential, get_cached_byok_credential, ) -from litellm.proxy._experimental.mcp_server.capabilities import ( +from litellm.proxy.mcp_server.capabilities import ( build_discovery, configured_versions, disabled_capabilities, enabled_gateway_operations, ) -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.contracts import ( +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.contracts import ( AuthorizedToolCall, OperationContext, ProgressCallback, ) -from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.db import OAuthCredentialPayload +from litellm.proxy.mcp_server.exceptions import ( MCPToolResultError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( AggregateToolListing, ServerListOk, ServerOutcome, classify_list_exception, outcome_wire_value, ) -from litellm.proxy._experimental.mcp_server.interactions import ( +from litellm.proxy.mcp_server.interactions import ( BoundInputRequiredResult, ContinuationState, InteractionOperation, @@ -97,8 +108,8 @@ from litellm.proxy._experimental.mcp_server.interactions import ( seal_continuation, target_digest, ) -from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response +from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports MCPServerManager, _caller_authorization_fans_out, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _client_forwarded_authorization_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -111,12 +122,12 @@ from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: resolve_openapi_tool_auth, should_strip_caller_authorization, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export get_byok_www_authenticate, redact_mcp_resource_url, ) -from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( # noqa: F401 # legacy module exports _request_auth_header, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _request_extra_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _request_resolved_auth_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -124,16 +135,16 @@ from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( # request_extra_headers, request_resolved_auth_headers, ) -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.proxy.mcp_server.result_conversion import ( WireCompat, complete_call_tool_result, handler_outcome, to_call_tool_result, ) -from litellm.proxy._experimental.mcp_server.tool_registry import ( +from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( MCP_TOOL_PREFIX_SEPARATOR, MCPMissingUserEnvVarsError, add_server_prefix_to_name, @@ -148,20 +159,9 @@ from litellm.proxy._experimental.mcp_server.utils import ( split_server_prefix_from_name, strip_known_server_prefix, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( server_answers_to as _server_answers_to, ) -from litellm.proxy._types import ( - UserAPIKeyAuth, -) -from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import ( - publish_auth_cache_invalidation, -) -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError -from litellm.proxy.litellm_pre_call_utils import ( - LiteLLMProxyRequestSetup, - get_chain_id_from_headers, -) from litellm.types.mcp import ( DEFAULT_CREDENTIAL_HEADER, MCP_LEGACY_VERSIONS, @@ -426,7 +426,7 @@ async def _dispatch_virtual_mcp_tool( the caller falls through to normal tool routing. """ from litellm.llms.litellm_proxy.skills.skill_search import DEFAULT_SKILL_SEARCH_TOP_K - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( AGENT_SEARCH_TOOL_NAME, DEFAULT_AGENT_SEARCH_TOP_K, MCP_PROXY_CALL_TOOL_NAME, @@ -799,7 +799,7 @@ def filter_tools_by_allowed_tools( Returns: Filtered list of tools """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( server_applies_tool_allowlist, ) @@ -911,7 +911,7 @@ def _client_has_per_server_auth_header( """ if not mcp_server_auth_headers: return False - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, ) @@ -960,7 +960,7 @@ async def _get_user_oauth_extra_headers_from_db( """ if server.auth_type != MCPAuth.oauth2 or user_api_key_auth is None: return None - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 resolve_user_oauth_access_token, ) @@ -981,7 +981,7 @@ async def _prefetch_oauth_creds_for_user( if not user_id: return {} try: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 list_user_oauth_credentials, ) from litellm.proxy.utils import get_prisma_client_or_throw # noqa: PLC0415 @@ -1015,7 +1015,7 @@ def _prepare_mcp_server_headers( """ server_auth_header: dict[str, str] | str | None = None if mcp_server_auth_headers: - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, ) @@ -1182,8 +1182,8 @@ async def find_mcp_proxy_tool( ) -> MCPTool | None: """Resolve an /mcp/proxy tool_id against the caller's catalog, returning as soon as the server that owns it has listed instead of waiting for every allowed server.""" - from litellm.proxy._experimental.mcp_server.catalog import get_filtered_server_tools - from litellm.proxy._experimental.mcp_server.tool_search import mcp_proxy_tool_id + from litellm.proxy.mcp_server.catalog import get_filtered_server_tools + from litellm.proxy.mcp_server.tool_search import mcp_proxy_tool_id allowed_mcp_servers: Final = await _get_allowed_mcp_servers( user_api_key_auth=user_api_key_auth, @@ -1366,7 +1366,7 @@ async def _get_tools_from_mcp_servers( await _prefetch_oauth_creds_for_user(user_api_key_auth) if _has_oauth2_server else {} ) - from litellm.proxy._experimental.mcp_server.catalog import get_filtered_server_tools + from litellm.proxy.mcp_server.catalog import get_filtered_server_tools context: Final = OperationContext( _caller=user_api_key_auth, @@ -1413,7 +1413,7 @@ async def _get_tools_from_mcp_servers( }, ) else: - from litellm.proxy._experimental.mcp_server.catalog import aggregate_gateway_tools + from litellm.proxy.mcp_server.catalog import aggregate_gateway_tools aggregated = await aggregate_gateway_tools( context, @@ -1912,7 +1912,7 @@ async def _get_byok_credential( if cached is not None: return cached.credential - from litellm.proxy._experimental.mcp_server.db import get_user_credential + from litellm.proxy.mcp_server.db import get_user_credential from litellm.proxy.proxy_server import prisma_client if prisma_client is None: @@ -1970,7 +1970,7 @@ async def _check_byok_credential( ) return - from litellm.proxy._experimental.mcp_server.db import get_user_credential + from litellm.proxy.mcp_server.db import get_user_credential from litellm.proxy.proxy_server import prisma_client if prisma_client is None: @@ -2032,7 +2032,7 @@ def _challenge_missing_token_exchange_subject( return if global_mcp_server_manager.extract_subject_token(oauth2_headers, raw_headers, user_api_key_auth) is not None: return - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph raise_token_exchange_challenge, ) from litellm.proxy.middleware.per_request_root_path_middleware import ( # noqa: PLC0415 # lazy: middleware imports proxy utils @@ -3262,7 +3262,7 @@ async def _execute_handle_list_tools( ) from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( get_mcp_proxy_tool_definitions, get_virtual_tool_definitions, ) @@ -3280,8 +3280,8 @@ async def _execute_handle_list_tools( raise MCPError(code=INVALID_PARAMS, message="Invalid pagination cursor; start a fresh listing") return ListToolsResult(tools=[Tool.model_validate(d) for d in get_virtual_tool_definitions()]) - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog catalog: Final = MCPServerTargetCatalog( global_mcp_server_manager, @@ -3310,7 +3310,7 @@ async def _execute_handle_list_tools( async def _discover_tools_listing( context: OperationContext, host_progress_callback: ProgressCallback | None ) -> ListToolsResult: - from litellm.proxy._experimental.mcp_server.catalog import ToolListingFailedOutright + from litellm.proxy.mcp_server.catalog import ToolListingFailedOutright try: return await _execute_handle_list_tools( @@ -3487,8 +3487,8 @@ async def _execute_list_prompts( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS, INVALID_REQUEST - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog if context.mcp_proxy_mode: _reject_mcp_proxy_operation() @@ -3551,8 +3551,8 @@ async def _execute_list_resources( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS, INVALID_REQUEST - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog if context.mcp_proxy_mode: _reject_mcp_proxy_operation() @@ -3581,8 +3581,8 @@ async def _execute_list_resource_templates( from mcp.shared.exceptions import MCPError from mcp.types import INVALID_PARAMS, INVALID_REQUEST - from litellm.proxy._experimental.mcp_server.catalog import list_gateway_catalog - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.catalog import list_gateway_catalog + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog if context.mcp_proxy_mode: _reject_mcp_proxy_operation() @@ -3809,7 +3809,7 @@ class GatewayOperations: ) try: results: Final = await asyncio.gather(*tasks) - from litellm.proxy._experimental.mcp_server.subscriptions import subscription_capabilities + from litellm.proxy.mcp_server.subscriptions import subscription_capabilities async def discover_notifications() -> tuple[frozenset[str], ServerCapabilities]: remaining: Final = deadline - time.monotonic() diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/__init__.py b/litellm/proxy/mcp_server/outbound_credentials/__init__.py similarity index 85% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/__init__.py rename to litellm/proxy/mcp_server/outbound_credentials/__init__.py index 3260603c3ca..3d5fcf08d8e 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/__init__.py +++ b/litellm/proxy/mcp_server/outbound_credentials/__init__.py @@ -8,19 +8,19 @@ CredError]``) rather than raised, so every seam is total. Nothing here is wired request path yet. """ -from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( +from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, StaticHeaderAuth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import ( +from litellm.proxy.mcp_server.outbound_credentials.resolver import ( UpstreamCredentialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, Ambient, ApiKeyConfig, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py b/litellm/proxy/mcp_server/outbound_credentials/adapter.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py rename to litellm/proxy/mcp_server/outbound_credentials/adapter.py index 37404ceece8..1aac70cd847 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py +++ b/litellm/proxy/mcp_server/outbound_credentials/adapter.py @@ -20,11 +20,11 @@ from fastapi import HTTPException from pydantic import SecretStr from typing_extensions import assert_never -from litellm.experimental_mcp_client.client import MCPClient, strip_auth_scheme, to_basic_credentials -from litellm.proxy._experimental.mcp_server.exceptions import TOKEN_EXCHANGE_SUBJECT_ERROR, MCPServerURLCredentialsError -from litellm.proxy._experimental.mcp_server.oauth_utils import resolve_upstream_resource -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.mcp_client.client import MCPClient, strip_auth_scheme, to_basic_credentials +from litellm.proxy.mcp_server.exceptions import TOKEN_EXCHANGE_SUBJECT_ERROR, MCPServerURLCredentialsError +from litellm.proxy.mcp_server.oauth_utils import resolve_upstream_resource +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, ApiKeyConfig, AuthorizationCodeConfig, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/authz_code_refresher.py b/litellm/proxy/mcp_server/outbound_credentials/authz_code_refresher.py similarity index 94% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/authz_code_refresher.py rename to litellm/proxy/mcp_server/outbound_credentials/authz_code_refresher.py index a653ef5e5ff..286b761b969 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/authz_code_refresher.py +++ b/litellm/proxy/mcp_server/outbound_credentials/authz_code_refresher.py @@ -17,16 +17,16 @@ from typing import TYPE_CHECKING, Final, Protocol from fastapi import HTTPException from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointAuthConfigError, ) -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( +from litellm.proxy.mcp_server.oauth_identity_binding import ( BindingValidator, RefreshTokenPresented, enforce_oauth_identity_binding, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request, get_cimd_client_id -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request, get_cimd_client_id +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py b/litellm/proxy/mcp_server/outbound_credentials/bridge_credentials.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py rename to litellm/proxy/mcp_server/outbound_credentials/bridge_credentials.py index 1441d9662be..2326bcebdc3 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py +++ b/litellm/proxy/mcp_server/outbound_credentials/bridge_credentials.py @@ -16,7 +16,7 @@ from typing import Final, Literal, TypeAlias from pydantic import ConfigDict, SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( EnvelopeIdentity, EnvelopeKeys, EnvelopeMintError, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py b/litellm/proxy/mcp_server/outbound_credentials/client_credentials.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py rename to litellm/proxy/mcp_server/outbound_credentials/client_credentials.py index 1652f5d8bd4..d130de4f405 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py +++ b/litellm/proxy/mcp_server/outbound_credentials/client_credentials.py @@ -40,17 +40,17 @@ from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from typing_extensions import assert_never from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InMemoryTokenCacheBackend, OAuthToken, TokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, CredError, HeaderCarrier, @@ -105,7 +105,7 @@ async def post_client_credentials_grant( from litellm.llms.custom_httpx.http_handler import ( # noqa: PLC0415 # defer heavy handler import to call time get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # handler factory params are coarsely typed ) - from litellm.proxy._experimental.mcp_server.mcp_debug import ( # noqa: PLC0415 # diagnostics import credential enums through this package + from litellm.proxy.mcp_server.mcp_debug import ( # noqa: PLC0415 # diagnostics import credential enums through this package describe_upstream_http_failure, describe_upstream_response, safe_upstream_url, @@ -298,7 +298,7 @@ def _prepare_grant(config: ClientCredentialsConfig) -> Result[_PreparedGrant, Cr ) return Error(CredError.of_misconfigured(f"client_credentials config is missing: {missing}")) - from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( # noqa: PLC0415 # keep package v1-free at import time + from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( # noqa: PLC0415 # keep package v1-free at import time build_token_endpoint_client_auth, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/dual_cache_token_backend.py b/litellm/proxy/mcp_server/outbound_credentials/dual_cache_token_backend.py similarity index 92% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/dual_cache_token_backend.py rename to litellm/proxy/mcp_server/outbound_credentials/dual_cache_token_backend.py index 69ff7cda2b7..b360b787962 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/dual_cache_token_backend.py +++ b/litellm/proxy/mcp_server/outbound_credentials/dual_cache_token_backend.py @@ -14,13 +14,13 @@ from typing import Final, Protocol from litellm._internal_context import with_service_target from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) -from litellm.proxy._experimental.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET +from litellm.proxy.mcp_server.utils import MCP_OAUTH_TOKENS_TARGET class AsyncCache(Protocol): diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py b/litellm/proxy/mcp_server/outbound_credentials/envelope.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py rename to litellm/proxy/mcp_server/outbound_credentials/envelope.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/httpx_auth.py b/litellm/proxy/mcp_server/outbound_credentials/httpx_auth.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/httpx_auth.py rename to litellm/proxy/mcp_server/outbound_credentials/httpx_auth.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/login_assertion_exchange.py b/litellm/proxy/mcp_server/outbound_credentials/login_assertion_exchange.py similarity index 92% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/login_assertion_exchange.py rename to litellm/proxy/mcp_server/outbound_credentials/login_assertion_exchange.py index fcd8ae22ce3..6280a313f1a 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/login_assertion_exchange.py +++ b/litellm/proxy/mcp_server/outbound_credentials/login_assertion_exchange.py @@ -27,24 +27,24 @@ from datetime import datetime, timezone from typing import Final, Protocol from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy._types import LiteLLM_MCPServerTable +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( SSOClientConfig, sso_client_config, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( SSOIdentityAssertion, with_login_refresh_token, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ExchangedToken -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ExchangedToken +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientAuth, CredError, IdJagConfig, IdJagSubjectSource, ServerSpec, ) -from litellm.proxy._types import LiteLLM_MCPServerTable from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -236,14 +236,14 @@ async def exchange_login_assertion_if_configured( exchange when one of them presents a login refresh token. Nothing here can fail the login.""" if assertion is None: return None - from litellm.proxy._experimental.mcp_server.db import get_all_mcp_servers # noqa: PLC0415 # import cycle - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle + from litellm.proxy.mcp_server.db import get_all_mcp_servers # noqa: PLC0415 # import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # import cycle + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # import cycle to_server_spec, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( # noqa: PLC0415 # cycle + from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( # noqa: PLC0415 # cycle TokenEndpointClient, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 # runtime global diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/oauth_token_store.py b/litellm/proxy/mcp_server/outbound_credentials/oauth_token_store.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/oauth_token_store.py rename to litellm/proxy/mcp_server/outbound_credentials/oauth_token_store.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/per_user_oauth_store.py b/litellm/proxy/mcp_server/outbound_credentials/per_user_oauth_store.py similarity index 92% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/per_user_oauth_store.py rename to litellm/proxy/mcp_server/outbound_credentials/per_user_oauth_store.py index 2e9f3232c8d..f3748f99ba4 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/per_user_oauth_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/per_user_oauth_store.py @@ -16,15 +16,15 @@ from functools import partial from typing import TYPE_CHECKING, Final from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import credential_binding_matches -from litellm.proxy._experimental.mcp_server.outbound_credentials.authz_code_refresher import ( +from litellm.proxy.mcp_server.oauth_identity_binding import credential_binding_matches +from litellm.proxy.mcp_server.outbound_credentials.authz_code_refresher import ( AuthorizationCodeRefresher, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.dual_cache_token_backend import ( +from litellm.proxy.mcp_server.outbound_credentials.dual_cache_token_backend import ( AsyncCache, DualCacheTokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( CachedOAuthTokenStore, InvalidatableOAuthTokenStore, OAuthToken, @@ -33,13 +33,13 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_sto TokenCacheBackend, TokenStoreUnavailable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( runtime_refresh_coordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import ( V2PerUserTokenStore, ) @@ -54,7 +54,7 @@ StoreBuilder = Callable[[ServerLookup], tuple[InvalidatableOAuthTokenStore, bool async def _read_credential(user_id: str, server_id: str) -> Mapping[str, object] | None: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 get_user_oauth_credential, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 @@ -74,7 +74,7 @@ async def _persist_credential( identity_binding_proof: str | None = None, cimd_client_id: str | None = None, ) -> None: - from litellm.proxy._experimental.mcp_server.db import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.db import ( # noqa: PLC0415 store_user_oauth_credential, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/presented_token_store.py b/litellm/proxy/mcp_server/outbound_credentials/presented_token_store.py similarity index 90% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/presented_token_store.py rename to litellm/proxy/mcp_server/outbound_credentials/presented_token_store.py index c88d31dd6bc..a7078676528 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/presented_token_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/presented_token_store.py @@ -11,7 +11,7 @@ from __future__ import annotations from dataclasses import dataclass -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_distributed_lock.py b/litellm/proxy/mcp_server/outbound_credentials/redis_distributed_lock.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_distributed_lock.py rename to litellm/proxy/mcp_server/outbound_credentials/redis_distributed_lock.py index c7eefed75ed..7262cb6f100 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_distributed_lock.py +++ b/litellm/proxy/mcp_server/outbound_credentials/redis_distributed_lock.py @@ -21,7 +21,7 @@ from dataclasses import KW_ONLY, dataclass from typing import Final, Protocol from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( LockAcquisition, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_refresh_coordinator.py b/litellm/proxy/mcp_server/outbound_credentials/redis_refresh_coordinator.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_refresh_coordinator.py rename to litellm/proxy/mcp_server/outbound_credentials/redis_refresh_coordinator.py index d2c660eb2af..98446f2b66e 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/redis_refresh_coordinator.py +++ b/litellm/proxy/mcp_server/outbound_credentials/redis_refresh_coordinator.py @@ -28,7 +28,7 @@ from dataclasses import KW_ONLY, dataclass from enum import Enum from typing import Final, Protocol -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py b/litellm/proxy/mcp_server/outbound_credentials/resolver.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py rename to litellm/proxy/mcp_server/outbound_credentials/resolver.py index ea0cdee5c1c..dff578ef274 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py +++ b/litellm/proxy/mcp_server/outbound_credentials/resolver.py @@ -30,28 +30,28 @@ import httpx2 from typing_extensions import assert_never from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ClientCredentialsTokenSource, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( +from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, StaticHeaderAuth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, OAuthTokenStore, TokenStoreUnavailable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( default_sso_assertion_store, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( AssertionStoreUnavailable, SSOAssertionStore, SSOIdentityAssertion, @@ -59,15 +59,15 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_s exchanged_refresh_token_issued_for, login_refresh_token_expired, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( ExchangedToken, ExchangedTokenCache, TokenEndpointClient, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( TokenExchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ApiKeyConfig, AuthorizationCodeConfig, AuthResolution, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/result.py b/litellm/proxy/mcp_server/outbound_credentials/result.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/result.py rename to litellm/proxy/mcp_server/outbound_credentials/result.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/runtime_refresh_coordinator.py b/litellm/proxy/mcp_server/outbound_credentials/runtime_refresh_coordinator.py similarity index 85% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/runtime_refresh_coordinator.py rename to litellm/proxy/mcp_server/outbound_credentials/runtime_refresh_coordinator.py index e799838b5b7..9376d1bda50 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/runtime_refresh_coordinator.py +++ b/litellm/proxy/mcp_server/outbound_credentials/runtime_refresh_coordinator.py @@ -14,13 +14,13 @@ from __future__ import annotations from typing import Final -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( RefreshCoordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_distributed_lock import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_distributed_lock import ( RedisDistributedLock, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( RedisRefreshCoordinator, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py b/litellm/proxy/mcp_server/outbound_credentials/session_credentials.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py rename to litellm/proxy/mcp_server/outbound_credentials/session_credentials.py index b216f463824..6e3d09f4dd2 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py +++ b/litellm/proxy/mcp_server/outbound_credentials/session_credentials.py @@ -22,7 +22,7 @@ from typing import Final, Literal, TypeAlias from pydantic import ConfigDict, Field, SecretStr, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( AsymmetricSessionKeys, OpenedSessionToken, SessionExpired, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py b/litellm/proxy/mcp_server/outbound_credentials/session_token.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py rename to litellm/proxy/mcp_server/outbound_credentials/session_token.py diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_refresher.py b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_refresher.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_refresher.py rename to litellm/proxy/mcp_server/outbound_credentials/sso_assertion_refresher.py index ae5e9d0417e..84a20bf4f5c 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_refresher.py +++ b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_refresher.py @@ -58,22 +58,22 @@ from litellm.exceptions import Timeout from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # litellm http handler is untyped ) -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( build_token_endpoint_client_auth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InProcessRefreshCoordinator, RefreshCoordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.runtime_refresh_coordinator import ( runtime_refresh_coordinator, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( AssertionStoreUnavailable, DbSSOAssertionStore, SSOAssertionStore, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py rename to litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py index 19b3bc294d5..fb4d838aff9 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py @@ -294,7 +294,7 @@ async def ema_assertion_retention_enabled() -> bool: snapshot of the DB state that can be stale both ways (a server added on another pod would silently drop the write, one removed on another pod would keep retaining bearer material), and a gate guarding a shared-DB write must judge against that storage's authority.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: PLC0415 # avoids import cycle global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client # noqa: PLC0415 # runtime global diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_cache_codec.py b/litellm/proxy/mcp_server/outbound_credentials/token_cache_codec.py similarity index 95% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_cache_codec.py rename to litellm/proxy/mcp_server/outbound_credentials/token_cache_codec.py index 56dc3f19cdd..4576e925939 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_cache_codec.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_cache_codec.py @@ -14,7 +14,7 @@ from typing import Final from pydantic import TypeAdapter, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py b/litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py rename to litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py index 1ee1b7ecf2f..6fd63450b26 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py @@ -39,12 +39,12 @@ from litellm.exceptions import Timeout from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # litellm http handler is untyped ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientAuth, ClientSecretAuth, CredError, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchange_provider.py b/litellm/proxy/mcp_server/outbound_credentials/token_exchange_provider.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchange_provider.py rename to litellm/proxy/mcp_server/outbound_credentials/token_exchange_provider.py index d84a65fee02..0beab749076 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchange_provider.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_exchange_provider.py @@ -21,10 +21,10 @@ from litellm.constants import ( MCP_OAUTH2_TOKEN_EXPIRY_BUFFER_SECONDS, MCP_TOKEN_EXCHANGE_CACHE_MAX_SIZE, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InMemoryTokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, SubjectTokenRejected, TokenExchangeClientError, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchanger.py b/litellm/proxy/mcp_server/outbound_credentials/token_exchanger.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchanger.py rename to litellm/proxy/mcp_server/outbound_credentials/token_exchanger.py index 2e72d98c77d..83457d5cef1 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_exchanger.py +++ b/litellm/proxy/mcp_server/outbound_credentials/token_exchanger.py @@ -27,22 +27,22 @@ from typing import Final, Literal, Protocol from typing_extensions import assert_never from litellm._logging import verbose_logger -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( build_token_endpoint_client_auth, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InMemoryTokenCacheBackend, InProcessRefreshCoordinator, OAuthToken, RefreshCoordinator, TokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( CredError, ServerSpec, TokenExchangeConfig, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py b/litellm/proxy/mcp_server/outbound_credentials/types.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py rename to litellm/proxy/mcp_server/outbound_credentials/types.py index 45c53af9349..5a30fafd7d9 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py +++ b/litellm/proxy/mcp_server/outbound_credentials/types.py @@ -35,7 +35,7 @@ from expression import case, tag, tagged_union from pydantic import ConfigDict, Field, SecretStr, field_validator from typing_extensions import assert_never -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/v2_token_store.py b/litellm/proxy/mcp_server/outbound_credentials/v2_token_store.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/outbound_credentials/v2_token_store.py rename to litellm/proxy/mcp_server/outbound_credentials/v2_token_store.py index 56ab8e6bbdc..a1a3b88259e 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/v2_token_store.py +++ b/litellm/proxy/mcp_server/outbound_credentials/v2_token_store.py @@ -14,7 +14,7 @@ from collections.abc import Awaitable, Callable, Mapping from datetime import datetime, timezone from typing import Final -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) diff --git a/litellm/proxy/_experimental/mcp_server/proxy_api_credentials.py b/litellm/proxy/mcp_server/proxy_api_credentials.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/proxy_api_credentials.py rename to litellm/proxy/mcp_server/proxy_api_credentials.py index fd637a2f187..53fe4ce457d 100644 --- a/litellm/proxy/_experimental/mcp_server/proxy_api_credentials.py +++ b/litellm/proxy/mcp_server/proxy_api_credentials.py @@ -8,13 +8,6 @@ from collections.abc import Sequence from typing import Final from litellm.constants import CLI_JWT_EXPIRATION_HOURS -from litellm.proxy._experimental.mcp_server.bridge_token_flow import load_active_user_by_id -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( - ConsentTeam, - MintedProxyCredential, - ProxyCredentialMintFailure, - ReloadUserFailure, -) from litellm.proxy._types import LiteLLM_UserTable from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken, effective_user_role from litellm.proxy.management_endpoints.ui_sso import ( @@ -22,6 +15,13 @@ from litellm.proxy.management_endpoints.ui_sso import ( fetch_cli_sso_team_details, selected_cli_sso_team_detail, ) +from litellm.proxy.mcp_server.bridge_token_flow import load_active_user_by_id +from litellm.proxy.mcp_server.gateway_dcr_flow import ( + ConsentTeam, + MintedProxyCredential, + ProxyCredentialMintFailure, + ReloadUserFailure, +) async def lookup_consent_teams(user_id: str) -> tuple[ConsentTeam, ...] | ReloadUserFailure: diff --git a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py b/litellm/proxy/mcp_server/rest_endpoints.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/rest_endpoints.py rename to litellm/proxy/mcp_server/rest_endpoints.py index 62387b7cc28..2737b567985 100644 --- a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py +++ b/litellm/proxy/mcp_server/rest_endpoints.py @@ -24,35 +24,6 @@ from litellm.exceptions import ( GuardrailRaisedException, ModifyResponseException, ) -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.exceptions import ( - MCPServerListError, - MCPServerURLCredentialsError, - MCPUpstreamAuthError, -) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( - ServerListOk, - ServerOutcome, - classify_list_exception, - list_fault_http_status, - outcome_wire_value, -) -from litellm.proxy._experimental.mcp_server.faults.traversal import iter_exception_tree -from litellm.proxy._experimental.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports - _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export - redact_mcp_resource_url, -) -from litellm.proxy._experimental.mcp_server.result_conversion import WireCompat, complete_call_tool_result -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - acting_user_auth, - build_effective_auth_contexts, -) -from litellm.proxy._experimental.mcp_server.utils import ( - MCPMissingUserEnvVarsError, - add_server_prefix_to_name, - get_server_prefix, - merge_mcp_headers, -) from litellm.proxy._types import ( LitellmUserRoles, UserAPIKeyAuth, @@ -61,13 +32,42 @@ from litellm.proxy._types import ( from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.exceptions import ( + MCPServerListError, + MCPServerURLCredentialsError, + MCPUpstreamAuthError, +) +from litellm.proxy.mcp_server.faults.list_outcomes import ( + ServerListOk, + ServerOutcome, + classify_list_exception, + list_fault_http_status, + outcome_wire_value, +) +from litellm.proxy.mcp_server.faults.traversal import iter_exception_tree +from litellm.proxy.mcp_server.oauth_utils import ( # noqa: F401 # legacy module exports + _redact_mcp_resource_url, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export + redact_mcp_resource_url, +) +from litellm.proxy.mcp_server.result_conversion import WireCompat, complete_call_tool_result +from litellm.proxy.mcp_server.ui_session_utils import ( + acting_user_auth, + build_effective_auth_contexts, +) +from litellm.proxy.mcp_server.utils import ( + MCPMissingUserEnvVarsError, + add_server_prefix_to_name, + get_server_prefix, + merge_mcp_headers, +) from litellm.responses.mcp.request_context import MCPRequestContext if TYPE_CHECKING: from mcp.types import CallToolResult, InputRequiredResult from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj - from litellm.proxy._experimental.mcp_server.db import OAuthCredentialPayload + from litellm.proxy.mcp_server.db import OAuthCredentialPayload from litellm.proxy.utils import ProxyLogging from litellm.proxy.common_utils.http_parsing_utils import ( # noqa: F401 # legacy module exports _safe_get_request_headers, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -82,7 +82,7 @@ class _MCPModelMetadata(TypedDict): def _stamp_mcp_tool_metadata(logging_obj: "LiteLLMLoggingObj | None", server_id: str, tool_name: str) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager if logging_obj is None: return @@ -227,22 +227,22 @@ if MCP_AVAILABLE: from mcp.shared.exceptions import MCPError from mcp.types import Tool as MCPTool - from litellm.experimental_mcp_client.client import MCPClient, as_mcp_read_timeout from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.llms.litellm_proxy.skills.skill_search import ( DEFAULT_SKILL_SEARCH_TOP_K, ) - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports + from litellm.mcp_client.client import MCPClient, as_mcp_read_timeout + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_server_manager import ( # noqa: F401 # legacy module exports _UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES, ListedToolsCaller, global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( ListMCPToolsRestAPIResponseObject, MCPInfo, MCPServer, @@ -254,12 +254,12 @@ if MCP_AVAILABLE: fire_mcp_tool_call_failure_logging, resolve_native_tool_name_for_server, ) - from litellm.proxy._experimental.mcp_server.server import ( # noqa: F401 # legacy module exports + from litellm.proxy.mcp_server.server import ( # noqa: F401 # legacy module exports _apply_toolset_scope, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export apply_toolset_scope, reject_disallowed_mcp_client, ) - from litellm.proxy._experimental.mcp_server.tool_catalog_guard import ( + from litellm.proxy.mcp_server.tool_catalog_guard import ( apply_description_overrides, scan_tool_descriptions, ) @@ -337,7 +337,8 @@ if MCP_AVAILABLE: ``mcp_tool_search_enabled``). Kept out of ``call_tool_rest_api`` so that endpoint stays a single dispatch. An upstream 401 raised by the virtual ``mcp_tool_call`` propagates unhandled to the caller's ``except MCPUpstreamAuthError`` relay, the same as the direct call path.""" - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing + from litellm.proxy.mcp_server.tool_search import ( AGENT_SEARCH_TOOL_NAME, DEFAULT_AGENT_SEARCH_TOP_K, MCP_TOOL_SEARCH_TOOL_NAME, @@ -348,7 +349,6 @@ if MCP_AVAILABLE: handle_mcp_tool_search, handle_skill_search, ) - from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing from litellm.proxy.proxy_server import general_settings, proxy_config, proxy_logging_obj if not getattr(getattr(user_api_key_dict, "object_permission", None), "mcp_tool_search_enabled", False): @@ -443,7 +443,7 @@ if MCP_AVAILABLE: mcp_auth_header: str | None, ) -> dict[str, str] | str | None: """Helper function to get server-specific auth header with case-insensitive matching.""" - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, ) @@ -466,7 +466,7 @@ if MCP_AVAILABLE: round-trip whose result is discarded. Mirrors the same guard on the protocol listing path and in ``_resolve_oauth2_headers_for_tool_call``. """ - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( to_server_spec, ) @@ -511,7 +511,7 @@ if MCP_AVAILABLE: if not user_id or not server_id: return None try: - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( get_user_oauth_credential, resolve_valid_user_oauth_token, ) @@ -555,7 +555,7 @@ if MCP_AVAILABLE: if not user_id: return {} try: - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( list_user_oauth_credentials, ) from litellm.proxy.utils import get_prisma_client_or_throw @@ -603,7 +603,7 @@ if MCP_AVAILABLE: Returns: Tuple of (mcp_auth_header, mcp_server_auth_headers, raw_headers, oauth2_headers) """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( OPTIONAL_STRING_ADAPTER, MCPRequestHandler, ) @@ -1062,7 +1062,7 @@ if MCP_AVAILABLE: False, ) ): - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( get_virtual_tool_definitions, ) @@ -1344,7 +1344,7 @@ if MCP_AVAILABLE: tool_name: Final[str | None] = data.get("name") tool_arguments: Final[dict[str, object]] = data.get("arguments") or {} - from litellm.proxy._experimental.mcp_server.tool_search import VIRTUAL_TOOL_NAMES + from litellm.proxy.mcp_server.tool_search import VIRTUAL_TOOL_NAMES if tool_name in VIRTUAL_TOOL_NAMES: return await _handle_virtual_mcp_tool(request, data, tool_name, user_api_key_dict) @@ -1594,7 +1594,7 @@ if MCP_AVAILABLE: temporary client the same credentials, or a server that the saved connection reaches fine fails one of them. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -1725,16 +1725,16 @@ if MCP_AVAILABLE: # becomes the upstream credential, so it is not also forwarded as a caller header. Gated # to the v2-mapped oauth2 case (to_server_spec non-None); M2M (client_credentials), # delegate/passthrough, and token-exchange are unaffected. - from litellm.proxy._experimental.mcp_server.outbound_credentials import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials import ( # noqa: PLC0415 UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 to_server_spec, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( # noqa: PLC0415 OAuthToken, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.presented_token_store import ( # noqa: PLC0415 + from litellm.proxy.mcp_server.outbound_credentials.presented_token_store import ( # noqa: PLC0415 PresentedOAuthTokenStore, ) @@ -1795,7 +1795,7 @@ if MCP_AVAILABLE: async def _preview_openapi_tools(spec_path: str) -> dict: """Generate tool previews from an OpenAPI spec without creating a server.""" - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( OPENAPI_TOOL_NAME_MAX_LEN, build_input_schema, load_openapi_spec_async, diff --git a/litellm/proxy/_experimental/mcp_server/result_conversion.py b/litellm/proxy/mcp_server/result_conversion.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/result_conversion.py rename to litellm/proxy/mcp_server/result_conversion.py index fdb9a01fea6..8955381add1 100644 --- a/litellm/proxy/_experimental/mcp_server/result_conversion.py +++ b/litellm/proxy/mcp_server/result_conversion.py @@ -18,7 +18,7 @@ from typing import Final, Protocol, TypeAlias, TypeVar from mcp.types import CacheableResult, CallToolResult, ContentBlock, InputRequiredResult, TextContent, Tool from typing_extensions import ReadOnly, TypedDict, assert_never -from litellm.proxy._experimental.mcp_server.tool_outcome import ( +from litellm.proxy.mcp_server.tool_outcome import ( JsonResult, TextResult, WireCompat, diff --git a/litellm/proxy/_experimental/mcp_server/sampling_handler.py b/litellm/proxy/mcp_server/sampling_handler.py similarity index 99% rename from litellm/proxy/_experimental/mcp_server/sampling_handler.py rename to litellm/proxy/mcp_server/sampling_handler.py index d049ada4dfd..ec14f81aef2 100644 --- a/litellm/proxy/_experimental/mcp_server/sampling_handler.py +++ b/litellm/proxy/mcp_server/sampling_handler.py @@ -1047,7 +1047,7 @@ def _build_sampling_request( ) -> "Request": """The synthetic FastAPI Request for sampling sub-calls, carrying the original MCP connection's headers and client IP.""" - from litellm.proxy._experimental.mcp_server.utils import build_synthetic_mcp_request + from litellm.proxy.mcp_server.utils import build_synthetic_mcp_request return build_synthetic_mcp_request( path="/mcp/sampling/createMessage", diff --git a/litellm/proxy/_experimental/mcp_server/scope_challenge.py b/litellm/proxy/mcp_server/scope_challenge.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/scope_challenge.py rename to litellm/proxy/mcp_server/scope_challenge.py index 121234e305d..128b27b0f91 100644 --- a/litellm/proxy/_experimental/mcp_server/scope_challenge.py +++ b/litellm/proxy/mcp_server/scope_challenge.py @@ -10,7 +10,7 @@ from starlette.requests import Request from starlette.responses import JSONResponse from starlette.types import Message, Send -from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError +from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError if TYPE_CHECKING: from mcp.server.context import CallNext, HandlerResult, ServerRequestContext diff --git a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py b/litellm/proxy/mcp_server/semantic_tool_filter.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py rename to litellm/proxy/mcp_server/semantic_tool_filter.py index a7748b9ca88..4fe723d6b24 100644 --- a/litellm/proxy/_experimental/mcp_server/semantic_tool_filter.py +++ b/litellm/proxy/mcp_server/semantic_tool_filter.py @@ -11,9 +11,9 @@ from typing import TYPE_CHECKING, Final, TypeVar from litellm._logging import verbose_logger from litellm.exceptions import ContextWindowExceededError from litellm.litellm_core_utils.exception_mapping_utils import ExceptionCheckers -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.faults import iter_exception_tree -from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.faults import iter_exception_tree +from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR if TYPE_CHECKING: from semantic_router.routers import SemanticRouter @@ -84,7 +84,7 @@ class SemanticMCPToolFilter: @catalog_operation(global_manager) async def build_router_from_mcp_registry(self) -> None: """Build semantic router from all MCP tools in the registry (no auth checks).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/mcp_server/server.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/server.py rename to litellm/proxy/mcp_server/server.py index 7207c4150ad..32f790a8e81 100644 --- a/litellm/proxy/_experimental/mcp_server/server.py +++ b/litellm/proxy/mcp_server/server.py @@ -35,23 +35,29 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports +from litellm.proxy._types import ( + ProxyException, + SpecialMCPServerNames, + UserAPIKeyAuth, +) +from litellm.proxy.auth.ip_address_utils import IPAddressUtils +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( # noqa: F401 # legacy module exports MCPRequestHandler, _is_mcp_admitted_user_subject, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export is_mcp_admitted_user_subject, ) -from litellm.proxy._experimental.mcp_server.client_allowlist import ( +from litellm.proxy.mcp_server.client_allowlist import ( MCPClientAllowlist, check_mcp_client_allowed, load_mcp_client_allowlist, ) -from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( +from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.mcp_context import ( # noqa: F401 # legacy module exports +from litellm.proxy.mcp_server.mcp_context import ( # noqa: F401 # legacy module exports _mcp_active_toolset_id, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _mcp_gateway_initialize_instructions, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export _mcp_gateway_server_name, # pyright: ignore[reportPrivateUsage,reportUnusedImport] # backwards-compatible package export @@ -62,43 +68,37 @@ from litellm.proxy._experimental.mcp_server.mcp_context import ( # noqa: F401 mcp_gateway_initialize_instructions, mcp_gateway_server_name, ) -from litellm.proxy._experimental.mcp_server.mcp_debug import ( +from litellm.proxy.mcp_server.mcp_debug import ( MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics, MCPDebug, ) -from litellm.proxy._experimental.mcp_server.oauth_utils import ( +from litellm.proxy.mcp_server.oauth_utils import ( get_passthrough_www_authenticate, get_route_relative_request_path, redact_mcp_resource_url, well_known_root_suffix, ) -from litellm.proxy._experimental.mcp_server.scope_challenge import ( +from litellm.proxy.mcp_server.scope_challenge import ( SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response, is_tool_call_request, ) -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( +from litellm.proxy.mcp_server.ui_session_utils import ( ActingUser, GrantedToolsetIds, acting_user_auth, granted_toolset_ids, is_ui_session_credential, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( LITELLM_MCP_SERVER_DESCRIPTION, LITELLM_MCP_SERVER_NAME, LITELLM_MCP_SERVER_VERSION, asgi_scope_fields, merge_mcp_headers, ) -from litellm.proxy._types import ( - ProxyException, - SpecialMCPServerNames, - UserAPIKeyAuth, -) -from litellm.proxy.auth.ip_address_utils import IPAddressUtils from litellm.types.mcp import ( MCPAuth, MCPGatewaySession, @@ -162,7 +162,7 @@ def _raw_header_pairs(source: _RawHeaderPairsSource) -> Sequence[tuple[bytes | s def unsupported_protocol_version(scope: Scope) -> str | None: """Admit configured HTTP revisions while keeping SSE on the legacy protocol.""" - from litellm.proxy._experimental.mcp_server.capabilities import configured_versions + from litellm.proxy.mcp_server.capabilities import configured_versions headers: Final[Iterable[tuple[bytes, bytes]]] = scope.get("headers") or () values: Final = tuple( @@ -547,14 +547,14 @@ if MCP_AVAILABLE: ReadResourceRequest, ) - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.interactions import InteractionOperation - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.interactions import InteractionOperation + from litellm.proxy.mcp_server.operations import ( _invalidate_byok_cred_cache, _mcp_session_id_from_headers, ) - from litellm.proxy._experimental.mcp_server.result_conversion import wire_compat_for + from litellm.proxy.mcp_server.result_conversion import wire_compat_for try: from mcp.server.streamable_http_manager import StreamableHTTPSessionManager @@ -576,16 +576,16 @@ if MCP_AVAILABLE: ReadResourceRequestParams, ) - from litellm.proxy._experimental.mcp_server.auth.litellm_auth_handler import ( + from litellm.proxy.mcp_server.auth.litellm_auth_handler import ( MCPAuthenticatedUser, ) - from litellm.proxy._experimental.mcp_server.capabilities import ( + from litellm.proxy.mcp_server.capabilities import ( GatewayVersionPolicy, configured_versions, disabled_capabilities, disabled_operations, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, global_mcp_server_manager, ) @@ -595,10 +595,10 @@ if MCP_AVAILABLE: # Defined here because we don't want to add `mcp` as a # required dependency for `litellm` pip package ###################################################### - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( ListMCPToolsRestAPIResponseObject, ) - from litellm.proxy._experimental.mcp_server.sse_transport import SseServerTransport + from litellm.proxy.mcp_server.sse_transport import SseServerTransport def _gateway_create_initialization_options( self, @@ -946,7 +946,7 @@ if MCP_AVAILABLE: raise MCPError(code=METHOD_NOT_FOUND, message="Operation unavailable on /mcp/proxy") - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _build_virtual_call_logging_obj, _dispatch_virtual_mcp_tool, ) @@ -1036,7 +1036,7 @@ if MCP_AVAILABLE: UnsubscribeRequestParams, ) - from litellm.proxy._experimental.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionAuthorization + from litellm.proxy.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionAuthorization subscriptions: Final = GatewaySubscriptions() legacy_subscription_request: Final[contextvars.ContextVar[StarletteRequest | None]] = contextvars.ContextVar( @@ -1126,7 +1126,7 @@ if MCP_AVAILABLE: ############ Helper Functions ########################## ######################################################## - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _client_has_passthrough_authorization, _client_has_per_server_auth_header, _get_allowed_mcp_servers, @@ -1189,7 +1189,7 @@ if MCP_AVAILABLE: mcp_gateway_initialize_instructions.reset(instructions_token) mcp_gateway_server_name.reset(server_name_token) - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _MCP_CREDENTIAL_REQUEST_FIELDS, _aggregate_server_key, _check_byok_credential, @@ -1836,7 +1836,7 @@ if MCP_AVAILABLE: await operations.global_mcp_server_manager.resolve_toolset_tool_permissions(toolset_ids=[toolset_id]) ) - from litellm.proxy._experimental.mcp_server.catalog import catalog_operation + from litellm.proxy.mcp_server.catalog import catalog_operation @catalog_operation(lambda: operations.global_mcp_server_manager) async def _raise_preemptive_401_for_unauthenticated_servers( @@ -1971,7 +1971,7 @@ if MCP_AVAILABLE: ) is None ): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( # noqa: PLC0415 # lazy: adapter pulls MCP subgraph raise_token_exchange_challenge, ) from litellm.proxy.middleware.per_request_root_path_middleware import ( # noqa: PLC0415 # lazy: middleware imports proxy utils diff --git a/litellm/proxy/_experimental/mcp_server/server_resolution.py b/litellm/proxy/mcp_server/server_resolution.py similarity index 96% rename from litellm/proxy/_experimental/mcp_server/server_resolution.py rename to litellm/proxy/mcp_server/server_resolution.py index 31bcd897e72..96c485c0d3c 100644 --- a/litellm/proxy/_experimental/mcp_server/server_resolution.py +++ b/litellm/proxy/mcp_server/server_resolution.py @@ -6,12 +6,12 @@ from typing import TYPE_CHECKING, Final, Literal, Protocol from fastapi import HTTPException, status -from litellm.proxy._experimental.mcp_server.ui_session_utils import can_access_mcp_server from litellm.proxy._types import LiteLLM_MCPServerTable, UserAPIKeyAuth +from litellm.proxy.mcp_server.ui_session_utils import can_access_mcp_server from litellm.types.mcp_server.mcp_server_manager import MCPServer if TYPE_CHECKING: - from litellm.proxy._experimental.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext + from litellm.proxy.mcp_server.contracts import CatalogListRequest, CatalogListResult, OperationContext class MCPServerRegistry(Protocol): diff --git a/litellm/proxy/_experimental/mcp_server/sse_transport.py b/litellm/proxy/mcp_server/sse_transport.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/sse_transport.py rename to litellm/proxy/mcp_server/sse_transport.py diff --git a/litellm/proxy/_experimental/mcp_server/state_tokens.py b/litellm/proxy/mcp_server/state_tokens.py similarity index 97% rename from litellm/proxy/_experimental/mcp_server/state_tokens.py rename to litellm/proxy/mcp_server/state_tokens.py index 88f98bef6b8..b65a8ca4e88 100644 --- a/litellm/proxy/_experimental/mcp_server/state_tokens.py +++ b/litellm/proxy/mcp_server/state_tokens.py @@ -12,7 +12,7 @@ from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.kdf.hkdf import HKDF from pydantic import BaseModel, ConfigDict, JsonValue, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result _PREFIX: Final = "mcp_state_v1." _MAX_TOKEN_LENGTH: Final = 65536 diff --git a/litellm/proxy/_experimental/mcp_server/stdio_gate.py b/litellm/proxy/mcp_server/stdio_gate.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/stdio_gate.py rename to litellm/proxy/mcp_server/stdio_gate.py diff --git a/litellm/proxy/_experimental/mcp_server/subscriptions.py b/litellm/proxy/mcp_server/subscriptions.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/subscriptions.py rename to litellm/proxy/mcp_server/subscriptions.py index e9de5692d83..f133752ee32 100644 --- a/litellm/proxy/_experimental/mcp_server/subscriptions.py +++ b/litellm/proxy/mcp_server/subscriptions.py @@ -48,17 +48,17 @@ from mcp.types import ( ) from litellm.constants import MCP_TOOL_LISTING_MAX_PAGES, MCP_TOOL_LISTING_TIMEOUT -from litellm.experimental_mcp_client.client import MCPClient -from litellm.proxy._experimental.mcp_server import operations -from litellm.proxy._experimental.mcp_server.catalog import ( - ToolListingFailedOutright, -) -from litellm.proxy._experimental.mcp_server.catalog import ( - _configuration_identity as configuration_identity, # pyright: ignore[reportPrivateUsage] # reuse catalog-owned configuration identity without treating discovered metadata as configuration -) -from litellm.proxy._experimental.mcp_server.contracts import OperationContext +from litellm.mcp_client.client import MCPClient from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server import operations +from litellm.proxy.mcp_server.catalog import ( + ToolListingFailedOutright, +) +from litellm.proxy.mcp_server.catalog import ( + _configuration_identity as configuration_identity, # pyright: ignore[reportPrivateUsage] # reuse catalog-owned configuration identity without treating discovered metadata as configuration +) +from litellm.proxy.mcp_server.contracts import OperationContext from litellm.types.mcp import MCP_LEGACY_VERSIONS from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/litellm/proxy/_experimental/mcp_server/tool_catalog_guard.py b/litellm/proxy/mcp_server/tool_catalog_guard.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/tool_catalog_guard.py rename to litellm/proxy/mcp_server/tool_catalog_guard.py index b3c70a33d0e..4bf7b584977 100644 --- a/litellm/proxy/_experimental/mcp_server/tool_catalog_guard.py +++ b/litellm/proxy/mcp_server/tool_catalog_guard.py @@ -12,7 +12,7 @@ from mcp.types import Tool as MCPTool from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict -from litellm.proxy._experimental.mcp_server.utils import logging_safe_mcp_headers, strip_known_server_prefix +from litellm.proxy.mcp_server.utils import logging_safe_mcp_headers, strip_known_server_prefix from litellm.types.mcp import MCPPreCallRequestObject from litellm.types.mcp_server.mcp_server_manager import MCPServer, PinnedMCPTool from litellm.types.utils import CallTypes diff --git a/litellm/proxy/_experimental/mcp_server/tool_outcome.py b/litellm/proxy/mcp_server/tool_outcome.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/tool_outcome.py rename to litellm/proxy/mcp_server/tool_outcome.py diff --git a/litellm/proxy/_experimental/mcp_server/tool_registry.py b/litellm/proxy/mcp_server/tool_registry.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/tool_registry.py rename to litellm/proxy/mcp_server/tool_registry.py diff --git a/litellm/proxy/_experimental/mcp_server/tool_search.py b/litellm/proxy/mcp_server/tool_search.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/tool_search.py rename to litellm/proxy/mcp_server/tool_search.py index 371a1ff6fc9..96bcf8fbacf 100644 --- a/litellm/proxy/_experimental/mcp_server/tool_search.py +++ b/litellm/proxy/mcp_server/tool_search.py @@ -20,7 +20,6 @@ from typing_extensions import ReadOnly, Required, assert_never import litellm from litellm.llms.litellm_proxy.skills.skill_search import DEFAULT_SKILL_SEARCH_TOP_K -from litellm.proxy._experimental.mcp_server.result_conversion import WireCompat, complete_call_tool_result from litellm.proxy.agent_endpoints.agent_search import DEFAULT_AGENT_SEARCH_TOP_K from litellm.proxy.common_utils.semantic_text_index import ( Embedder, @@ -28,6 +27,7 @@ from litellm.proxy.common_utils.semantic_text_index import ( SemanticTextIndex, router_embedder, ) +from litellm.proxy.mcp_server.result_conversion import WireCompat, complete_call_tool_result from litellm.types.mcp import MCPToolSearchSettings if TYPE_CHECKING: @@ -549,7 +549,7 @@ async def handle_mcp_tool_search( oauth2_headers: dict[str, str] | None = None, raw_headers: dict[str, str] | None = None, ) -> CallToolResult: - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _list_mcp_tools, ) from litellm.proxy.proxy_server import llm_router, proxy_logging_obj @@ -606,7 +606,7 @@ async def handle_mcp_proxy_tool( from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _list_mcp_tools, find_mcp_proxy_tool, ) @@ -713,7 +713,7 @@ async def handle_mcp_tool_call( incoming_bearer_token: SecretStr | None | EllipsisType = ..., guardrail_auth: UserAPIKeyAuth | None = None, ) -> CallToolResult: - from litellm.proxy._experimental.mcp_server.operations import ( + from litellm.proxy.mcp_server.operations import ( _get_allowed_mcp_servers, execute_mcp_tool, raise_denied_scoped_mcp_access, diff --git a/litellm/proxy/_experimental/mcp_server/toolset_db.py b/litellm/proxy/mcp_server/toolset_db.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/toolset_db.py rename to litellm/proxy/mcp_server/toolset_db.py index 35906c793b4..ae40e8af0d9 100644 --- a/litellm/proxy/_experimental/mcp_server/toolset_db.py +++ b/litellm/proxy/mcp_server/toolset_db.py @@ -117,7 +117,7 @@ async def list_mcp_toolsets( except Exception as e: if use_writer: raise - verbose_proxy_logger.warning("litellm.proxy._experimental.mcp_server.toolset_db::list_mcp_toolsets - %s", e) + verbose_proxy_logger.warning("litellm.proxy.mcp_server.toolset_db::list_mcp_toolsets - %s", e) return [] diff --git a/litellm/proxy/_experimental/mcp_server/ui_session_utils.py b/litellm/proxy/mcp_server/ui_session_utils.py similarity index 98% rename from litellm/proxy/_experimental/mcp_server/ui_session_utils.py rename to litellm/proxy/mcp_server/ui_session_utils.py index 9f60f0afbb6..308a41b8938 100644 --- a/litellm/proxy/_experimental/mcp_server/ui_session_utils.py +++ b/litellm/proxy/mcp_server/ui_session_utils.py @@ -97,7 +97,7 @@ async def admitted_user_context(user_api_key_auth: UserAPIKeyAuth) -> UserAPIKey user_id: Final = user_api_key_auth.user_id if not is_ui_session_credential(user_api_key_auth) or user_id is None: return None - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -192,7 +192,7 @@ async def toolset_grant_contexts( if not is_keyless_mcp_subject(user_api_key_auth): return (user_api_key_auth,) - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -269,7 +269,7 @@ async def granted_toolset_ids( ``require_key_mcp_access_defined``, which inherits nothing. A keyless subject's team sources always inherit. A team that cannot be read contributes nothing while every other source still counts, and an own grant that is named but cannot be read grants nothing. No grant anywhere yields the empty set.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) from litellm.proxy.proxy_server import general_settings diff --git a/litellm/proxy/_experimental/mcp_server/upstream.py b/litellm/proxy/mcp_server/upstream.py similarity index 94% rename from litellm/proxy/_experimental/mcp_server/upstream.py rename to litellm/proxy/mcp_server/upstream.py index 1e39c068806..96a1c2db9ba 100644 --- a/litellm/proxy/_experimental/mcp_server/upstream.py +++ b/litellm/proxy/mcp_server/upstream.py @@ -7,12 +7,13 @@ import httpx2 from fastapi import HTTPException from litellm.constants import MCP_CLIENT_TIMEOUT, MCP_NPM_CACHE_DIR, MCP_STDIO_ALLOWED_COMMANDS -from litellm.experimental_mcp_client.client import MCPClient, MCPSigV4Auth -from litellm.proxy._experimental.mcp_server.legacy_callbacks import ElicitationCallback, SamplingCallback -from litellm.proxy._experimental.mcp_server.mcp_debug import record_auth_resolution -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import resolve_mcp_auth, resolved_token_header -from litellm.proxy._experimental.mcp_server.outbound_credentials import Error, Ok, UpstreamCredentialProvider -from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( +from litellm.mcp_client.client import MCPClient, MCPSigV4Auth +from litellm.proxy._types import MCPTransport, UserAPIKeyAuth +from litellm.proxy.mcp_server.legacy_callbacks import ElicitationCallback, SamplingCallback +from litellm.proxy.mcp_server.mcp_debug import record_auth_resolution +from litellm.proxy.mcp_server.oauth2_token_cache import resolve_mcp_auth, resolved_token_header +from litellm.proxy.mcp_server.outbound_credentials import Error, Ok, UpstreamCredentialProvider +from litellm.proxy.mcp_server.outbound_credentials.adapter import ( prepare_mcp_client, raise_public, raise_token_exchange_challenge, @@ -20,8 +21,8 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec, to_subject, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source +from litellm.proxy.mcp_server.outbound_credentials.types import ( DEFAULT_CREDENTIAL_HEADER, AuthorizationCodeConfig, AuthResolution, @@ -32,8 +33,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( ServerSpec, TokenExchangeConfig, ) -from litellm.proxy._experimental.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled -from litellm.proxy._types import MCPTransport, UserAPIKeyAuth +from litellm.proxy.mcp_server.stdio_gate import MCP_STDIO_DISABLED_MESSAGE, is_mcp_stdio_enabled from litellm.types.mcp import ( MCPAuth, MCPStdioConfig, diff --git a/litellm/proxy/_experimental/mcp_server/utils.py b/litellm/proxy/mcp_server/utils.py similarity index 100% rename from litellm/proxy/_experimental/mcp_server/utils.py rename to litellm/proxy/mcp_server/utils.py diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index bcba76ca1b3..bc79becf7bb 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -383,9 +383,6 @@ from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.llms.openai.live import parse_live_session_start from litellm.llms.openai_like.model_info import MODEL_INFO_REFRESH_SECONDS from litellm.llms.vertex_ai.vertex_llm_base import VertexBase -from litellm.proxy._experimental.mcp_server.byok_credential_cache import byok_credential_cache -from litellm.proxy._experimental.mcp_server.catalog import public_catalog_operation -from litellm.proxy._experimental.mcp_server.stdio_gate import MCP_STDIO_ENABLED_ENV_VAR, is_mcp_stdio_flag_key from litellm.proxy._lazy_features import attach_lazy_features, reserve_lazy_slot from litellm.proxy._types import * from litellm.proxy.agent_endpoints.auth.agent_access_groups import CeilingResolver, resolve_agent_access_group_ceiling @@ -786,6 +783,9 @@ from litellm.proxy.management_helpers.team_metadata_validation import ( TEAM_METADATA_VALIDATOR_REGISTRY, parse_team_metadata_schema, ) +from litellm.proxy.mcp_server.byok_credential_cache import byok_credential_cache +from litellm.proxy.mcp_server.catalog import public_catalog_operation +from litellm.proxy.mcp_server.stdio_gate import MCP_STDIO_ENABLED_ENV_VAR, is_mcp_stdio_flag_key from litellm.proxy.memory.memory_endpoints import router as memory_router from litellm.proxy.middleware.billable_request_metrics_middleware import ( BillableRequestMetricsMiddleware, @@ -7381,7 +7381,7 @@ class ProxyConfig: ## MCP TOOLS mcp_tools_config: Final = config.get("mcp_tools", None) if mcp_tools_config: - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -7398,7 +7398,7 @@ class ProxyConfig: mcp_servers_config: Final = config.get("mcp_servers", None) if mcp_servers_config: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -9402,19 +9402,19 @@ class ProxyConfig: ) async def _init_mcp_servers_in_db(self): - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): verbose_proxy_logger.debug("MCP module not available, skipping MCP server initialization") return - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.oauth2_flow_backfill import ( + from litellm.proxy.mcp_server.oauth2_flow_backfill import ( backfill_null_oauth2_flows, ) - from litellm.proxy._experimental.mcp_server.oauth_issuer_stamp_backfill import ( + from litellm.proxy.mcp_server.oauth_issuer_stamp_backfill import ( backfill_discovery_stamped_issuers, ) @@ -9453,11 +9453,11 @@ class ProxyConfig: """ if not self._should_load_db_object(object_type="mcp"): return - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): return - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -21764,11 +21764,11 @@ async def _stream_mcp_asgi_response(handle_fn, scope: dict, receive) -> "Streami ) async def proxy_mcp_route(request: Request) -> Response: """Serve the fixed three-tool MCP proxy surface.""" - from litellm.proxy._experimental.mcp_server.mcp_context import ( # pyright: ignore[reportPrivateUsage] # route-owned mode + from litellm.proxy.mcp_server.mcp_context import ( # pyright: ignore[reportPrivateUsage] # route-owned mode _mcp_proxy_mode, # pyright: ignore[reportPrivateUsage] # route-owned mode ) - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): raise HTTPException(status_code=404, detail="Not Found") @@ -21791,12 +21791,12 @@ async def aggregate_mcp_route(request: Request): """Serve the aggregate MCP endpoint on the bare ``/mcp`` spelling: the ``/mcp`` mount cannot match its bare prefix, and the resulting 307 breaks MCP clients behind TLS-terminating proxies.""" - from litellm.proxy._experimental.mcp_server.utils import is_mcp_available + from litellm.proxy.mcp_server.utils import is_mcp_available if not is_mcp_available(): raise HTTPException(status_code=404, detail="Not Found") - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -21822,10 +21822,10 @@ async def toolset_mcp_route(toolset_name: str, request: Request): will be rejected with a 403. """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, mcp_active_toolset_id, ) @@ -21857,7 +21857,7 @@ async def toolset_mcp_route(toolset_name: str, request: Request): async def _mcp_forward_as_path(path_segment: str, request: Request): """Rewrite path to /mcp/{path_segment} and stream the response.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -21890,11 +21890,11 @@ async def _resolve_mcp_csv_tokens(csv_segment: str, client_ip: str | None) -> li all-unmatched server filter falls back to the full ``allowed_mcp_servers`` list and silently broadens the request scope). """ - from litellm.proxy._experimental.mcp_server.catalog import global_manager + from litellm.proxy.mcp_server.catalog import global_manager async with global_manager().catalog.operation(): from litellm.constants import DEFAULT_MCP_NAMESPACE_CSV_MAX_TOKENS - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -21924,7 +21924,7 @@ async def _is_mcp_access_group_cached(name: str) -> bool: list) cannot hide a real group for long. """ from litellm.constants import DEFAULT_MCP_ACCESS_GROUP_NEGATIVE_CACHE_TTL - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -21957,10 +21957,10 @@ async def dynamic_mcp_route(mcp_server_name: str, request: Request): 4. MCP access group tag (DB lookup, cached) """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.auth.ip_address_utils import IPAddressUtils + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy.auth.ip_address_utils import IPAddressUtils client_ip: Final = IPAddressUtils.get_mcp_client_ip(request) @@ -21987,7 +21987,7 @@ async def dynamic_mcp_route(mcp_server_name: str, request: Request): # 3. Toolset name (cached) if prisma_client is not None: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, mcp_active_toolset_id, ) diff --git a/litellm/proxy/public_endpoints/public_endpoints.py b/litellm/proxy/public_endpoints/public_endpoints.py index 351e4c10d87..9f33e0d2adc 100644 --- a/litellm/proxy/public_endpoints/public_endpoints.py +++ b/litellm/proxy/public_endpoints/public_endpoints.py @@ -342,7 +342,7 @@ async def get_agents(request: Request): response_model=list[MCPPublicServer], ) async def get_mcp_servers(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py index 1bb88d5ff69..0efd4e4c619 100644 --- a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py +++ b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py @@ -24,7 +24,6 @@ import litellm from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger from litellm.litellm_core_utils.sensitive_data_masker import mask_sensitive_keys -from litellm.proxy._experimental.mcp_server.tool_search import MCP_TOOL_SEARCH_SETTINGS_KEY from litellm.proxy._types import * from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.common_utils.validation_error_body import public_validation_errors @@ -40,6 +39,7 @@ from litellm.proxy.management_endpoints.team_admin_field_permissions import ( TEAM_ADMIN_EDITABLE_TEAM_FIELDS_SETTING, TEAM_ADMIN_RAISE_MAX_BUDGET_PERMISSION, ) +from litellm.proxy.mcp_server.tool_search import MCP_TOOL_SEARCH_SETTINGS_KEY from litellm.proxy.spend_tracking.ptu_feature_flag import ( PTU_COST_ATTRIBUTION_ENV_VAR, is_ptu_cost_attribution_enabled, diff --git a/litellm/proxy/vector_store_endpoints/utils.py b/litellm/proxy/vector_store_endpoints/utils.py index b97c3a949d5..8ce48fc3516 100644 --- a/litellm/proxy/vector_store_endpoints/utils.py +++ b/litellm/proxy/vector_store_endpoints/utils.py @@ -9,15 +9,15 @@ from pydantic import ConfigDict, TypeAdapter import litellm from litellm._logging import verbose_proxy_logger -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - is_ui_session_credential, - resolve_ui_session_team_ids, -) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, LitellmUserRoles, UserAPIKeyAuth, ) +from litellm.proxy.mcp_server.ui_session_utils import ( + is_ui_session_credential, + resolve_ui_session_team_ids, +) from litellm.types.utils import LlmProviders from litellm.types.vector_stores import LiteLLM_ManagedVectorStore from litellm.utils import ProviderConfigManager diff --git a/litellm/responses/mcp/litellm_proxy_mcp_handler.py b/litellm/responses/mcp/litellm_proxy_mcp_handler.py index e3c3ab671ea..c01d07fb5c3 100644 --- a/litellm/responses/mcp/litellm_proxy_mcp_handler.py +++ b/litellm/responses/mcp/litellm_proxy_mcp_handler.py @@ -11,8 +11,8 @@ from typing_extensions import Unpack from litellm._logging import verbose_logger from litellm.constants import MAXIMUM_TRACEBACK_LINES_TO_LOG from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj -from litellm.proxy._experimental.mcp_server.catalog import catalog_operation, global_manager -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.catalog import catalog_operation, global_manager +from litellm.proxy.mcp_server.utils import ( iter_known_server_prefixes, logging_safe_mcp_headers, split_server_prefix_from_name, @@ -48,7 +48,7 @@ if TYPE_CHECKING: from mcp.types import CallToolResult from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.ui_session_utils import GrantedToolsetIds + from litellm.proxy.mcp_server.ui_session_utils import GrantedToolsetIds from litellm.proxy.utils import ProxyLogging from litellm.responses.mcp.mcp_streaming_iterator import MCPEnhancedStreamingIterator from litellm.types.proxy.auth.user_api_key_auth import UserAPIKeyAuth @@ -71,7 +71,7 @@ class _AresponsesOptions(ExtraItemsTypedDict, total=False, extra_items=object): def _registered_mcp_servers() -> Collection[MCPServer]: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -89,7 +89,7 @@ def _registry_serves(name: str, servers: Collection[MCPServer]) -> bool: async def _toolset_exists(name: str) -> bool: try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.proxy.proxy_server import prisma_client @@ -193,7 +193,7 @@ class LiteLLM_Proxy_MCP_Handler: from litellm.proxy._types import LiteLLM_ObjectPermissionTable try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -253,10 +253,10 @@ class LiteLLM_Proxy_MCP_Handler: List of MCP tools List names of allowed MCP servers """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, _get_tools_from_mcp_servers, ) @@ -282,12 +282,12 @@ class LiteLLM_Proxy_MCP_Handler: toolset = await global_mcp_server_manager.get_toolset_by_name_cached(prisma_client, name) if toolset is not None: if user_api_key_auth is not None: - from litellm.proxy._experimental.mcp_server.ui_session_utils import ( - granted_toolset_ids, - ) from litellm.proxy.management_endpoints.common_utils import ( user_api_key_has_admin_view, ) + from litellm.proxy.mcp_server.ui_session_utils import ( + granted_toolset_ids, + ) if not user_api_key_has_admin_view(user_api_key_auth) and toolset.toolset_id not in ( await (granted_toolsets or granted_toolset_ids)(user_api_key_auth) @@ -527,7 +527,7 @@ class LiteLLM_Proxy_MCP_Handler: target_format: Literal["responses", "chat"] = "responses", ) -> Sequence[FunctionToolParam | ChatCompletionToolParam]: """Transform MCP tools to OpenAI-compatible format.""" - from litellm.experimental_mcp_client.tools import ( + from litellm.mcp_client.tools import ( transform_mcp_tool_to_openai_responses_api_tool, transform_mcp_tool_to_openai_tool, ) @@ -720,10 +720,10 @@ class LiteLLM_Proxy_MCP_Handler: from litellm._uuid import uuid from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _resolve_display_name_to_original, ) from litellm.proxy.proxy_server import proxy_logging_obj diff --git a/litellm/responses/mcp/mcp_streaming_iterator.py b/litellm/responses/mcp/mcp_streaming_iterator.py index 9e51e2533ea..cc79d1c88bb 100644 --- a/litellm/responses/mcp/mcp_streaming_iterator.py +++ b/litellm/responses/mcp/mcp_streaming_iterator.py @@ -368,7 +368,7 @@ class MCPEnhancedStreamingIterator(BaseResponsesAPIStreamingIterator): from starlette.datastructures import Headers - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) diff --git a/litellm/responses/mcp/tool_precheck.py b/litellm/responses/mcp/tool_precheck.py index b76f4066e6d..a29e6895f9a 100644 --- a/litellm/responses/mcp/tool_precheck.py +++ b/litellm/responses/mcp/tool_precheck.py @@ -7,7 +7,7 @@ LITELLM_PROXY_MCP_SERVER_URL: Final = "litellm_proxy" LITELLM_PROXY_MCP_SERVER_URL_PREFIX: Final = f"{LITELLM_PROXY_MCP_SERVER_URL}/mcp/" _PROXY_MCP_PATH_RE: Final = re.compile(r"^https?://.+/mcp/([^/]+)$") -_GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy._experimental.mcp_server.mcp_server_manager" +_GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy.mcp_server.mcp_server_manager" def _mcp_server_url(tool: object) -> str | None: diff --git a/litellm/responses/utils.py b/litellm/responses/utils.py index 2d0873a218a..a6b042a2234 100644 --- a/litellm/responses/utils.py +++ b/litellm/responses/utils.py @@ -1190,7 +1190,7 @@ class ResponsesAPIRequestUtils: """ from starlette.datastructures import Headers - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) diff --git a/scripts/check_mcp_operation_boundary.py b/scripts/check_mcp_operation_boundary.py index b6c9dcefabf..65c92828fd8 100644 --- a/scripts/check_mcp_operation_boundary.py +++ b/scripts/check_mcp_operation_boundary.py @@ -3,7 +3,7 @@ import sys from pathlib import Path from typing import Final -PACKAGE: Final = Path("litellm/proxy/_experimental/mcp_server") +PACKAGE: Final = Path("litellm/proxy/mcp_server") LEGACY_ADAPTERS: Final = frozenset({"server.py", "legacy_callbacks.py", "mcp_context.py", "mcp_debug.py"}) CONFINED_NAMES: Final = frozenset( { diff --git a/scripts/check_mcp_sdk_install.py b/scripts/check_mcp_sdk_install.py index f5ab51b2f55..f2c2891bfd8 100644 --- a/scripts/check_mcp_sdk_install.py +++ b/scripts/check_mcp_sdk_install.py @@ -8,11 +8,11 @@ MINIMUM_MCP_VERSION: Final[tuple[int, int, int]] = (2, 2, 0) IMPORTED_MODULES: Final[tuple[str, ...]] = ( "litellm", - "litellm.experimental_mcp_client", - "litellm.experimental_mcp_client.client", - "litellm.proxy._experimental.mcp_server.server", - "litellm.proxy._experimental.mcp_server.mcp_server_manager", - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.mcp_client", + "litellm.mcp_client.client", + "litellm.proxy.mcp_server.server", + "litellm.proxy.mcp_server.mcp_server_manager", + "litellm.proxy.mcp_server.rest_endpoints", ) @@ -50,7 +50,7 @@ def main() -> int: "path": "/mcp", "headers": [(b"mcp-protocol-version", b"2026-07-28")], } - mcp_server: Final = sys.modules["litellm.proxy._experimental.mcp_server.server"] + mcp_server: Final = sys.modules["litellm.proxy.mcp_server.server"] if mcp_server.unsupported_protocol_version(scope) != "2026-07-28": sys.stderr.write("unsupported_protocol_version accepted a modern-only version\n") return 1 diff --git a/scripts/openapi_docs_gate.py b/scripts/openapi_docs_gate.py index a2a8fad78e9..5f5d1021c22 100755 --- a/scripts/openapi_docs_gate.py +++ b/scripts/openapi_docs_gate.py @@ -76,7 +76,10 @@ def parse_violations(out: str) -> tuple[Violation, ...]: def _check(root: Path, checker: Path) -> tuple[Violation, ...]: resolved: Final = root.resolve() - env: Final = {**os.environ, "PYTHONPATH": os.pathsep.join((str(resolved), os.environ.get("PYTHONPATH", "")))} + env: Final = { + **os.environ, + "PYTHONPATH": os.pathsep.join((str(resolved), str(resolved / "enterprise"), os.environ.get("PYTHONPATH", ""))), + } return parse_violations(_run([sys.executable, str(checker)], cwd=resolved, env=env)) diff --git a/scripts/pre_commit_lint.sh b/scripts/pre_commit_lint.sh index edb69f24e29..371884fb791 100755 --- a/scripts/pre_commit_lint.sh +++ b/scripts/pre_commit_lint.sh @@ -103,7 +103,7 @@ ui_prettier_pattern='^ui/litellm-dashboard/.*\.(js|jsx|ts|tsx|mjs|cjs|json|css|s ui_eslint_pattern='^ui/litellm-dashboard/.*\.(js|jsx|ts|tsx|mjs|cjs)$' litellm_py_files=$(scope_match "$litellm_py_pattern") -if [ -n "$(scope_match '^(litellm/proxy/_experimental/mcp_server/|scripts/check_mcp_operation_boundary\.py)')" ]; then +if [ -n "$(scope_match '^(litellm/proxy/mcp_server/|scripts/check_mcp_operation_boundary\.py)')" ]; then uv run --no-sync python scripts/check_mcp_operation_boundary.py || exit 1 fi e2e_py_files=$(scope_match "$e2e_py_pattern") diff --git a/tests/base_sdk_tests/check_base_sdk_install.py b/tests/base_sdk_tests/check_base_sdk_install.py index 4abd71e39a6..e546549d25f 100644 --- a/tests/base_sdk_tests/check_base_sdk_install.py +++ b/tests/base_sdk_tests/check_base_sdk_install.py @@ -127,7 +127,7 @@ def check_completion_with_function_tool() -> str: def check_mcp_install_guidance() -> str: try: - import litellm.experimental_mcp_client + import litellm.mcp_client except ImportError as error: _require("pip install 'litellm[mcp]'" in str(error), f"missing MCP installation guidance: {error}") _require(isinstance(error.__cause__, ModuleNotFoundError), "original missing-dependency cause was lost") @@ -174,8 +174,8 @@ def check_token_counter() -> str: def check_tokenizer_dependencies() -> str: import litellm - from litellm.rust_bridge import tokenizer from litellm.litellm_core_utils.tokenizer import HuggingFace, HuggingFaceTokenizer, Tokenizer + from litellm.rust_bridge import tokenizer from litellm.utils import claude_json_str _require(isinstance(litellm.encoding, Tokenizer), "runtime alias rejects the default encoding") diff --git a/tests/benchmarks/test_mcp_benchmarks.py b/tests/benchmarks/test_mcp_benchmarks.py index 7e23ab1b4f5..d4464d803cf 100644 --- a/tests/benchmarks/test_mcp_benchmarks.py +++ b/tests/benchmarks/test_mcp_benchmarks.py @@ -10,11 +10,11 @@ request. Both are pure-CPU and deterministic. import pytest from mcp.types import Tool as MCPTool -from litellm.experimental_mcp_client.tools import ( +from litellm.mcp_client.tools import ( transform_mcp_tool_to_openai_tool, transform_openai_tool_call_request_to_mcp_tool_call_request, ) -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, split_server_prefix_from_name, ) diff --git a/tests/code_coverage_tests/ensure_async_clients_test.py b/tests/code_coverage_tests/ensure_async_clients_test.py index 93ae2e2837b..f4922a11806 100644 --- a/tests/code_coverage_tests/ensure_async_clients_test.py +++ b/tests/code_coverage_tests/ensure_async_clients_test.py @@ -17,7 +17,7 @@ ALLOWED_FILES = [ "../../litellm/llms/base.py", "../../litellm/llms/custom_httpx/httpx_handler.py", "../../litellm/llms/openai/common_utils.py", - "../../litellm/experimental_mcp_client/client.py", + "../../litellm/mcp_client/client.py", # when running on ci/cd "./litellm/__init__.py", "./litellm/llms/custom_httpx/http_handler.py", @@ -27,7 +27,7 @@ ALLOWED_FILES = [ "./litellm/llms/base.py", "./litellm/llms/custom_httpx/httpx_handler.py", "./litellm/llms/openai/common_utils.py", - "./litellm/experimental_mcp_client/client.py", + "./litellm/mcp_client/client.py", ] warning_msg = "this is a serious violation that can impact latency. Creating Async clients per request can add +500ms per request" diff --git a/tests/code_coverage_tests/unbounded_in_baseline.txt b/tests/code_coverage_tests/unbounded_in_baseline.txt index 1286ea25c4e..1da964681a9 100644 --- a/tests/code_coverage_tests/unbounded_in_baseline.txt +++ b/tests/code_coverage_tests/unbounded_in_baseline.txt @@ -2,12 +2,12 @@ # Fix a site and delete its line; regenerate with `check_unbounded_in_lists.py --update-baseline`. litellm/integrations/shadow_eval_logger.py ShadowEvalLogger._active_jobs prisma job_id.in `[str(record.id) for record in records]` 0 litellm/llms/litellm_proxy/skills/handler.py LiteLLMSkillsHandler.list_skills prisma created_by.in `owner_scopes` 0 -litellm/proxy/_experimental/mcp_server/db.py get_mcp_servers prisma server_id.in `server_ids` 0 -litellm/proxy/_experimental/mcp_server/db.py get_user_env_vars_bulk prisma server_id.in `ids` 0 -litellm/proxy/_experimental/mcp_server/db.py purge_user_oauth_credentials_for_server prisma user_id.in `[row.user_id for row in oauth_rows]` 0 -litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids_for_flow` 0 -litellm/proxy/_experimental/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids` 0 -litellm/proxy/_experimental/mcp_server/toolset_db.py list_mcp_toolsets prisma toolset_id.in `toolset_ids` 0 +litellm/proxy/mcp_server/db.py get_mcp_servers prisma server_id.in `server_ids` 0 +litellm/proxy/mcp_server/db.py get_user_env_vars_bulk prisma server_id.in `ids` 0 +litellm/proxy/mcp_server/db.py purge_user_oauth_credentials_for_server prisma user_id.in `[row.user_id for row in oauth_rows]` 0 +litellm/proxy/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids_for_flow` 0 +litellm/proxy/mcp_server/oauth2_flow_backfill.py backfill_null_oauth2_flows prisma server_id.in `server_ids` 0 +litellm/proxy/mcp_server/toolset_db.py list_mcp_toolsets prisma toolset_id.in `toolset_ids` 0 litellm/proxy/agent_endpoints/endpoints.py _attach_keys_to_agents prisma agent_id.in `agent_ids` 0 litellm/proxy/agent_endpoints/endpoints.py get_agents prisma agent_id.in `agent_ids` 0 litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_skill_access.py SkillVisibility.where prisma name.in `sorted(self.granted)` 0 diff --git a/tests/e2e/coverage_registry/mcp.yaml b/tests/e2e/coverage_registry/mcp.yaml index 2ad815930a9..8eac9adeb33 100644 --- a/tests/e2e/coverage_registry/mcp.yaml +++ b/tests/e2e/coverage_registry/mcp.yaml @@ -1,4 +1,4 @@ -# MCP module. Grounded in litellm/proxy/_experimental/mcp_server/. See tests/e2e/AGENTS.md for the grammar. +# MCP module. Grounded in litellm/proxy/mcp_server/. See tests/e2e/AGENTS.md for the grammar. - id: mcp.list_tools.api_key.succeeds module: mcp tier: P0 diff --git a/tests/integration/mcp/test_interactions.py b/tests/integration/mcp/test_interactions.py index 8a4bdb8e8ec..5577cf16067 100644 --- a/tests/integration/mcp/test_interactions.py +++ b/tests/integration/mcp/test_interactions.py @@ -93,6 +93,8 @@ def sdk_interaction_peer(*, sampling: bool = False): import queue from contextlib import asynccontextmanager + from integration._support.asgi import asgi_server + from integration._support.mcp import McpPeer, _capturing, _drain_sse_streams from mcp.server import Server from mcp.server.streamable_http_manager import StreamableHTTPSessionManager from mcp.server.transport_security import TransportSecuritySettings @@ -100,27 +102,25 @@ def sdk_interaction_peer(*, sampling: bool = False): CallToolResult, CreateMessageRequest, CreateMessageRequestParams, - SamplingMessage, ElicitRequest, ElicitRequestFormParams, GetPromptResult, InputRequiredResult, - ListToolsResult, ListPromptsResult, ListResourcesResult, + ListToolsResult, Prompt, PromptMessage, ReadResourceResult, Resource, + SamplingMessage, TextContent, TextResourceContents, Tool, ) + from sse_starlette.sse import AppStatus from starlette.applications import Starlette from starlette.routing import Mount - from integration._support.asgi import asgi_server - from integration._support.mcp import McpPeer, _capturing, _drain_sse_streams - from sse_starlette.sse import AppStatus async def tools(ctx, params): return ListToolsResult(tools=[Tool(name="confirm", input_schema={"type": "object"})]) @@ -666,7 +666,7 @@ def test_modern_subscription_delivers_changes_between_calls_and_refreshes_tools( " data = json.loads(Path(__file__).with_suffix('.json').read_text())\n" " change = data.pop('subscription_test_update', None)\n" " if change:\n" - " from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager as manager\n" + " from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager as manager\n" " server = manager.config_mcp_servers['subscription-server']\n" " fields = {'authorization_url': 'https://authorization.example/authorize'} if change == 'metadata' else {'url': server.url.rstrip('/') + '/changed'}\n" " manager.config_mcp_servers[server.server_id] = server.model_copy(update=fields)\n" @@ -1295,9 +1295,9 @@ def test_subscription_partial_setup_releases_upstream_capacity() -> None: from starlette.applications import Starlette from starlette.routing import Mount - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionTarget + from litellm.mcp_client.client import MCPClient + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.subscriptions import GatewaySubscriptions, SubscriptionTarget from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer as RegisteredServer diff --git a/tests/integration/mcp/test_mcp_protocol_errors.py b/tests/integration/mcp/test_mcp_protocol_errors.py index 4930258ec07..d6e5ac66a34 100644 --- a/tests/integration/mcp/test_mcp_protocol_errors.py +++ b/tests/integration/mcp/test_mcp_protocol_errors.py @@ -4,7 +4,6 @@ import uuid from typing import Final import pytest - from integration._support.client import Gateway from integration._support.mcp import McpPeer, call_tool, register_mcp, tool_names from integration._support.wire import Reply, Request, wire_server @@ -98,11 +97,12 @@ def test_configured_revision_blocks_unadvertised_handshake_and_keeps_allowed_con import yaml from integration._support.mcp import mcp_peer from integration._support.process import owned_proxy - from litellm.experimental_mcp_client.client import MCPClient - from litellm.types.mcp import MCPTransport from mcp import MCPError from mcp.types import CallToolRequestParams + from litellm.mcp_client.client import MCPClient + from litellm.types.mcp import MCPTransport + with mcp_peer() as upstream, gateway.scenario() as scenario: alias: Final = "restricted" + uuid.uuid4().hex[:8] identity: Final = register_mcp(scenario, upstream, alias) diff --git a/tests/integration/mcp/test_mcp_transports.py b/tests/integration/mcp/test_mcp_transports.py index ef240cba570..92fcf37994e 100644 --- a/tests/integration/mcp/test_mcp_transports.py +++ b/tests/integration/mcp/test_mcp_transports.py @@ -8,7 +8,6 @@ from typing import Final import httpx import pytest import yaml -from mcp.shared.exceptions import MCPError from integration._support.client import Gateway from integration._support.database import read_rows from integration._support.mcp import ( @@ -34,6 +33,7 @@ from integration._support.mcp import ( ) from integration._support.mcp_grants import create_toolset from integration._support.process import owned_proxy +from mcp.shared.exceptions import MCPError ADD: Final = {"http": "add", "sse": "add", "stdio": "add", "openapi": "getpet"} ARGUMENTS: Final = {"add": {"a": 3, "b": 4}, "getpet": {"petId": "7"}} @@ -571,7 +571,7 @@ def test_pinned_revision_pairs_list_and_call_through_gateway( from mcp.types import CallToolRequestParams - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient from litellm.types.mcp import MCPTransport with peer_of(peer_kind) as peer, gateway.scenario() as scenario: @@ -616,7 +616,7 @@ def test_legacy_gateway_calls_modern_upstream_without_initialize( from mcp.types import CallToolRequestParams - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient from litellm.types.mcp import MCPTransport with peer_of(peer_kind) as peer, gateway.scenario() as scenario: @@ -661,13 +661,16 @@ def test_sdk_progress_and_cancellation_reach_upstream_without_losing_session( ) -> None: import asyncio import os + from contextlib import asynccontextmanager from pathlib import Path from threading import Event - from contextlib import asynccontextmanager import httpx import httpx2 import yaml + from integration._support.asgi import asgi_server + from integration._support.mcp import _drain_sse_streams + from integration._support.process import owned_proxy from mcp import ClientSession, MCPError from mcp.client.streamable_http import streamable_http_client from mcp.server.mcpserver import Context, MCPServer @@ -677,10 +680,6 @@ def test_sdk_progress_and_cancellation_reach_upstream_without_losing_session( from starlette.applications import Starlette from starlette.routing import Mount - from integration._support.asgi import asgi_server - from integration._support.mcp import _drain_sse_streams - from integration._support.process import owned_proxy - upstream: Final = MCPServer("progress-cancellation-peer") started: Final = Event() stopped: Final = Event() diff --git a/tests/integration/mcp/test_pagination.py b/tests/integration/mcp/test_pagination.py index e52757ec19a..aa464eca30e 100644 --- a/tests/integration/mcp/test_pagination.py +++ b/tests/integration/mcp/test_pagination.py @@ -6,14 +6,14 @@ from typing import Final, Literal import httpx import pytest import yaml +from integration._support.client import Gateway +from integration._support.mcp import McpPeer, paginated_mcp_peer +from integration._support.process import owned_proxy from mcp import ClientSession, MCPError from mcp.client.streamable_http import streamable_http_client from mcp.types import CallToolRequest, CallToolRequestParams, CallToolResult, DiscoverResult, PaginatedRequestParams -from integration._support.client import Gateway -from integration._support.mcp import McpPeer, paginated_mcp_peer -from integration._support.process import owned_proxy -from litellm.experimental_mcp_client.client import MCPClient +from litellm.mcp_client.client import MCPClient from litellm.types.mcp import MCPTransport @@ -422,7 +422,7 @@ def test_failed_upstream_continuation_requires_restart_for_every_catalog(tmp_pat @pytest.mark.parametrize("foreign", [{"foreign": {"status": "error", "message": "foreign outcome"}}, "malformed"]) def test_optional_catalog_ignores_upstream_gateway_outcomes(tmp_path: Path, foreign): - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY async def exercise(gateway): async with catalog_session(gateway) as session: @@ -577,7 +577,8 @@ def test_aggregate_freshness_matches_real_upstream() -> None: ListToolsRequest, ListToolsResult, ) - from litellm.proxy._experimental.mcp_server.catalog import combine_optional_catalog, list_tools_page + + from litellm.proxy.mcp_server.catalog import combine_optional_catalog, list_tools_page async def exercise(peer: McpPeer) -> None: client: Final = MCPClient(server_url=peer.url, transport_type=MCPTransport.http, protocol_version="2026-07-28") @@ -604,8 +605,8 @@ def test_aggregate_freshness_matches_real_upstream() -> None: @pytest.mark.parametrize("ttl_ms", [0, 9000]) def test_discovery_cache_freshness_and_caller_isolation_over_http(ttl_ms: int) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer async def exercise(peer: McpPeer) -> None: diff --git a/tests/integration/mcp/test_proxy_mcp_e2e.py b/tests/integration/mcp/test_proxy_mcp_e2e.py index 2f690463143..6fb8d284016 100644 --- a/tests/integration/mcp/test_proxy_mcp_e2e.py +++ b/tests/integration/mcp/test_proxy_mcp_e2e.py @@ -31,8 +31,8 @@ from starlette.requests import Request import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.proxy._experimental.mcp_server.tool_search import handle_mcp_proxy_tool from litellm.proxy._types import LiteLLM_ObjectPermissionTable, ProxyException, UserAPIKeyAuth +from litellm.proxy.mcp_server.tool_search import handle_mcp_proxy_tool from litellm.proxy.proxy_server import ( app as proxy_app, ) @@ -41,11 +41,11 @@ from litellm.proxy.proxy_server import ( initialize, ) from tests._master_key import MASTER_KEY +from tests.integration._support.ports import allocate_port from tests.integration._support.process import stop_child from tests.integration._support.timing import assert_enforced_within from tests.integration._support.wire import Reply, Wire, wire_server from tests.integration._support.wire import Request as WireRequest -from tests.integration._support.ports import allocate_port CONFIG_TEMPLATE_PATH = Path("tests/integration/mcp/_config_mcp_e2e.yaml") MCP_SERVER_SCRIPT = Path("tests/integration/mcp/_math_server.py") @@ -86,7 +86,7 @@ async def drain_logging_worker() -> typing.AsyncIterator[None]: async def test_schema_validation_stops_expensive_work_and_recovers(cancel: bool, concurrency: int) -> None: import psutil - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( _VALIDATION_TIMEOUT_SECONDS, _tool_argument_validation_error, ) @@ -246,8 +246,8 @@ def _clear_proxy_database_env() -> typing.Iterator[None]: async def _initialize_proxy(config_path: str) -> None: - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager cleanup_router_config_variables() global_mcp_server_manager.catalog = CatalogSnapshots(global_mcp_server_manager) @@ -307,7 +307,7 @@ def _start_proxy_server( failure: Final[Future[BaseException | None]] = Future() async def _serve() -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server await _initialize_proxy(config_path) async with proxy_app.router.lifespan_context(proxy_app), mcp_server.lifespan(proxy_app): diff --git a/tests/integration/mcp_coverage.toml b/tests/integration/mcp_coverage.toml index daa782eade2..439fac10169 100644 --- a/tests/integration/mcp_coverage.toml +++ b/tests/integration/mcp_coverage.toml @@ -4,10 +4,10 @@ core = "sysmon" parallel = true relative_files = true include = [ - "litellm/proxy/_experimental/mcp_server/*", + "litellm/proxy/mcp_server/*", "litellm/proxy/management_endpoints/mcp_management_endpoints.py", "litellm/responses/mcp/*", - "litellm/experimental_mcp_client/*", + "litellm/mcp_client/*", "litellm/proxy/guardrails/guardrail_hooks/mcp_*", ] diff --git a/tests/unit/experimental_mcp_client/test_init.py b/tests/unit/experimental_mcp_client/test_init.py new file mode 100644 index 00000000000..9d2f1137470 --- /dev/null +++ b/tests/unit/experimental_mcp_client/test_init.py @@ -0,0 +1,29 @@ +import importlib +import sys +from collections.abc import Mapping + +import pytest + +import litellm.mcp_client +import litellm.mcp_client.client +import litellm.mcp_client.tools + +OLD_PACKAGE = "litellm.experimental_mcp_client" + + +def test_old_package_warns_and_deep_imports_resolve_to_mcp_client(monkeypatch: pytest.MonkeyPatch) -> None: + for name in tuple(sys.modules): + if name.startswith(OLD_PACKAGE): + monkeypatch.delitem(sys.modules, name) + + with pytest.warns(DeprecationWarning, match="litellm.mcp_client"): + import litellm.experimental_mcp_client as old + + assert old.__all__ == litellm.mcp_client.__all__ + assert old.load_mcp_tools is litellm.mcp_client.load_mcp_tools + assert old.call_openai_tool is litellm.mcp_client.call_openai_tool + assert importlib.import_module(f"{OLD_PACKAGE}.client") is litellm.mcp_client.client + assert importlib.import_module(f"{OLD_PACKAGE}.tools") is litellm.mcp_client.tools + attrs: Mapping[str, object] = vars(old) + assert attrs["tools"] is litellm.mcp_client.tools + assert attrs["client"] is litellm.mcp_client.client diff --git a/tests/unit/llms/litellm_proxy/skills/test_skill_search.py b/tests/unit/llms/litellm_proxy/skills/test_skill_search.py index c0754f6f1af..0647b203aff 100644 --- a/tests/unit/llms/litellm_proxy/skills/test_skill_search.py +++ b/tests/unit/llms/litellm_proxy/skills/test_skill_search.py @@ -456,7 +456,7 @@ class TestHandleSkillSearchMCP: self, accessible_skills: AsyncMock, embedding_router: MagicMock ) -> None: from litellm.llms.litellm_proxy.skills.skill_search import MAX_SKILL_SEARCH_TOP_K - from litellm.proxy._experimental.mcp_server.tool_search import handle_skill_search + from litellm.proxy.mcp_server.tool_search import handle_skill_search many_skills: Final = tuple( LiteLLM_SkillsTable( @@ -476,7 +476,7 @@ class TestHandleSkillSearchMCP: async def test_top_k_below_one_is_raised_to_one( self, accessible_skills: AsyncMock, embedding_router: MagicMock ) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import handle_skill_search + from litellm.proxy.mcp_server.tool_search import handle_skill_search result = await handle_skill_search( query="language translation", top_k=0, user_api_key_dict=UserAPIKeyAuth(user_id="u") diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/__init__.py b/tests/unit/mcp_client/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/auth/__init__.py rename to tests/unit/mcp_client/__init__.py diff --git a/tests/unit/experimental_mcp_client/test_mcp_client.py b/tests/unit/mcp_client/test_mcp_client.py similarity index 98% rename from tests/unit/experimental_mcp_client/test_mcp_client.py rename to tests/unit/mcp_client/test_mcp_client.py index 60600afab84..43021d248a9 100644 --- a/tests/unit/experimental_mcp_client/test_mcp_client.py +++ b/tests/unit/mcp_client/test_mcp_client.py @@ -49,8 +49,8 @@ from starlette.responses import Response from starlette.types import ASGIApp, Message, Receive, Scope, Send # Add the parent directory to the path so we can import litellm -import litellm.experimental_mcp_client.client as mcp_client_module -from litellm.experimental_mcp_client.client import ( +import litellm.mcp_client.client as mcp_client_module +from litellm.mcp_client.client import ( MCPClient, MCPSigV4Auth, PersistentMCPSession, @@ -61,16 +61,16 @@ from litellm.experimental_mcp_client.client import ( as_mcp_read_timeout, strip_auth_scheme, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, classify_list_exception, list_fault_http_status, upstream_rate_limit, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( +from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth +from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth from litellm.types.mcp import MCPAuth, MCPStdioConfig, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer from tests._support.clock_loops import AutojumpClockLoop, ManualClockLoop @@ -163,7 +163,7 @@ async def test_modern_input_request_uses_existing_elicitation_callback( TextContent, ) - from litellm.proxy._experimental.mcp_server.interactions import BoundInputRequiredResult + from litellm.proxy.mcp_server.interactions import BoundInputRequiredResult observed: Final[SimpleQueue[str]] = SimpleQueue() sampled: Final = CreateMessageResult( @@ -379,8 +379,8 @@ class TestMCPClient: await client.run_with_session(_noop) @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.stdio_client") - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.stdio_client") + @patch("litellm.mcp_client.client.ClientSession") async def test_mcp_client_stdio_connect_success(self, mock_session, mock_stdio_client): """Test successful stdio connection""" # Setup mocks - create proper async context manager @@ -432,7 +432,7 @@ class TestMCPClient: mock_streamable_http_client.return_value = mock_http_ctx # Mock the session - with patch("litellm.experimental_mcp_client.client.ClientSession") as mock_session: + with patch("litellm.mcp_client.client.ClientSession") as mock_session: mock_session_instance = AsyncMock() mock_session_instance.initialize = AsyncMock(return_value=_initialized()) mock_session_ctx = AsyncMock() @@ -478,7 +478,7 @@ class TestMCPClient: mock_sse_client.return_value = mock_sse_ctx # Mock the session - with patch("litellm.experimental_mcp_client.client.ClientSession") as mock_session: + with patch("litellm.mcp_client.client.ClientSession") as mock_session: mock_session_instance = AsyncMock() mock_session_instance.initialize = AsyncMock(return_value=_initialized()) mock_session_ctx = AsyncMock() @@ -530,7 +530,7 @@ class TestMCPClient: mock_streamable_http_client.return_value = mock_http_ctx # Mock the session - with patch("litellm.experimental_mcp_client.client.ClientSession") as mock_session: + with patch("litellm.mcp_client.client.ClientSession") as mock_session: mock_session_instance = AsyncMock() mock_session_instance.initialize = AsyncMock(return_value=_initialized()) mock_session_ctx = AsyncMock() @@ -670,7 +670,7 @@ class TestMCPClientInstructionsCapture: assert client._last_initialize_instructions is None @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_captures_instructions_from_initialize(self, mock_session_cls): """Instructions from upstream initialize() are captured and stripped.""" client = MCPClient( @@ -698,7 +698,7 @@ class TestMCPClientInstructionsCapture: assert client._last_initialize_instructions == "upstream says hello" @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_none_instructions_stays_none(self, mock_session_cls): """When upstream returns no instructions the field stays None.""" client = MCPClient( @@ -787,7 +787,7 @@ class TestExecuteSessionOperationSurfacesTransportError: return transport_ctx @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_surfaces_connect_error_over_cancelled(self, mock_session_cls): client = MCPClient(server_url="http://example.com/mcp", transport_type="http") self._make_session( @@ -804,7 +804,7 @@ class TestExecuteSessionOperationSurfacesTransportError: await client._execute_session_operation(transport_ctx, _op) @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_genuine_cancellation_is_not_replaced(self, mock_session_cls): client = MCPClient(server_url="http://example.com/mcp", transport_type="http") self._make_session(mock_session_cls, AsyncMock(side_effect=asyncio.CancelledError())) @@ -818,7 +818,7 @@ class TestExecuteSessionOperationSurfacesTransportError: @pytest.mark.asyncio @pytest.mark.parametrize("failure_phase", ("early", "late", "mixed")) - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_response_close_preserves_cancellation_and_original_errors(self, session_class, failure_phase): closed: Final = asyncio.Event() close_error: Final = httpx2.ReadError("response close failed") @@ -863,7 +863,7 @@ class TestExecuteSessionOperationSurfacesTransportError: assert closed.is_set() @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_cleanup_error_after_success_is_swallowed(self, mock_session_cls): client = MCPClient(server_url="http://example.com/mcp", transport_type="http") init_result = _initialized() @@ -877,7 +877,7 @@ class TestExecuteSessionOperationSurfacesTransportError: assert result == "done" @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_session_entry_failure_still_closes_transport(self, session_class): failure: Final = RuntimeError("session dispatcher did not start") session_class.return_value.__aenter__ = AsyncMock(side_effect=failure) @@ -896,7 +896,7 @@ class TestExecuteSessionOperationSurfacesTransportError: @pytest.mark.asyncio @pytest.mark.parametrize("original_error", (False, True)) - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_session_exit_cancellation_preserves_original_failure(self, session_class, original_error): self._make_session(session_class, AsyncMock(return_value=_initialized())) cancelled: Final = asyncio.CancelledError("cancelled while closing session") @@ -918,7 +918,7 @@ class TestExecuteSessionOperationSurfacesTransportError: @pytest.mark.asyncio @pytest.mark.parametrize("signal_type", (SystemExit, KeyboardInterrupt)) @pytest.mark.parametrize("phase", ("session", "transport")) - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_cleanup_preserves_process_exit(self, session_class, phase, signal_type): self._make_session(session_class, AsyncMock(return_value=_initialized())) signal: Final = signal_type("process stopping") @@ -932,7 +932,7 @@ class TestExecuteSessionOperationSurfacesTransportError: transport.__aexit__.assert_awaited_once() @pytest.mark.asyncio - @patch("litellm.experimental_mcp_client.client.ClientSession") + @patch("litellm.mcp_client.client.ClientSession") async def test_session_and_termination_share_one_cleanup_deadline(self, session_class): self._make_session(session_class, AsyncMock(return_value=_initialized())) deleting: Final = asyncio.Event() @@ -1835,7 +1835,7 @@ def test_a_differently_cased_injected_header_cannot_shadow_the_slot() -> None: async def test_invalid_http_response_surfaces_without_waiting_for_timeout( content_type: str, body: bytes, expected_type: type[Exception] ) -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import _connection_error_message + from litellm.proxy.mcp_server.rest_endpoints import _connection_error_message def respond(request: httpx2.Request) -> httpx2.Response: if expected_type is ValidationError: @@ -1979,7 +1979,7 @@ async def test_sse_catalog_limit_reports_the_failure_and_allows_smaller_pages(pa @pytest.mark.asyncio async def test_http_status_check_allows_auth_refresh_before_rejecting() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) @@ -1993,7 +1993,7 @@ async def test_http_status_check_allows_auth_refresh_before_rejecting() -> None: seen.append(request.headers["authorization"]) return httpx2.Response(401 if len(seen) == 1 else 200, json={"ok": True}) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ClientCredentialsConfig + from litellm.proxy.mcp_server.outbound_credentials.types import ClientCredentialsConfig auth = ClientCredentialsBearerAuth("stale", refresh, ClientCredentialsConfig()) client = MCPClient(server_url="https://example.com/mcp", resolved_auth=auth) @@ -2057,7 +2057,7 @@ async def test_http_response_handler_preserves_notifications_and_tool_listing() @pytest.mark.asyncio async def test_invalid_tool_list_schema_is_identified_as_an_upstream_response() -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import _connection_error_message + from litellm.proxy.mcp_server.rest_endpoints import _connection_error_message def respond(request: httpx2.Request) -> httpx2.Response: if request.method == "DELETE": @@ -2249,7 +2249,7 @@ async def test_transport_completion_and_normal_messages( ) -> None: from mcp import ClientSession - from litellm.proxy._experimental.mcp_server.rest_endpoints import _connection_error_message + from litellm.proxy.mcp_server.rest_endpoints import _connection_error_message logging_callback: Final = AsyncMock() read_timeout: Final = 0.2 if mode == "silent" else 30 @@ -2847,7 +2847,7 @@ def test_standalone_client_request_does_not_require_proxy_dependencies(): for name in ("fastapi", "orjson", "email_validator", "annotated_doc"): sys.modules[name] = None import httpx2 - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient async def request(): upstream = MCPClient(server_url="https://upstream.example/mcp") @@ -2872,7 +2872,7 @@ def test_client_import_before_proxy_credentials_succeeds_in_fresh_process(): [ sys.executable, "-c", - "import litellm.experimental_mcp_client.client; from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager; print(MCPServerManager.__name__)", + "import litellm.mcp_client.client; from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager; print(MCPServerManager.__name__)", ], capture_output=True, text=True, @@ -2886,7 +2886,7 @@ def test_client_import_before_proxy_credentials_succeeds_in_fresh_process(): @pytest.mark.asyncio @pytest.mark.parametrize("resolved", (False, True)) async def test_discovery_auth_fingerprint_tracks_effective_credentials(resolved: bool) -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth def client(token: str) -> MCPClient: return MCPClient( @@ -2932,7 +2932,7 @@ async def test_discovery_auth_fingerprint_tracks_aws_sigv4_credential_identity() @pytest.mark.asyncio async def test_request_auth_preview_uses_the_same_effective_headers_as_egress() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth client: Final = MCPClient( server_url="https://upstream.example/mcp", @@ -3027,11 +3027,11 @@ async def test_404_before_session_initialization_preserves_method_not_found() -> def test_public_mcp_import_missing_dependency(missing_module: str) -> None: with patch.dict(sys.modules): for name in tuple(sys.modules): - if name.startswith(("litellm.experimental_mcp_client", "mcp.", "mcp_types.")) or name == "mcp": + if name.startswith(("litellm.mcp_client", "mcp.", "mcp_types.")) or name == "mcp": del sys.modules[name] with patch.dict(sys.modules, {missing_module: None}): with pytest.raises(ImportError) as caught: - importlib.import_module("litellm.experimental_mcp_client.client") + importlib.import_module("litellm.mcp_client.client") if missing_module in ("mcp", "httpx2"): assert "pip install 'litellm[mcp]'" in str(caught.value) @@ -3047,11 +3047,11 @@ def test_public_mcp_import_missing_dependency(missing_module: str) -> None: def test_public_mcp_import_preserves_incompatible_sdk_error() -> None: with patch.dict(sys.modules): for name in tuple(sys.modules): - if name.startswith("litellm.experimental_mcp_client"): + if name.startswith("litellm.mcp_client"): del sys.modules[name] with patch.dict(sys.modules, {"mcp": ModuleType("mcp")}): with pytest.raises(ImportError, match="cannot import name 'ClientSession'") as caught: - importlib.import_module("litellm.experimental_mcp_client.client") + importlib.import_module("litellm.mcp_client.client") assert not isinstance(caught.value, ModuleNotFoundError) assert caught.value.__cause__ is None @@ -3635,7 +3635,7 @@ async def test_modern_call_requires_schema_from_bounded_listing( from mcp.types import ToolsCapability - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) methods: Final[SimpleQueue[str]] = SimpleQueue() def respond(request: httpx2.Request) -> httpx2.Response: @@ -5047,7 +5047,7 @@ async def test_persistent_session_reports_an_upstream_cancellation_as_a_runtime_ @pytest.mark.asyncio async def test_closing_persistent_session_fails_a_caller_blocked_on_a_full_queue_instead_of_hanging() -> None: - from litellm.experimental_mcp_client.client import _MAX_PENDING_OPERATIONS + from litellm.mcp_client.client import _MAX_PENDING_OPERATIONS app: Final = _stateful_upstream() async with app.router.lifespan_context(app): @@ -5089,8 +5089,9 @@ async def test_persistent_session_ends_after_a_broken_stream_so_the_next_call_ge @pytest.mark.parametrize("session_started_in_request", [True, False]) async def test_persistent_session_releases_the_current_requests_scope_response(session_started_in_request) -> None: from mcp.server.context import ServerRequestContext - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse app = _stateful_upstream() async with app.router.lifespan_context(app): @@ -5205,8 +5206,8 @@ async def test_cancelling_persistent_operation_stops_work_and_keeps_session_usab @pytest.mark.asyncio @pytest.mark.parametrize("header_name", ["Authorization", "x-upstream-token"]) async def test_subscription_fingerprint_preserves_context_across_managed_renewal(header_name): - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ClientCredentialsBearerAuth - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ClientCredentialsConfig + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ClientCredentialsBearerAuth + from litellm.proxy.mcp_server.outbound_credentials.types import ClientCredentialsConfig async def refetch(token: str) -> str | None: return None @@ -5234,7 +5235,7 @@ async def test_subscription_fingerprint_preserves_context_across_managed_renewal @pytest.mark.asyncio async def test_notification_callback_keeps_stream_errors_separate_from_protocol_errors() -> None: - from litellm.experimental_mcp_client.client import _receive_session_message + from litellm.mcp_client.client import _receive_session_message stream_error = asyncio.get_running_loop().create_future() receiver = AsyncMock() diff --git a/tests/unit/experimental_mcp_client/test_tools.py b/tests/unit/mcp_client/test_tools.py similarity index 96% rename from tests/unit/experimental_mcp_client/test_tools.py rename to tests/unit/mcp_client/test_tools.py index ac7afe4c74b..ca3cf29bd90 100644 --- a/tests/unit/experimental_mcp_client/test_tools.py +++ b/tests/unit/mcp_client/test_tools.py @@ -2,8 +2,6 @@ import json from unittest.mock import AsyncMock, MagicMock import pytest - - from mcp.types import ( CallToolRequestParams, CallToolResult, @@ -13,14 +11,14 @@ from mcp.types import ( ) from mcp.types import Tool as MCPTool -from litellm.experimental_mcp_client.tools import ( - list_tools_with_pagination, - transform_mcp_tool_to_anthropic_tool, +from litellm.mcp_client.tools import ( _get_function_arguments, _normalize_mcp_input_schema, call_mcp_tool, call_openai_tool, + list_tools_with_pagination, load_mcp_tools, + transform_mcp_tool_to_anthropic_tool, transform_mcp_tool_to_openai_responses_api_tool, transform_mcp_tool_to_openai_tool, transform_openai_tool_call_request_to_mcp_tool_call_request, @@ -131,7 +129,7 @@ async def test_load_mcp_tools_follows_pagination(mock_session): @pytest.mark.asyncio() @pytest.mark.parametrize("require_complete", [False, True]) async def test_pagination_walk_stops_at_page_cap(mock_session, monkeypatch, require_complete): - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_MAX_PAGES", 2) mock_session.list_tools.side_effect = [ ListToolsResult( tools=[MCPTool(name="tool_0", description="0", inputSchema={})], @@ -189,10 +187,10 @@ async def test_pagination_walk_treats_empty_cursor_as_terminal(mock_session): async def test_pagination_walk_stops_at_whole_walk_deadline(mock_session, monkeypatch, require_complete): import anyio - from litellm.experimental_mcp_client.tools import list_tools_with_pagination + from litellm.mcp_client.tools import list_tools_with_pagination - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.2) - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.2) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.2) async def slow_page(params=None): await anyio.sleep(0.15) @@ -218,10 +216,10 @@ async def test_pagination_walk_stops_at_whole_walk_deadline(mock_session, monkey async def test_pagination_walk_honors_explicit_deadline_over_globals(mock_session, monkeypatch): import anyio - from litellm.experimental_mcp_client.tools import list_tools_with_pagination + from litellm.mcp_client.tools import list_tools_with_pagination - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.1) - monkeypatch.setattr("litellm.experimental_mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.1) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_CLIENT_TIMEOUT", 0.1) + monkeypatch.setattr("litellm.mcp_client.tools.MCP_TOOL_LISTING_TIMEOUT", 0.1) async def slow_page(params=None): await anyio.sleep(0.15) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_init.py b/tests/unit/proxy/_experimental/mcp_server/test_init.py new file mode 100644 index 00000000000..2f933e11351 --- /dev/null +++ b/tests/unit/proxy/_experimental/mcp_server/test_init.py @@ -0,0 +1,30 @@ +import importlib +import sys +from collections.abc import Mapping + +import pytest + +import litellm.proxy.mcp_server.auth.user_api_key_auth_mcp +import litellm.proxy.mcp_server.server +import litellm.proxy.mcp_server.utils + +OLD_PACKAGE = "litellm.proxy._experimental.mcp_server" + + +def test_old_package_warns_and_deep_imports_resolve_to_proxy_mcp_server(monkeypatch: pytest.MonkeyPatch) -> None: + for name in tuple(sys.modules): + if name.startswith(OLD_PACKAGE): + monkeypatch.delitem(sys.modules, name) + + with pytest.warns(DeprecationWarning, match="litellm.proxy.mcp_server"): + old = importlib.import_module(OLD_PACKAGE) + + assert importlib.import_module(f"{OLD_PACKAGE}.server") is litellm.proxy.mcp_server.server + assert importlib.import_module(f"{OLD_PACKAGE}.utils") is litellm.proxy.mcp_server.utils + assert ( + importlib.import_module(f"{OLD_PACKAGE}.auth.user_api_key_auth_mcp") + is litellm.proxy.mcp_server.auth.user_api_key_auth_mcp + ) + attrs: Mapping[str, object] = vars(old) + assert attrs["server"] is litellm.proxy.mcp_server.server + assert attrs["auth"] is litellm.proxy.mcp_server.auth diff --git a/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py b/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py index 8c2d8e4f157..0f064622f2d 100644 --- a/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py +++ b/tests/unit/proxy/anthropic_endpoints/test_gateway_endpoints.py @@ -20,21 +20,6 @@ from fastapi import FastAPI from fastapi.testclient import TestClient from litellm.caching.dual_cache import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( - MintedProxyCredential, - ProxyCredentialMintFailure, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( - SessionRefreshOpened, - open_session_refresh_bearer, - session_keys_from_master_key, -) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( - SESSION_REFRESH_PREFIX, - MintedSessionToken, - SessionPrincipal, - mint_session_refresh_token, -) from litellm.proxy._types import ProxyException from litellm.proxy.anthropic_endpoints import gateway_endpoints from litellm.proxy.management_endpoints.ui_sso import ( @@ -42,6 +27,21 @@ from litellm.proxy.management_endpoints.ui_sso import ( _hash_cli_sso_secret, _set_cli_sso_flow, ) +from litellm.proxy.mcp_server.gateway_dcr_flow import ( + MintedProxyCredential, + ProxyCredentialMintFailure, +) +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( + SessionRefreshOpened, + open_session_refresh_bearer, + session_keys_from_master_key, +) +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( + SESSION_REFRESH_PREFIX, + MintedSessionToken, + SessionPrincipal, + mint_session_refresh_token, +) from litellm.proxy.middleware.prometheus_auth_middleware import PrometheusAuthMiddleware _DEVICE_CODE_GRANT: Final = "urn:ietf:params:oauth:grant-type:device_code" diff --git a/tests/unit/proxy/auth/test_login_utils.py b/tests/unit/proxy/auth/test_login_utils.py index ec9b9a04f72..37ea05f8ba9 100644 --- a/tests/unit/proxy/auth/test_login_utils.py +++ b/tests/unit/proxy/auth/test_login_utils.py @@ -9,8 +9,8 @@ import hashlib import os from collections.abc import Mapping from contextlib import ExitStack -from typing import TYPE_CHECKING, Final from datetime import datetime, timedelta, timezone +from typing import TYPE_CHECKING, Final from unittest.mock import AsyncMock, MagicMock, patch import httpx @@ -638,10 +638,10 @@ class TestEncodeUiSessionJwt: this helper must now be accepted.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.auth.login_utils import encode_ui_session_jwt + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( user_id_from_session_cookie, ) - from litellm.proxy.auth.login_utils import encode_ui_session_jwt token_object = {"user_id": "cornell-user", "key": "sk-abc", "login_method": "sso"} with patch("litellm.proxy.auth.login_utils.LITELLM_UI_SESSION_DURATION", "24h"): diff --git a/tests/unit/proxy/auth/test_mcp_ip_filtering.py b/tests/unit/proxy/auth/test_mcp_ip_filtering.py index c403daf733f..b28dd8bbab5 100644 --- a/tests/unit/proxy/auth/test_mcp_ip_filtering.py +++ b/tests/unit/proxy/auth/test_mcp_ip_filtering.py @@ -36,7 +36,7 @@ def _make_server(server_id, available_on_public_internet=False): def _make_manager(servers): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) diff --git a/tests/unit/proxy/db/mcp_server/test_db.py b/tests/unit/proxy/db/mcp_server/test_db.py index e2440e49f19..51c350dc1ce 100644 --- a/tests/unit/proxy/db/mcp_server/test_db.py +++ b/tests/unit/proxy/db/mcp_server/test_db.py @@ -3,8 +3,7 @@ from unittest.mock import AsyncMock, MagicMock import pytest - -from litellm.proxy._experimental.mcp_server.db import ( +from litellm.proxy.mcp_server.db import ( approve_mcp_server, get_mcp_servers_by_team, reject_mcp_server, diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py b/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py index 8fa544819e9..e2f10225568 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/akto/test_akto.py @@ -3,9 +3,8 @@ import base64 import json import os from types import SimpleNamespace -from unittest.mock import AsyncMock, MagicMock, patch - from typing import Final, Literal +from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest @@ -1709,7 +1708,7 @@ async def test_one_text_masked_two_ways_blocks(akto_pre_call): @pytest.mark.asyncio async def test_masking_a_payload_too_deep_to_map_back_blocks(akto_pre_call): - from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH + from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH deep: object = CARD for _ in range(MAX_STRUCTURED_CONTENT_SCAN_DEPTH + 1): diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py index e4c7bcba951..0e6670c26e7 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_mcp_security.py @@ -63,7 +63,7 @@ class TestExtractMCPServerNames: class TestMCPSecurityGuardrailPreCall: @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) async def test_blocks_unregistered_server_chat_completions( self, mock_manager, guardrail @@ -93,7 +93,7 @@ class TestMCPSecurityGuardrailPreCall: @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) async def test_blocks_unregistered_server_responses_api( self, mock_manager, guardrail @@ -122,7 +122,7 @@ class TestMCPSecurityGuardrailPreCall: @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) async def test_allows_registered_servers(self, mock_manager, guardrail): """All MCP servers are registered - request passes through.""" @@ -211,8 +211,9 @@ class TestInitializeGuardrail: @pytest.mark.parametrize("call_type", ["acompletion", "aresponses"]) async def test_guardrail_observes_saved_server_creation_and_deletion_on_another_worker(guardrail, call_type): from unittest.mock import AsyncMock + from litellm.proxy._types import LiteLLM_MCPServerTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() row = LiteLLM_MCPServerTable(server_id="peer-server", alias="peer_server", transport="http", @@ -226,7 +227,7 @@ async def test_guardrail_observes_saved_server_creation_and_deletion_on_another_ with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch("litellm.proxy.proxy_server.general_settings", {}), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), ): result = await guardrail.async_pre_call_hook(UserAPIKeyAuth(), MagicMock(), data, call_type) assert result == data diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py index a5c543528c2..83301db5d86 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_panw_prisma_airs.py @@ -3243,7 +3243,7 @@ class TestPanwAirsMcpToolEventScan: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_manager, patch.object(handler, "_call_panw_api", new_callable=AsyncMock) as mock_api, ): diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py b/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py index bd1e9ae4068..e312378969a 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/test_presidio.py @@ -15,27 +15,25 @@ from typing import Final, Literal from unittest.mock import MagicMock, patch import aiohttp +import pytest from aiohttp import web from aiohttp.client_proto import ResponseHandler from aiohttp.test_utils import TestServer -import pytest from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict - import litellm from litellm import mock_completion from litellm.caching.caching import DualCache +from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.guardrails.guardrail_hooks.presidio import ( - PresidioPerRequestConfig, OPTIONAL_PresidioPIIMasking, + PresidioPerRequestConfig, ) -from litellm.exceptions import GuardrailRaisedException from litellm.types.guardrails import LitellmParams, PiiAction, PiiEntityType from litellm.types.proxy.guardrails.guardrail_hooks.presidio import PresidioAnalyzeRequest, PresidioAnalyzeResponseItem from litellm.types.utils import Choices, Delta, Message, ModelResponse, StreamingChoices -from litellm.exceptions import BlockedPiiEntityError def _make_mock_session_iterator(json_response, status=200, content_type="application/json", text_response=""): @@ -4434,9 +4432,9 @@ async def test_pii_masking_replays_a_byte_identical_prefix_across_turns(mock_use async def test_initialized_presidio_scans_selected_surface(surface: str, action: PiiAction, has_tokens: bool) -> None: from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import MCPGuardrailTranslationHandler from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail.unified_guardrail import UnifiedLLMGuardrails from litellm.proxy.guardrails.guardrail_initializers import initialize_presidio + from litellm.proxy.mcp_server.guardrail_translation.handler import MCPGuardrailTranslationHandler params: Final = LitellmParams( guardrail="presidio", diff --git a/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py b/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py index a132ce8eada..a6177ff9e3a 100644 --- a/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py +++ b/tests/unit/proxy/guardrails/guardrail_hooks/unified_guardrails/test_unified_guardrail.py @@ -37,9 +37,6 @@ from litellm.llms.openai.responses.guardrail_translation.handler import ( OpenAIResponsesHandler, ) from litellm.llms.pass_through.guardrail_translation.handler import PassThroughEndpointHandler -from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import ( - MCPGuardrailTranslationHandler, -) from litellm.proxy._types import LiteLLMRoutes, UserAPIKeyAuth from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail import ( unified_guardrail as unified_module, @@ -47,6 +44,9 @@ from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail import ( from litellm.proxy.guardrails.guardrail_hooks.unified_guardrail.unified_guardrail import ( UnifiedLLMGuardrails, ) +from litellm.proxy.mcp_server.guardrail_translation.handler import ( + MCPGuardrailTranslationHandler, +) from litellm.types.guardrails import GuardrailEventHooks from litellm.types.llms.openai import ResponsesAPIResponse from litellm.types.utils import ( diff --git a/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py b/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py index 345f37f1db4..b8dba5e1e68 100644 --- a/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py +++ b/tests/unit/proxy/hooks/test_parallel_request_limiter_v3.py @@ -4000,10 +4000,10 @@ async def test_billed_personal_key_auth_produces_team_rpm_descriptors(monkeypatc from litellm.models.budget import LiteLLM_BudgetTable from litellm.models.team_membership import LiteLLM_TeamMembership from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = MCPServer( server_id="math_a", diff --git a/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py b/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py index d6ee9b1d29e..4266c2ed6d1 100644 --- a/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_key_management_endpoints.py @@ -1,30 +1,29 @@ import asyncio +import inspect +import json from collections.abc import Mapping from contextlib import ExitStack -from typing import Final -from types import SimpleNamespace -import json from datetime import datetime, timedelta, timezone +from types import SimpleNamespace +from typing import Final +from unittest.mock import AsyncMock, MagicMock, patch from uuid import UUID -import litellm import pytest import yaml -from fastapi.testclient import TestClient - -from unittest.mock import AsyncMock, MagicMock, patch - from fastapi import HTTPException +from fastapi.testclient import TestClient from pydantic import JsonValue -import inspect - +import litellm +from litellm.constants import PROXY_DB_LOOKUP_STALL_WINDOW_SECONDS +from litellm.litellm_core_utils.duration_parser import duration_in_seconds +from litellm.models.object_permission import LiteLLM_ObjectPermissionTable from litellm.models.project import LiteLLM_ProjectTable from litellm.proxy._types import ( - GenerateKeyResponse, GenerateKeyRequest, + GenerateKeyResponse, KeyManagementRoutes, - NewUserRequest, LiteLLM_BudgetTable, LiteLLM_ObjectPermissionBase, LiteLLM_OrganizationTable, @@ -36,46 +35,42 @@ from litellm.proxy._types import ( LiteLLMKeyType, LitellmUserRoles, Member, + NewUserRequest, ProxyException, RegenerateKeyRequest, ResetSpendRequest, UpdateKeyRequest, ) -from litellm.models.object_permission import LiteLLM_ObjectPermissionTable from litellm.proxy.auth.auth_checks import ( delete_cache_key_object, jwt_key_mapping_cache_key, ) from litellm.proxy.auth.user_api_key_auth import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache, project_cache_key -from litellm.constants import PROXY_DB_LOOKUP_STALL_WINDOW_SECONDS from litellm.proxy.db.db_lookup_gate import db_lookup_stall_tracker -from litellm.litellm_core_utils.duration_parser import duration_in_seconds from litellm.proxy.management_endpoints.key_management_endpoints import ( + KeyProjectBindingError, _check_key_project_team, _check_key_project_team_on_mutation, _check_org_key_limits, _check_project_key_limits, _check_team_key_limits, - _is_team_key, - _key_generation_required_param_check, - _personal_key_generation_check, - _team_key_generation_check, _common_key_generation_helper, - _member_key_request, - _team_admin_requests_member_key, - KeyProjectBindingError, _effective_key_after_update, _effective_key_for_generate, _enforce_custom_key_policy, _enforce_upperbound_key_params, _execute_virtual_key_regeneration, _get_and_validate_existing_key, - list_key_helper, - persist_deleted_verification_tokens, + _is_team_key, + _key_generation_required_param_check, + _member_key_request, + _personal_key_generation_check, _process_single_key_update, _requested_end_user_budget_id, _save_deleted_verification_token_records, + _team_admin_requests_member_key, + _team_key_generation_check, _transform_verification_tokens_to_deleted_records, _validate_end_user_budget_id_change, _validate_max_budget, @@ -90,7 +85,9 @@ from litellm.proxy.management_endpoints.key_management_endpoints import ( generate_service_account_key_fn, key_aliases, key_generation_check, + list_key_helper, list_keys, + persist_deleted_verification_tokens, prepare_key_update_data, prepare_metadata_fields, reset_key_spend_fn, @@ -837,7 +834,7 @@ async def test_update_key_grandfathers_existing_mcp_servers(monkeypatch): } mock_mgr.get_allow_all_keys_server_ids.return_value = [] monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ) @@ -10955,10 +10952,10 @@ class TestValidateKeyAliasFormat: _validate_key_alias_format("team/user@example.com") def test_validate_key_alias_format_invalid(self, monkeypatch): + from litellm.proxy._types import ProxyException from litellm.proxy.management_endpoints.key_management_endpoints import ( _validate_key_alias_format, ) - from litellm.proxy._types import ProxyException monkeypatch.setattr(litellm, "enable_key_alias_format_validation", True) invalid_aliases = [ @@ -12798,14 +12795,14 @@ class TestKeyAliasSkipValidationOnUnchanged: Updating a key without changing its key_alias should skip format validation — even if the alias wouldn't pass current rules. """ + # Temporarily make the regex reject '@' to simulate stricter rules + import re + + from litellm.proxy.management_endpoints import key_management_endpoints as mod from litellm.proxy.management_endpoints.key_management_endpoints import ( _validate_key_alias_format, ) - # Temporarily make the regex reject '@' to simulate stricter rules - import re - from litellm.proxy.management_endpoints import key_management_endpoints as mod - original_pattern = mod._KEY_ALIAS_PATTERN mod._KEY_ALIAS_PATTERN = re.compile( r"^[a-zA-Z0-9][a-zA-Z0-9_\-/\.]{0,253}[a-zA-Z0-9]$" @@ -20431,7 +20428,6 @@ async def test_regenerate_key_repoints_access_group_assigned_key_ids(monkeypatch from litellm.proxy.management_endpoints.key_management_endpoints import ( _execute_virtual_key_regeneration, ) - from litellm.proxy.utils import hash_token new_token_hash = hash_token("sk-newtoken1234ab12") diff --git a/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py b/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py index 65c4a8faeb7..4b1415c8879 100644 --- a/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_mcp_management_endpoints.py @@ -1,14 +1,11 @@ -from contextlib import nullcontext - - import asyncio +import json +import logging import os import sys import types -import json -import logging from collections.abc import Iterator, Mapping -from contextlib import ExitStack, contextmanager +from contextlib import ExitStack, contextmanager, nullcontext from dataclasses import dataclass, field from datetime import datetime, timedelta from types import SimpleNamespace @@ -17,28 +14,23 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -from pydantic import BaseModel, TypeAdapter, ValidationError -from respx import MockRouter from fastapi import FastAPI, HTTPException, Request from fastapi.testclient import TestClient +from pydantic import BaseModel, TypeAdapter, ValidationError +from respx import MockRouter import litellm from litellm._uuid import uuid from litellm.caching.caching import DualCache -from litellm.integrations.custom_guardrail import CustomGuardrail -from litellm.proxy.utils import ProxyLogging from litellm.constants import UI_SESSION_TOKEN_TEAM_ID +from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.models.access_group import LiteLLM_AccessGroupTable from litellm.models.organization import LiteLLM_OrganizationTable from litellm.models.team import LiteLLM_TeamTable from litellm.models.user import LiteLLM_UserTable -from litellm.proxy.management_endpoints import ( - mcp_management_endpoints as mgmt_endpoints, -) - from litellm.proxy._types import ( - LiteLLM_ObjectPermissionTable, LiteLLM_MCPServerTable, + LiteLLM_ObjectPermissionTable, LitellmUserRoles, MakeMCPServersPublicRequest, MCPTransport, @@ -47,7 +39,11 @@ from litellm.proxy._types import ( UpdateMCPServerRequest, UserAPIKeyAuth, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerConfig, MCPServerManager +from litellm.proxy.management_endpoints import ( + mcp_management_endpoints as mgmt_endpoints, +) +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerConfig, MCPServerManager +from litellm.proxy.utils import ProxyLogging from litellm.types.mcp import MCPAuth, MCPCredentials from litellm.types.mcp_server.mcp_server_manager import MCPServer, PinnedMCPTool @@ -173,7 +169,7 @@ def patch_proxy_general_settings(settings: dict): async def test_mcp_publication_list_and_detail_derive_current_status( from_db: bool, strict: bool, explicit: bool, expected_public: bool ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() server: Final = MCPServer( @@ -227,7 +223,7 @@ async def test_mcp_publication_list_and_detail_derive_current_status( def test_mcp_publication_projection_excludes_unregistered_lifecycle_records( approval_status: str, strict: bool ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager record: Final = LiteLLM_MCPServerTable( server_id="unregistered-server", @@ -275,7 +271,7 @@ async def test_mcp_publication_updates_runtime_only_after_successful_save( error_status: int | None, ) -> None: import litellm - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() server: Final = generate_mock_mcp_server_config_record(server_id="new-server") @@ -299,7 +295,7 @@ async def test_mcp_publication_updates_runtime_only_after_successful_save( patch("litellm.public_mcp_servers", previous_ids), patch("litellm.proxy.proxy_server.proxy_config", proxy_config), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -1537,11 +1533,11 @@ class TestListMCPServers: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_servers_by_verificationtoken", + "litellm.proxy.mcp_server.db.get_mcp_servers_by_verificationtoken", AsyncMock(return_value=["env-server"]), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_servers", + "litellm.proxy.mcp_server.db.get_mcp_servers", AsyncMock(return_value=[generate_mock_mcp_server_db_record(server_id="env-server")]), ), patch( @@ -2343,7 +2339,7 @@ class TestTemporaryMCPSessionEndpoints: """The edit form authorizes against a saved server's own id, so a draft write would collide on the primary key. That row is already visible to every worker, so it is returned untouched and no draft is created.""" - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server + from litellm.proxy.mcp_server.db import create_draft_mcp_server real_row = generate_mock_mcp_server_db_record(server_id="already-saved") real_row.approval_status = "active" @@ -2352,15 +2348,15 @@ class TestTemporaryMCPSessionEndpoints: with ( patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", + "litellm.proxy.mcp_server.db._db_find_mcp_server_row", AsyncMock(return_value=real_row), ), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", AsyncMock(return_value=[]), ), - patch("litellm.proxy._experimental.mcp_server.db.create_mcp_server", create_call), - patch("litellm.proxy._experimental.mcp_server.db.delete_mcp_server", delete_call), + patch("litellm.proxy.mcp_server.db.create_mcp_server", create_call), + patch("litellm.proxy.mcp_server.db.delete_mcp_server", delete_call), ): result = await create_draft_mcp_server( MagicMock(), @@ -2381,7 +2377,7 @@ class TestTemporaryMCPSessionEndpoints: live two-worker proxy. The loser's session is in fact ready, because the winner wrote a draft for it, so it adopts that row instead of failing the caller. """ - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server + from litellm.proxy.mcp_server.db import create_draft_mcp_server winner_draft = generate_mock_mcp_server_db_record(server_id="raced") winner_draft.approval_status = "draft" @@ -2389,13 +2385,13 @@ class TestTemporaryMCPSessionEndpoints: lookups = AsyncMock(side_effect=[None, winner_draft]) with ( - patch("litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", lookups), + patch("litellm.proxy.mcp_server.db._db_find_mcp_server_row", lookups), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server", + "litellm.proxy.mcp_server.db.create_mcp_server", AsyncMock(side_effect=Exception("duplicate key value violates unique constraint")), ), ): @@ -2412,19 +2408,19 @@ class TestTemporaryMCPSessionEndpoints: @pytest.mark.asyncio async def test_create_draft_mcp_server_reraises_when_the_create_failure_was_not_a_race(self): """A genuine database error must not be swallowed by the race-adoption path.""" - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server + from litellm.proxy.mcp_server.db import create_draft_mcp_server with ( patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", + "litellm.proxy.mcp_server.db._db_find_mcp_server_row", AsyncMock(side_effect=[None, None]), ), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server", + "litellm.proxy.mcp_server.db.create_mcp_server", AsyncMock(side_effect=Exception("connection refused")), ), pytest.raises(Exception, match="connection refused"), @@ -2440,10 +2436,10 @@ class TestTemporaryMCPSessionEndpoints: async def test_create_draft_mcp_server_prunes_drafts_past_their_lifetime(self): """Regression: abandoned OAuth sessions accumulated forever. Verified against a live proxy, where 12 drafts aged past the lifetime were still present and a 13th was added.""" - from litellm.proxy._experimental.mcp_server.db import create_draft_mcp_server - from datetime import timezone + from litellm.proxy.mcp_server.db import create_draft_mcp_server + now = datetime.now(timezone.utc) stale_one = generate_mock_mcp_server_db_record(server_id="stale-1") stale_one.updated_at = now - timedelta(hours=1) @@ -2456,14 +2452,14 @@ class TestTemporaryMCPSessionEndpoints: delete_call = AsyncMock() with ( - patch("litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", find_rows), + patch("litellm.proxy.mcp_server.db._db_find_mcp_server_rows", find_rows), patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_row", + "litellm.proxy.mcp_server.db._db_find_mcp_server_row", AsyncMock(return_value=None), ), - patch("litellm.proxy._experimental.mcp_server.db.delete_mcp_server", delete_call), + patch("litellm.proxy.mcp_server.db.delete_mcp_server", delete_call), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server", + "litellm.proxy.mcp_server.db.create_mcp_server", AsyncMock(return_value=generate_mock_mcp_server_db_record(server_id="fresh")), ), ): @@ -2483,11 +2479,11 @@ class TestTemporaryMCPSessionEndpoints: """Drafts are addressable only by their own id and must never appear in a listing, but a bare inequality would also drop pre-approval-workflow rows, since SQL evaluates NULL != 'draft' as NULL.""" - from litellm.proxy._experimental.mcp_server.db import get_all_mcp_servers + from litellm.proxy.mcp_server.db import get_all_mcp_servers find_rows = AsyncMock(return_value=[]) with patch( - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", find_rows, ): await get_all_mcp_servers(MagicMock()) @@ -2499,11 +2495,11 @@ class TestTemporaryMCPSessionEndpoints: async def test_get_all_mcp_servers_propagates_read_failures(self): """Regression: a swallowed read failure returned [] and silently disabled the bulk-import dedupe, so a flaky DB read turned a re-import into duplicate servers.""" - from litellm.proxy._experimental.mcp_server.db import get_all_mcp_servers + from litellm.proxy.mcp_server.db import get_all_mcp_servers find_rows = AsyncMock(side_effect=RuntimeError("db down")) with patch( # test-quality-ok: the helper takes its row reader from module scope, matching the suite's pattern - "litellm.proxy._experimental.mcp_server.db._db_find_mcp_server_rows", + "litellm.proxy.mcp_server.db._db_find_mcp_server_rows", find_rows, ): with pytest.raises(RuntimeError, match="db down"): @@ -2681,7 +2677,7 @@ class TestTemporaryMCPSessionEndpoints: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.ui_session_utils.build_effective_auth_contexts", + "litellm.proxy.mcp_server.ui_session_utils.build_effective_auth_contexts", AsyncMock(return_value=[non_admin]), ) as effective_contexts, patch.object(mgmt_endpoints, "build_effective_auth_contexts", effective_contexts), @@ -2769,7 +2765,7 @@ class TestTemporaryMCPSessionEndpoints: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.ui_session_utils.build_effective_auth_contexts", + "litellm.proxy.mcp_server.ui_session_utils.build_effective_auth_contexts", AsyncMock(return_value=[ui_session_auth, team_context]), ) as effective_contexts, patch.object(mgmt_endpoints, "build_effective_auth_contexts", effective_contexts), @@ -3027,7 +3023,7 @@ class TestTemporaryMCPSessionEndpoints: with ( patch.dict(sys.modules, {"litellm.proxy.proxy_server": fake_proxy_server}), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch( @@ -3081,7 +3077,7 @@ class TestTemporaryMCPSessionEndpoints: with ( patch.dict(sys.modules, {"litellm.proxy.proxy_server": fake_proxy_server}), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch( @@ -3139,8 +3135,8 @@ class TestTemporaryMCPSessionEndpoints: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.management_endpoints.mcp_management_endpoints import mcp_authorize + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager row: Final = LiteLLM_MCPServerTable( server_id="saved-server", @@ -3269,7 +3265,7 @@ class TestTemporaryMCPSessionEndpoints: if mint_mock is not None: patches.append( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", mint_mock, ) ) @@ -3324,7 +3320,7 @@ class TestTemporaryMCPSessionEndpoints: through to a gateway-side DCR mint and proceed with the minted client instead of dead-ending on a 400 missing_client_id. Both modes share the caller-held-client contract, so both get the fall-through.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, ) @@ -3367,7 +3363,7 @@ class TestTemporaryMCPSessionEndpoints: return_value=nullcontext(server), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", mint_mock, ), ): @@ -3448,7 +3444,7 @@ class TestTemporaryMCPSessionEndpoints: one (the minted flow runs the bridge short-circuit arm) instead of dead-ending on missing_client_id. The relay front door stays reserved for clients that present their own client_id.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, ) @@ -3492,12 +3488,12 @@ class TestTemporaryMCPSessionEndpoints: callback forwarded, so the token endpoint recovers the ephemeral client and the real upstream code from it and authenticates the exchange with them, with no client_id supplied by the caller and none stored on the server.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() request.base_url = "https://litellm.example.com/" @@ -3549,13 +3545,13 @@ class TestTemporaryMCPSessionEndpoints: async def test_mcp_token_prefers_sealed_client_when_server_has_shared_client( self: "TestTemporaryMCPSessionEndpoints", ) -> None: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager request: Final = MagicMock() request.base_url = "https://litellm.example.com/" @@ -3590,7 +3586,7 @@ class TestTemporaryMCPSessionEndpoints: return_value=prisma_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -3599,7 +3595,7 @@ class TestTemporaryMCPSessionEndpoints: new=mock_update_server, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), ): @@ -3640,12 +3636,12 @@ class TestTemporaryMCPSessionEndpoints: contract: a refresh_token grant that echoes a leftover sealed passthrough code (plus any verifier) must not recover the minted credentials, so a clientless server answers missing_client_id and the client re-runs authorize instead.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() request.base_url = "https://litellm.example.com/" @@ -3696,12 +3692,12 @@ class TestTemporaryMCPSessionEndpoints: """A sealed code is minted only for S256 PKCE flows, so redeeming one without the corresponding verifier is refused at the gateway rather than trusting the upstream to enforce the binding.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() server = generate_mock_mcp_server_config_record(server_id="server-1") @@ -3746,12 +3742,12 @@ class TestTemporaryMCPSessionEndpoints: """A sealed passthrough code is bound to the server it was minted for: presenting it at another server's token endpoint is a 400 before any upstream exchange, so a code cannot be replayed across a server boundary.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( - seal_passthrough_authorization_code, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( mcp_token, ) + from litellm.proxy.mcp_server.discoverable_endpoints import ( + seal_passthrough_authorization_code, + ) request = MagicMock() server = generate_mock_mcp_server_config_record(server_id="server-1") @@ -4790,8 +4786,8 @@ async def test_health_discovery_respects_route_restricted_key_grants( ) -> None: from typing import Final - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import mcp_server_manager monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") manager: Final = mcp_server_manager.MCPServerManager() @@ -4865,8 +4861,8 @@ async def test_health_checks_probe_shared_servers_once_across_auth_contexts( expected: tuple[str, ...], include_reachability: bool, ) -> None: - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import mcp_server_manager monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") manager: Final = mcp_server_manager.MCPServerManager() @@ -4934,8 +4930,8 @@ async def test_health_reachability_requires_explicit_api_opt_in( detail: bool, flag: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import mcp_server_manager class HealthResponse(BaseModel): server_id: str @@ -5770,10 +5766,10 @@ async def test_store_mcp_oauth_user_credential_blocked_when_identity_binding_enf if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( store_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-binding-1" bound_server = MCPServer( @@ -5875,10 +5871,10 @@ async def test_store_mcp_oauth_user_credential_invalidates_cached_token(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( store_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-inv-1" user_id = "user-inv-1" @@ -5927,10 +5923,10 @@ async def test_delete_mcp_oauth_user_credential_invalidates_cached_token(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-inv-2" user_id = "user-inv-2" @@ -5971,10 +5967,10 @@ async def test_delete_mcp_oauth_user_credential_invalidates_when_record_already_ if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module server_id = "srv-inv-3" user_id = "user-inv-3" @@ -6018,10 +6014,10 @@ async def test_admin_revokes_another_users_byok_credential(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_user_credential, ) + from litellm.proxy.mcp_server import server as mcp_server delete_mock = AsyncMock(return_value=None) invalidate_mock = AsyncMock() @@ -6087,10 +6083,10 @@ async def test_user_naming_themselves_still_deletes_own_byok_credential(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_user_credential, ) + from litellm.proxy.mcp_server import server as mcp_server deleted_rows: list[tuple[str, str]] = [] # mutable-ok: test-local recorder for the fake delete boundary @@ -6126,10 +6122,10 @@ async def test_admin_revokes_another_users_oauth_credential(): if not mgmt_endpoints.MCP_AVAILABLE: pytest.skip("MCP module not installed") - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_oauth_user_credential, ) + from litellm.proxy.mcp_server import mcp_server_manager as manager_module get_mock = AsyncMock(return_value={"type": "oauth2", "access_token": "mallory-tok"}) delete_mock = AsyncMock(return_value=None) @@ -7427,7 +7423,7 @@ class TestMCPUserEnvVarsAccessControl: def test_oauth2_flow_accepted_on_create_request(): """NewMCPServerRequest carries oauth2_flow through to the persisted dict.""" - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data payload = NewMCPServerRequest( server_name="m2m-server", @@ -7506,8 +7502,8 @@ def test_dcr_bridge_rejected_on_create_when_auth_type_omitted(): @pytest.mark.parametrize("auth_type", ["true_passthrough", "oauth_delegate"]) def test_dcr_bridge_accepted_on_create_for_client_forwarded_modes(auth_type): - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data from litellm.proxy._types import NewMCPServerRequest + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data payload = NewMCPServerRequest( server_name="bridge-server", @@ -8037,7 +8033,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8069,7 +8065,7 @@ class TestConnectedAppViewAnnotation: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(return_value=UserAPIKeyAuth(user_id="test_user_id")), ), ): @@ -8108,11 +8104,11 @@ class TestConnectedAppViewAnnotation: mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(return_value=admitted_auth), ), ): @@ -8140,7 +8136,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(side_effect=HTTPException(status_code=401, detail="expired")), ), ): @@ -8168,7 +8164,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8202,7 +8198,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8233,7 +8229,7 @@ class TestConnectedAppViewAnnotation: AsyncMock(return_value=[caller_auth]), ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ), ): @@ -8433,10 +8429,10 @@ class TestGetMCPGatewaySessions: async def test_admin_roles_receive_live_session_report(self, role): from mcp.types import Implementation - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( get_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server from litellm.types.mcp import MCPGatewaySessionsResponse session_id = "gateway-sessions-endpoint-1" @@ -8470,7 +8466,7 @@ class TestGetMCPGatewaySessions: class TestDeleteMCPGatewaySessions: @pytest.fixture(autouse=True) def _forget_admin_terminated_ids(self): - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server yield mcp_server._admin_terminated_session_ids.clear() @@ -8478,10 +8474,10 @@ class TestDeleteMCPGatewaySessions: @pytest.mark.asyncio @pytest.mark.parametrize("role", [LitellmUserRoles.INTERNAL_USER, LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY]) async def test_non_full_admin_forbidden_before_any_session_is_touched(self, role): - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server session_id = "gateway-terminate-forbidden-1" transport = MagicMock(terminate=AsyncMock()) @@ -8522,10 +8518,10 @@ class TestDeleteMCPGatewaySessions: @pytest.mark.asyncio async def test_admin_terminates_only_the_selected_session(self): - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server from litellm.types.mcp import MCPGatewaySessionsTerminateResponse target_id = "11111111-target-session" @@ -8569,10 +8565,10 @@ class TestDeleteMCPGatewaySessions: @pytest.mark.asyncio async def test_admin_terminates_every_session_of_the_selected_user(self): - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy.management_endpoints.mcp_management_endpoints import ( delete_mcp_gateway_sessions, ) + from litellm.proxy.mcp_server import server as mcp_server def auth_user(user_id: str): return mcp_server.MCPAuthenticatedUser( @@ -8620,7 +8616,7 @@ class TestGetMcpToolsWireShape: tools=[Tool(name="add", description="Add", inputSchema=add_schema, outputSchema={"type": "integer"})] ) with patch( - "litellm.proxy._experimental.mcp_server.server._list_mcp_tools", + "litellm.proxy.mcp_server.server._list_mcp_tools", AsyncMock(return_value=listed), ): result = await mgmt_endpoints.get_mcp_tools(user_api_key_dict=generate_mock_user_api_key_auth()) @@ -8641,7 +8637,7 @@ class TestGetMcpToolsWireShape: ], ) async def test_config_server_edit_preserves_api_contract_without_creating_rows(role, expected_status): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() server = generate_mock_mcp_server_config_record(server_id="read-only-config") @@ -8675,7 +8671,7 @@ async def test_config_server_edit_preserves_api_contract_without_creating_rows(r @pytest.mark.asyncio async def test_saved_server_authorize_denial_does_not_dispatch_upstream(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() row: Final = LiteLLM_MCPServerTable(server_id="denied-peer", alias="denied_peer", transport=MCPTransport.http, @@ -8715,7 +8711,7 @@ class TestDuplicateIdentifierRejection: @staticmethod def _conflict(field: str, value: str, server_id: str = "existing-1"): - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict return McpIdentifierConflict(field=field, value=value, server_id=server_id) @@ -8963,7 +8959,7 @@ class TestPinMCPServerTools: ), patch("litellm.proxy.management_endpoints.mcp_management_endpoints.set_mcp_server_pinned_tools", store_mock), patch("litellm.proxy.management_endpoints.mcp_management_endpoints.global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager", manager), patch.dict( sys.modules, { @@ -9171,9 +9167,9 @@ class _ResolutionEffects: patch.object(mgmt_endpoints, "merge_user_env_vars", self.env_merge), patch.object(mgmt_endpoints, "delete_user_env_vars", self.env_delete), patch.object(manager, "invalidate_user_oauth_token_cache", self.oauth_invalidate), - patch("litellm.proxy._experimental.mcp_server.server._invalidate_byok_cred_cache", self.byok_invalidate), + patch("litellm.proxy.mcp_server.server._invalidate_byok_cred_cache", self.byok_invalidate), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.invalidate_user_env_vars_cache", + "litellm.proxy.mcp_server.mcp_server_manager.invalidate_user_env_vars_cache", self.env_invalidate, ), ): @@ -10182,7 +10178,7 @@ class TestMCPServerResolutionCharacterization: with ( patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), patch("litellm.proxy.proxy_server.prisma_client", prisma), patch("litellm.proxy.proxy_server.user_api_key_cache", _mock_mcp_resolution_cache()), patch("litellm.proxy.proxy_server.general_settings", {}), @@ -10293,7 +10289,7 @@ class TestMCPServerResolutionCharacterization: patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), patch.object(manager, "add_server", add_server), @@ -10477,7 +10473,7 @@ class TestMCPServerResolutionCharacterization: patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), patch.object(manager, "invalidate_user_oauth_token_cache", invalidate), @@ -11268,7 +11264,7 @@ class TestMCPServerResolutionCharacterization: MockRouter(assert_all_called=False) as httpx_mock, patch.object(mgmt_endpoints, "get_prisma_client_or_throw", return_value=prisma), patch.object(mgmt_endpoints, "global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager), patch.object(manager, "add_server", add_server), patch.object(manager, "health_check_server", health_check), patch("litellm.proxy.proxy_server.prisma_client", prisma), diff --git a/tests/unit/proxy/management_endpoints/test_mcp_servers.py b/tests/unit/proxy/management_endpoints/test_mcp_servers.py index 77afe510267..4c0288f0e6f 100644 --- a/tests/unit/proxy/management_endpoints/test_mcp_servers.py +++ b/tests/unit/proxy/management_endpoints/test_mcp_servers.py @@ -9,14 +9,14 @@ from litellm.proxy._types import ( MCPTransport, NewMCPServerRequest, ) -from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict -from litellm.proxy._experimental.mcp_server.utils import validate_mcp_server_name from litellm.proxy.management_endpoints.mcp_management_endpoints import ( _redact_mcp_credentials, does_mcp_server_exist, raise_mcp_identifier_conflict, validate_and_normalize_mcp_server_payload, ) +from litellm.proxy.mcp_server.db import McpIdentifierConflict +from litellm.proxy.mcp_server.utils import validate_mcp_server_name def test_does_mcp_server_exist() -> None: diff --git a/tests/unit/proxy/management_endpoints/test_saml_sso.py b/tests/unit/proxy/management_endpoints/test_saml_sso.py index 181c5e65dae..ff2117ea533 100644 --- a/tests/unit/proxy/management_endpoints/test_saml_sso.py +++ b/tests/unit/proxy/management_endpoints/test_saml_sso.py @@ -31,7 +31,6 @@ from starlette.datastructures import URL from litellm.caching.dual_cache import DualCache from litellm.caching.in_memory_cache import InMemoryCache from litellm.caching.redis_cache import RedisCache -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import SSOIdentityAssertion from litellm.proxy._types import LitellmUserRoles from litellm.proxy.management_endpoints.sso.saml_sso import ( _SAML_AUTHN_REQUEST_CACHE_PREFIX, @@ -42,6 +41,7 @@ from litellm.proxy.management_endpoints.sso.saml_sso import ( SAMLAuthHandler, ) from litellm.proxy.management_endpoints.types import CustomOpenID +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import SSOIdentityAssertion def _shared_cache(store: InMemoryCache | None = None) -> DualCache: diff --git a/tests/unit/proxy/management_endpoints/test_ui_sso.py b/tests/unit/proxy/management_endpoints/test_ui_sso.py index e1a939273ae..4135e9be6f6 100644 --- a/tests/unit/proxy/management_endpoints/test_ui_sso.py +++ b/tests/unit/proxy/management_endpoints/test_ui_sso.py @@ -10,9 +10,9 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -from pydantic import SecretStr import respx from fastapi import HTTPException, Request +from pydantic import SecretStr import litellm from litellm._uuid import uuid @@ -4119,7 +4119,7 @@ class TestCLIKeyRegenerationFlow: cli_state = f"{LITELLM_CLI_SESSION_TOKEN_PREFIX}:cli-new-session-key-456" # Mock the CLI callback and required proxy server components - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( assertion_from_sso_login, ) @@ -9625,7 +9625,7 @@ async def test_redirect_from_openid_persists_assertion_under_canonical_user_id() """The browser funnel persists the captured assertion AFTER canonical user resolution, keyed by the user_id admission will later resolve (the key-generation response user_id), not the raw IdP subject.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( assertion_from_sso_login, ) @@ -9696,7 +9696,7 @@ async def test_redirect_from_openid_persists_the_login_exchanged_assertion(): """A server with ``id_jag_subject_source: refresh_token`` needs the refresh token the login assertion was exchanged for, so the funnel persists what the login-time exchange returns, not the raw capture.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( assertion_from_sso_login, ) @@ -9921,12 +9921,12 @@ async def test_microsoft_login_asks_for_offline_access_only_while_an_id_jag_serv @pytest.mark.asyncio async def test_cli_completion_persists_assertion_under_db_user_id(): """The CLI funnel persists the captured assertion under the DB-resolved user_id.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - assertion_from_sso_login, - ) from litellm.proxy.management_endpoints.ui_sso import ( _complete_cli_sso_callback_session, ) + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + assertion_from_sso_login, + ) assertion = assertion_from_sso_login(_ema_id_token(), None) assert assertion is not None @@ -10041,12 +10041,12 @@ async def test_a_capturing_provider_that_returned_no_id_token_still_warns(monkey @pytest.mark.asyncio async def test_no_warning_when_the_assertion_was_captured(monkeypatch, caplog): - from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - assertion_from_sso_login, - ) from litellm.proxy.management_endpoints.ui_sso import ( warn_if_id_jag_assertion_uncaptured, ) + from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( + assertion_from_sso_login, + ) monkeypatch.setenv("GOOGLE_CLIENT_ID", "cid") assertion = assertion_from_sso_login(_ema_id_token(), None) diff --git a/tests/unit/proxy/management_helpers/test_object_permission_utils.py b/tests/unit/proxy/management_helpers/test_object_permission_utils.py index 33557713162..5814d8d2a97 100644 --- a/tests/unit/proxy/management_helpers/test_object_permission_utils.py +++ b/tests/unit/proxy/management_helpers/test_object_permission_utils.py @@ -19,9 +19,9 @@ from litellm.proxy.management_helpers.object_permission_utils import ( _extract_requested_mcp_access_groups, _extract_requested_mcp_server_ids, _resolve_team_allowed_mcp_servers, - set_object_permission, enforce_all_proxy_mcp_servers_grant_is_admin_only, prepare_object_permission_upsert, + set_object_permission, validate_key_mcp_servers_against_team, validate_key_search_tools_against_team, validate_key_vector_stores_against_team, @@ -277,7 +277,7 @@ def _make_mock_mcp_manager(*existing_ids: str, servers=None): return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -291,7 +291,7 @@ async def test_validate_no_object_permission(mock_access_groups, mock_allow_all) @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "server-2"), ) @patch( @@ -299,7 +299,7 @@ async def test_validate_no_object_permission(mock_access_groups, mock_allow_all) return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -316,7 +316,7 @@ async def test_validate_key_servers_within_team_scope( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "server-outside"), ) @patch( @@ -324,7 +324,7 @@ async def test_validate_key_servers_within_team_scope( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -344,7 +344,7 @@ async def test_validate_key_servers_outside_team_scope_raises( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "global-server"), ) @patch( @@ -352,7 +352,7 @@ async def test_validate_key_servers_outside_team_scope_raises( return_value={"global-server"}, ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -369,7 +369,7 @@ async def test_validate_allow_all_keys_servers_always_allowed( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("global-server"), ) @patch( @@ -377,7 +377,7 @@ async def test_validate_allow_all_keys_servers_always_allowed( return_value={"global-server"}, ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -391,7 +391,7 @@ async def test_validate_no_team_only_allow_all_keys(mock_access_groups, mock_all @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("private-server"), ) @patch( @@ -399,7 +399,7 @@ async def test_validate_no_team_only_allow_all_keys(mock_access_groups, mock_all return_value={"global-server"}, ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -418,7 +418,7 @@ async def test_validate_no_team_non_global_server_raises( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("private-server"), ) @patch( @@ -426,7 +426,7 @@ async def test_validate_no_team_non_global_server_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -444,7 +444,7 @@ async def test_validate_no_team_proxy_admin_can_assign_private_server( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("private-server"), ) @patch( @@ -452,7 +452,7 @@ async def test_validate_no_team_proxy_admin_can_assign_private_server( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -475,7 +475,7 @@ async def test_validate_no_team_non_admin_private_server_still_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -493,7 +493,7 @@ async def test_validate_no_team_proxy_admin_can_assign_access_group( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-1", "server-outside"), ) @patch( @@ -501,7 +501,7 @@ async def test_validate_no_team_proxy_admin_can_assign_access_group( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -522,7 +522,7 @@ async def test_validate_proxy_admin_still_bounded_by_team_scope( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("some-server"), ) @patch( @@ -530,7 +530,7 @@ async def test_validate_proxy_admin_still_bounded_by_team_scope( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -569,7 +569,7 @@ def unified_mcp_prisma() -> Iterator[MagicMock]: manager.get_allow_all_keys_server_ids.return_value = [] with ( patch( # test-quality-ok: management helpers read this module singleton without a registry injection seam - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=manager, ), patch( # test-quality-ok: unified group resolver obtains its cache from the proxy singleton @@ -675,7 +675,7 @@ async def test_team_unified_access_group_without_servers_preserves_direct_grants @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("server-outside"), ) @patch( @@ -683,7 +683,7 @@ async def test_team_unified_access_group_without_servers_preserves_direct_grants return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -703,7 +703,7 @@ async def test_validate_tool_permissions_validated_against_team( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), # empty registry — all IDs are stale ) @patch( @@ -711,7 +711,7 @@ async def test_validate_tool_permissions_validated_against_team( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -735,7 +735,7 @@ async def test_validate_stale_mcp_server_ids_are_silently_dropped( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), # empty registry — all IDs are stale ) @patch( @@ -743,7 +743,7 @@ async def test_validate_stale_mcp_server_ids_are_silently_dropped( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -765,7 +765,7 @@ async def test_validate_stale_ids_in_mcp_tool_permissions_silently_dropped( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), # empty registry — all IDs are stale ) @patch( @@ -773,7 +773,7 @@ async def test_validate_stale_ids_in_mcp_tool_permissions_silently_dropped( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -791,7 +791,7 @@ async def test_validate_stale_mcp_server_ids_are_removed_from_object_permission( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager( "team-server", servers=[ @@ -808,7 +808,7 @@ async def test_validate_stale_mcp_server_ids_are_removed_from_object_permission( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -827,7 +827,7 @@ async def test_validate_mcp_server_alias_outside_team_scope_raises( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager( servers=[ _make_mock_mcp_server( @@ -843,7 +843,7 @@ async def test_validate_mcp_server_alias_outside_team_scope_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -878,7 +878,7 @@ def test_alias_grant_expands_on_other_region_after_save(): _drop_stale_object_permission_mcp_servers(object_permission, {"github-mcp": {"west-id"}}) assert object_permission["mcp_servers"] == ["github-mcp"] - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager expand = MCPServerManager.expand_permission_list assert expand(west_mgr, object_permission["mcp_servers"]) == ["west-id"] @@ -887,7 +887,7 @@ def test_alias_grant_expands_on_other_region_after_save(): @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager(), ) @patch( @@ -895,7 +895,7 @@ def test_alias_grant_expands_on_other_region_after_save(): return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -929,7 +929,7 @@ async def test_validate_db_mcp_server_alias_outside_team_scope_raises_when_regis return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -950,7 +950,7 @@ async def test_validate_access_groups_within_team_scope( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -974,7 +974,7 @@ async def test_validate_access_groups_outside_team_scope_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -997,7 +997,7 @@ async def test_validate_access_groups_no_team_raises( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=["server-from-group"], ) @@ -1018,7 +1018,7 @@ async def test_validate_team_access_groups_resolve_to_servers( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1037,7 +1037,7 @@ async def test_resolve_team_allowed_mcp_servers_string_tool_permissions( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1059,7 +1059,7 @@ async def test_resolve_team_allowed_mcp_servers_dict_tool_permissions( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1081,7 +1081,7 @@ async def test_resolve_team_all_proxy_sentinel_resolves_dynamically(mock_access_ team_perm.mcp_tool_permissions = {} with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ): assert await _resolve_team_allowed_mcp_servers(team_perm) == {"srv-x", "srv-y"} @@ -1096,7 +1096,7 @@ async def test_resolve_team_all_proxy_sentinel_resolves_dynamically(mock_access_ @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("srv-x", "srv-y", "srv-z"), ) @patch( @@ -1104,7 +1104,7 @@ async def test_resolve_team_all_proxy_sentinel_resolves_dynamically(mock_access_ return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1127,7 +1127,7 @@ async def test_validate_key_scoped_to_server_added_after_team_all_proxy( @pytest.mark.asyncio @patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", new=_make_mock_mcp_manager("srv-x", "srv-z"), ) @patch( @@ -1135,7 +1135,7 @@ async def test_validate_key_scoped_to_server_added_after_team_all_proxy( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1278,7 +1278,7 @@ async def test_validate_search_tools_raises_when_not_subset(): return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1301,7 +1301,7 @@ async def test_personal_non_admin_cannot_assign_mcp_toolsets( return_value=set(), ) @patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], ) @@ -1403,7 +1403,7 @@ def _make_grandfather_fixtures(mcp_servers=None, mcp_tool_permissions=None): def _patch_grandfather_env(monkeypatch, mock_mgr): monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ) monkeypatch.setattr( diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/__init__.py b/tests/unit/proxy/mcp_server/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/faults/__init__.py rename to tests/unit/proxy/mcp_server/__init__.py diff --git a/tests/unit/proxy/_experimental/mcp_server/guardrail_translation/__init__.py b/tests/unit/proxy/mcp_server/auth/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/guardrail_translation/__init__.py rename to tests/unit/proxy/mcp_server/auth/__init__.py diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/test_managed_agent_access.py b/tests/unit/proxy/mcp_server/auth/test_managed_agent_access.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/auth/test_managed_agent_access.py rename to tests/unit/proxy/mcp_server/auth/test_managed_agent_access.py index 1524aad5b66..fa4f80a2b96 100644 --- a/tests/unit/proxy/_experimental/mcp_server/auth/test_managed_agent_access.py +++ b/tests/unit/proxy/mcp_server/auth/test_managed_agent_access.py @@ -5,10 +5,10 @@ import pytest from fastapi import HTTPException from litellm.proxy import proxy_server -from litellm.proxy._experimental.mcp_server import mcp_server_manager -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable, UserAPIKeyAuth from litellm.proxy.auth import auth_checks +from litellm.proxy.mcp_server import mcp_server_manager +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler from litellm.types.agents import AgentResponse from litellm.types.proxy.agent_identity import ManagedAgentContext @@ -219,7 +219,7 @@ async def test_autonomous_agent_toolset_and_access_group_revocations_bind_on_the writer revokes a tool or drops the server from the group, the next managed request must be denied even though the legacy cache still holds the warm grant and the replica still shows the old rows""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server import toolset_db + from litellm.proxy.mcp_server import toolset_db warm_toolset: Final = _toolset_row("slack", "read") list_toolsets: Final = AsyncMock(return_value=[warm_toolset]) @@ -285,7 +285,7 @@ async def test_delegated_mcp_uses_explicit_team_grants_even_for_dashboard_admins ) for name in ("slack", "linear") } - from litellm.proxy._experimental.mcp_server import db + from litellm.proxy.mcp_server import db monkeypatch.setattr( db, @@ -322,7 +322,7 @@ async def test_delegated_mcp_uses_explicit_team_grants_even_for_dashboard_admins async def test_explicit_grants_never_fall_back_to_open_servers_on_resolution_failure( monkeypatch: pytest.MonkeyPatch, ) -> None: - from litellm.proxy._experimental.mcp_server import db + from litellm.proxy.mcp_server import db from litellm.types.mcp_server.mcp_server_manager import MCPServer manager: Final = mcp_server_manager.global_mcp_server_manager @@ -339,7 +339,7 @@ async def test_explicit_grants_never_fall_back_to_open_servers_on_resolution_fai @pytest.mark.asyncio async def test_absent_agent_policy_and_missing_delegated_subject_grant_no_servers() -> None: - from litellm.proxy._experimental.mcp_server.auth.managed_agent_access import managed_agent_servers + from litellm.proxy.mcp_server.auth.managed_agent_access import managed_agent_servers assert await managed_agent_servers(UserAPIKeyAuth()) == () auth: Final = actor(None, delegated=True) @@ -367,8 +367,8 @@ async def test_tool_policy_outage_after_server_admission_fails_closed(monkeypatc async def test_manager_preserves_managed_server_grants_across_open_channels( monkeypatch: pytest.MonkeyPatch, role: str | None, scoped: bool ) -> None: - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.types.mcp_server.mcp_server_manager import MCPServer manager: Final = mcp_server_manager.global_mcp_server_manager diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/test_token_endpoint_auth.py b/tests/unit/proxy/mcp_server/auth/test_token_endpoint_auth.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/auth/test_token_endpoint_auth.py rename to tests/unit/proxy/mcp_server/auth/test_token_endpoint_auth.py index 47b5fac23eb..c65e7d4db26 100644 --- a/tests/unit/proxy/_experimental/mcp_server/auth/test_token_endpoint_auth.py +++ b/tests/unit/proxy/mcp_server/auth/test_token_endpoint_auth.py @@ -4,7 +4,7 @@ import base64 import pytest -from litellm.proxy._experimental.mcp_server.auth.token_endpoint_auth import ( +from litellm.proxy.mcp_server.auth.token_endpoint_auth import ( TokenEndpointAuthConfigError, build_token_endpoint_client_auth, normalize_token_endpoint_auth_method, diff --git a/tests/unit/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py b/tests/unit/proxy/mcp_server/auth/test_user_api_key_auth_mcp.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py rename to tests/unit/proxy/mcp_server/auth/test_user_api_key_auth_mcp.py index 16130364364..b7795b4d2f0 100644 --- a/tests/unit/proxy/_experimental/mcp_server/auth/test_user_api_key_auth_mcp.py +++ b/tests/unit/proxy/mcp_server/auth/test_user_api_key_auth_mcp.py @@ -16,12 +16,6 @@ from starlette.datastructures import Headers from litellm.caching.caching import DualCache from litellm.constants import MCP_ALL_TOOLS_WILDCARD from litellm.models.access_group import LiteLLM_AccessGroupTable -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - UnloadableEntitlementError, - _agent_capped_servers, - is_mcp_admitted_user_subject, -) from litellm.proxy._types import ( UI_TEAM_ID, LiteLLM_ObjectPermissionTable, @@ -32,6 +26,12 @@ from litellm.proxy._types import ( SpecialMCPServerNames, UserAPIKeyAuth, ) +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + UnloadableEntitlementError, + _agent_capped_servers, + is_mcp_admitted_user_subject, +) from litellm.types.agents import AgentCaller @@ -376,7 +376,7 @@ class TestMCPRequestHandler: def _real_manager_with_toolsets(self, toolset_perms): """A real MCPServerManager so the real expand_tool_permissions runs; only the DB-backed toolset lookup is stubbed""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() manager.resolve_toolset_tool_permissions = AsyncMock(return_value=toolset_perms) @@ -392,7 +392,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -413,7 +413,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -433,7 +433,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -458,7 +458,7 @@ class TestMCPRequestHandler: with ( patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object(MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[])), @@ -483,7 +483,7 @@ class TestMCPRequestHandler: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -507,7 +507,7 @@ class TestMCPRequestHandler: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -539,7 +539,7 @@ class TestMCPRequestHandler: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -620,7 +620,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -654,7 +654,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -706,7 +706,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -740,7 +740,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -760,7 +760,7 @@ class TestMCPRequestHandler: with ( patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -798,7 +798,7 @@ class TestMCPRequestHandler: AsyncMock(return_value=[]), ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -835,7 +835,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: stub the level's perm loader; the resolver reads module globals with no injection seam @@ -872,7 +872,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: stub the level's perm loader; the resolver reads module globals with no injection seam @@ -915,7 +915,7 @@ class TestMCPRequestHandler: AsyncMock(return_value=[]), ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -944,7 +944,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_org_object_permission", AsyncMock(return_value=org_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -974,7 +974,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -995,7 +995,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_user_object_permission", AsyncMock(return_value=user_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1026,7 +1026,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1054,7 +1054,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=team_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1079,7 +1079,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1101,7 +1101,7 @@ class TestMCPRequestHandler: MCPRequestHandler, "get_mcp_servers_from_access_groups", AsyncMock(return_value=[]) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1254,7 +1254,7 @@ class TestMCPRequestHandler: "litellm.proxy.auth.auth_checks.get_mcp_server_ids_from_access_groups", new=AsyncMock(return_value=[]), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): result = await MCPRequestHandler._get_key_access_group_mcp_server_extras(auth) assert result == [] @@ -1269,7 +1269,7 @@ class TestMCPRequestHandler: "litellm.proxy.auth.auth_checks.get_mcp_server_ids_from_access_groups", new=AsyncMock(return_value=["alias-a", "srv-b"]), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.expand_permission_list.return_value = ["srv-a", "srv-b"] result = await MCPRequestHandler._get_key_access_group_mcp_server_extras(auth) @@ -1426,7 +1426,7 @@ class TestMCPRequestHandler: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ): # Call the method @@ -1600,7 +1600,7 @@ class TestMCPRequestHandler: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" ) as mock_user_api_key_auth: mock_user_api_key_auth.return_value = mock_auth_result @@ -1686,11 +1686,11 @@ class TestMCPOAuth2AuthFlow: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id="admitted-user"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = oauth2_server ( @@ -1726,7 +1726,7 @@ class TestMCPOAuth2AuthFlow: return UserAPIKeyAuth(api_key=api_key, user_id="test-user") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: ( @@ -1765,7 +1765,7 @@ class TestMCPOAuth2AuthFlow: with ( patch( # test-quality-ok: capturing the exact api_key handed to key validation is the regression under test - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth ): @@ -1793,7 +1793,7 @@ class TestMCPOAuth2AuthFlow: return UserAPIKeyAuth(api_key=api_key, user_id="test-user") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: ( @@ -1831,7 +1831,7 @@ class TestMCPOAuth2AuthFlow: raise HTTPException(status_code=500, detail="Internal server error") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_server_error, ): with pytest.raises(HTTPException) as exc_info: @@ -1882,10 +1882,10 @@ class TestMCPOAuth2AuthFlow: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_proxy_exception, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = oauth2_server with pytest.raises(HTTPException) as exc_info: @@ -1921,7 +1921,7 @@ class TestMCPOAuth2AuthFlow: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_500, ): with pytest.raises(ProxyException): @@ -1956,10 +1956,10 @@ class TestMCPPublicRouteGuard: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): # Explicit unresolvable target — proves auth still fails even # when the registry has no info to fall back to. @@ -1987,10 +1987,10 @@ class TestMCPPublicRouteGuard: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2011,7 +2011,7 @@ class TestMCPPublicRouteGuard: # No mock needed — public path should not call user_api_key_auth at all with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", ) as mock_auth: auth_result, *_rest = await MCPRequestHandler.process_mcp_request(scope) mock_auth.assert_not_called() @@ -2041,12 +2041,12 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp._is_mcp_passthrough_cold_start" + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp._is_mcp_passthrough_cold_start" ) as mock_cold_start, ): mock_mgr.get_mcp_server_by_name.return_value = ( @@ -2081,10 +2081,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2109,10 +2109,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2137,14 +2137,14 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.10", ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2168,10 +2168,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_forbidden, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2201,10 +2201,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_server_error, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2227,10 +2227,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2260,10 +2260,10 @@ class TestMCPPassthroughColdStartAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ( TestMCPPassthroughColdStartAdmission._make_passthrough_server() @@ -2312,10 +2312,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPOAuth2FallbackTargetGating._make_server( MCPAuth.api_key @@ -2343,10 +2343,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2381,10 +2381,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPOAuth2FallbackTargetGating._make_server( MCPAuth.oauth2 @@ -2418,10 +2418,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPOAuth2FallbackTargetGating._make_server( auth_type=MCPAuth.none, @@ -2446,14 +2446,14 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.10", ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2497,10 +2497,10 @@ class TestMCPOAuth2FallbackTargetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup with pytest.raises(HTTPException) as exc_info: @@ -2533,7 +2533,7 @@ class TestMCPOAuth2FallbackTargetGating: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_no_code, ): with pytest.raises(ProxyException): @@ -2563,7 +2563,7 @@ class TestMCPDelegateAuthToUpstream: ) def test_legacy_delegate_cold_start_fails_closed_without_targets(self): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_legacy_delegate_cold_start, ) @@ -2571,7 +2571,7 @@ class TestMCPDelegateAuthToUpstream: def test_build_mcp_server_table_preserves_delegate_auth_to_upstream(self): """Registry → API list rows must expose delegate_auth_to_upstream for the UI.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -2598,7 +2598,7 @@ class TestMCPDelegateAuthToUpstream: distinct from ``delegate_auth_to_upstream`` (oauth2-only). Both must round-trip independently so neither flag silently implies the other. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -2638,11 +2638,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="No key provided"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2668,11 +2668,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid API key"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2705,10 +2705,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2740,10 +2740,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.api_key, @@ -2788,10 +2788,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup with pytest.raises(HTTPException) as exc_info: @@ -2818,10 +2818,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = None with pytest.raises(HTTPException) as exc_info: @@ -2846,11 +2846,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id="real-user"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2878,11 +2878,11 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id="real-user"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.oauth2, @@ -2936,10 +2936,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = m2m_server # No delegate bypass → normal auth is attempted → 401 raised @@ -2987,10 +2987,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = legacy_m2m_server with pytest.raises(HTTPException) as exc_info: @@ -3029,10 +3029,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = pkce_server auth, *_rest = await MCPRequestHandler.process_mcp_request(scope) @@ -3069,10 +3069,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = internal_server auth, *_rest = await MCPRequestHandler.process_mcp_request(scope) @@ -3081,7 +3081,7 @@ class TestMCPDelegateAuthToUpstream: async def test_get_allowed_servers_excludes_legacy_delegates(self): """Legacy delegated servers are never added to anonymous access.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -3134,10 +3134,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = TestMCPDelegateAuthToUpstream._make_server( auth_type=MCPAuth.true_passthrough, @@ -3180,10 +3180,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup with pytest.raises(HTTPException) as exc_info: @@ -3192,7 +3192,7 @@ class TestMCPDelegateAuthToUpstream: async def test_get_allowed_servers_includes_true_passthrough(self): """Anonymous callers can reach true_passthrough servers; admission is delegated upstream.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -3230,7 +3230,7 @@ class TestMCPDelegateAuthToUpstream: allow-list which can include ``allow_all_keys`` servers that normally require a LiteLLM key. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_mcp_servers_in_path, ) @@ -3307,10 +3307,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = lookup_by_name with pytest.raises(HTTPException) as exc_info: @@ -3370,10 +3370,10 @@ class TestMCPDelegateAuthToUpstream: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_auth_raises, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.side_effect = lookup_by_name # Bypass MUST NOT fire — path-derived target is the non-delegate @@ -3568,7 +3568,7 @@ class TestMCPCustomHeaderName: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: # Call the method @@ -3737,7 +3737,7 @@ class TestMCPAccessGroupsE2E: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: # Call the method @@ -3786,7 +3786,7 @@ class TestMCPAccessGroupsE2E: ) with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth: # Call the method @@ -3811,7 +3811,7 @@ class TestMCPAccessGroupsE2E: def test_mcp_path_based_server_segregation(monkeypatch): # Import the MCP server FastAPI app and context getter - from litellm.proxy._experimental.mcp_server.server import app, get_auth_context + from litellm.proxy.mcp_server.server import app, get_auth_context captured_mcp_servers = {} @@ -3848,21 +3848,21 @@ def test_mcp_path_based_server_segregation(monkeypatch): ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", MagicMock(handle_request=dummy_handle_request), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", MagicMock(handle_request=dummy_handle_request), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server.initialize_session_managers", + "litellm.proxy.mcp_server.server.initialize_session_managers", AsyncMock(), ) # Patch user_api_key_auth to always return a dummy user monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", AsyncMock(return_value=UserAPIKeyAuth(api_key="test", user_id="user")), ) @@ -4121,10 +4121,10 @@ async def test_get_allowed_mcp_servers_for_team_uses_helper(): object_permission fields (mcp_servers, mcp_access_groups) and the unified team.access_group_ids → access_mcp_server_ids path. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4309,10 +4309,10 @@ async def test_get_allowed_mcp_servers_for_key_returns_empty_when_db_returns_non async def test_get_allowed_mcp_servers_for_key_prefers_in_memory_permission(): """Ensure in-memory object_permission is used without hitting the DB.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4597,8 +4597,8 @@ class TestAgentMCPPermissions: mock_agent.assert_called_once_with(user_api_key_auth) async def test_agent_access_group_server_ceiling_expands_group_servers(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.agent_endpoints.auth.agent_access_groups import AgentAccessGroupCeiling + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4733,7 +4733,7 @@ class TestAgentMCPPermissions: MCPRequestHandler, "_get_agent_object_permission", AsyncMock(return_value=agent_object_permission) ), patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling toolset tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), patch.object( # test-quality-ok: access-group lookup hits the DB, not under test here @@ -4945,7 +4945,7 @@ async def test_tool_permission_servers_included_in_allowed_servers(): Regression test for https://github.com/BerriAI/litellm/issues/21954 """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPTransport @@ -5101,7 +5101,7 @@ class TestOrgMCPPermissions: async def test_get_org_object_permission_no_prisma(self): auth = self._make_auth(org_id="org-123") with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_org_object_permission", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_org_object_permission", new_callable=AsyncMock, return_value=None, ): @@ -5326,7 +5326,7 @@ async def test_mcp_key_access_group_extras_when_team_authorized(): return_value=fake_ag, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ), ] @@ -5363,7 +5363,7 @@ async def test_mcp_key_access_group_extras_when_key_directly_authorized(): return_value=fake_ag, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_mgr, ), ] @@ -5599,10 +5599,10 @@ async def test_team_access_group_ids_resolve_to_mcp_servers(): async def test_team_access_group_ids_union_with_object_permission(): """When both legacy object_permission and unified team.access_group_ids grant MCP servers, the final list is their union.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5760,10 +5760,10 @@ async def test_allowed_mcp_servers_for_key_uses_object_permission_not_access_gro also carries access_group_ids that would resolve to other servers, those grants do NOT enter this (intersected) scope — only the object_permission server comes back. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5841,10 +5841,10 @@ def test_expand_permission_list_does_not_honor_all_proxy_sentinel(): downstream). Concrete ids still resolve normally. If the sentinel were expanded here, any stored key/org/end_user permission holding it would silently gain every server.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import SpecialMCPServerName + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import SpecialMCPServerName from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5874,14 +5874,14 @@ async def test_get_allowed_mcp_servers_for_team_expands_all_proxy_sentinel_dynam registry without any change to its stored permission. Reverting the team-side expansion collapses this to the inert literal and the result no longer contains the real servers.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, SpecialMCPServerName, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5952,13 +5952,13 @@ async def test_key_with_all_proxy_sentinel_does_not_grant_all_servers(): teamless key with the sentinel resolves to no real server — never srv-secret or the full registry. On the pre-hardening code the key path expanded the sentinel and this key would reach srv-secret.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, SpecialMCPServerName, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -6000,14 +6000,14 @@ async def test_get_allowed_mcp_servers_team_all_proxy_key_scoped_to_one_end_to_e exactly that server (key ∩ all-servers == key). If the sentinel branch is reverted the team ceiling collapses to the literal marker, the intersection empties, and the result is [] instead of ["srv-x"].""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - global_mcp_server_manager, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, SpecialMCPServerName, ) + from litellm.proxy.mcp_server.mcp_server_manager import ( + global_mcp_server_manager, + ) from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -6121,10 +6121,10 @@ class TestMCPDcrBridgeDelegateAdmission: ): from pydantic import SecretStr - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( SealedEnvelope, UpstreamTokenGrant, key_hash_identity, @@ -6281,7 +6281,7 @@ class TestMCPDcrBridgeDelegateAdmission: server.alias = None with patch( # test-quality-ok: isolate the MCP registry when testing target selection - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr: mock_mgr.get_mcp_server_by_name.return_value = server assert ( @@ -6303,11 +6303,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: observe the auth boundary while testing admission orchestration - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -6342,12 +6342,12 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: force credential rejection through request admission - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid key"), ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -6372,10 +6372,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key()) as get_key_object, ): @@ -6418,10 +6418,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( return_value=MagicMock( @@ -6461,10 +6461,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( return_value=MagicMock( @@ -6497,7 +6497,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload(side_effect=self._wrapped_user_lookup_error(Exception())), ): @@ -6521,7 +6521,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( side_effect=self._wrapped_user_lookup_error(ConnectionError("auth database unreachable")) @@ -6552,7 +6552,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling admission tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: the envelope opener reads master_key off the proxy module, no injection seam "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -6583,7 +6583,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_user_reload( return_value=MagicMock(user_id="offboarded-user", organization_id=None, metadata={"scim_active": False}) @@ -6617,10 +6617,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), revoked, ): @@ -6642,7 +6642,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(blocked=True)), ): @@ -6665,7 +6665,7 @@ class TestMCPDcrBridgeDelegateAdmission: expired_at = datetime.now(timezone.utc) - timedelta(hours=1) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(expires=expired_at)), ): @@ -6688,7 +6688,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(), team_blocked=True), ): @@ -6712,7 +6712,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload( return_value=self._reloaded_key(), @@ -6738,7 +6738,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload( return_value=self._reloaded_key(), @@ -6765,7 +6765,7 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload( return_value=self._reloaded_key(project_id="project-restricted"), @@ -6778,7 +6778,7 @@ class TestMCPDcrBridgeDelegateAdmission: assert exc_info.value.status_code == 401 - _POLICY_GATE = "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.run_centralized_common_checks" + _POLICY_GATE = "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.run_centralized_common_checks" async def _enforce_with_gate_error(self, error): """Drive _enforce_admitted_live_policy with the centralized gate raising ``error`` and return @@ -6820,7 +6820,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(side_effect=ConnectionError("could not reach database server")), ): @@ -6864,9 +6864,9 @@ class TestMCPDcrBridgeDelegateAdmission: [(True, "scoped", []), (False, "scoped", ["public"]), (True, "unscoped", ["public"])], ) async def test_master_envelope_respects_allow_all_scope(self, flag_enabled, scope, expected): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import hash_token + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() with patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY): @@ -6902,7 +6902,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key(allowed_routes=["/chat/completions"])), ): @@ -6926,7 +6926,7 @@ class TestMCPDcrBridgeDelegateAdmission: "headers": [(b"authorization", f"Bearer {envelope}".encode("latin-1"))], } with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch("litellm.proxy.proxy_server.general_settings", {"allowed_routes": ["/chat/completions"]}), ): @@ -6961,10 +6961,10 @@ class TestMCPDcrBridgeDelegateAdmission: } with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._patch_key_reload(return_value=self._reloaded_key()), ): @@ -7015,7 +7015,7 @@ class TestMCPDcrBridgeDelegateAdmission: ``lookup_mcp_server_auth_in_headers`` called the way egress calls it (alias first, then server_name) must recover exactly that token. This pins the agreement between the two key hierarchies so neither side can drift and silently drop the forwarded token.""" - from litellm.proxy._experimental.mcp_server.utils import lookup_mcp_server_auth_in_headers + from litellm.proxy.mcp_server.utils import lookup_mcp_server_auth_in_headers envelope = self._mint_bridge_envelope() server = self._bridge_delegate_server(server_name=server_name, alias=alias) @@ -7054,11 +7054,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid key"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server(server_name=None, alias=None) @@ -7086,10 +7086,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7122,10 +7122,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7157,10 +7157,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7194,11 +7194,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: prove standard admission is never consulted for an envelope bearer - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry, same seam as the sibling challenge tests - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: envelope keys derive from the proxy master_key module global "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -7233,11 +7233,11 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=401, detail="Invalid key"), ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7264,12 +7264,12 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: supply standard key admission through the auth boundary - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=admitted, ) as mock_auth, patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: configure key classification for the orchestration test "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -7299,12 +7299,12 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( # test-quality-ok: force a non-401 auth result through request admission - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, side_effect=HTTPException(status_code=403, detail="Key blocked"), ), patch( # test-quality-ok: isolate the MCP registry used by request admission - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch( # test-quality-ok: configure key classification for the orchestration test "litellm.proxy.proxy_server.master_key", self._MASTER_KEY @@ -7339,10 +7339,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server() @@ -7379,10 +7379,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.return_value = self._bridge_delegate_server( @@ -7421,10 +7421,10 @@ class TestMCPDcrBridgeDelegateAdmission: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", side_effect=mock_user_api_key_auth_fails, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): mock_mgr.get_mcp_server_by_name.side_effect = mock_lookup @@ -7554,7 +7554,7 @@ class TestMCPDcrBridgeDualCredential: ) with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new=AsyncMock(return_value=self._DELEGATE._reloaded_key()), ), patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), @@ -7583,11 +7583,11 @@ class TestMCPDcrBridgeDualCredential: presented_token = "aaa.bbb.ccc" if mapped_jwt else "sk-explicit-key" with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=explicit_auth, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._DELEGATE._patch_key_reload() as get_key_object, ): @@ -7618,11 +7618,11 @@ class TestMCPDcrBridgeDualCredential: envelope = self._DELEGATE._mint_bridge_envelope(key_hash=self._KEY_HASH) with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=self._DELEGATE._reloaded_key(api_key="a-different-key-hash"), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._DELEGATE._patch_key_reload(), ): @@ -7640,12 +7640,12 @@ class TestMCPDcrBridgeDualCredential: envelope = self._DELEGATE._mint_bridge_envelope(user_id="sso-user-7") with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=UserAPIKeyAuth(user_id=presented_user, api_key="any-hash"), ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), ): @@ -7677,11 +7677,11 @@ class TestMCPDcrBridgeDualCredential: tampered = envelope[:-4] + "AAAA" with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, return_value=self._DELEGATE._reloaded_key(), ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), self._DELEGATE._patch_key_reload(), ): @@ -7703,8 +7703,8 @@ def test_gateway_challenge_metadata_contains_the_public_resource( from starlette.requests import Request from starlette.types import Scope - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import _gateway_dcr_challenge - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import _gateway_dcr_challenge + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_aggregate_protected_resource_response, oauth_protected_resource_root, ) @@ -7741,7 +7741,7 @@ class TestAggregateGatewayDcrChallenge: own protected-resource metadata, and must NOT fire for named-server targets, explicit litellm keys, or non-401 failures.""" - _AUTH_PATCH_TARGET = "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" + _AUTH_PATCH_TARGET = "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth" _EXPECTED_RESOURCE_METADATA = 'resource_metadata="http://testserver/.well-known/oauth-protected-resource/mcp"' def _scope(self, path="/mcp", extra_headers=()): @@ -7880,7 +7880,7 @@ class TestAggregateGatewayDcrChallenge: ) with ( patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, ): manager.get_mcp_server_by_identifier.side_effect = lambda identifier, client_ip=None: { "alpha": alpha, @@ -7925,7 +7925,7 @@ class TestAggregateGatewayDcrChallenge: with ( patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = server @@ -7973,7 +7973,7 @@ class TestAggregateGatewayDcrChallenge: patch.dict(os.environ, {"SERVER_ROOT_PATH": "/litellm"}), patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = server @@ -8006,7 +8006,7 @@ class TestAggregateGatewayDcrChallenge: with ( patch(self._AUTH_PATCH_TARGET, side_effect=self._auth_401()), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = resolved @@ -8018,7 +8018,7 @@ class TestAggregateGatewayDcrChallenge: def test_challenge_target_excludes_every_non_gateway_managed_mode(self): """Gateway challenges exclude unresolved, delegated, and client-forwarded targets.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _gateway_dcr_challenge_target, ) from litellm.types.mcp import MCPAuth @@ -8053,13 +8053,13 @@ class TestAggregateGatewayDcrChallenge: ] for resolved, expected in cases: with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" ) as mock_mgr: mock_mgr.get_mcp_server_by_identifier.return_value = resolved assert _gateway_dcr_challenge_target("/mcp/srv", None, None) == expected, resolved assert _gateway_dcr_challenge_target("/mcp/a,b", None, None) is None assert _gateway_dcr_challenge_target("/mcp", None, None) is None - with patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr: + with patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr: mock_mgr.get_mcp_server_by_identifier.return_value = _server(MCPAuth.oauth2) assert _gateway_dcr_challenge_target("/mcp/srv", ["other"], None) is None @@ -8108,10 +8108,10 @@ class TestGatewaySessionAdmission: _MASTER_KEY = "sk-gateway-session-admission-master-key" def _session_bearer(self, user_id="sso-user-42", client_id="llm_dcrc_abc"): - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( session_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( + from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SessionPrincipal, mint_session_refresh_token, mint_session_token, @@ -8168,7 +8168,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="org-user", organization_id="org-123"), @@ -8185,7 +8185,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="rl-user", tpm_limit=1000, rpm_limit=50), @@ -8199,7 +8199,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, self._patch_user_reload(user_id="sso-user-42") as get_user_object, @@ -8250,7 +8250,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="offboarded-user", active=False), @@ -8268,7 +8268,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="sso-user-42"), @@ -8301,7 +8301,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, self._patch_user_reload(user_id="sso-user-42"), @@ -8333,7 +8333,7 @@ class TestGatewaySessionAdmission: ) with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = server with pytest.raises(HTTPException) as exc_info: @@ -8353,7 +8353,7 @@ class TestGatewaySessionAdmission: with ( patch("litellm.proxy.proxy_server.master_key", self._MASTER_KEY), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), self._patch_user_reload(user_id="sso-user-42"), @@ -8441,7 +8441,7 @@ class TestUserSubjectTeamUnion: async def test_toolsets_of_a_team_that_dropped_the_user_from_its_roster_are_not_granted(self): """The user's cached team list still names team-revoked, but its live roster no longer lists the user, so its toolset is withheld exactly as its servers are on the aggregate /mcp.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import granted_toolset_ids + from litellm.proxy.mcp_server.ui_session_utils import granted_toolset_ids teams = { "team-kept": _make_team("team-kept", [], toolsets=["ts-kept"]), @@ -8455,7 +8455,7 @@ class TestUserSubjectTeamUnion: async def test_a_pinned_toolset_narrows_every_source_to_the_toolset_servers_and_tools(self): """On /toolset/{name}/mcp the admitted subject carries mcp_toolset_id; team-a's grant on srv1 and srv2 with every tool collapses to the toolset's srv1 and its one tool, and team-b's srv3 drops.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager teams = {"team-a": _make_team("team-a", ["srv1", "srv2"]), "team-b": _make_team("team-b", ["srv3"])} auth = _make_admitted_subject("sso-user") @@ -8478,7 +8478,7 @@ class TestUserSubjectTeamUnion: async def test_a_fresh_policy_pinned_toolset_bypasses_the_toolset_permission_cache(self): """A session admitted under requires_fresh_policy reads the pinned toolset from the writer, so a tool revoked from the toolset is gone on the very next request (Devin Review 4150024092).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager teams = {"team-a": _make_team("team-a", ["srv1", "srv2"])} auth = _make_admitted_subject("sso-user") @@ -8646,7 +8646,7 @@ class TestUserSubjectTeamUnion: assert billed is None, "and billing agrees: the user is billed, not a team" def _manager_with(self, server_ids, allow_all=()): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8688,7 +8688,7 @@ class TestUserSubjectTeamUnion: server = MagicMock(server_id="srv1") with self._patch(teams_by_id={"t-grant": t_grant}, user_teams=["t-grant"]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.get_mcp_server_from_tool_name", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.get_mcp_server_from_tool_name", MagicMock(return_value=server), ): billed = await MCPRequestHandler.billing_auth_for_tool_call( @@ -8744,7 +8744,7 @@ class TestUserSubjectTeamUnion: boom = AsyncMock(side_effect=RuntimeError("toolset resolution exploded")) with self._patch(teams_by_id=teams, user_teams=["t1"]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.resolve_toolset_tool_permissions", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.resolve_toolset_tool_permissions", boom, ): tools = await MCPRequestHandler.get_allowed_tools_for_server("srv1", auth) @@ -8867,7 +8867,7 @@ class TestUserSubjectTeamUnion: plain = _make_admitted_subject("plain-user") with self._patch(teams_by_id={}, user_teams=[]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", AsyncMock(return_value=set()), ): admin_tools = await MCPRequestHandler.get_allowed_tools_for_server("srv-any", admin) @@ -8912,7 +8912,7 @@ class TestUserSubjectTeamUnion: open_ids = AsyncMock(return_value={"srv-open"}) with self._patch(teams_by_id={}, user_teams=[]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", open_ids, ): tools = await MCPRequestHandler.get_allowed_tools_for_server("srv-open", auth) @@ -8927,7 +8927,7 @@ class TestUserSubjectTeamUnion: open_ids = AsyncMock(return_value={"srv-open"}) with self._patch(teams_by_id={}, user_teams=[]): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.operator_open_server_ids", open_ids, ): open_tools = await MCPRequestHandler.get_allowed_tools_for_server("srv-open", auth) @@ -9290,7 +9290,7 @@ class TestAdmittedSubjectPerTeamOrgCap: patch("litellm.proxy.proxy_server.proxy_logging_obj", MagicMock()), ] if registry is not None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -9585,10 +9585,10 @@ class TestSessionBearerEgressScrub: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ) as mock_auth, - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ttp_server (_auth, _mah, _srv, _sah, oauth2_headers, raw_headers) = await MCPRequestHandler.process_mcp_request(scope) @@ -9613,10 +9613,10 @@ class TestSessionBearerEgressScrub: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.user_api_key_auth", new_callable=AsyncMock, ), - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as mock_mgr, ): mock_mgr.get_mcp_server_by_name.return_value = ttp_server (_auth, _mah, _srv, _sah, oauth2_headers, _raw) = await MCPRequestHandler.process_mcp_request(scope) @@ -10296,7 +10296,7 @@ class TestUserMCPEntitlement: async def test_tool_call_is_rejected_at_call_time(self): """The end-to-end contract: a tool the human is not entitled to is refused when INVOKED, not merely hidden from the advertised list.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPTransport @@ -10348,7 +10348,7 @@ class TestUserMCPEntitlement: async def test_servers_named_only_under_tool_permissions_are_entitled(self): """Granting one tool on a server entitles the human to that server, so an admin never has to name it twice.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPTransport @@ -10778,10 +10778,10 @@ class TestScopedSessionAdmission: def _bearer(self, resource_server_ids): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( session_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( + from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SessionPrincipal, mint_session_token, ) @@ -10858,7 +10858,7 @@ async def test_fresh_mcp_user_permission_link_ignores_cached_and_replica_grants( @pytest.mark.asyncio @pytest.mark.parametrize("operation", ["servers", "tools"]) async def test_managed_agent_permission_resolution_outage_is_not_an_unrestricted_grant(monkeypatch, operation): - from litellm.proxy._experimental.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server import mcp_server_manager from litellm.types.agents import AgentResponse auth = UserAPIKeyAuth(agent_id="managed") @@ -11006,7 +11006,7 @@ async def test_catalog_refresh_uses_current_virtual_key_policy_and_keeps_session @pytest.mark.asyncio async def test_admission_request_body_serves_stashed_peek_callable(): from litellm.constants import MCP_PEEKED_BODY_SCOPE_KEY - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import _admission_request + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import _admission_request admission_body: Final = b'{"method":"tools/list"}' @@ -11422,7 +11422,7 @@ class TestAccessGroupToolOwnershipAndFaults: assert await MCPRequestHandler.get_allowed_tools_for_server("srv", auth) == ["read"] async def test_legacy_tag_carried_by_the_server_keeps_the_key_unrestricted(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -11684,11 +11684,11 @@ async def test_token_minted_credential_lists_tools_for_every_scope_shape(monkeyp from mcp.types import ListToolsRequest, ListToolsResult, Tool from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.id_jag_grant import SubjectTokenRefusal, granted_scope - from litellm.proxy._experimental.mcp_server.operations import GatewayOperations, prepare_context from litellm.proxy._types import MCPTransport from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.id_jag_grant import SubjectTokenRefusal, granted_scope + from litellm.proxy.mcp_server.operations import GatewayOperations, prepare_context from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("LITELLM_SALT_KEY", "sk-session-credential-tools-list") @@ -11768,9 +11768,9 @@ def personal_key_owner_teams(monkeypatch: pytest.MonkeyPatch, request: pytest.Fi srv-open (``allow_all_keys``, granted to no team).""" import litellm from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import LiteLLM_UserTable from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -11821,8 +11821,8 @@ async def test_personal_key_mcp_servers_are_the_union_of_its_owner_team_grants( async def test_personal_key_mcp_listing_applies_agent_caller_ceiling( personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.proxy.agent_endpoints.auth.agent_caller import agent_caller_from_headers + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess auth: Final = personal_key_owner_teams.model_copy(update={"agent_id": "agent-1"}) caller: Final = agent_caller_from_headers( @@ -11863,9 +11863,9 @@ async def test_personal_key_tool_call_bills_granting_team( ) -> None: from litellm.models.budget import LiteLLM_BudgetTable from litellm.models.team_membership import LiteLLM_TeamMembership - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix team_membership: Final = LiteLLM_TeamMembership( user_id=personal_key_owner_teams.user_id, @@ -11923,9 +11923,9 @@ async def test_personal_key_mcp_billing_preserves_key_organization( team_org_id: str | None, expected_org_id: str, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return LiteLLM_TeamTable( @@ -11958,8 +11958,8 @@ async def test_personal_key_mcp_billing_preserves_key_organization( async def test_personal_key_display_name_billing_uses_original_tool_grant( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = global_mcp_server_manager.registry["srv-a"].model_copy( update={ @@ -11986,8 +11986,8 @@ async def test_personal_key_display_name_billing_uses_allowed_servers( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -12035,9 +12035,9 @@ async def test_personal_key_display_name_billing_uses_allowed_servers( async def test_personal_key_tool_call_bills_lowest_team_when_both_allow( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools(team_id, ("multiply",)) @@ -12056,8 +12056,8 @@ async def test_personal_key_tool_call_bills_lowest_team_when_both_allow( async def test_personal_key_attribution_preserves_hyphenated_native_tool_names( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools( @@ -12087,8 +12087,8 @@ async def test_personal_key_guardrail_auth_preserves_native_tool_name_matching_s monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools( @@ -12117,9 +12117,9 @@ async def test_personal_key_mcp_billing_inherits_adopted_organization_limits( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: from litellm.models.budget import LiteLLM_BudgetTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_OrganizationTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager organization: Final = LiteLLM_OrganizationTable( organization_id="org-1", @@ -12167,9 +12167,9 @@ async def test_personal_key_mcp_billing_keeps_key_organization_limits( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: from litellm.models.budget import LiteLLM_BudgetTable - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_OrganizationTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager organization: Final = LiteLLM_OrganizationTable( organization_id="org-1", @@ -12204,10 +12204,10 @@ async def test_personal_key_mcp_billing_keeps_key_organization_limits( async def test_personal_key_mcp_billing_keeps_team_controls_when_org_lookup_fails( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy import proxy_server from litellm.proxy.auth import auth_checks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools(team_id, ("divide",)).model_copy( @@ -12253,10 +12253,10 @@ async def test_personal_key_mcp_billing_keeps_team_id_when_membership_lookup_fai monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy import proxy_server from litellm.proxy.auth import auth_checks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team_granting_tools(team_id, ("divide",)) @@ -12307,9 +12307,9 @@ async def test_personal_key_mcp_billing_uses_fresh_team_and_membership_for_stric from litellm.models.budget import LiteLLM_BudgetTable from litellm.models.team_membership import LiteLLM_TeamMembership from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **kwargs: object) -> LiteLLM_TeamTable: database_value: Final = bool(kwargs.get("check_db_only")) @@ -12361,12 +12361,12 @@ async def test_personal_key_mcp_billing_uses_fresh_team_and_membership_for_stric async def test_personal_key_team_mcp_rpm_limit_charges_granting_team( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks from litellm.proxy.hooks.parallel_request_limiter_v3 import ( PROXY_MaxParallelRequestsHandler_v3, RateLimitDescriptor, ) + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: team: Final = _personal_key_team_granting_tools(team_id, ("divide",) if team_id == "team-a" else ("multiply",)) @@ -12532,8 +12532,8 @@ async def test_personal_key_unreadable_team_permission_is_not_a_server_or_billin monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess async def _unreadable_team(team_id: str, **_: object) -> LiteLLM_TeamTable: return LiteLLM_TeamTable( @@ -12558,8 +12558,8 @@ async def test_personal_key_team_server_access_group_read_fault_stays_scoped( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess async def _team_with_access_group(team_id: str, **_: object) -> LiteLLM_TeamTable: return LiteLLM_TeamTable(team_id=team_id, access_group_ids=["unreadable-group"]) @@ -12583,9 +12583,9 @@ async def test_personal_key_scoped_bare_tool_name_bills_granting_team( monkeypatch: pytest.MonkeyPatch, personal_key_owner_teams: UserAPIKeyAuth, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy import proxy_server from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: return _personal_key_team(team_id).model_copy( @@ -12624,8 +12624,8 @@ async def test_personal_key_prefixed_tool_billing_resolves_server_without_loaded personal_key_owner_teams: UserAPIKeyAuth, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -12674,8 +12674,8 @@ async def test_personal_key_scoped_tool_billing_prefers_scoped_server( personal_key_owner_teams: UserAPIKeyAuth, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def _get_team_object(team_id: str, **_: object) -> LiteLLM_TeamTable: server_id: Final = "srv-a" if team_id == "team-a" else "srv-b" diff --git a/tests/unit/proxy/_experimental/mcp_server/conftest.py b/tests/unit/proxy/mcp_server/conftest.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/conftest.py rename to tests/unit/proxy/mcp_server/conftest.py index de7ed4d45e8..da5b7d8d9a3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/conftest.py +++ b/tests/unit/proxy/mcp_server/conftest.py @@ -70,7 +70,7 @@ def pytest_collection_modifyitems(config, items): @pytest.fixture def config_only_mcp_manager_factory(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager class ConfigOnlyManager(MCPServerManager): def initialize_tool_name_to_mcp_server_name_mapping(self): @@ -81,13 +81,11 @@ def config_only_mcp_manager_factory(): @pytest.fixture(autouse=True) def _hermetic_mcp_server_registry(): - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots - - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry saved_tools = global_mcp_tool_registry.published_tools global_mcp_tool_registry.published_tools = {} diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/__init__.py b/tests/unit/proxy/mcp_server/faults/__init__.py similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/__init__.py rename to tests/unit/proxy/mcp_server/faults/__init__.py diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_classify.py b/tests/unit/proxy/mcp_server/faults/test_classify.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_classify.py rename to tests/unit/proxy/mcp_server/faults/test_classify.py index 30107db4055..33b5632cf23 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_classify.py +++ b/tests/unit/proxy/mcp_server/faults/test_classify.py @@ -3,19 +3,19 @@ code and whose credentials the gateway presented, never on the upstream's HTTP s from typing import Final -import pytest import httpx +import pytest -from litellm.proxy._experimental.mcp_server.faults.classify import ( +from litellm.proxy.mcp_server.faults.classify import ( classify_upstream_dcr_rejection, classify_upstream_token_rejection, ) -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.types import ( CallerRejected, GatewayRejected, UpstreamProtocolFault, - UpstreamReportedFault, UpstreamRegistrationRefused, + UpstreamReportedFault, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py b/tests/unit/proxy/mcp_server/faults/test_list_outcomes.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py rename to tests/unit/proxy/mcp_server/faults/test_list_outcomes.py index fdae575276d..df016d38ada 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_list_outcomes.py +++ b/tests/unit/proxy/mcp_server/faults/test_list_outcomes.py @@ -14,18 +14,18 @@ import pytest from mcp import MCPError from mcp.types import CONNECTION_CLOSED, ErrorData -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, ServerListOk, classify_list_exception, list_fault_http_status, outcome_wire_value, ) -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError def test_carried_fault_passes_through(): @@ -202,7 +202,7 @@ async def test_cancelled_fetch_propagates_instead_of_masquerading_as_a_healthy_e import asyncio from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() client = MagicMock() @@ -230,8 +230,8 @@ async def test_client_side_cancelled_error_is_a_classified_fault_not_a_cancellat import asyncio from unittest.mock import AsyncMock, MagicMock - from litellm.experimental_mcp_client.client import SESSION_CLEANUP_TIMEOUT_MESSAGE - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.mcp_client.client import SESSION_CLEANUP_TIMEOUT_MESSAGE + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() client = MagicMock() @@ -247,7 +247,7 @@ def test_auth_challenge_and_status_come_from_the_causal_response(): """An incidental 403 raised while handling the causal 401 (context chain) must not shadow it: the carrier channel and the challenge both derive from the response on the explicit causal chain, so the caller is challenged to authenticate rather than told it is forbidden.""" - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import upstream_auth_challenge + from litellm.proxy.mcp_server.faults.list_outcomes import upstream_auth_challenge causal = httpx.HTTPStatusError( "auth", @@ -277,7 +277,7 @@ def test_auth_challenge_and_status_come_from_the_causal_response(): def test_raise_classified_list_failure_routes_auth_to_upstream_auth_error(): """The single choice-point sends 401/403 through MCPUpstreamAuthError with the upstream's own challenge and everything else through MCPServerListError, so fetch sites cannot drift.""" - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import raise_classified_list_failure + from litellm.proxy.mcp_server.faults.list_outcomes import raise_classified_list_failure auth_exc = httpx.HTTPStatusError( "auth", @@ -302,7 +302,7 @@ def test_causal_auth_behind_unrelated_response_is_still_found(): """The auth scan must not end at the first response of any status: a causal 401 sitting deeper in the tree than an unrelated 5xx (retry attempts, multi-stream task groups) must still surface with its challenge, or the client is told upstream_error and never re-authenticates.""" - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import upstream_auth_challenge + from litellm.proxy.mcp_server.faults.list_outcomes import upstream_auth_challenge deep_auth = httpx.HTTPStatusError( "auth", @@ -381,7 +381,7 @@ def test_pure_non_auth_response_still_classifies_upstream_error(): def test_managed_scope_step_up_only_accepts_unambiguous_bearer_challenges(status, challenge, expected, client): import httpx2 - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import upstream_insufficient_scope + from litellm.proxy.mcp_server.faults.list_outcomes import upstream_insufficient_scope transport = httpx if client == "httpx" else httpx2 response = transport.Response(status, headers={"www-authenticate": challenge}, request=transport.Request("POST", "https://peer.test/mcp")) @@ -403,7 +403,7 @@ def _rate_limited_error(retry_after: str | None = None) -> httpx.HTTPStatusError @pytest.mark.asyncio async def test_retry_upstream_rate_limit_backs_off_then_reraises() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls: Final[list[httpx.HTTPStatusError]] = [] @@ -435,7 +435,7 @@ async def test_retry_upstream_rate_limit_backs_off_then_reraises() -> None: @pytest.mark.asyncio async def test_retry_upstream_rate_limit_honors_retry_after_up_to_cap() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] @@ -464,7 +464,7 @@ async def test_retry_upstream_rate_limit_parses_http_date_retry_after() -> None: import email.utils import time - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] attempts: Final[list[None]] = [] @@ -495,7 +495,7 @@ async def test_retry_upstream_rate_limit_parses_http_date_retry_after() -> None: @pytest.mark.asyncio async def test_retry_upstream_rate_limit_passes_through_non_429() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls = 0 @@ -522,7 +522,7 @@ async def test_retry_upstream_rate_limit_passes_through_non_429() -> None: @pytest.mark.asyncio async def test_retry_upstream_rate_limit_negative_max_retries_is_a_single_attempt() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls = 0 @@ -555,7 +555,7 @@ async def test_retry_upstream_rate_limit_negative_max_retries_is_a_single_attemp @pytest.mark.asyncio async def test_retry_deadline_skips_sleep_that_would_pass_deadline() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit now: Final[list[float]] = [100.0] sleeps: Final[list[float]] = [] @@ -593,7 +593,7 @@ async def test_retry_deadline_skips_sleep_that_would_pass_deadline() -> None: async def test_retry_attempt_is_interrupted_at_deadline() -> None: import anyio - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit calls = 0 failure: Final = _rate_limited_error("0") @@ -619,7 +619,7 @@ async def test_retry_attempt_is_interrupted_at_deadline() -> None: async def test_retry_deadline_does_not_bound_first_attempt() -> None: import anyio - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit async def slow() -> str: await anyio.sleep(0.15) @@ -636,7 +636,7 @@ async def test_retry_deadline_does_not_bound_first_attempt() -> None: async def test_retry_upstream_rate_limit_never_retries_cancellation() -> None: import asyncio - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import retry_upstream_rate_limit + from litellm.proxy.mcp_server.faults.list_outcomes import retry_upstream_rate_limit sleeps: Final[list[float]] = [] calls = 0 @@ -659,7 +659,7 @@ async def test_retry_upstream_rate_limit_never_retries_cancellation() -> None: def test_listing_failed_outright_only_when_every_server_faulted_non_auth() -> None: - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListOk, listing_failed_outright, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_render_oauth.py b/tests/unit/proxy/mcp_server/faults/test_render_oauth.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_render_oauth.py rename to tests/unit/proxy/mcp_server/faults/test_render_oauth.py index a6807ae1454..49d7c14c285 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_render_oauth.py +++ b/tests/unit/proxy/mcp_server/faults/test_render_oauth.py @@ -6,16 +6,16 @@ from typing import Final, Literal import pytest -from litellm.proxy._experimental.mcp_server.faults.render_oauth import ( +from litellm.proxy.mcp_server.faults.render_oauth import ( dcr_fault_detail, render_token_fault, ) -from litellm.proxy._experimental.mcp_server.faults.types import ( +from litellm.proxy.mcp_server.faults.types import ( CallerRejected, GatewayRejected, UpstreamProtocolFault, - UpstreamReportedFault, UpstreamRegistrationRefused, + UpstreamReportedFault, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/faults/test_traversal.py b/tests/unit/proxy/mcp_server/faults/test_traversal.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/faults/test_traversal.py rename to tests/unit/proxy/mcp_server/faults/test_traversal.py index b8bf4da1dc4..a2ba75058f3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/faults/test_traversal.py +++ b/tests/unit/proxy/mcp_server/faults/test_traversal.py @@ -7,7 +7,7 @@ import sys if sys.version_info < (3, 11): # BaseExceptionGroup is a builtin only from 3.11 from exceptiongroup import BaseExceptionGroup -from litellm.proxy._experimental.mcp_server.faults import iter_exception_tree +from litellm.proxy.mcp_server.faults import iter_exception_tree def test_yields_the_root_itself_first(): diff --git a/tests/unit/proxy/experimental/__init__.py b/tests/unit/proxy/mcp_server/guardrail_translation/__init__.py similarity index 100% rename from tests/unit/proxy/experimental/__init__.py rename to tests/unit/proxy/mcp_server/guardrail_translation/__init__.py diff --git a/tests/unit/proxy/_experimental/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py b/tests/unit/proxy/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py rename to tests/unit/proxy/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py index f3e1bcf979f..a6f94cbd961 100644 --- a/tests/unit/proxy/_experimental/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py +++ b/tests/unit/proxy/mcp_server/guardrail_translation/test_mcp_guardrail_handler.py @@ -11,11 +11,11 @@ import litellm.llms as litellm_llms from litellm.caching.caching import DualCache from litellm.exceptions import BlockedPiiEntityError from litellm.integrations.custom_guardrail import CustomGuardrail -from litellm.proxy._experimental.mcp_server.guardrail_translation.handler import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.guardrail_translation.handler import ( MCPGuardrailTranslationHandler, ) -from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH -from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH from litellm.proxy.utils import ProxyLogging from litellm.types.utils import GenericGuardrailAPIInputs @@ -698,7 +698,7 @@ async def test_structured_content_nested_too_deeply_is_blocked(): """Too deep to walk must block rather than pass the deeper values unscanned.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH + from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH handler = MCPGuardrailTranslationHandler() guardrail = SubstitutingGuardrail("jane@example.com", "") @@ -727,7 +727,7 @@ def test_too_deep_json_returns_a_sentinel_rather_than_raising(): the helper so this pins the contract without reloading the module and leaking that reload into other tests. """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( MAX_STRUCTURED_CONTENT_SCAN_DEPTH, json_string_leaves, ) diff --git a/tests/unit/proxy/experimental/mcp_server/__init__.py b/tests/unit/proxy/mcp_server/outbound_credentials/__init__.py similarity index 100% rename from tests/unit/proxy/experimental/mcp_server/__init__.py rename to tests/unit/proxy/mcp_server/outbound_credentials/__init__.py diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_adapter.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_adapter.py index 9cd19e9a1c9..c39fb215ef3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_adapter.py @@ -13,9 +13,9 @@ import pytest from fastapi import HTTPException from pydantic import ValidationError -from litellm.experimental_mcp_client.client import MCPClient -from litellm.proxy._experimental.mcp_server.exceptions import MCPServerURLCredentialsError -from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( +from litellm.mcp_client.client import MCPClient +from litellm.proxy.mcp_server.exceptions import MCPServerURLCredentialsError +from litellm.proxy.mcp_server.outbound_credentials.adapter import ( oauth_protected_resource_path, raise_public, raise_user_oauth_challenge, @@ -23,8 +23,8 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_subject, validate_static_credential, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok +from litellm.proxy.mcp_server.outbound_credentials.types import ( ApiKeyConfig, AuthorizationCodeConfig, ClientCredentialsConfig, @@ -601,7 +601,7 @@ def test_raise_user_oauth_challenge_per_request_prefix_is_routable(monkeypatch): def test_raise_token_exchange_challenge_is_rfc9728_invalid_token(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -621,7 +621,7 @@ def test_raise_token_exchange_challenge_is_rfc9728_invalid_token(): def test_raise_token_exchange_challenge_includes_server_root_path(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -633,7 +633,7 @@ def test_raise_token_exchange_challenge_includes_server_root_path(monkeypatch): def test_raise_token_exchange_challenge_per_request_prefix_is_routable(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -645,7 +645,7 @@ def test_raise_token_exchange_challenge_per_request_prefix_is_routable(monkeypat def test_raise_token_exchange_challenge_static_form_is_unchanged_without_step_up(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) @@ -661,7 +661,7 @@ def test_raise_token_exchange_challenge_static_form_is_unchanged_without_step_up def test_raise_token_exchange_challenge_uses_insufficient_claims_with_claims_present(): # Per the Microsoft claims-challenge format, a claims challenge MUST use error=insufficient_claims # (the value MSAL-family clients key on), and the claims ride base64-encoded, never raw. - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_token_exchange_challenge, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_authz_code_refresher.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_authz_code_refresher.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_authz_code_refresher.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_authz_code_refresher.py index 3068e5a0116..3a1bb024464 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_authz_code_refresher.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_authz_code_refresher.py @@ -2,10 +2,10 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.authz_code_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.authz_code_refresher import ( AuthorizationCodeRefresher, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) @@ -374,7 +374,7 @@ async def test_cimd_refresh_on_fresh_replica_preserves_user_and_client_identity( @pytest.mark.asyncio async def test_saved_cimd_identity_refreshes_without_discovery(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore + from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_bridge_credentials.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_bridge_credentials.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_bridge_credentials.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_bridge_credentials.py index f8fb22469f1..47b6c3c2fa9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_bridge_credentials.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_bridge_credentials.py @@ -13,7 +13,7 @@ from datetime import datetime, timedelta, timezone import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, BridgeEnvelopeInvalid, BridgeRefreshInvalid, @@ -26,7 +26,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credenti open_bridge_refresh_envelope, resolve_bridge_envelope, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( ENVELOPE_PREFIX, EnvelopeIdentity, EnvelopeKeys, @@ -117,7 +117,7 @@ def test_refresh_jwt_wearing_the_access_prefix_is_rejected_at_the_edge(): """Belt-and-suspenders against a swapped wire prefix: a refresh JWT re-prefixed as an access envelope opens far enough to hit the signed kind claim, which rejects it, so admission fails closed rather than forwarding a refresh credential's contents upstream.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import REFRESH_ENVELOPE_PREFIX + from litellm.proxy.mcp_server.outbound_credentials.envelope import REFRESH_ENVELOPE_PREFIX keys = envelope_keys_from_master_key(_MASTER_KEY) swapped = ENVELOPE_PREFIX + _sealed_refresh(keys).removeprefix(REFRESH_ENVELOPE_PREFIX) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_client_credentials.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_client_credentials.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_client_credentials.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_client_credentials.py index 77cbd8fa464..1086c374622 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_client_credentials.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_client_credentials.py @@ -10,7 +10,7 @@ import httpx2 import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ClientCredentialsTokenSource, TokenEndpointDenied, @@ -18,8 +18,8 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credenti TokenEndpointSuccess, TokenEndpointUnreachable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, ) @@ -486,8 +486,9 @@ async def test_bearer_auth_advertises_the_header_it_will_occupy(): async def test_token_exchange_failure_diagnostics(mode, monkeypatch, caplog): import asyncio import logging + from litellm.llms.custom_httpx import http_handler - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import post_client_credentials_grant + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import post_client_credentials_grant class Poster: async def post(self, url, headers, data): @@ -557,7 +558,7 @@ def test_subscription_identity_tracks_grant_configuration(changed): def test_subscription_identity_requires_managed_grant_metadata(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import HeaderCarrier + from litellm.proxy.mcp_server.outbound_credentials.types import HeaderCarrier async def refetch(token: str) -> str | None: return None diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_dual_cache_token_backend.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_dual_cache_token_backend.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_dual_cache_token_backend.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_dual_cache_token_backend.py index f27bc987434..00db27a60b8 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_dual_cache_token_backend.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_dual_cache_token_backend.py @@ -2,13 +2,13 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.dual_cache_token_backend import ( +from litellm.proxy.mcp_server.outbound_credentials.dual_cache_token_backend import ( DualCacheTokenCacheBackend, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_envelope.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_envelope.py index bd310339a1d..6da509a0d37 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_envelope.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_envelope.py @@ -19,7 +19,8 @@ import pytest from cryptography.hazmat.primitives.asymmetric import rsa from pydantic import SecretStr, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value, encrypt_value +from litellm.proxy.mcp_server.outbound_credentials.envelope import ( ENVELOPE_ISSUER, ENVELOPE_PREFIX, MAX_ENVELOPE_BYTES, @@ -50,7 +51,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import open_refresh_envelope, user_identity, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value, encrypt_value _NOW = datetime(2026, 7, 9, 12, 0, 0, tzinfo=timezone.utc) _SIGNING_KEY = "unit-test-signing-key-0123456789abcdef0123456789abcdef" @@ -480,7 +480,7 @@ def test_open_size_guard_measures_bytes_not_characters(): _decode_claims to fail loudly proves the guard short-circuits before decode.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.outbound_credentials import envelope + from litellm.proxy.mcp_server.outbound_credentials import envelope multibyte_body = "é" * 7000 # 7000 chars, 14000 UTF-8 bytes candidate = ENVELOPE_PREFIX + multibyte_body @@ -500,7 +500,7 @@ def test_open_size_guard_rejects_oversize_character_count_before_decode(): character precheck makes this O(1) since UTF-8 byte length is never below character length.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.outbound_credentials import envelope + from litellm.proxy.mcp_server.outbound_credentials import envelope candidate = ENVELOPE_PREFIX + ("a" * (MAX_ENVELOPE_BYTES + 1)) assert len(candidate) > MAX_ENVELOPE_BYTES diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_httpx_auth.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_httpx_auth.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_httpx_auth.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_httpx_auth.py index 5a5eea60fce..aa75f52b540 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_httpx_auth.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_httpx_auth.py @@ -6,7 +6,7 @@ pin the header emission the api_key family and passthrough depend on. import httpx2 -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( NoOpAuth, StaticHeaderAuth, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_login_assertion_exchange.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_login_assertion_exchange.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_login_assertion_exchange.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_login_assertion_exchange.py index ab2b5b3d966..754a56c2f00 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_login_assertion_exchange.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_login_assertion_exchange.py @@ -7,22 +7,23 @@ from datetime import datetime, timedelta, timezone import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.login_assertion_exchange import ( +from litellm.proxy._types import LiteLLM_MCPServerTable +from litellm.proxy.mcp_server.outbound_credentials.login_assertion_exchange import ( exchange_login_assertion_for_refresh_token, login_exchange_servers, refresh_token_exchange_targets, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import SSOClientConfig -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import SSOClientConfig +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( SAML2_SUBJECT_TOKEN_TYPE, SSOIdentityAssertion, assertion_from_saml_login, login_refresh_token_expired, with_login_refresh_token, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ExchangedToken -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ExchangedToken +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientAuth, ClientSecretAuth, CredError, @@ -32,7 +33,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( NoneConfig, ServerSpec, ) -from litellm.proxy._types import LiteLLM_MCPServerTable from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_oauth_token_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_oauth_token_store.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_oauth_token_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_oauth_token_store.py index d72afaf46b6..88d095e53ab 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_oauth_token_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_oauth_token_store.py @@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Tuple import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( CachedOAuthTokenStore, OAuthToken, RefreshingTokenStore, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_per_user_oauth_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_per_user_oauth_store.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_per_user_oauth_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_per_user_oauth_store.py index 5e2bb0f3722..621e206b74c 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_per_user_oauth_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_per_user_oauth_store.py @@ -2,11 +2,11 @@ import asyncio import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( InvalidatableOAuthTokenStore, OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( +from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ServerLookup, ) @@ -43,8 +43,8 @@ def credential_database(monkeypatch): @pytest.mark.asyncio @pytest.mark.parametrize("scopes, expected", [(None, None), ((), []), (("read",), ["read"])]) async def test_credential_persistence_preserves_known_and_unknown_scopes(credential_database, scopes, expected): - from litellm.proxy._experimental.mcp_server.db import decode_oauth_payload - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential + from litellm.proxy.mcp_server.db import decode_oauth_payload + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential await _persist_credential("alice", "srv", "access", "refresh", 60, scopes) row = credential_database.upsert.call_args.kwargs["data"]["create"] @@ -61,9 +61,9 @@ async def test_credential_persistence_preserves_known_and_unknown_scopes(credent async def test_native_refresh_persists_actual_grant_through_storage_adapter( credential_database, prior_scopes, response_scope, expected, ): - from litellm.proxy._experimental.mcp_server.db import decode_oauth_payload - from litellm.proxy._experimental.mcp_server.outbound_credentials.authz_code_refresher import AuthorizationCodeRefresher - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential + from litellm.proxy.mcp_server.db import decode_oauth_payload + from litellm.proxy.mcp_server.outbound_credentials.authz_code_refresher import AuthorizationCodeRefresher + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import _persist_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -337,8 +337,8 @@ async def test_enforcement_invalidates_cached_legacy_credentials_before_use(): async def test_enforced_cache_hit_avoids_credential_read_and_rejects_changed_policy(monkeypatch): from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import current_binding_proof - from litellm.proxy._experimental.mcp_server.outbound_credentials import per_user_oauth_store as module + from litellm.proxy.mcp_server.oauth_identity_binding import current_binding_proof + from litellm.proxy.mcp_server.outbound_credentials import per_user_oauth_store as module from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -373,7 +373,7 @@ async def test_enforced_cache_hit_avoids_credential_read_and_rejects_changed_pol async def test_expired_unverified_credential_never_reaches_refresh(monkeypatch): from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.outbound_credentials import per_user_oauth_store as module + from litellm.proxy.mcp_server.outbound_credentials import per_user_oauth_store as module from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_presented_token_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_presented_token_store.py similarity index 73% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_presented_token_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_presented_token_store.py index 8b715fa717b..cc7f2236e6f 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_presented_token_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_presented_token_store.py @@ -2,10 +2,10 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.presented_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.presented_token_store import ( PresentedOAuthTokenStore, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_distributed_lock.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_distributed_lock.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_distributed_lock.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_redis_distributed_lock.py index e06f3bcd5cf..d50ef6d6ba6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_distributed_lock.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_distributed_lock.py @@ -2,10 +2,10 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_distributed_lock import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_distributed_lock import ( RedisDistributedLock, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( LockAcquisition, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py index a6831562018..18bd4a66b65 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_redis_refresh_coordinator.py @@ -4,10 +4,10 @@ import asyncio import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.redis_refresh_coordinator import ( +from litellm.proxy.mcp_server.outbound_credentials.redis_refresh_coordinator import ( LockAcquisition, RedisRefreshCoordinator, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_resolver.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_resolver.py index 527475b86a9..f832f9560bd 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_resolver.py @@ -19,7 +19,7 @@ import jwt as pyjwt import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( ApiKeyConfig, AuthConfig, AuthorizationCodeConfig, @@ -46,23 +46,23 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials import ( TokenExchangeConfig, UpstreamCredentialProvider, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, TokenStoreUnavailable, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( RefreshingSSOAssertionStore, SSOAssertionRefresher, SSOClientConfig, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( SAML2_SUBJECT_TOKEN_TYPE, AssertionStoreUnavailable, SSOIdentityAssertion, assertion_from_saml_login, with_login_refresh_token, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( ExchangedToken, ) @@ -1314,7 +1314,7 @@ async def test_passthrough_ignores_the_carrier_and_keeps_the_callers_slot(): async def test_resolved_source_matches_the_credential_sent_upstream( config: AuthConfig, subject: Subject, expected_source: str, expected_header: str | None ) -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source store = _FakeTokenStore({("alice", "s"): OAuthToken(access_token="stored-alice")}) provider = UpstreamCredentialProvider(oauth_token_store=store) @@ -1328,7 +1328,7 @@ async def test_resolved_source_matches_the_credential_sent_upstream( @pytest.mark.asyncio async def test_resolved_source_preserves_missing_user_token_error() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source result = await resolve_credentials_with_source( UpstreamCredentialProvider(), _SUBJECT, _spec(AuthorizationCodeConfig()) @@ -1339,7 +1339,7 @@ async def test_resolved_source_preserves_missing_user_token_error() -> None: @pytest.mark.asyncio async def test_minted_token_sources_match_egress_and_do_not_fetch_twice() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source source = _FakeM2MSource(Ok(OAuthToken(access_token="m2m-at"))) m2m = await resolve_credentials_with_source( @@ -1363,7 +1363,7 @@ async def test_minted_token_sources_match_egress_and_do_not_fetch_twice() -> Non @pytest.mark.asyncio async def test_id_jag_source_describes_final_token_after_both_exchanges() -> None: - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source + from litellm.proxy.mcp_server.outbound_credentials.resolver import resolve_credentials_with_source endpoint = _FakeTokenEndpoint(_two_leg_ok("resource-token")) provider = UpstreamCredentialProvider(token_endpoint=endpoint) @@ -1382,7 +1382,7 @@ async def test_client_credentials_subscription_identity_preserves_resolved_grant _SUBJECT, _spec(_M2M) ) assert isinstance(result, Ok) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_result.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_result.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_result.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_result.py index 5d26a530214..96288a62c9a 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_result.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_result.py @@ -6,7 +6,7 @@ the runtime contract consumers rely on: each arm carries its payload and discrim type. The union is exercised for real where it is used (see PR2's parse_auth_spec_kind). """ -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Error, Ok, Result, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_credentials.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_credentials.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_credentials.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_session_credentials.py index a49c43bedb5..f084d5c7d1d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_credentials.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_credentials.py @@ -8,10 +8,10 @@ from cryptography.hazmat.primitives.asymmetric import rsa from jwt.utils import base64url_decode, base64url_encode from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( NotSessionBearer, SessionBearerAdmitted, SessionBearerInvalid, @@ -24,7 +24,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credent resolve_session_signing_keys, session_keys_from_master_key, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SESSION_TTL_SECONDS, AsymmetricSessionKeys, MintedSessionToken, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_token.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_token.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_token.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_session_token.py index 641aca2446e..2e648fb86ed 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_session_token.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_session_token.py @@ -9,7 +9,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa from jwt.utils import base64url_decode, base64url_encode from pydantic import SecretStr, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( MAX_SESSION_TOKEN_BYTES, SESSION_ISSUER, SESSION_REFRESH_PREFIX, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_refresher.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_refresher.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_refresher.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_refresher.py index 53d0d82a7f2..38d203bd77d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_refresher.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_refresher.py @@ -20,12 +20,12 @@ import jwt as pyjwt import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_refresher import ( +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_refresher import ( HttpxTokenEndpointTransport, RefreshFailure, RefreshingSSOAssertionStore, @@ -34,11 +34,11 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_r default_sso_assertion_store, sso_client_config, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( - with_login_refresh_token, +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( AssertionStoreUnavailable, SSOIdentityAssertion, assertion_from_saml_login, + with_login_refresh_token, ) SIGNING_KEY = "test-idp-signing-key-32-bytes-long-xxxx" diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_store.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_store.py index 3c8e7a9b448..8bcd802d497 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_sso_assertion_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_sso_assertion_store.py @@ -18,7 +18,8 @@ from unittest.mock import AsyncMock, MagicMock, patch import jwt as pyjwt import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper, encrypt_value_helper +from litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store import ( _ASSERTION_CACHE, SAML2_SUBJECT_TOKEN_TYPE, AssertionStoreUnavailable, @@ -35,7 +36,6 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_s rotate_sso_identity_assertions_master_key, with_login_refresh_token, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper, encrypt_value_helper from litellm.types.mcp import MCPAuth SALT_KEY = "test-salt-key-for-sso-assertion-tests-1234" @@ -184,7 +184,7 @@ def test_assertion_without_exp_or_iss_still_retained(): @pytest.mark.asyncio async def test_retention_gate_requires_an_id_jag_server(): with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", _make_prisma({}, db_has_id_jag_server=False)), ): manager.config_mcp_servers = { @@ -203,7 +203,7 @@ async def test_retention_gate_requires_an_id_jag_server(): async def test_retention_gate_reads_the_db_when_config_declares_no_id_jag_server(): """A DB-backed server added on another pod (or before this pod's DB load) must still enable retention off the authoritative DB row; False only when neither authority knows one.""" - with patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager: + with patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager: manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2)} db_backed = _make_prisma({}, db_has_id_jag_server=True) with patch("litellm.proxy.proxy_server.prisma_client", db_backed): @@ -223,7 +223,7 @@ async def test_retention_gate_never_consults_the_registry_snapshot(): judge only the config declaration and the DB row, so a stale snapshot listing an id_jag server changes nothing.""" with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", _make_prisma({}, db_has_id_jag_server=False)), ): manager.config_mcp_servers = {} @@ -237,7 +237,7 @@ async def test_retain_persists_when_only_the_db_knows_the_id_jag_server(): stored = {} prisma = _make_prisma(stored, db_has_id_jag_server=True) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {} @@ -460,7 +460,7 @@ async def test_retain_noop_when_no_id_jag_server(): stored = {} prisma = _make_prisma(stored) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2)} @@ -476,7 +476,7 @@ async def test_retain_persists_when_id_jag_server_registered(): stored = {} prisma = _make_prisma(stored) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2_id_jag)} @@ -490,7 +490,7 @@ async def test_retain_persists_when_id_jag_server_registered(): async def test_retain_none_assertion_never_consults_gate_or_store(): gate = MagicMock() with patch( - "litellm.proxy._experimental.mcp_server.outbound_credentials.sso_assertion_store.ema_assertion_retention_enabled", + "litellm.proxy.mcp_server.outbound_credentials.sso_assertion_store.ema_assertion_retention_enabled", gate, ): await retain_sso_identity_assertion_for_ema(user_id="user-a", assertion=None) @@ -502,7 +502,7 @@ async def test_retain_swallows_store_failure(): prisma = MagicMock() prisma.db.litellm_ssoidentityassertion.upsert = AsyncMock(side_effect=RuntimeError("db down")) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, + patch("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager") as manager, patch("litellm.proxy.proxy_server.prisma_client", prisma), ): manager.config_mcp_servers = {"s1": _server_with_auth(MCPAuth.oauth2_id_jag)} diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_cache_codec.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_cache_codec.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_cache_codec.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_cache_codec.py index 12a04c4b4dc..d3cb701df33 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_cache_codec.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_cache_codec.py @@ -1,9 +1,9 @@ """Tests for the cache codec: encrypt on encode, drop the refresh_token, round-trip the bearer.""" -from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_cache_codec import ( +from litellm.proxy.mcp_server.outbound_credentials.token_cache_codec import ( OAuthTokenCacheCodec, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_endpoint.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_endpoint.py index db3a1a386a3..e9b2b8ba589 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_endpoint.py @@ -13,31 +13,31 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import jwt -import litellm import pytest from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa +from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( +import litellm +from litellm.proxy.mcp_server.outbound_credentials.result import ( Error, Ok, Result, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_endpoint import ( +from litellm.proxy.mcp_server.outbound_credentials.token_endpoint import ( CLIENT_ASSERTION_TYPE, ExchangedToken, ExchangedTokenCache, TokenEndpointClient, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientSecretAuth, CredError, PrivateKeyJwtAuth, ) -from pydantic import SecretStr _PATCH_TARGET = ( - "litellm.proxy._experimental.mcp_server.outbound_credentials." + "litellm.proxy.mcp_server.outbound_credentials." "token_endpoint.get_async_httpx_client" ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchange_provider.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchange_provider.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchange_provider.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchange_provider.py index cf15fdb3e26..40a10053dd2 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchange_provider.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchange_provider.py @@ -8,11 +8,11 @@ from unittest.mock import patch import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchange_provider import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchange_provider import ( _post_exchange_endpoint, build_token_exchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, SubjectTokenRejected, TokenExchangeClientError, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchanger.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchanger.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchanger.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchanger.py index f2750cc3632..e1930931b03 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_exchanger.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_token_exchanger.py @@ -9,15 +9,15 @@ import asyncio import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Error, Ok, ServerSpec, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( +from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( +from litellm.proxy.mcp_server.outbound_credentials.types import ( TokenExchangeConfig, ) @@ -127,7 +127,7 @@ async def test_client_secret_post_keeps_creds_in_body_with_no_auth_header(): async def test_exchange_maps_idp_rejection_to_unauthorized(): """An IdP 4xx (surfaced as SubjectTokenRejected by the post adapter) is non-retryable: it maps to ``unauthorized`` (the 401 OBO challenge), not the retryable ``upstream_unavailable`` (503).""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( SubjectTokenRejected, ) @@ -144,7 +144,7 @@ async def test_exchange_maps_gateway_fault_to_misconfigured(): """A gateway-fault RFC 6749 code (invalid_client / invalid_target / ..., surfaced as TokenExchangeClientError) is the gateway's problem, not the caller's, so it maps to misconfigured (500) rather than the retryable 503 or the 401 OBO challenge the caller can't act on.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( TokenExchangeClientError, ) @@ -298,7 +298,7 @@ async def test_non_bearer_token_type_is_logged(): post = _RecordingPost({"access_token": "x", "token_type": "N_A", "expires_in": 3600}) with patch( - "litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger.verbose_logger" + "litellm.proxy.mcp_server.outbound_credentials.token_exchanger.verbose_logger" ) as mock_logger: await OboTokenExchanger(post, clock=_Clock()).exchange("jwt", _SERVER, _CONFIG) assert mock_logger.warning.called @@ -542,7 +542,7 @@ async def test_distributed_coordinator_refresh_and_reread_use_the_cache(): @pytest.mark.asyncio async def test_step_up_rejection_threads_claims_into_unauthorized(): - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( SubjectTokenRejected, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_types.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_types.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_types.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_types.py index 7f5c17de8b4..1f50444f09e 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_types.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_types.py @@ -10,7 +10,7 @@ corresponding guarantee is mutated away. import pytest from pydantic import SecretStr, TypeAdapter, ValidationError -from litellm.proxy._experimental.mcp_server.outbound_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials import ( Ambient, ApiKeyConfig, AuthConfig, diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_v2_token_store.py b/tests/unit/proxy/mcp_server/outbound_credentials/test_v2_token_store.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_v2_token_store.py rename to tests/unit/proxy/mcp_server/outbound_credentials/test_v2_token_store.py index 97d14b65f5a..f531491cfa3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_v2_token_store.py +++ b/tests/unit/proxy/mcp_server/outbound_credentials/test_v2_token_store.py @@ -2,7 +2,7 @@ import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import ( +from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import ( V2PerUserTokenStore, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_byok_credential_cache.py b/tests/unit/proxy/mcp_server/test_byok_credential_cache.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_byok_credential_cache.py rename to tests/unit/proxy/mcp_server/test_byok_credential_cache.py index 0ec4b431276..7ca169366a6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_byok_credential_cache.py +++ b/tests/unit/proxy/mcp_server/test_byok_credential_cache.py @@ -2,15 +2,15 @@ import json import pytest -from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( +from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import AuthCacheInvalidationSubscriber +from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache +from litellm.proxy.mcp_server.byok_credential_cache import ( CachedByokCredential, byok_credential_cache, byok_credential_cache_key, cache_byok_credential, get_cached_byok_credential, ) -from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import AuthCacheInvalidationSubscriber -from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _FakeRedisCache: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_byok_oauth_endpoints.py b/tests/unit/proxy/mcp_server/test_byok_oauth_endpoints.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/test_byok_oauth_endpoints.py rename to tests/unit/proxy/mcp_server/test_byok_oauth_endpoints.py index b2364647e53..37da00ab2ba 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_byok_oauth_endpoints.py +++ b/tests/unit/proxy/mcp_server/test_byok_oauth_endpoints.py @@ -1,4 +1,5 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """ Unit tests for the BYOK OAuth 2.1 authorization server endpoints. @@ -23,12 +24,12 @@ import pytest from fastapi import HTTPException from fastapi.testclient import TestClient -from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.byok_oauth_endpoints import ( _byok_auth_codes, _verify_pkce, router, ) -from litellm.proxy._types import MCPTransport # --------------------------------------------------------------------------- # _verify_pkce @@ -64,10 +65,10 @@ def test_verify_pkce_tampered_challenge(): from fastapi import FastAPI -from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.byok_oauth_endpoints import ( _byok_session_auth, ) -from litellm.proxy._types import UserAPIKeyAuth _test_app = FastAPI() _test_app.include_router(router) @@ -101,8 +102,8 @@ def unauthenticated_client(): @pytest.mark.parametrize("byok_first", [True, False]) def test_byok_challenge_discovers_api_key_flow(monkeypatch, byok_first): - from litellm.proxy._experimental.mcp_server import byok_oauth_endpoints, discoverable_endpoints - from litellm.proxy._experimental.mcp_server.oauth_utils import get_byok_www_authenticate + from litellm.proxy.mcp_server import byok_oauth_endpoints, discoverable_endpoints + from litellm.proxy.mcp_server.oauth_utils import get_byok_www_authenticate monkeypatch.delenv("PROXY_BASE_URL", raising=False) monkeypatch.delenv("SERVER_ROOT_PATH", raising=False) @@ -137,7 +138,7 @@ def test_byok_challenge_discovers_api_key_flow(monkeypatch, byok_first): ], ) def test_byok_challenge_preserves_external_base(monkeypatch, base_url, root_path, expected): - from litellm.proxy._experimental.mcp_server.oauth_utils import get_byok_www_authenticate + from litellm.proxy.mcp_server.oauth_utils import get_byok_www_authenticate monkeypatch.setenv("PROXY_BASE_URL", base_url) monkeypatch.setenv("SERVER_ROOT_PATH", root_path) @@ -147,7 +148,7 @@ def test_byok_challenge_preserves_external_base(monkeypatch, base_url, root_path def test_byok_discovery_preserves_per_request_prefixes(monkeypatch): from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.proxy.middleware.per_request_root_path_middleware import PerRequestRootPathMiddleware from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -385,25 +386,25 @@ async def test_token_endpoint_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", mock_store, ), patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.router", + "litellm.proxy.mcp_server.byok_oauth_endpoints.router", ), ): # Import the actual handler function directly - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) mock_request = MagicMock() # Patch module-level globals in the function's module with patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", mock_store, ): - import litellm.proxy._experimental.mcp_server.byok_oauth_endpoints as mod + import litellm.proxy.mcp_server.byok_oauth_endpoints as mod original_prisma = None original_master_key = None @@ -454,7 +455,7 @@ async def test_token_endpoint_success(): @pytest.mark.asyncio async def test_token_endpoint_invalid_code(): - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -486,7 +487,7 @@ async def test_token_endpoint_expired_code(): ttl=-10, # already expired ) - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -517,7 +518,7 @@ async def test_token_endpoint_wrong_verifier(): redirect_uri="http://127.0.0.1:3000/cb", ) - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -538,7 +539,7 @@ async def test_token_endpoint_wrong_verifier(): @pytest.mark.asyncio async def test_token_endpoint_unsupported_grant_type(): - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import byok_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import byok_token mock_request = MagicMock() with ( @@ -565,7 +566,7 @@ async def test_token_endpoint_unsupported_grant_type(): @pytest.mark.asyncio async def test_check_byok_credential_not_byok(): """Non-BYOK servers should pass through without any DB check.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -581,7 +582,7 @@ async def test_check_byok_credential_not_byok(): @pytest.mark.asyncio async def test_check_byok_credential_no_user_id(): """BYOK server with no user identity → 401.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -601,8 +602,8 @@ async def test_check_byok_credential_no_user_id(): @pytest.mark.asyncio async def test_check_byok_credential_missing_credential(monkeypatch): """BYOK server with a known user but no stored credential → 401.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -613,7 +614,7 @@ async def test_check_byok_credential_missing_credential(monkeypatch): ) user_auth = UserAPIKeyAuth(user_id="user-99", api_key="sk-test") - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module monkeypatch.delenv("PROXY_BASE_URL", raising=False) monkeypatch.delenv("SERVER_ROOT_PATH", raising=False) @@ -622,7 +623,7 @@ async def test_check_byok_credential_missing_credential(monkeypatch): with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_user_credential", + "litellm.proxy.mcp_server.db.get_user_credential", new=AsyncMock(return_value=None), ), patch("litellm.proxy.proxy_server.prisma_client", mock_prisma), @@ -647,9 +648,9 @@ async def test_check_byok_credential_missing_credential(monkeypatch): async def test_execute_byok_tool_missing_credential_advertises_api_key_flow(monkeypatch): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy import proxy_server from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_module from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com/proxy") @@ -680,8 +681,8 @@ async def test_execute_byok_tool_missing_credential_advertises_api_key_flow(monk @pytest.mark.asyncio async def test_check_byok_credential_has_credential(): """BYOK server with a valid stored credential → no error raised.""" - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -696,7 +697,7 @@ async def test_check_byok_credential_has_credential(): with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_user_credential", + "litellm.proxy.mcp_server.db.get_user_credential", new=AsyncMock(return_value="some-credential-value"), ), patch("litellm.proxy.proxy_server.prisma_client", mock_prisma), @@ -708,9 +709,9 @@ async def test_check_byok_credential_has_credential(): @pytest.mark.asyncio async def test_invalidate_byok_cred_cache_evicts_locally_and_broadcasts_the_same_key(): """A revoked credential must stop being served here and on every peer worker within the TTL.""" - from litellm.proxy._experimental.mcp_server import server as server_module - from litellm.proxy._experimental.mcp_server.byok_credential_cache import byok_credential_cache_key from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as server_module + from litellm.proxy.mcp_server.byok_credential_cache import byok_credential_cache_key from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer(server_id="byok-revoke", name="byok-server", transport=MCPTransport.http, is_byok=True) @@ -721,7 +722,7 @@ async def test_invalidate_byok_cred_cache_evicts_locally_and_broadcasts_the_same with ( patch( # test-quality-ok: the DB row lookup is the only seam below the credential resolver; no Prisma fake exists - "litellm.proxy._experimental.mcp_server.db.get_user_credential", new=db_lookup + "litellm.proxy.mcp_server.db.get_user_credential", new=db_lookup ), patch( # test-quality-ok: the resolver reads the module-level prisma_client singleton; the suite's only seam "litellm.proxy.proxy_server.prisma_client", MagicMock() @@ -746,8 +747,8 @@ async def test_check_byok_credential_db_unavailable_fails_closed(): Regression for GHSA-6762: previously returned silently, bypassing the ownership check during DB outage windows. """ - from litellm.proxy._experimental.mcp_server.server import _check_byok_credential from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import _check_byok_credential from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -859,7 +860,7 @@ async def test_token_endpoint_rejects_missing_user_id_in_code_record(): """Defense in depth: if a code record somehow lacks user_id (older format / manual DB write), /token must reject rather than fall back to the form's client_id.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1050,7 +1051,7 @@ def test_authorize_post_rejects_non_loopback_redirect_uri(client): async def test_token_endpoint_rejects_redirect_uri_mismatch(): """RFC 6749 §4.1.3 / OAuth 2.1 §4.1.3: if redirect_uri was sent at /authorize, the /token redirect_uri MUST match exactly.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1104,7 +1105,7 @@ async def test_token_endpoint_accepts_spec_compliant_client_id(): identifier, not the user. It must not be cross-checked against the record's user_id — that cross-check would break spec-compliant MCP clients that pass e.g. client_id="claude-desktop".""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1122,7 +1123,7 @@ async def test_token_endpoint_accepts_spec_compliant_client_id(): with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", new=AsyncMock(), ), patch("litellm.proxy.proxy_server.master_key", "test-master"), @@ -1146,7 +1147,7 @@ async def test_token_endpoint_rejects_client_id_mismatch(): client_id, the token request must submit the same value. An attacker who steals a code from another client (different native app) can't redeem it.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1220,7 +1221,7 @@ async def test_token_endpoint_missing_master_key_preserves_code_and_db(): code or writing the credential — otherwise a misconfigured deploy burns the code and persists the key with no way for the user to retrieve a session token without restarting the flow.""" - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1240,7 +1241,7 @@ async def test_token_endpoint_missing_master_key_preserves_code_and_db(): mock_store = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", mock_store, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -1308,7 +1309,7 @@ async def test_token_endpoint_accepts_oauth21_client_omitting_redirect_uri(): Enforcement still fires when the client DOES submit a value that disagrees with the record (see test_token_endpoint_rejects_redirect_uri_mismatch). """ - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import ( + from litellm.proxy.mcp_server.byok_oauth_endpoints import ( byok_token, ) @@ -1327,7 +1328,7 @@ async def test_token_endpoint_accepts_oauth21_client_omitting_redirect_uri(): with ( patch( - "litellm.proxy._experimental.mcp_server.byok_oauth_endpoints.store_user_credential", + "litellm.proxy.mcp_server.byok_oauth_endpoints.store_user_credential", new=AsyncMock(), ), patch("litellm.proxy.proxy_server.master_key", "test-master"), @@ -1345,7 +1346,7 @@ async def test_token_endpoint_accepts_oauth21_client_omitting_redirect_uri(): def test_validate_loopback_redirect_uri_rejects_fragment(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_loopback_redirect_uri, ) @@ -1357,7 +1358,7 @@ def test_validate_loopback_redirect_uri_rejects_fragment(): def test_validate_loopback_redirect_uri_rejects_malformed_cleanly(): """Malformed / unparseable URIs should surface as 400 invalid_request, not a 500 from an unhandled exception inside ip_address().""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_loopback_redirect_uri, ) @@ -1388,7 +1389,7 @@ def _make_trusted_request(base_url: str = "https://llm.example.com/"): def test_validate_trusted_redirect_uri_accepts_same_origin(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1401,7 +1402,7 @@ def test_validate_trusted_redirect_uri_same_origin_normalizes_default_port(): otherwise produce a proxy_base of ``https://llm.example.com:443`` which wouldn't literally match the browser's port-less ``llm.example.com`` redirect_uri even though both represent the same origin.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1415,7 +1416,7 @@ def test_validate_trusted_redirect_uri_same_origin_normalizes_default_port(): def test_validate_trusted_redirect_uri_accepts_loopback(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1432,7 +1433,7 @@ def test_validate_trusted_redirect_uri_accepts_loopback(): def test_validate_trusted_redirect_uri_rejects_cross_origin_by_default( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1444,7 +1445,7 @@ def test_validate_trusted_redirect_uri_rejects_cross_origin_by_default( def test_validate_trusted_redirect_uri_rejects_fragment_and_bad_scheme(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1460,7 +1461,7 @@ def test_validate_trusted_redirect_uri_rejects_fragment_and_bad_scheme(): def test_validate_trusted_redirect_uri_accepts_cursor_native_callback(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1471,14 +1472,14 @@ def test_validate_trusted_redirect_uri_accepts_cursor_native_callback(): def test_validate_trusted_redirect_uri_rejects_unlisted_native_callback( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setenv("MCP_TRUSTED_NATIVE_REDIRECT_URIS", "") # Clear defaults by patching — env-only path for this test monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) req = _make_trusted_request("http://localhost:4000/") @@ -1492,12 +1493,12 @@ def test_validate_trusted_redirect_uri_rejects_unlisted_native_callback( def test_validate_trusted_redirect_uri_accepts_env_native_redirect_uri( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1509,7 +1510,7 @@ def test_validate_trusted_redirect_uri_accepts_env_native_redirect_uri( def test_validate_trusted_redirect_uri_rejects_native_callback_with_fragment(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1522,7 +1523,7 @@ def test_validate_trusted_redirect_uri_rejects_native_callback_with_fragment(): def test_validate_trusted_redirect_uri_rejects_native_callback_with_query(): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1536,12 +1537,12 @@ def test_validate_trusted_redirect_uri_rejects_native_callback_with_query(): def test_validate_trusted_redirect_uri_native_path_case_insensitive(monkeypatch): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1555,12 +1556,12 @@ def test_validate_trusted_redirect_uri_native_path_case_insensitive(monkeypatch) def test_validate_trusted_redirect_uri_native_wildcard_respects_path_boundary( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1580,12 +1581,12 @@ def test_validate_trusted_redirect_uri_native_wildcard_respects_path_boundary( def test_validate_trusted_redirect_uri_native_wildcard_directory_prefix( monkeypatch, ): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", + "litellm.proxy.mcp_server.oauth_utils._DEFAULT_NATIVE_REDIRECT_URIS", [], ) monkeypatch.setenv( @@ -1600,7 +1601,7 @@ def test_validate_trusted_redirect_uri_rejects_scheme_mismatch_on_same_host(): """Regression: an attacker who can serve http on the proxy's own host (e.g. by MITMing an unencrypted LAN hop) must not be able to pass same-origin validation — scheme must match as well as host.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1622,7 +1623,7 @@ def test_validate_trusted_redirect_uri_rejects_userinfo(monkeypatch): allowlist, and wildcard allowlist — so the bypass is closed on every path through the validator. """ - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1675,7 +1676,7 @@ def test_validate_trusted_redirect_uri_rejects_backslash_in_netloc(monkeypatch): exact-entry, and wildcard — by bouncing the netloc before any matching runs. """ - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1709,7 +1710,7 @@ def test_validate_trusted_redirect_uri_allowlist_entry_with_default_port(monkeyp away for the same-origin compare; the allowlist side has to apply the same normalization or the comparison is asymmetric and silently fails.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( _parse_trusted_redirect_origins, validate_trusted_redirect_uri, ) @@ -1729,7 +1730,7 @@ def test_validate_trusted_redirect_uri_allowlist_entry_with_default_port(monkeyp def test_validate_trusted_redirect_uri_accepts_exact_allowlisted_host(monkeypatch): - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1754,7 +1755,7 @@ def test_validate_trusted_redirect_uri_allowlist_rejects_http_even_on_listed_hos """An attacker must not be able to elevate to the allowlist by serving http:// on the listed host — only https is accepted for non-loopback allowlist entries.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1769,7 +1770,7 @@ def test_validate_trusted_redirect_uri_wildcard_allowlist(monkeypatch): """``*.suffix`` entries match any strictly-deeper subdomain of ``suffix`` but must not match the bare suffix, nor unrelated domains that happen to end with the same characters.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1794,7 +1795,7 @@ def test_validate_trusted_redirect_uri_wildcard_allowlist(monkeypatch): def test_validate_trusted_redirect_uri_wildcard_rejects_http(monkeypatch): """The https-only gate applies to wildcard entries too.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1810,7 +1811,7 @@ def test_validate_trusted_redirect_uri_wildcard_host_with_port_still_matches( ): """Wildcard entries don't express port constraints — an allowlisted subdomain should match regardless of explicit port on the URL.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1822,7 +1823,7 @@ def test_validate_trusted_redirect_uri_wildcard_host_with_port_still_matches( def test_validate_trusted_redirect_uri_accepts_ipv6_loopback_with_default_port(): """IPv6 loopback with explicit ``:443`` on an ``https`` URL should still match — exercises ``_strip_default_port``'s IPv6 branch.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1835,7 +1836,7 @@ def test_validate_trusted_redirect_uri_tolerates_malformed_env_entries(monkeypat ``*.``, non-numeric ports). None of those should raise; unmatched entries must simply fail to grant access while well-formed entries in the same list continue to work.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1863,7 +1864,7 @@ def test_validate_trusted_redirect_uri_rejects_wildcard_entry_with_dot_leading_s whose own leading ``.`` makes it look like a deeper subdomain. Operators who mistype an extra dot should get an ignored entry, not a broader match than they intended.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1885,7 +1886,7 @@ def test_validate_trusted_redirect_uri_falls_through_when_origin_lookup_fails(): """If ``get_request_base_url`` can't determine the proxy's origin, same-origin is skipped silently but loopback + allowlist paths are still reachable.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1905,7 +1906,7 @@ def test_strip_default_port_empty_netloc(): """``_strip_default_port("", "")`` should round-trip — validator rejects empty-netloc URLs upstream so this is purely a defensive contract on the helper itself.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import _strip_default_port + from litellm.proxy.mcp_server.oauth_utils import _strip_default_port assert _strip_default_port("https", "") == "" @@ -1914,7 +1915,7 @@ def test_strip_default_port_handles_non_numeric_port(): """Raw netloc with a non-numeric port is returned unchanged. Reached in practice when a malformed ``Host`` header survives upstream parsing — we stay out of its way rather than 500ing.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import _strip_default_port + from litellm.proxy.mcp_server.oauth_utils import _strip_default_port assert _strip_default_port("https", "foo.com:bar") == "foo.com:bar" assert _strip_default_port("https", "[::1]:bar") == "[::1]:bar" @@ -1923,7 +1924,7 @@ def test_strip_default_port_handles_non_numeric_port(): def test_validate_trusted_redirect_uri_rejects_public_ip_without_allowlist(): """A redirect_uri whose host is a public IP (parseable by ``ip_address`` but not loopback) must fail all three tiers and 400.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) @@ -1937,7 +1938,7 @@ def test_parse_trusted_redirect_origins_drops_bare_path_entries(monkeypatch): """``/foo`` has a scheme-less leading slash and would strip to the empty string — drop silently rather than allowlisting empty origins.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( _parse_trusted_redirect_origins, ) @@ -1965,12 +1966,14 @@ async def test_authenticated_browser_identity_checks_embedded_session( monkeypatch: pytest.MonkeyPatch, case: str, expected: str | None ) -> None: from datetime import datetime, timezone + import jwt from starlette.requests import Request + from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.byok_oauth_endpoints import get_authenticated_browser_user_id - from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_bearer_token from litellm.proxy.auth.auth_checks import LITELLM_SESSION_TOKEN_PREFIX + from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_bearer_token + from litellm.proxy.mcp_server.byok_oauth_endpoints import get_authenticated_browser_user_id monkeypatch.setenv("LITELLM_SALT_KEY", "local-test-encryption-key") monkeypatch.setattr(proxy_server, "master_key", "local-test-cookie-signing-key-32-bytes") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_callback_oauth_error_responses.py b/tests/unit/proxy/mcp_server/test_callback_oauth_error_responses.py similarity index 94% rename from tests/unit/proxy/_experimental/mcp_server/test_callback_oauth_error_responses.py rename to tests/unit/proxy/mcp_server/test_callback_oauth_error_responses.py index 11ef40b9961..5a66689a5bb 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_callback_oauth_error_responses.py +++ b/tests/unit/proxy/mcp_server/test_callback_oauth_error_responses.py @@ -27,7 +27,7 @@ def _mock_mcp_client_ip(): from unittest.mock import patch with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): yield @@ -45,7 +45,7 @@ def callback_test_client(monkeypatch): monkeypatch.setenv("LITELLM_SALT_KEY", "sk-test-salt-for-LIT-2750") - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( router, ) @@ -100,7 +100,7 @@ class TestCallbackOAuthErrorResponses: """When state decodes to a trusted (loopback) redirect_uri, propagate the error back so the MCP client's OAuth library can surface it instead of timing out waiting on the loopback.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( encode_state_with_base_url, ) @@ -136,7 +136,7 @@ class TestCallbackOAuthErrorResponses: """If the state minted earlier carries a redirect_uri that the proxy no longer trusts, we must surface the error inline rather than 302-ing to an attacker-controlled URL (open-redirect).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( encode_state_with_base_url, ) @@ -188,7 +188,7 @@ class TestCallbackOAuthErrorResponses: """Regression: the successful (``code``+``state``) flow must still redirect back to the trusted client redirect_uri with the original state preserved.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( encode_state_with_base_url, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_capabilities.py b/tests/unit/proxy/mcp_server/test_capabilities.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_capabilities.py rename to tests/unit/proxy/mcp_server/test_capabilities.py index e5104e7941f..55d338e64aa 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_capabilities.py +++ b/tests/unit/proxy/mcp_server/test_capabilities.py @@ -15,7 +15,7 @@ from mcp.types import ( ) from mcp_types.version import HANDSHAKE_PROTOCOL_VERSIONS -from litellm.proxy._experimental.mcp_server.capabilities import ( +from litellm.proxy.mcp_server.capabilities import ( GATEWAY_OPERATIONS, REVISION_SUPPORT, TRANSLATION_PAIRS, @@ -130,6 +130,7 @@ async def test_version_policy_gates_the_actual_sdk_handshake(versions, accepted) def test_modern_discovery_requires_opt_in_and_keeps_unsupported_features_disabled() -> None: from pydantic import TypeAdapter + from litellm.types.mcp import MCPAdvertisedVersions configured: Final = TypeAdapter(MCPAdvertisedVersions).validate_python(["2026-07-28"]) @@ -154,7 +155,7 @@ def test_modern_discovery_requires_opt_in_and_keeps_unsupported_features_disable @pytest.mark.parametrize("path", ["/mcp/sse", "/mcp/example/sse/"]) def test_modern_protocol_is_rejected_on_legacy_sse_paths(path: str, monkeypatch: pytest.MonkeyPatch) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.server import unsupported_protocol_version + from litellm.proxy.mcp_server.server import unsupported_protocol_version monkeypatch.setitem(proxy_server.general_settings, "mcp_advertised_versions", ["2025-11-25", "2026-07-28"]) assert unsupported_protocol_version({"path": "/mcp", "headers": [(b"mcp-protocol-version", b"2026-07-28")]}) is None @@ -194,8 +195,9 @@ def test_subscription_flags_require_a_supported_protocol_pair(revision, upstream async def test_subscription_discovery_never_probes_unsupported_targets(mode, monkeypatch): from types import SimpleNamespace from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server import subscriptions - from litellm.proxy._experimental.mcp_server.contracts import OperationContext + + from litellm.proxy.mcp_server import subscriptions + from litellm.proxy.mcp_server.contracts import OperationContext probe = AsyncMock() target = SimpleNamespace( diff --git a/tests/unit/proxy/_experimental/mcp_server/test_catalog.py b/tests/unit/proxy/mcp_server/test_catalog.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_catalog.py rename to tests/unit/proxy/mcp_server/test_catalog.py index 4f6530e5de1..45c648b81d2 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_catalog.py +++ b/tests/unit/proxy/mcp_server/test_catalog.py @@ -19,15 +19,15 @@ from mcp.types import ( Tool, ) -from litellm.proxy._experimental.mcp_server import catalog -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.mcp_server import catalog +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListOk, ) -from litellm.proxy._types import UserAPIKeyAuth -from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -55,10 +55,10 @@ async def test_catalog_refresh_keeps_selected_toolset_with_current_grants_and_co from litellm.caching.dual_cache import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry from litellm.types.mcp_server.mcp_toolset import MCPToolset, MCPToolsetTool grants: Final = LiteLLM_ObjectPermissionTable( @@ -145,7 +145,7 @@ def rate_limit_catalog_setup( monkeypatch: pytest.MonkeyPatch, rejected_server_ids: frozenset[str] ) -> tuple[tuple[MCPServer, MCPServer], OperationContext, AsyncMock]: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations monkeypatch.setenv("LITELLM_SALT_KEY", "catalog-rate-limit-test-key") servers: Final = ( @@ -322,7 +322,7 @@ async def test_changed_upstream_revision_requires_restart(monkeypatch): @pytest.mark.asyncio async def test_failed_upstream_remains_visible_when_other_sources_continue(monkeypatch): - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY monkeypatch.setenv("LITELLM_SALT_KEY", "shared-test-key") @@ -366,8 +366,8 @@ async def test_cursor_cannot_be_reused_for_a_different_catalog_kind(monkeypatch) @pytest.mark.asyncio async def test_authenticated_state_with_invalid_catalog_schema_is_rejected(monkeypatch): - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok - from litellm.proxy._experimental.mcp_server.state_tokens import seal_state + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.state_tokens import seal_state monkeypatch.setenv("LITELLM_SALT_KEY", "shared-test-key") token = seal_state({"not": "catalog state"}, purpose="mcp.catalog.list.v1:tools/list", expires_at=200, now=100) @@ -426,8 +426,8 @@ async def test_page_limit_rejects_an_unending_upstream(monkeypatch): def test_caller_binding_covers_identity_scope_and_forwarded_credentials(change): from dataclasses import replace - from litellm.proxy._experimental.mcp_server.contracts import OperationContext from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.contracts import OperationContext original = OperationContext(_caller=UserAPIKeyAuth(api_key="synthetic-key", user_id="owner")) assert catalog._caller_scope(original, ()) != catalog._caller_scope(replace(original, **change), ()) @@ -436,8 +436,8 @@ def test_caller_binding_covers_identity_scope_and_forwarded_credentials(change): def test_caller_binding_ignores_transport_headers_and_header_case(): from dataclasses import replace - from litellm.proxy._experimental.mcp_server.contracts import OperationContext from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.contracts import OperationContext original = OperationContext( _caller=UserAPIKeyAuth(user_id="owner"), raw_headers={"Authorization": "Bearer synthetic"} @@ -510,8 +510,8 @@ async def test_gateway_tools_continuation_rejects_an_upstream_failure(monkeypatc from mcp.types import PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk, classify_list_exception from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -546,8 +546,8 @@ async def test_optional_gateway_catalog_reports_initial_failure_and_rejects_fail from mcp import types from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -729,6 +729,7 @@ async def test_discovery_cache_uses_upstream_freshness_and_configured_cap( upstream_ttl: int, limit: float, expected_ttl: int ) -> None: from unittest.mock import AsyncMock + from mcp.types import ListPromptsResult, Prompt from pydantic import TypeAdapter @@ -759,7 +760,8 @@ async def test_discovery_cache_uses_upstream_freshness_and_configured_cap( def test_partial_optional_catalog_never_advertises_freshness() -> None: from mcp.types import ListPromptsRequest, ListPromptsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY + + from litellm.proxy.mcp_server.faults.list_outcomes import SERVER_OUTCOMES_META_KEY result: Final = catalog.combine_optional_catalog( ListPromptsRequest(), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_client_allowlist.py b/tests/unit/proxy/mcp_server/test_client_allowlist.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_client_allowlist.py rename to tests/unit/proxy/mcp_server/test_client_allowlist.py index d1f852e504e..e05f23cbf33 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_client_allowlist.py +++ b/tests/unit/proxy/mcp_server/test_client_allowlist.py @@ -3,7 +3,7 @@ from typing import Final import pytest -from litellm.proxy._experimental.mcp_server.client_allowlist import ( +from litellm.proxy.mcp_server.client_allowlist import ( MCP_ALLOWED_CLIENTS_SETTING, MCP_CLIENT_ID_HEADER_SETTING, MCP_CLIENT_ID_JWT_FIELD_SETTING, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_contracts.py b/tests/unit/proxy/mcp_server/test_contracts.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_contracts.py rename to tests/unit/proxy/mcp_server/test_contracts.py index adb17590d74..db30f2a4af9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_contracts.py +++ b/tests/unit/proxy/mcp_server/test_contracts.py @@ -4,8 +4,8 @@ from typing import Final import pytest from pydantic import SecretStr -from litellm.proxy._experimental.mcp_server.operations import prepare_context from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.operations import prepare_context def test_guardrail_bearer_stays_out_of_egress_and_context_representations() -> None: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py b/tests/unit/proxy/mcp_server/test_db_credentials.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py rename to tests/unit/proxy/mcp_server/test_db_credentials.py index ce31a83075c..db2572ef954 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_db_credentials.py +++ b/tests/unit/proxy/mcp_server/test_db_credentials.py @@ -18,7 +18,15 @@ from unittest.mock import AsyncMock, MagicMock import pytest from prisma.models import LiteLLM_MCPServerTable as PrismaMCPServer -from litellm.proxy._experimental.mcp_server.db import ( +from litellm.proxy._types import LiteLLM_MCPServerTable, NewMCPServerRequest, UpdateMCPServerRequest +from litellm.proxy.common_utils.encrypt_decrypt_utils import ( + SecretMapDecodeError, + decode_secret_map, + decrypt_value_helper, + encrypt_secret_map, + encrypt_value_helper, +) +from litellm.proxy.mcp_server.db import ( _decode_user_credential, _prepare_mcp_server_data, create_mcp_server, @@ -39,14 +47,6 @@ from litellm.proxy._experimental.mcp_server.db import ( store_user_oauth_credential, update_mcp_server, ) -from litellm.proxy._types import LiteLLM_MCPServerTable, NewMCPServerRequest, UpdateMCPServerRequest -from litellm.proxy.common_utils.encrypt_decrypt_utils import ( - SecretMapDecodeError, - decode_secret_map, - decrypt_value_helper, - encrypt_secret_map, - encrypt_value_helper, -) from litellm.types.mcp import MCPAuth, MCPTransport SALT_KEY = "test-salt-key-for-byok-credential-tests-1234" @@ -121,7 +121,7 @@ def _identity_server(**overrides): ], ) def test_mcp_oauth_token_identity_changes_on_mint_relevant_fields(overrides): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity assert mcp_oauth_token_identity(_identity_server()) != mcp_oauth_token_identity(_identity_server(**overrides)) @@ -134,13 +134,13 @@ def test_mcp_oauth_token_identity_changes_on_mint_relevant_fields(overrides): ], ) def test_mcp_oauth_token_identity_stable_on_non_mint_fields(overrides): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity assert mcp_oauth_token_identity(_identity_server()) == mcp_oauth_token_identity(_identity_server(**overrides)) def _encrypted_creds_json(client_id: str = "cid", client_secret: str = "csec") -> str: - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.db import encrypt_credentials encrypted = encrypt_credentials( credentials={"client_id": client_id, "client_secret": client_secret, "scopes": ["a"]}, @@ -154,7 +154,7 @@ def test_mcp_oauth_token_identity_stable_across_reencryption(): saves of the SAME plaintext produce different ciphertext. The identity must compare decrypted values; comparing ciphertext would flag every routine save as a mint-relevant change and purge per-user tokens that are still valid.""" - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity first = _encrypted_creds_json() second = _encrypted_creds_json() @@ -166,7 +166,7 @@ def test_mcp_oauth_token_identity_stable_across_reencryption(): def test_mcp_oauth_token_identity_detects_change_under_encryption(): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity unchanged = _identity_server(credentials=_encrypted_creds_json()) changed = _identity_server(credentials=_encrypted_creds_json(client_id="other")) @@ -174,7 +174,7 @@ def test_mcp_oauth_token_identity_detects_change_under_encryption(): def test_mcp_oauth_token_identity_reads_client_and_scopes_from_json_string_credentials(): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity credentials: Final = json.dumps( {"client_id": "cid", "client_secret": "csec", "scopes": ["a"], "upstream_resource": "api://audience"} @@ -198,7 +198,7 @@ def test_mcp_oauth_token_identity_reads_client_and_scopes_from_json_string_crede @pytest.mark.parametrize("credentials", ["[]", '["client_id"]', '"cid"', "5", "null", "not json"]) def test_mcp_oauth_token_identity_treats_stored_credentials_that_are_not_a_json_object_as_empty(credentials): - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity assert mcp_oauth_token_identity(_identity_server(credentials=credentials)) == ( "https://up.example.com/mcp", @@ -235,7 +235,7 @@ def _byok_row(user_id: str, server_id: str = "srv-1"): @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_invalidates_each_user(): """The purge must route each (user, server) row through the invalidator exactly once.""" - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_oauth_row("alice"), _oauth_row("bob")]) @@ -259,7 +259,7 @@ async def test_purge_user_oauth_credentials_for_server_invalidates_each_user(): async def test_list_server_user_credentials_types_each_row_without_leaking_the_secret(): """The admin view of one server's stored credentials names the user and the kind of credential (OAuth2 vs BYOK) and echoes OAuth expiry, but never the token or key itself.""" - from litellm.proxy._experimental.mcp_server.db import list_server_user_credentials + from litellm.proxy.mcp_server.db import list_server_user_credentials oauth_row = _legacy_row( json.dumps( @@ -307,7 +307,7 @@ async def test_purge_user_oauth_credentials_for_server_spares_byok_rows(): """Regression: the purge used to delete_many on server_id alone, wiping BYOK API keys that share the LiteLLM_MCPUserCredentials table. Only rows holding an OAuth2 payload may be deleted (one batched query filtered to their user_ids), and only their users' token caches invalidated.""" - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_byok_row("carol"), _oauth_row("alice")]) @@ -330,7 +330,7 @@ async def test_purge_user_oauth_credentials_for_server_spares_byok_rows(): @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_all_byok_is_noop(): """An api_key (BYOK-only) server whose identity tuple changes (e.g. its url) must purge nothing.""" - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_byok_row("carol"), _byok_row("dave")]) @@ -348,8 +348,8 @@ async def test_purge_user_oauth_credentials_for_server_defaults_to_manager_inval invalidate_user_oauth_token_cache, the single point covering both the legacy per-user token cache and the v2 per-user OAuth token store; a wrong or no-op default silently leaves every cache serving tokens minted for the superseded config.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_oauth_row("alice")]) @@ -370,8 +370,8 @@ async def test_purge_user_oauth_credentials_for_server_defaults_to_manager_inval @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_logs_raced_rows(monkeypatch): - from litellm.proxy._experimental.mcp_server import db as db_module - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server import db as db_module + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[_oauth_row("alice")]) @@ -390,7 +390,7 @@ async def test_delete_mcp_server_invalidates_cached_tokens_for_enumerated_users( """Deleting a server must invalidate each enumerated user's cached per-user token: the caches are keyed by (user_id, server_id), so a re-created server reusing the same server_id would otherwise serve tokens minted for the deleted server until TTL.""" - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = MagicMock() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=MagicMock(server_id="srv-1")) @@ -411,7 +411,7 @@ async def test_delete_mcp_server_invalidates_cached_tokens_for_enumerated_users( @pytest.mark.asyncio async def test_delete_mcp_server_returns_none_without_cleanup_when_server_missing(): - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = MagicMock() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=None) @@ -425,7 +425,7 @@ async def test_delete_mcp_server_returns_none_without_cleanup_when_server_missin @pytest.mark.asyncio async def test_purge_user_oauth_credentials_for_server_noop_when_empty(): - from litellm.proxy._experimental.mcp_server.db import purge_user_oauth_credentials_for_server + from litellm.proxy.mcp_server.db import purge_user_oauth_credentials_for_server prisma = MagicMock() prisma.db.litellm_mcpusercredentials.find_many = AsyncMock(return_value=[]) @@ -1164,7 +1164,7 @@ def test_expiry_missing_expires_at_is_never_expired(): @pytest.mark.asyncio async def test_resolve_returns_valid_token_without_refreshing(monkeypatch): # A token good for 10 minutes must be returned as-is, with no refresh call. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock() monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1183,7 +1183,7 @@ async def test_resolve_returns_valid_token_without_refreshing(monkeypatch): async def test_resolve_refreshes_expired_token_with_refresh_token(monkeypatch): # The core regression: an expired OBO cred with a refresh_token must mint a # new token rather than returning None (which left the UI tool list empty). - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refreshed = _oauth_cred(access_token="at-fresh", refresh_token="rt-2", expires_in_seconds=3600) refresh = AsyncMock(return_value=refreshed) @@ -1202,7 +1202,7 @@ async def test_resolve_refreshes_expired_token_with_refresh_token(monkeypatch): async def test_resolve_refreshes_token_expiring_within_buffer(monkeypatch): # A token still technically valid (30s left) but inside the 60s buffer must # be proactively refreshed, not handed back. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refreshed = _oauth_cred(access_token="at-fresh", expires_in_seconds=3600) refresh = AsyncMock(return_value=refreshed) @@ -1220,7 +1220,7 @@ async def test_resolve_refreshes_token_expiring_within_buffer(monkeypatch): @pytest.mark.asyncio async def test_resolve_returns_none_when_expired_without_refresh_token(monkeypatch): # No refresh_token means nothing to refresh with — return None, never call refresh. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock() monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1237,7 +1237,7 @@ async def test_resolve_returns_none_when_expired_without_refresh_token(monkeypat @pytest.mark.asyncio async def test_resolve_returns_none_when_refresh_fails(monkeypatch): # A failed refresh (provider returns nothing usable) must surface as None. - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock(return_value=None) monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1253,7 +1253,7 @@ async def test_resolve_returns_none_when_refresh_fails(monkeypatch): @pytest.mark.asyncio async def test_resolve_returns_none_for_missing_credential(monkeypatch): - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod refresh = AsyncMock() monkeypatch.setattr(db_mod, "refresh_user_oauth_token", refresh) @@ -1301,7 +1301,7 @@ def _refresh_server(**overrides): async def _run_refresh(monkeypatch, server, response_body=None): - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod captured: dict = {} @@ -1411,7 +1411,7 @@ async def test_rotate_user_env_vars_skips_undecryptable_rows(): async def test_refresh_user_oauth_token_uses_client_secret_basic(monkeypatch): """LIT-4091: a per-user refresh against a server with token_endpoint_auth_method=client_secret_basic sends HTTP Basic and keeps the secret out of the body.""" - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod server = MagicMock(oauth_identity_binding=None) server.token_url = "https://idp.example.com/oauth2/token" @@ -1450,7 +1450,7 @@ async def test_refresh_user_oauth_token_uses_client_secret_basic(monkeypatch): async def test_refresh_user_oauth_token_defaults_to_client_secret_post(monkeypatch): """Backward compatibility: with no token_endpoint_auth_method the refresh keeps credentials in the body (client_secret_post) and sends no Authorization header.""" - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod server = MagicMock(oauth_identity_binding=None) server.token_url = "https://idp.example.com/oauth2/token" @@ -1537,7 +1537,7 @@ async def test_master_key_rotation_reencrypts_oauth_client_store(monkeypatch): force a full re-authorization.""" import litellm.proxy.common_utils.encrypt_decrypt_utils as enc from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( decrypt_credentials, encrypt_credentials, rotate_mcp_server_credentials_master_key, @@ -1580,7 +1580,7 @@ async def test_delete_mcp_server_cleans_oauth_client_store(): """Deleting a server must remove its server-scoped DCR client store entry alongside the per-user credential and env-var rows, or a re-created server reusing the same server_id would inherit the deleted server's OAuth client.""" - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = MagicMock() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=SimpleNamespace(server_id="s1")) @@ -1603,7 +1603,7 @@ def test_mcp_oauth_token_identity_changes_when_only_upstream_resource_is_edited( calling tools with the previous audience's token until it expires, which is the token-reuse RFC 8707 exists to stop. """ - from litellm.proxy._experimental.mcp_server.db import mcp_oauth_token_identity + from litellm.proxy.mcp_server.db import mcp_oauth_token_identity creds = {"client_id": "cid", "client_secret": "csec", "scopes": ["a"]} unset = _identity_server(credentials=dict(creds)) @@ -1736,7 +1736,8 @@ async def test_enforcement_rejects_preexisting_unverified_credential(): @pytest.mark.asyncio async def test_refresh_identity_rejection_returns_reauthentication_without_persisting(monkeypatch): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import db as module + + from litellm.proxy.mcp_server import db as module validator = AsyncMock(side_effect=HTTPException(status_code=403, detail="oauth_principal_mismatch")) monkeypatch.setattr(module, "enforce_oauth_identity_binding", validator) @@ -1752,9 +1753,9 @@ async def test_refresh_identity_rejection_returns_reauthentication_without_persi async def test_verified_legacy_cache_reads_avoid_database_and_reject_policy_changes(monkeypatch): from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db as module - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import mcp_per_user_token_cache - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import current_binding_proof + from litellm.proxy.mcp_server import db as module + from litellm.proxy.mcp_server.oauth2_token_cache import mcp_per_user_token_cache + from litellm.proxy.mcp_server.oauth_identity_binding import current_binding_proof from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -1789,8 +1790,8 @@ async def test_verified_legacy_cache_reads_avoid_database_and_reject_policy_chan async def test_unverified_legacy_cache_cannot_bypass_enforcement(monkeypatch): from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db as module - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import mcp_per_user_token_cache + from litellm.proxy.mcp_server import db as module + from litellm.proxy.mcp_server.oauth2_token_cache import mcp_per_user_token_cache from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -1815,9 +1816,9 @@ async def test_saved_cimd_grant_refreshes_from_encrypted_storage_on_a_fresh_repl from urllib.parse import parse_qs from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db as db_module - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _store_per_user_token_server_side - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( + from litellm.proxy.mcp_server import db as db_module + from litellm.proxy.mcp_server.discoverable_endpoints import _store_per_user_token_server_side + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1869,7 +1870,7 @@ async def test_saved_cimd_grant_refreshes_from_encrypted_storage_on_a_fresh_repl @pytest.mark.asyncio @pytest.mark.parametrize("provider_scope, expected", [(None, ["a"]), ("b", ["b"]), ("", [])]) async def test_silent_refresh_preserves_omitted_scope_but_accepts_explicit_grant(monkeypatch, provider_scope, expected): - import litellm.proxy._experimental.mcp_server.db as db_mod + import litellm.proxy.mcp_server.db as db_mod await _run_refresh(monkeypatch, _refresh_server(), { "access_token": "new-access", diff --git a/tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py b/tests/unit/proxy/mcp_server/test_discoverable_endpoints.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py rename to tests/unit/proxy/mcp_server/test_discoverable_endpoints.py index cedfa296515..c17f4b392cd 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_discoverable_endpoints.py +++ b/tests/unit/proxy/mcp_server/test_discoverable_endpoints.py @@ -63,8 +63,8 @@ def _stored_grant(access_token="access-token", refresh_token=None, expires_in_se ], ) async def test_vendor_credential_state_agrees_with_egress_token_resolution(monkeypatch, fields, egress_has_token): - from litellm.proxy._experimental.mcp_server import db as mcp_db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server import db as mcp_db + from litellm.proxy.mcp_server import discoverable_endpoints monkeypatch.setattr(mcp_db, "MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS", 60) credential = _stored_grant(**fields) if fields is not None else None @@ -97,7 +97,7 @@ def mock_mcp_client_ip(): have proper client IP context. """ with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): yield @@ -111,8 +111,8 @@ def isolate_global_mcp_registry(monkeypatch): restore, entries leak into other test modules sharing the same worker and break assertions over the full registry contents. """ - from litellm.proxy._experimental.mcp_server.catalog import CatalogSnapshots - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.catalog import CatalogSnapshots + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setattr(global_mcp_server_manager, "catalog", CatalogSnapshots(global_mcp_server_manager)) snapshot = dict(global_mcp_server_manager.registry) @@ -169,8 +169,8 @@ def _resolved_oauth_metadata(): async def test_authorize_resolves_cold_oauth_metadata(monkeypatch): """The route hands the registered server to the flow, whose deferred-discovery join resolves the cold metadata; the redirect must land on the discovered authorization endpoint.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("LITELLM_SALT_KEY", "sk-test-salt-for-lit-6255") server = _unresolved_oauth_server() @@ -199,8 +199,8 @@ async def test_authorize_resolves_cold_oauth_metadata(monkeypatch): async def test_token_resolves_cold_oauth_metadata(): """The route hands the registered server to the exchange, whose deferred-discovery join resolves the cold metadata; the exchange must post to the discovered token endpoint.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _unresolved_oauth_server() global_mcp_server_manager.registry[server.server_id] = server @@ -241,8 +241,8 @@ async def test_token_resolves_cold_oauth_metadata(): async def test_register_resolves_cold_oauth_metadata(): """The route hands the registered server to the registration flow, whose deferred-discovery join resolves the cold metadata; DCR must post to the discovered registration endpoint.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _unresolved_oauth_server().model_copy(update={"client_id": None}) global_mcp_server_manager.registry[server.server_id] = server @@ -281,9 +281,9 @@ async def test_register_route_bridge_missing_registration_url_joins_discovery(): endpoint instead of short-circuiting to dummy credentials because authorization resolves.""" import json - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -340,9 +340,9 @@ async def test_token_route_bridge_missing_registration_url_joins_discovery(): registration endpoint must rejoin discovery at the exchange: the relay-vs-callback arm hinges on the registration url, so skipping discovery would swap the client's own redirect_uri for the gateway callback and the upstream would reject the code.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -402,7 +402,7 @@ def trust_xff(): ``test_get_request_base_url_xff_trust_gate``. """ with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", return_value=True, ): yield @@ -414,13 +414,13 @@ async def test_authorize_endpoint_includes_response_type(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -451,7 +451,7 @@ async def test_authorize_endpoint_includes_response_type(): mock_request.headers = {} # Mock the encryption functions to avoid needing a signing key - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" # Call authorize endpoint @@ -481,13 +481,13 @@ async def test_authorize_endpoint_allows_client_forwarded_modes(auth_type_value) try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -512,7 +512,7 @@ async def test_authorize_endpoint_allows_client_forwarded_modes(auth_type_value) mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" response = await authorize( @@ -534,13 +534,13 @@ async def test_authorize_endpoint_preserves_existing_query_params(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -568,7 +568,7 @@ async def test_authorize_endpoint_preserves_existing_query_params(): mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" response = await authorize( @@ -610,7 +610,7 @@ async def test_authorize_preserves_contract_with_provider_defaults( ) -> None: from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server monkeypatch.setenv("LITELLM_SALT_KEY", "isolated-oauth-test-salt") is_bridge: Final = auth_mode != "direct" @@ -655,13 +655,13 @@ async def test_authorize_endpoint_forwards_pkce_parameters(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -692,7 +692,7 @@ async def test_authorize_endpoint_forwards_pkce_parameters(): mock_request.headers = {} # Mock the encryption function - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state_with_pkce" # Call authorize endpoint with PKCE parameters @@ -724,13 +724,13 @@ async def test_token_endpoint_forwards_code_verifier(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -774,7 +774,7 @@ async def test_token_endpoint_forwards_code_verifier(): from unittest.mock import AsyncMock with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_async_client = MagicMock() # Use AsyncMock for the async post method @@ -819,10 +819,10 @@ async def test_register_client_without_mcp_server_name_returns_dummy(server_name try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -835,7 +835,7 @@ async def test_register_client_without_mcp_server_name_returns_dummy(server_name mock_request.base_url = "https://proxy.litellm.example/" mock_request.headers = {} with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): result = await register_client(request=mock_request, mcp_server_name=server_name) @@ -853,13 +853,13 @@ async def test_register_client_returns_existing_server_credentials(use_root): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -886,7 +886,7 @@ async def test_register_client_returns_existing_server_credentials(use_root): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): result = await register_client( @@ -907,13 +907,13 @@ async def test_register_client_remote_registration_success(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -958,11 +958,11 @@ async def test_register_client_remote_registration_success(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -997,9 +997,9 @@ async def test_register_client_non_bridge_returns_client_redirect_not_gateway_ca verbatim makes a spec-compliant DCR client adopt /callback as its own redirect and loop.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1044,11 +1044,11 @@ async def test_register_client_non_bridge_returns_client_redirect_not_gateway_ca try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -1071,9 +1071,9 @@ async def test_register_client_admin_client_id_echoes_client_redirect_uris(): the gateway /callback and self-redirect loop (#33699).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1100,7 +1100,7 @@ async def test_register_client_admin_client_id_echoes_client_redirect_uris(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": [client_redirect]}), ): result = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) @@ -1126,14 +1126,14 @@ async def test_dcr_full_loop_lands_on_client_redirect_not_gateway_callback(monke from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1176,7 +1176,7 @@ async def test_dcr_full_loop_lands_on_client_redirect_not_gateway_callback(monke try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock( return_value={ "client_name": "Open WebUI", @@ -1187,7 +1187,7 @@ async def test_dcr_full_loop_lands_on_client_redirect_not_gateway_callback(monke ), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -1249,9 +1249,9 @@ async def test_authorize_rejects_untrusted_cross_origin_redirect_with_allowlist_ the mechanism a legitimate separate-origin DCR client needs, not only to PROXY_BASE_URL.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import authorize + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1310,9 +1310,9 @@ async def test_register_client_malformed_redirect_uris_falls_back_to_gateway_cal callback so downstream never iterates a string as URIs or leaks non-string element types (#33699).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1337,7 +1337,7 @@ async def test_register_client_malformed_redirect_uris_falls_back_to_gateway_cal try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": malformed_redirect_uris}), ): result = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) @@ -1353,9 +1353,9 @@ async def test_register_client_valid_multi_redirect_uris_all_echoed(): unchanged, so the element-type guard does not narrow a legitimate multi-entry list (#33699).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import register_client - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import register_client + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1381,7 +1381,7 @@ async def test_register_client_valid_multi_redirect_uris_all_echoed(): client_redirects = ["https://app.example/cb", "http://127.0.0.1:6274/callback"] try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": client_redirects}), ): result = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) @@ -1405,13 +1405,13 @@ async def test_register_client_persists_dcr_client_identity(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1452,11 +1452,11 @@ async def test_register_client_persists_dcr_client_identity(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), ): response = await register_client_with_server( @@ -1502,13 +1502,13 @@ async def _register_persistence_attempted_for_auth_type(auth_type: MCPAuth) -> b to the browser either way, since the caller needs the minted client to run its own flow.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -1545,11 +1545,11 @@ async def _register_persistence_attempted_for_auth_type(auth_type: MCPAuth) -> b with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), ): response = await register_client_with_server( @@ -1601,13 +1601,13 @@ async def test_register_client_persists_only_to_its_own_row_when_another_server_ upstream registration (adopting the sibling's client) or persist onto the wrong row.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer shared_url = "https://provider.example/mcp" @@ -1648,12 +1648,12 @@ async def test_register_client_persists_only_to_its_own_row_when_another_server_ with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(side_effect=_get_row)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(side_effect=_get_row)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), ): response = await register_client_with_server( @@ -1684,13 +1684,13 @@ async def test_register_client_does_not_clobber_token_url_when_absent(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1727,11 +1727,11 @@ async def test_register_client_does_not_clobber_token_url_when_absent(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), ): await register_client_with_server( @@ -1755,13 +1755,13 @@ async def test_register_client_reuses_persisted_client_id_for_non_admin_when_reg try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1795,16 +1795,16 @@ async def test_register_client_reuses_persisted_client_id_for_non_admin_when_reg with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -1831,13 +1831,13 @@ async def test_register_client_reuse_refreshes_request_server_when_manager_updat try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1874,12 +1874,12 @@ async def test_register_client_reuse_refreshes_request_server_when_manager_updat with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -1908,13 +1908,13 @@ async def test_register_client_returns_reused_client_when_concurrent_persist_win try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -1955,16 +1955,16 @@ async def test_register_client_returns_reused_client_when_concurrent_persist_win with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -2020,10 +2020,10 @@ async def test_register_client_re_registers_when_persisted_redirect_uri_no_longe try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2057,16 +2057,16 @@ async def test_register_client_re_registers_when_persisted_redirect_uri_no_longe with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -2106,7 +2106,7 @@ async def test_register_client_grandfathers_persisted_client_without_recorded_re try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) except ImportError: @@ -2128,16 +2128,16 @@ async def test_register_client_grandfathers_persisted_client_without_recorded_re with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), ): @@ -2164,7 +2164,7 @@ async def test_register_client_keeps_persisted_client_when_recorded_redirect_uri try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) except ImportError: @@ -2189,16 +2189,16 @@ async def test_register_client_keeps_persisted_client_when_recorded_redirect_uri with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update_mcp_server, ), ): @@ -2226,10 +2226,10 @@ async def test_register_client_non_admin_reuses_persisted_client_despite_redirec try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2254,12 +2254,12 @@ async def test_register_client_non_admin_reuses_persisted_client_despite_redirec with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -2288,8 +2288,8 @@ async def test_register_client_without_replace_authority_adopts_concurrently_per try: from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2310,23 +2310,23 @@ async def test_register_client_without_replace_authority_adopts_concurrently_per with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(side_effect=[None, winner]), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", + "litellm.proxy.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", new=AsyncMock(return_value=False), ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), ): @@ -2351,7 +2351,7 @@ async def test_persist_without_replace_authority_never_overwrites_a_row_client_i """A DB-declared server already holds a shared DCR client that this process cannot adopt (it was bound to another server URL). A caller without replace authority must get a failure, not fall through to update_mcp_server and overwrite the client every signed-in user depends on.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, ) @@ -2362,8 +2362,8 @@ async def test_persist_without_replace_authority_never_overwrites_a_row_client_i with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=row)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=row)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), ): result = await _persist_dcr_client_registration( server, {"client_id": "my-client"}, "https://proxy.litellm.example/callback", replace_stale_client=False @@ -2383,13 +2383,13 @@ async def test_register_client_reuses_existing_client_id_without_re_dcr(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2428,11 +2428,11 @@ async def test_register_client_reuses_existing_client_id_without_re_dcr(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), ): @@ -2483,10 +2483,10 @@ async def test_public_register_route_persists_first_dcr_client_when_origin_is_co registers: the caller's grant types, response types, auth method and name are not sent upstream, so an anonymous caller cannot shape or phish the shared client.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2511,20 +2511,20 @@ async def test_public_register_route_persists_first_dcr_client_when_origin_is_co try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=persisted_row), ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), ): response = await register_client(request=mock_request, mcp_server_name=oauth2_server.server_name) finally: @@ -2548,10 +2548,10 @@ async def test_public_register_route_persists_first_dcr_client_for_config_server must reach the server-scoped OAuth client store, so a token refresh has a client_id and a second connect reuses the same client instead of minting another.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2578,27 +2578,27 @@ async def test_public_register_route_persists_first_dcr_client_for_config_server try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(side_effect=lambda **kwargs: store.get("blob")), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", + "litellm.proxy.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", new=mock_create, ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), ): @@ -2623,10 +2623,10 @@ async def test_public_register_route_without_configured_origin_does_not_pin_the_ the body it sent, echo the upstream response, and persist nothing. An admin's Connect (or setting PROXY_BASE_URL) is what establishes the shared client.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2644,27 +2644,27 @@ async def test_public_register_route_without_configured_origin_does_not_pin_the_ try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value=request_payload), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", + "litellm.proxy.mcp_server.db.create_mcp_server_oauth_client_credentials_if_absent", new=mock_create, ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), ): @@ -2688,13 +2688,13 @@ async def test_authorize_endpoint_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2725,7 +2725,7 @@ async def test_authorize_endpoint_respects_x_forwarded_proto(): mock_request.headers = {"X-Forwarded-Proto": "https"} # Behind HTTPS proxy # Mock the encryption functions - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" # Call authorize endpoint @@ -2754,13 +2754,13 @@ async def test_token_endpoint_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2804,7 +2804,7 @@ async def test_token_endpoint_respects_x_forwarded_proto(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -2830,13 +2830,13 @@ async def test_oauth_protected_resource_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( oauth_protected_resource_mcp, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2883,13 +2883,13 @@ async def test_oauth_authorization_server_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( oauth_authorization_server_mcp, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -2939,10 +2939,10 @@ async def test_register_client_respects_x_forwarded_proto(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -2957,7 +2957,7 @@ async def test_register_client_respects_x_forwarded_proto(): mock_request.headers = {"X-Forwarded-Proto": "https"} # Behind HTTPS proxy with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): result = await register_client(request=mock_request) @@ -2977,13 +2977,13 @@ async def test_authorize_endpoint_respects_x_forwarded_host(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3019,7 +3019,7 @@ async def test_authorize_endpoint_respects_x_forwarded_host(): } # Mock the encryption functions - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" # Call authorize endpoint @@ -3048,13 +3048,13 @@ async def test_token_endpoint_respects_x_forwarded_host(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3101,7 +3101,7 @@ async def test_token_endpoint_respects_x_forwarded_host(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -3279,7 +3279,7 @@ def test_get_request_base_url_comprehensive( try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) except ImportError: @@ -3302,7 +3302,7 @@ def test_get_request_base_url_comprehensive( mock_request.headers.get = mock_get with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.is_request_from_trusted_proxy", return_value=True, ): result = get_request_base_url(mock_request) @@ -3363,7 +3363,7 @@ def test_get_request_base_url_xff_trust_gate(general_settings, direct_ip, expect try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) except ImportError: @@ -3403,10 +3403,10 @@ def test_xff_misconfig_warning_emitted_once(caplog): from fastapi import Request from litellm.proxy import auth as proxy_auth_pkg # noqa: F401 - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.auth import ip_address_utils + from litellm.proxy.mcp_server.discoverable_endpoints import ( get_request_base_url, ) - from litellm.proxy.auth import ip_address_utils except ImportError: pytest.skip("MCP discoverable endpoints not available") @@ -3441,7 +3441,7 @@ def test_get_request_base_url_honors_proxy_base_url_env(monkeypatch): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) except ImportError: @@ -3469,7 +3469,7 @@ def test_validate_trusted_redirect_uri_logs_diagnostic_on_rejection(caplog, monk try: from fastapi import HTTPException, Request - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) except ImportError: @@ -3531,7 +3531,7 @@ def test_validate_trusted_redirect_uri_follows_the_xff_trust_gate(direct_ip, exp try: from fastapi import HTTPException, Request - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( validate_trusted_redirect_uri, ) except ImportError: @@ -3584,8 +3584,8 @@ def test_get_request_base_url_rejects_malformed_proxy_base_url(bad_value, monkey try: from fastapi import Request - from litellm.proxy._experimental.mcp_server import oauth_utils - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server import oauth_utils + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) except ImportError: @@ -3623,8 +3623,8 @@ def test_get_request_base_url_malformed_proxy_base_url_warning_is_one_shot(monke try: from fastapi import Request - from litellm.proxy._experimental.mcp_server import oauth_utils - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server import oauth_utils + from litellm.proxy.mcp_server.oauth_utils import ( get_request_base_url, ) except ImportError: @@ -3667,13 +3667,13 @@ async def test_oauth_protected_resource_returns_empty_scopes_when_none(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3724,13 +3724,13 @@ async def test_oauth_protected_resource_gateway_managed_oauth2_advertises_gatewa try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3808,9 +3808,9 @@ def test_root_protected_resource_discovers_gateway(monkeypatch, server_count, by from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server import byok_oauth_endpoints, discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import byok_oauth_endpoints, discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPServer monkeypatch.setenv("PROXY_BASE_URL", base_url) @@ -3858,7 +3858,7 @@ def test_root_protected_resource_discovers_gateway(monkeypatch, server_count, by async def test_unnamed_protected_resource_builder_uses_gateway_origin(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) @@ -3883,13 +3883,13 @@ async def test_oauth_authorization_server_returns_empty_scopes_when_none(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -3977,8 +3977,8 @@ def _create_id_lookup_oauth2_server(): async def test_authorize_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4014,8 +4014,8 @@ async def test_authorize_resolves_server_by_id_when_name_lookup_fails(): async def test_token_endpoint_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4057,8 +4057,8 @@ async def test_token_endpoint_resolves_server_by_id_when_name_lookup_fails(): async def test_register_client_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server().model_copy( update={"client_id": None, "client_secret": None, "registration_url": "https://provider.com/oauth/register"} @@ -4097,8 +4097,8 @@ async def test_register_client_resolves_server_by_id_when_name_lookup_fails(): async def test_protected_resource_metadata_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4128,8 +4128,8 @@ async def test_protected_resource_metadata_resolves_server_by_id_when_name_looku def test_authorization_server_metadata_resolves_server_by_id_when_name_lookup_fails(): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_id_lookup_oauth2_server() request = MagicMock(spec=Request) @@ -4161,10 +4161,10 @@ async def test_authorize_root_resolves_single_oauth2_server(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4180,7 +4180,7 @@ async def test_authorize_root_resolves_single_oauth2_server(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper" + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper" ) as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" @@ -4208,10 +4208,10 @@ async def test_authorize_root_fails_with_multiple_oauth2_servers(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4248,10 +4248,10 @@ async def test_authorize_root_does_not_resolve_private_server_for_external_clien try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4267,7 +4267,7 @@ async def test_authorize_root_does_not_resolve_private_server_for_external_clien try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ): with pytest.raises(HTTPException) as exc_info: @@ -4289,10 +4289,10 @@ async def test_token_root_resolves_single_oauth2_server(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4319,7 +4319,7 @@ async def test_token_root_resolves_single_oauth2_server(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -4354,10 +4354,10 @@ async def test_token_root_does_not_resolve_private_server_for_external_client(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4373,7 +4373,7 @@ async def test_token_root_does_not_resolve_private_server_for_external_client(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ): with pytest.raises(HTTPException) as exc_info: @@ -4401,10 +4401,10 @@ async def test_register_root_does_aggregate_dcr_not_single_server_resolution(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4419,7 +4419,7 @@ async def test_register_root_does_aggregate_dcr_not_single_server_resolution(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": ["https://claude.ai/cb"]}), ), patch("litellm.proxy.proxy_server.master_key", "sk-test-salt-for-lit3637"), @@ -4442,10 +4442,10 @@ async def test_register_root_does_not_leak_a_private_server(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -4460,11 +4460,11 @@ async def test_register_root_does_not_leak_a_private_server(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={"redirect_uris": ["https://claude.ai/cb"]}), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ), patch("litellm.proxy.proxy_server.master_key", "sk-test-salt-for-lit3637"), @@ -4484,10 +4484,10 @@ async def test_discovery_root_includes_server_name_prefix(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4523,11 +4523,11 @@ async def test_discovery_root_does_not_expose_private_server_for_external_client try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -4543,7 +4543,7 @@ async def test_discovery_root_does_not_expose_private_server_for_external_client try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="198.51.100.10", ): authorization_response = _build_oauth_authorization_server_response( @@ -4570,7 +4570,7 @@ async def test_discovery_root_does_not_expose_private_server_for_external_client async def test_oauth_callback_redirects_with_state(): """Test OAuth callback endpoint properly decodes state and redirects to client callback URL.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) except ImportError: @@ -4585,7 +4585,7 @@ async def test_oauth_callback_redirects_with_state(): "client_redirect_uri": "http://localhost:3000/ui/mcp/oauth/callback", } - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = mock_state_data # Call callback endpoint with code and state @@ -4611,13 +4611,13 @@ async def test_oauth_callback_preserves_client_redirect_uri_query(): try: from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) except ImportError: pytest.skip("MCP discoverable endpoints not available") - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "http://localhost:3000/ui/mcp/oauth/callback", "original_state": "test-uuid-state-123", @@ -4644,14 +4644,14 @@ async def test_oauth_callback_preserves_client_redirect_uri_query(): async def test_oauth_callback_handles_invalid_state(): """Test OAuth callback returns error page when state decryption fails.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) except ImportError: pytest.skip("MCP discoverable endpoints not available") # Mock state decoding to raise an exception - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.side_effect = Exception("Failed to decrypt state") # Call callback endpoint with invalid state @@ -4670,11 +4670,11 @@ async def test_oauth_callback_handles_invalid_state(): async def test_oauth_callback_accepts_same_origin_ui_redirect(): """UI OAuth flow: the callback should redirect to the proxy's own UI origin when the encrypted state carries a same-origin client_redirect_uri.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "https://proxy.example.com/ui/mcp/oauth/callback", "original_state": "state-123", @@ -4707,13 +4707,13 @@ async def test_authorize_forwards_short_state_and_round_trips_via_cookie(monkeyp from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, decode_state_hash, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -4806,7 +4806,7 @@ async def test_callback_error_path_reads_cookie_and_clears_it(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, callback, encode_state_with_base_url, @@ -4879,7 +4879,7 @@ async def _authorize_then_callback(server, iss, monkeypatch, expected_issuer_ove from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, @@ -5026,10 +5026,10 @@ async def test_oauth_authorize_includes_scopes_from_server_config(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5052,7 +5052,7 @@ async def test_oauth_authorize_includes_scopes_from_server_config(): mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "encrypted_state" # Call authorize without explicit scope parameter @@ -5082,10 +5082,10 @@ async def test_oauth_authorize_prefers_request_scope_over_server_config(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5107,7 +5107,7 @@ async def test_oauth_authorize_prefers_request_scope_over_server_config(): mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "encrypted_state" # Call authorize WITH explicit scope parameter @@ -5138,13 +5138,13 @@ async def test_token_endpoint_refresh_token_grant(): try: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5187,7 +5187,7 @@ async def test_token_endpoint_refresh_token_grant(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_get_client.return_value = mock_async_client @@ -5225,13 +5225,13 @@ async def test_token_endpoint_refresh_token_grant(): async def test_token_endpoint_authorization_code_missing_code(): """Test that authorization_code grant rejects missing code param.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -5278,13 +5278,13 @@ async def test_authorize_endpoint_rejects_non_loopback_redirect_uri(): primitive — reject with 400 before encoding anything into state.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5325,13 +5325,13 @@ async def test_authorize_endpoint_accepts_ipv4_loopback_range_and_ipv6_full_form would miss ``127.0.0.2`` and ``0:0:0:0:0:0:0:1``.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5360,7 +5360,7 @@ async def test_authorize_endpoint_accepts_ipv4_loopback_range_and_ipv6_full_form "http://localhost:3000/cb", ): with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper" + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper" ) as mock_encrypt: mock_encrypt.return_value = "mocked_encrypted_state" response = await authorize( @@ -5380,11 +5380,11 @@ async def test_callback_revalidates_loopback_on_decoded_base_url(): valid. /callback must re-validate the decoded base_url so those stale states can't be used as an open-redirect + code-theft primitive.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "https://attacker.example.com/cb", "original_state": "s", @@ -5404,11 +5404,11 @@ async def test_callback_revalidates_loopback_on_decoded_base_url(): @pytest.mark.asyncio async def test_callback_revalidates_loopback_on_decoded_client_redirect_uri(): """If a state contains a full client_redirect_uri, validate that exact sink.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "base_url": "http://localhost:3000/cb", "original_state": "s", @@ -5428,11 +5428,11 @@ async def test_callback_revalidates_loopback_on_decoded_client_redirect_uri(): @pytest.mark.asyncio async def test_callback_rejects_state_missing_redirect_uri(): """Malformed state without a redirect target should fail with a structured 400.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, ) - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash") as mock_decode: mock_decode.return_value = { "original_state": "s", "code_challenge": None, @@ -5454,10 +5454,10 @@ async def test_token_endpoint_sets_no_store_cache_control(): NOT be cached by intermediaries or the client.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5488,7 +5488,7 @@ async def test_token_endpoint_sets_no_store_cache_control(): fake_http_client.post = AsyncMock(return_value=fake_http_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ): response = await exchange_token_with_server( @@ -5509,10 +5509,10 @@ async def test_token_endpoint_sets_no_store_cache_control(): async def _exchange_with_upstream_token_response(upstream_body): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5539,7 +5539,7 @@ async def _exchange_with_upstream_token_response(upstream_body): fake_http_client.post = AsyncMock(return_value=fake_http_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ): response = await exchange_token_with_server( @@ -5618,7 +5618,7 @@ async def test_authorize_bridge_relay_passes_client_params_verbatim(auth_type_va and applies no gateway-side redirect trust (the upstream enforces its registered binding).""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth @@ -5655,7 +5655,7 @@ async def test_authorize_bridge_requires_s256_pkce(code_challenge, code_challeng """Bridge servers serve unauthenticated public clients, so the PKCE downgrade paths (missing challenge, or a method that is not S256; RFC 7636 defaults a missing method to plain) are rejected at the gateway on both bridge arms.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) @@ -5682,7 +5682,7 @@ async def test_authorize_bridge_short_circuit_keeps_callback_and_redirect_trust( through the gateway callback with the state cookie.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) @@ -5701,7 +5701,7 @@ async def test_authorize_bridge_short_circuit_keeps_callback_and_redirect_trust( assert exc.value.status_code in (400, 403) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ): response = await authorize_with_server( @@ -5725,12 +5725,12 @@ async def test_authorize_non_bridge_client_forwarded_keeps_pre_bridge_contract() requirement and the gateway /callback relay (this is the browser-only Authorize path).""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ): response = await authorize_with_server( @@ -5747,7 +5747,7 @@ async def test_authorize_non_bridge_client_forwarded_keeps_pre_bridge_contract() async def _bridge_token_post_data(server, redirect_uri): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) @@ -5758,7 +5758,7 @@ async def _bridge_token_post_data(server, redirect_uri): fake_http_client.post = AsyncMock(return_value=fake_http_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ): await exchange_token_with_server( @@ -5788,7 +5788,7 @@ async def test_token_bridge_relay_posts_client_redirect_uri(): @pytest.mark.asyncio async def test_token_bridge_relay_requires_redirect_uri(): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) @@ -5818,10 +5818,10 @@ async def test_token_non_bridge_keeps_gateway_callback(): def _named_as_metadata_response(server): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -5829,7 +5829,7 @@ def _named_as_metadata_response(server): global_mcp_server_manager.registry[server.server_id] = server try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): return _build_oauth_authorization_server_response( @@ -5865,7 +5865,7 @@ async def _bridge_register_response( replace_stale_client: bool = False, database_connected: bool = True, ) -> tuple[Response, MagicMock, AsyncMock]: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -5882,15 +5882,15 @@ async def _bridge_register_response( with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._persist_dcr_client_registration", + "litellm.proxy.mcp_server.discoverable_endpoints._persist_dcr_client_registration", new_callable=AsyncMock, ) as mock_persist, patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -5949,7 +5949,7 @@ async def test_register_bridge_relay_surfaces_upstream_error_not_500(): RFC 7591 error body to the client, not a bare 500 that hides the real reason.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -5967,11 +5967,11 @@ async def test_register_bridge_relay_surfaces_upstream_error_not_500(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -5998,7 +5998,7 @@ async def test_register_non_bridge_upstream_error_relays_status_not_500(): opaque 500 that hides the real reason from the create-flow UI.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -6016,11 +6016,11 @@ async def test_register_non_bridge_upstream_error_relays_status_not_500(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -6151,8 +6151,8 @@ async def test_authorize_clientless_bridge_loads_shared_client_before_choosing_t kept one), the caller keeps its own upstream binding through the relay.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("PROXY_BASE_URL", "https://litellm.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "test-registration-binding") @@ -6167,7 +6167,7 @@ async def test_authorize_clientless_bridge_loads_shared_client_before_choosing_t return_value=prisma_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -6176,7 +6176,7 @@ async def test_authorize_clientless_bridge_loads_shared_client_before_choosing_t new=mock_update_server, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ), ): @@ -6213,7 +6213,7 @@ async def test_token_clientless_bridge_loads_shared_client_before_choosing_the_a ) -> None: """The token leg mirrors authorize: with the shared client persisted it redeems the code with that client and the gateway /callback, and with none yet it relays the caller's own client and redirect.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("PROXY_BASE_URL", "https://litellm.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "test-registration-binding") @@ -6225,7 +6225,7 @@ async def test_token_clientless_bridge_loads_shared_client_before_choosing_the_a with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma_client), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -6251,10 +6251,10 @@ async def test_persist_dcr_client_for_client_forwarded_server_only_when_it_is_a_ ) -> None: """A DCR bridge keeps the shared gateway client on the server row (without stamping oauth2_flow on a client-forwarded row), while a client-forwarded server without the bridge still stores nothing.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) from litellm.types.mcp import MCPAuth @@ -6265,7 +6265,7 @@ async def test_persist_dcr_client_for_client_forwarded_server_only_when_it_is_a_ mock_update: Final = AsyncMock(return_value=MagicMock()) with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=prisma), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=mock_update), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=mock_update), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=False), ): @@ -6293,8 +6293,8 @@ async def test_token_sealed_ephemeral_client_is_not_replaced_by_persisted_gatewa server_has_shared_client: bool, ) -> None: """The token leg must use the sealed ephemeral client even if this worker's catalog has a shared client.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("PROXY_BASE_URL", "https://litellm.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "test-registration-binding") @@ -6320,7 +6320,7 @@ async def test_token_sealed_ephemeral_client_is_not_replaced_by_persisted_gatewa return_value=prisma_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=mock_get_mcp_server, ), patch.object( @@ -6329,7 +6329,7 @@ async def test_token_sealed_ephemeral_client_is_not_replaced_by_persisted_gatewa new=mock_update_server, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), ): @@ -6359,8 +6359,8 @@ _BRIDGE_MASTER_KEY = "sk-bridge-producer-master-key-0123456789abcdef" async def _exchange_for_bridge_server(server, upstream_body, key_hash, code="auth-code", fake_client_out=None): - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _ResolvedKey - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.bridge_token_flow import _ResolvedKey + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server fake_http_response = MagicMock() fake_http_response.json.return_value = upstream_body @@ -6376,11 +6376,11 @@ async def _exchange_for_bridge_server(server, upstream_body, key_hash, code="aut with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_active_litellm_key", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_active_litellm_key", new=key_resolver, ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -6395,7 +6395,7 @@ async def _exchange_for_bridge_server(server, upstream_body, key_hash, code="aut client_secret=None, code_verifier="verifier", ) - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import is_bridge_authorization_code + from litellm.proxy.mcp_server.discoverable_endpoints import is_bridge_authorization_code # The key_hash path resolves the presented litellm key; the interactive SSO path recovers identity # from the gateway authorization code instead, so it never awaits the resolver. @@ -6414,7 +6414,7 @@ async def test_oauth_delegate_bridge_token_exchange_mints_envelope_not_raw_token never appears in the bearer the client receives.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, @@ -6445,7 +6445,7 @@ def test_bridge_authorization_code_round_trips_and_rejects_hostile_input(): """The gateway authorization code seals and recovers the upstream code and the SSO user, and is total over hostile input: a raw upstream code (scripted path) opens to None, and a tampered or non-gateway value opens to None rather than raising.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( is_bridge_authorization_code, open_bridge_authorization_code, seal_bridge_authorization_code, @@ -6473,10 +6473,10 @@ async def test_interactive_bridge_token_exchange_mints_user_subject_envelope(): gateway code, not the sealed wrapper.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( seal_bridge_authorization_code, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, @@ -6508,7 +6508,7 @@ async def test_interactive_bridge_token_exchange_mints_user_subject_envelope(): async def test_interactive_bridge_gateway_code_for_another_server_is_rejected_400(): """A gateway authorization code is bound to the server it was minted for: presenting it at another server's token endpoint is a 400, so a code cannot be replayed across a server boundary.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( seal_bridge_authorization_code, ) from litellm.types.mcp import MCPAuth @@ -6530,11 +6530,11 @@ async def test_interactive_bridge_authorize_seals_sso_user_into_state(monkeypatc session cookie and seals it (and the target server) into the encrypted OAuth state, so the callback can later mint a user-bound gateway code; it still proceeds to the upstream redirect. The access gate runs for real against a granted resolver, so its interface stays exercised.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate, client_id="admin-client", registration_url=None) @@ -6549,7 +6549,7 @@ async def test_interactive_bridge_authorize_seals_sso_user_into_state(monkeypatc with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", new=AsyncMock(return_value=admitted), ), patch.object( @@ -6558,7 +6558,7 @@ async def test_interactive_bridge_authorize_seals_sso_user_into_state(monkeypatc new=AsyncMock(return_value=[server.server_id]), ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encode_state_with_base_url", + "litellm.proxy.mcp_server.discoverable_endpoints.encode_state_with_base_url", side_effect=_capture, ), ): @@ -6590,11 +6590,11 @@ async def test_bridge_authorize_gates_on_the_egress_server_access_resolver( from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.discoverable_endpoints import authorize + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import UserAPIKeyAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate, client_id="upstream-app", registration_url=None) global_mcp_server_manager.registry.clear() @@ -6613,7 +6613,7 @@ async def test_bridge_authorize_gates_on_the_egress_server_access_resolver( try: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", new=AsyncMock(return_value=admitted), ) as mock_reload, patch.object( @@ -6622,7 +6622,7 @@ async def test_bridge_authorize_gates_on_the_egress_server_access_resolver( new=AsyncMock(return_value=allowed), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper", + "litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper", return_value="mocked_encrypted_state", ), ): @@ -6666,8 +6666,8 @@ async def test_bridge_authorize_reload_failure_denies_or_stays_retryable( from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import authorize + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6683,7 +6683,7 @@ async def test_bridge_authorize_reload_failure_denies_or_stays_retryable( try: with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", new=AsyncMock(side_effect=HTTPException(status_code=reload_status, detail="x")), ), ): @@ -6720,7 +6720,7 @@ async def test_bridge_authorize_reload_failure_denies_or_stays_retryable( async def test_interactive_bridge_authorize_without_session_redirects_to_login(): """Without a UI session there is no identity to bind, so the short-circuit bridge oauth_delegate authorize sends the browser through litellm login instead of proceeding to the upstream.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import authorize_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import authorize_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate, client_id="admin-client", registration_url=None) @@ -6743,7 +6743,7 @@ async def test_interactive_bridge_callback_seals_user_into_gateway_code(): code, so the client's later token call can prove who signed in.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, is_bridge_authorization_code, ) @@ -6757,15 +6757,15 @@ async def test_interactive_bridge_callback_seals_user_into_gateway_code(): } with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", + "litellm.proxy.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", return_value="enc", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash", + "litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash", return_value=state_data, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", + "litellm.proxy.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", return_value="http://127.0.0.1:60108/cb", ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -6842,10 +6842,10 @@ async def test_bridge_access_envelope_never_carries_upstream_refresh_token(): refresh envelope returned as the response's refresh_token, encrypted, never in plaintext.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedEnvelope, open_envelope, ) @@ -6877,7 +6877,7 @@ async def test_bridge_refresh_grant_with_non_envelope_is_invalid_grant_before_up token, so a refresh_token grant carrying a bare (non-envelope) value is invalid_grant, rejected in _prepare_bridge_refresh BEFORE any upstream exchange. Rejecting before the exchange means a bad refresh request can never consume or rotate an upstream refresh token.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -6885,7 +6885,7 @@ async def test_bridge_refresh_grant_with_non_envelope_is_invalid_grant_before_up fake_http_client.post = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -6921,11 +6921,11 @@ def _mint_test_refresh_envelope( from pydantic import SecretStr - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( build_bridge_refresh_token_response, envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( RefreshCredential, SealedEnvelope, key_hash_identity, @@ -6952,7 +6952,7 @@ async def _refresh_for_bridge_server( ``upstream_body``. Patching the single subject-revalidation dispatch covers both a key_hash and a user_id refresh envelope. Returns the response; the captured client exposes the POST call so a test can assert what refresh token was actually sent upstream.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server fake_http_response = MagicMock() fake_http_response.json.return_value = upstream_body @@ -6964,11 +6964,11 @@ async def _refresh_for_bridge_server( with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._revalidate_active_subject", + "litellm.proxy.mcp_server.bridge_token_flow._revalidate_active_subject", new=AsyncMock(return_value=revalidate_result), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -6993,10 +6993,10 @@ async def test_bridge_mint_returns_refresh_envelope_that_opens_to_upstream_refre (under the same keys and server_id) to the upstream refresh token, so the client can renew later.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedRefreshEnvelope, open_refresh_envelope, ) @@ -7060,10 +7060,10 @@ async def test_bridge_refresh_grant_rotates_refresh_envelope_wrapping_new_upstre that wraps the NEW upstream refresh token, so the rotation is carried through faithfully.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedRefreshEnvelope, open_refresh_envelope, ) @@ -7132,12 +7132,12 @@ async def test_bridge_refresh_grant_renews_a_user_subject_envelope(): exchange received the real upstream refresh token, not the client's envelope.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import user_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import user_identity from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7190,10 +7190,10 @@ async def test_bridge_refresh_re_seals_scope_when_upstream_omits_it_so_the_chain the upstream response had none, and a second refresh off it still re-requests the scope.""" from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( + from litellm.proxy.mcp_server.outbound_credentials.envelope import ( OpenedRefreshEnvelope, open_refresh_envelope, ) @@ -7229,7 +7229,7 @@ async def test_bridge_refresh_grant_with_deactivated_user_is_invalid_grant_befor the user no longer exists) cannot keep refreshing: subject re-validation reports no_active_key and the refresh is invalid_grant, returned BEFORE the upstream exchange. Revocation kills renewal for the user subject exactly as it does for the key subject.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import user_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import user_identity from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7248,19 +7248,19 @@ async def test_bridge_refresh_grant_with_deactivated_user_is_invalid_grant_befor async def test_revalidate_active_subject_dispatches_on_subject_type(): """Subject re-validation routes a key_hash envelope to the key reload and a user_id envelope to the user reload, so revocation gates renewal for either identity source through one dispatch point.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.mcp_server.bridge_token_flow import ( _ResolvedKey, _revalidate_active_subject, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity, user_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity, user_identity with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=_ResolvedKey(key_hash="kh", key=MagicMock())), ) as key_reload, patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow.reload_active_user_by_id", + "litellm.proxy.mcp_server.bridge_token_flow.reload_active_user_by_id", new=AsyncMock(return_value=None), ) as user_reload, ): @@ -7270,11 +7270,11 @@ async def test_revalidate_active_subject_dispatches_on_subject_type(): with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(), ) as key_reload2, patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow.reload_active_user_by_id", + "litellm.proxy.mcp_server.bridge_token_flow.reload_active_user_by_id", new=AsyncMock(return_value="no_active_key"), ) as user_reload2, ): @@ -7288,7 +7288,7 @@ def test_upstream_refresh_credential_expired_refresh_token_is_not_sealed(): not be sealed: _upstream_refresh_credential returns None so the exchange degrades to an access-only response, mirroring how the access grant refuses an already-elapsed access token rather than capping a dead token to the full refresh TTL. A live or unspecified lifetime still yields a credential.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _upstream_refresh_credential + from litellm.proxy.mcp_server.bridge_token_flow import _upstream_refresh_credential assert _upstream_refresh_credential({"access_token": "A", "refresh_token": "R", "refresh_expires_in": 0}) is None assert _upstream_refresh_credential({"refresh_token": "R", "refresh_expires_in": -5}) is None @@ -7305,7 +7305,7 @@ async def test_bridge_refresh_upstream_invalid_grant_maps_to_invalid_grant(): client re-runs authorization_code, rather than surfacing the opaque upstream error it cannot act on.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7325,11 +7325,11 @@ async def test_bridge_refresh_upstream_invalid_grant_maps_to_invalid_grant(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._revalidate_active_subject", + "litellm.proxy.mcp_server.bridge_token_flow._revalidate_active_subject", new=AsyncMock(return_value=None), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7358,7 +7358,7 @@ async def test_bridge_refresh_upstream_error_detection_parses_json_not_substring as the classified upstream rejection rather than triggering a spurious authorization_code re-run.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7378,11 +7378,11 @@ async def test_bridge_refresh_upstream_error_detection_parses_json_not_substring with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._revalidate_active_subject", + "litellm.proxy.mcp_server.bridge_token_flow._revalidate_active_subject", new=AsyncMock(return_value=None), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7409,9 +7409,9 @@ async def test_revalidate_key_subject_revoked_when_owner_scim_deactivated(proxy_ """A key_hash refresh envelope whose key is still active but whose OWNING user was SCIM-deactivated must fail closed to no_active_key, mirroring how admission's _reject_if_admitted_owner_scim_deactivated revokes an offboarded owner's key. Without this, an offboarded user keeps renewing a live key.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -7419,7 +7419,7 @@ async def test_revalidate_key_subject_revoked_when_owner_scim_deactivated(proxy_ resolved = _ResolvedKey(key_hash="kh", key=MagicMock(user_id="offboarded-owner")) with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=resolved), ), patch( @@ -7437,9 +7437,9 @@ async def test_revalidate_key_subject_active_owner_renews_and_missing_owner_fail """The key-owner SCIM gate blocks only an explicit scim_active False: an active owner renews (None), and a missing owner (get_user_object's wrapped ValueError) fails OPEN, since a key may outlive its owner record and a transient blip must not revoke a live key.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import _ResolvedKey, _revalidate_active_subject + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -7448,7 +7448,7 @@ async def test_revalidate_key_subject_active_owner_renews_and_missing_owner_fail with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=resolved), ), patch( @@ -7460,7 +7460,7 @@ async def test_revalidate_key_subject_active_owner_renews_and_missing_owner_fail with ( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._reload_active_key_by_hash", + "litellm.proxy.mcp_server.bridge_token_flow._reload_active_key_by_hash", new=AsyncMock(return_value=resolved), ), patch( @@ -7477,7 +7477,7 @@ async def test_bridge_mint_fails_closed_before_upstream_when_master_key_unset(): misconfigured gateway returns a 500 server_error without consuming the single-use code, avoiding the burn-then-fail the pre-exchange phase exists to prevent. The failure is returned as an RFC 6749 error body, not raised.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7485,11 +7485,11 @@ async def test_bridge_mint_fails_closed_before_upstream_when_master_key_unset(): fake_http_client.post = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_active_litellm_key", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_active_litellm_key", new=AsyncMock(return_value="no_active_key"), ), patch("litellm.proxy.proxy_server.master_key", None), @@ -7514,7 +7514,7 @@ async def _prepare_only_bridge_exchange(resolver_result): """Drive exchange_token_with_server for a bridge oauth_delegate authorization_code request with the identity resolver stubbed to a given tagged result, returning (response, post_mock) so a test can assert the mapped status and that the single-use code was never exchanged.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth server = _bridge_server(auth_type=MCPAuth.oauth_delegate) @@ -7522,11 +7522,11 @@ async def _prepare_only_bridge_exchange(resolver_result): fake_http_client.post = AsyncMock() with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_active_litellm_key", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_active_litellm_key", new=AsyncMock(return_value=resolver_result), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7589,7 +7589,7 @@ async def _exchange_for_bridge_server_with_jwt(jwt_auth_result, upstream_body=No presented credential is JWT-shaped, with _resolve_jwt_auth stubbed to a given result. Returns (response, post_mock) so a test can assert the minted envelope's sealed identity or the mapped error status.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import exchange_token_with_server + from litellm.proxy.mcp_server.discoverable_endpoints import exchange_token_with_server from litellm.types.mcp import MCPAuth request = _bridge_mock_request() @@ -7606,11 +7606,11 @@ async def _exchange_for_bridge_server_with_jwt(jwt_auth_result, upstream_body=No server = _bridge_server(auth_type=MCPAuth.oauth_delegate) with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._resolve_jwt_auth", + "litellm.proxy.mcp_server.bridge_token_flow._resolve_jwt_auth", new=AsyncMock(return_value=jwt_auth_result), ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -7644,12 +7644,12 @@ async def test_bridge_mint_unmapped_jwt_is_rejected_before_upstream(): async def test_bridge_mint_jwt_mapped_to_virtual_key_seals_key_hash_subject(): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( BridgeEnvelopeAdmitted, envelope_keys_from_master_key, resolve_bridge_envelope, ) - from litellm.proxy._types import UserAPIKeyAuth response, _post = await _exchange_for_bridge_server_with_jwt( UserAPIKeyAuth(token="mapped-key-hash-99", user_id="mapped-user") @@ -7748,7 +7748,7 @@ def _jwt_auth_patches(mapped_key): stack.enter_context(patch("litellm.proxy.proxy_server.user_api_key_cache", cache)) stack.enter_context( patch( - "litellm.proxy._experimental.mcp_server.bridge_token_flow._key_owner_scim_deactivated", + "litellm.proxy.mcp_server.bridge_token_flow._key_owner_scim_deactivated", new=AsyncMock(return_value=False), ) ) @@ -7760,8 +7760,8 @@ async def test_jwt_mapped_to_service_account_key_without_user_id_resolves(): """A JWT mapped to a team or service-account virtual key (no user_id) is still an active credential: _resolve_jwt_auth returns the mapped key, and the mint seals a key_hash-subject envelope rather than 400ing with no_identity.""" - from litellm.proxy._experimental.mcp_server import bridge_token_flow from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import bridge_token_flow from litellm.types.mcp import MCPAuth mapped_key = UserAPIKeyAuth(user_id=None, token="svc-key-hash-1") @@ -7790,8 +7790,8 @@ async def test_jwt_mapped_to_service_account_key_without_user_id_resolves(): async def test_jwt_mapped_to_blocked_key_is_rejected(): """The relaxed gate is still active-state gated: a JWT mapped to a blocked virtual key resolves to None, so the mint cannot seal an envelope under it.""" - from litellm.proxy._experimental.mcp_server import bridge_token_flow from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import bridge_token_flow mapped_key = UserAPIKeyAuth(user_id=None, token="blocked-key-hash-1", blocked=True) request = _bridge_mock_request() @@ -7816,8 +7816,8 @@ async def test_master_key_at_token_endpoint_mints_key_hash_envelope(): credential: presented at the bridge /token endpoint it must mint a key_hash-subject envelope (sealed under hash_token(master_key)) even with no database connection at all. A presented key that is NOT the master key still hits the unresolvable gate when prisma is down, unchanged.""" - from litellm.proxy._experimental.mcp_server import bridge_token_flow from litellm.proxy._types import hash_token + from litellm.proxy.mcp_server import bridge_token_flow from litellm.types.mcp import MCPAuth master = "sk-test-master-key-mint-0000" @@ -7920,14 +7920,14 @@ def test_bridge_reported_expires_in_can_be_zero_at_jwt_exp_boundary(): from fastapi.responses import JSONResponse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _BridgeMintReady, finish_bridge_mint, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.bridge_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.bridge_credentials import ( envelope_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import key_hash_identity + from litellm.proxy.mcp_server.outbound_credentials.envelope import key_hash_identity from litellm.types.mcp import MCPAuth ready = _BridgeMintReady( @@ -7951,7 +7951,7 @@ def test_classify_upstream_lifetime(): oversized) is "unspecified" so the envelope caps it, while a parseable non-positive value is "expired": the upstream reporting an already-dead token, which the mint must reject rather than silently give the 1h cap.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _classify_upstream_lifetime + from litellm.proxy.mcp_server.bridge_token_flow import _classify_upstream_lifetime assert _classify_upstream_lifetime(300) == 300 assert _classify_upstream_lifetime(300.0) == 300 @@ -7984,7 +7984,7 @@ def test_bridge_grant_honors_and_rejects_upstream_lifetime(): """The grant validator honors a positive lifetime, leaves an unknown one None for the envelope to cap, and rejects an explicitly-expired one with "expired_lifetime" so a dead upstream token is never sealed into an hour-long envelope.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import _bridge_grant_from_token_response + from litellm.proxy.mcp_server.bridge_token_flow import _bridge_grant_from_token_response def grant(v): return _bridge_grant_from_token_response({"access_token": "x", "expires_in": v}) @@ -8065,10 +8065,10 @@ async def _exchange_persistence_attempted_for_auth_type(auth_type) -> bool: their contract is that the upstream token stays browser-held, minted/stored/refreshed nowhere.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -8095,21 +8095,21 @@ async def _exchange_persistence_attempted_for_auth_type(auth_type) -> bool: with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=fake_http_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.extract_user_id_from_request", + "litellm.proxy.mcp_server.discoverable_endpoints.extract_user_id_from_request", new_callable=AsyncMock, return_value="admin-user", ), patch( # test-quality-ok: this control tests persistence by auth mode; write-policy behavior is covered separately - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", + "litellm.proxy.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", new_callable=AsyncMock, return_value="admin-user", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._store_per_user_token_server_side", + "litellm.proxy.mcp_server.discoverable_endpoints._store_per_user_token_server_side", new_callable=AsyncMock, ) as mock_store, ): @@ -8147,7 +8147,7 @@ async def test_token_exchange_persists_for_oauth2(): # ------------------------------------------------------------------- _OBO_RESOURCE = "https://litellm.example.com/mcp/obo_mcp" -_PATCH_ISSUERS = "litellm.proxy._experimental.mcp_server.discoverable_endpoints._jwt_auth_issuers" +_PATCH_ISSUERS = "litellm.proxy.mcp_server.discoverable_endpoints._jwt_auth_issuers" def _obo_server(scopes=None): @@ -8169,7 +8169,7 @@ def _obo_server(scopes=None): def test_obo_protected_resource_response_names_jwt_issuers(): """An OBO server's PRM points authorization_servers at the configured JWT issuers (the IdP that mints and validates the subject token), with the gateway resource echoed back.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) @@ -8184,7 +8184,7 @@ def test_obo_protected_resource_response_names_jwt_issuers(): def test_obo_protected_resource_response_scopes_default_empty(): """A scopeless OBO server reports scopes_supported as [] rather than None.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) @@ -8196,7 +8196,7 @@ def test_obo_protected_resource_response_scopes_default_empty(): def test_obo_protected_resource_response_falls_back_when_no_issuer(): """With no JWT issuer configured, the OBO branch returns None so the caller falls back to the gateway-default PRM (discovery still works, it just can't name the IdP).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) @@ -8206,10 +8206,10 @@ def test_obo_protected_resource_response_falls_back_when_no_issuer(): def test_obo_protected_resource_response_ignores_non_obo_server(): """Non-OBO servers are not handled by this branch (returns None -> gateway default).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _obo_protected_resource_response, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8228,10 +8228,10 @@ async def test_build_oauth_protected_resource_response_obo_end_to_end(): authorization_servers, proving the extracted branch is wired into the public discovery path.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -8282,11 +8282,11 @@ async def test_extract_user_id_reads_x_litellm_api_key_header(proxy_globals): """The LiteLLM key arrives on x-litellm-api-key (what Claude Desktop/Code send), not Authorization. Reading only Authorization dropped the identity, so the per-user token was never stored and the egress 401'd forever. Resolution must honor x-litellm-api-key.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth, hash_token from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) key = "sk-alice-key" cache = UserApiKeyCache() @@ -8307,11 +8307,11 @@ async def test_extract_user_id_rehydrates_cross_replica_dict_cache(proxy_globals """Cross-replica, async_get_cache hands back a serialized dict, not a UserAPIKeyAuth. Resolution must rehydrate it; the old getattr(cached, "user_id") returned None on a dict, which is exactly why a multi-replica gateway never found the stored token.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import hash_token from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) key = "sk-alice-key" cache = UserApiKeyCache() @@ -8328,11 +8328,11 @@ async def test_extract_user_id_falls_back_to_db_on_cache_miss(proxy_globals): """A cache miss must read the key from the DB rather than returning None; the old code did a cache-only peek and skipped the DB, so any replica that hadn't just authenticated the key failed to store the token.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) key = "sk-bob-key" @@ -8350,10 +8350,10 @@ async def test_extract_user_id_falls_back_to_db_on_cache_miss(proxy_globals): @pytest.mark.asyncio async def test_extract_user_id_none_without_litellm_key(proxy_globals): """No LiteLLM key on the request resolves to None without consulting the resolver.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( extract_user_id_from_request, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8367,11 +8367,11 @@ async def test_extract_user_id_rejects_blocked_key(proxy_globals): """A blocked LiteLLM key must not resolve an identity. get_key_object returns the DB row without checking blocked/expiry (the main auth pipeline does, and the public token endpoint bypasses it), so a revoked key could otherwise overwrite the stored per-user OAuth token for its user.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) class _FakePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8389,11 +8389,11 @@ async def test_extract_user_id_rejects_expired_key(proxy_globals): """An expired LiteLLM key must not resolve an identity, for the same reason as a blocked key.""" from datetime import datetime, timedelta, timezone - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - extract_user_id_from_request, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + extract_user_id_from_request, + ) expired = (datetime.now(timezone.utc) - timedelta(hours=1)).isoformat() @@ -8414,12 +8414,12 @@ async def test_resolve_active_litellm_key_returns_resolved_key_for_active_key(pr record. For an active key the resolver returns exactly hash_token(key), the same value get_key_object and the whole cache/DB layer key the record by, so the sealed reference resolves back to this key at admission.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy._types import UserAPIKeyAuth, hash_token + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, _ResolvedKey, ) - from litellm.proxy._types import UserAPIKeyAuth, hash_token - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache key = "sk-alice-key" cache = UserApiKeyCache() @@ -8444,13 +8444,13 @@ async def test_resolve_active_litellm_key_resolves_key_without_user_id(proxy_glo presence wrongly rejected these keys with invalid_request; the active-state gate now checks only blocked and expiry, and the key hash (not the user) is what the mint seals. The per-user token store still gets no user for such a key, since there is none to key a stored credential by.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy._types import UserAPIKeyAuth, hash_token + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, _ResolvedKey, extract_user_id_from_request, ) - from litellm.proxy._types import UserAPIKeyAuth, hash_token - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache key = "sk-team-scoped-key" cache = UserApiKeyCache() @@ -8473,11 +8473,11 @@ async def test_resolve_active_litellm_key_resolves_key_without_user_id(proxy_glo async def test_resolve_active_litellm_key_rejects_blocked_key(proxy_globals): """A blocked key must not yield a hash, so no gateway-bound envelope is minted for a revoked key; the mint fails closed with invalid_request instead.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - _resolve_active_litellm_key, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + _resolve_active_litellm_key, + ) class _FakePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8496,11 +8496,11 @@ async def test_resolve_active_litellm_key_fails_closed_on_malformed_expiry(proxy returns invalid_request), not surface an unhandled 500. The active-state check runs outside the resolver's try, so it must be total over a bad expires rather than letting datetime.fromisoformat raise. Before the fix this raised a ValueError instead of returning None.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( - _resolve_active_litellm_key, - ) from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( + _resolve_active_litellm_key, + ) class _FakePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8516,10 +8516,10 @@ async def test_resolve_active_litellm_key_fails_closed_on_malformed_expiry(proxy @pytest.mark.asyncio async def test_resolve_active_litellm_key_no_active_key_without_litellm_key(proxy_globals): """No LiteLLM key on the request yields no hash without consulting the resolver.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8534,10 +8534,10 @@ async def test_resolve_active_litellm_key_db_outage_is_unavailable(proxy_globals the caller's fault, so the resolver reports "unavailable" (the mint statuses it 503) rather than collapsing it to the same value as a missing credential. is_database_service_unavailable_error classifies a connection error (an OSError) as an outage, matching admission's egress-side handling.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _OutagePrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8557,10 +8557,10 @@ async def test_resolve_active_litellm_key_permanent_engine_fault_is_faulted(prox whose wording promises the outage is transient and asks the client to retry.""" from prisma.engine.errors import BinaryNotFoundError - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _FaultedPrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8581,10 +8581,10 @@ async def test_resolve_active_litellm_key_transport_error_over_permanent_fault_i import httpx from prisma.engine.errors import BinaryNotFoundError - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _ReconnectFailedPrisma: async def get_data(self, token, table_name, parent_otel_span=None, proxy_logging_obj=None): @@ -8605,10 +8605,10 @@ async def test_resolve_active_litellm_key_no_database_is_unresolvable(proxy_glob """With no database connection configured the gateway cannot verify the presented key at all, so the resolver reports "unresolvable" (the mint statuses it 500) instead of blaming the caller. Mirrors admission, which 500s a missing prisma_client on the egress side.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( _resolve_active_litellm_key, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = None @@ -8639,8 +8639,8 @@ async def test_reload_active_user_by_id_missing_user_is_no_active_key(proxy_glob refresh path maps it to invalid_grant), not unresolvable/500. get_user_object catches the missing row and re-raises a bare ValueError, so a missing user must not be misclassified as a DB outage or an opaque gateway fault.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8658,8 +8658,8 @@ async def test_reload_active_user_by_id_db_outage_is_unavailable(proxy_globals): a missing user, so the refresh path surfaces "unavailable" (a 503) rather than blaming the caller. get_user_object wraps the outage in a bare ValueError, so this exercises the chain-aware classifier; a raw ConnectionError would falsely pass even a chain-blind check because it is an OSError.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8678,8 +8678,8 @@ async def test_reload_active_user_by_id_permanent_engine_fault_is_faulted(proxy_ wraps the fault in a bare ValueError, so the classification has to read the wrapped cause.""" from prisma.engine.errors import MismatchedVersionsError - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id proxy_globals.user_api_key_cache = UserApiKeyCache() proxy_globals.prisma_client = object() @@ -8699,9 +8699,9 @@ async def test_load_active_user_by_id_reads_the_row_from_the_database_not_the_ca member never evicts the cached row, so a credential minted off the cached row refused the very first token exchange as not a member. The database source has to read the row from the database and leave the fresh row in the cache for the requests the credential makes next.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import load_active_user_by_id from litellm.proxy._types import LiteLLM_UserTable from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import load_active_user_by_id cache = UserApiKeyCache() await cache.async_set_cache( @@ -8728,12 +8728,12 @@ async def test_load_active_user_by_id_serves_a_cached_row_without_a_database_rea """Introspection and refresh revalidation run per call, so the loader's default source is the cache: a cached row answers without a database read, and only a caller that asks for the database row pays for one.""" - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy._types import LiteLLM_UserTable + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.bridge_token_flow import ( load_active_user_by_id, reload_active_user_by_id, ) - from litellm.proxy._types import LiteLLM_UserTable - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache cache = UserApiKeyCache() await cache.async_set_cache( @@ -8766,13 +8766,13 @@ async def test_token_endpoint_uses_client_secret_basic_when_configured(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8805,7 +8805,7 @@ async def test_token_endpoint_uses_client_secret_basic_when_configured(): mock_response.raise_for_status = MagicMock() with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client" + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client" ) as mock_get_client: mock_async_client = MagicMock() mock_async_client.post = AsyncMock(return_value=mock_response) @@ -8837,13 +8837,13 @@ async def test_token_endpoint_client_secret_basic_without_secret_returns_400(): inbound /token endpoint surfaces it as a 400 rather than silently posting a downgraded request.""" from fastapi import HTTPException, Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -8903,10 +8903,10 @@ async def test_authorize_endpoint_rejects_non_oauth2_server(): """authorize() against a none-auth server returns an accurate 'does not use OAuth' 400, not the misleading 'client_id is required' that fired before the auth_type was checked.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -8942,10 +8942,10 @@ async def test_token_endpoint_rejects_non_oauth2_server(): """token_endpoint() against a none-auth server returns 'does not use OAuth' 400 instead of the misleading 'token url is not set'.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( token_endpoint, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -8984,10 +8984,10 @@ async def test_register_client_rejects_non_oauth2_server(): """register_client() against a named none-auth server returns 'does not use OAuth' 400 instead of the misleading 'authorization url is not set'.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9004,7 +9004,7 @@ async def test_register_client_rejects_non_oauth2_server(): try: with pytest.raises(HTTPException) as exc_info: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.read_request_body", + "litellm.proxy.mcp_server.discoverable_endpoints.read_request_body", new=AsyncMock(return_value={}), ): await register_client(request=mock_request, mcp_server_name="access_group_server") @@ -9024,10 +9024,10 @@ async def test_register_client_rejects_non_oauth2_server(): async def test_oauth_protected_resource_for_gateway_owned_auth(auth_type, use_standard_pattern): from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -9055,10 +9055,10 @@ async def test_oauth_protected_resource_for_gateway_owned_auth(auth_type, use_st async def test_oauth_authorization_server_404_for_non_oauth2_server(): """Discovery must not advertise a none-auth server as an OAuth authorization server.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9090,13 +9090,13 @@ async def test_oauth_protected_resource_passthrough_none_auth_not_404(): server that opted into OAuth pass-through must still proxy upstream metadata, it must NOT be 404'd. The gate has to sit after the pass-through branch.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -9122,7 +9122,7 @@ async def test_oauth_protected_resource_passthrough_none_auth_not_404(): try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.fetch_upstream_oauth_protected_resource", + "litellm.proxy.mcp_server.discoverable_endpoints.fetch_upstream_oauth_protected_resource", new=AsyncMock(return_value={"authorization_servers": ["https://upstream-idp.example.com"]}), ): response = await _build_oauth_protected_resource_response( @@ -9140,10 +9140,10 @@ async def test_oauth_protected_resource_passthrough_none_auth_not_404(): async def test_oauth_protected_resource_404_for_unknown_server_name(): """Unknown server names must not produce metadata advertising nonexistent resources.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9168,10 +9168,10 @@ async def test_oauth_authorization_server_404_for_unknown_server_name(): """A named authorization-server discovery request for an unknown server returns 404, not a 200 metadata document pointing at non-existent /{name}/authorize and /{name}/token.""" try: - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) except ImportError: @@ -9195,8 +9195,8 @@ async def test_store_per_user_token_server_side_invalidates_v2_token_cache(): """A token stored by the OAuth callback (code exchange or refresh) drops the v2 per-user token cache entry, so egress stops serving the replaced token immediately instead of until its TTL.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.discoverable_endpoints import ( _store_per_user_token_server_side, ) from litellm.types.mcp import MCPAuth @@ -9218,11 +9218,11 @@ async def test_store_per_user_token_server_side_invalidates_v2_token_cache(): return_value=MagicMock(), ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", new=cache_set_mock, ), patch.object( @@ -9245,8 +9245,8 @@ async def test_store_per_user_token_server_side_invalidates_v2_token_cache(): async def test_store_per_user_token_server_side_skips_invalidate_when_db_write_fails(): """A failed DB write neither warms the v1 cache nor drops the v2 cache entry; the previously stored token is still the truth.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.discoverable_endpoints import ( _store_per_user_token_server_side, ) from litellm.types.mcp import MCPAuth @@ -9268,11 +9268,11 @@ async def test_store_per_user_token_server_side_skips_invalidate_when_db_write_f return_value=MagicMock(), ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new=AsyncMock(side_effect=RuntimeError("db down")), ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_per_user_token_cache.set", new=cache_set_mock, ), patch.object( @@ -9300,10 +9300,10 @@ async def test_token_exchange_pairs_client_secret_with_server_client_id(): placeholder makes the IdP reject the exchange with 401 on every re-auth.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -9331,7 +9331,7 @@ async def test_token_exchange_pairs_client_secret_with_server_client_id(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): await exchange_token_with_server( @@ -9354,11 +9354,11 @@ async def test_token_exchange_pairs_client_secret_with_server_client_id(): async def test_token_exchange_refresh_passes_presented_refresh_ownership(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import RefreshTokenPresented - from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.oauth_identity_binding import RefreshTokenPresented from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer server = MCPServer( @@ -9386,15 +9386,15 @@ async def test_token_exchange_refresh_passes_presented_refresh_ownership(): with ( patch( # test-quality-ok: no injection seam exists for the exchange's HTTP and identity collaborators - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ), patch( # test-quality-ok: no injection seam exists for request identity extraction - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.extract_user_id_from_request", + "litellm.proxy.mcp_server.discoverable_endpoints.extract_user_id_from_request", new=AsyncMock(return_value="user-a"), ), patch( # test-quality-ok: captures the ownership value at the exchange boundary - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", + "litellm.proxy.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", new=enforce, ), ): @@ -9419,11 +9419,11 @@ async def test_token_exchange_refresh_passes_presented_refresh_ownership(): async def test_token_exchange_authorization_code_passes_no_refresh_ownership(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, seal_bridge_authorization_code, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer monkeypatch.setenv("LITELLM_SALT_KEY", "identity-binding-test-salt") @@ -9452,15 +9452,15 @@ async def test_token_exchange_authorization_code_passes_no_refresh_ownership(mon with ( patch( # test-quality-ok: no injection seam exists for the exchange's HTTP and identity collaborators - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ), patch( # test-quality-ok: no injection seam exists for request identity extraction - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.extract_user_id_from_request", + "litellm.proxy.mcp_server.discoverable_endpoints.extract_user_id_from_request", new=AsyncMock(return_value="user-a"), ), patch( # test-quality-ok: captures the ownership value at the exchange boundary - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", + "litellm.proxy.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding", new=enforce, ), ): @@ -9498,10 +9498,10 @@ async def _exchange_with_upstream_response( caller-supplied-credentials flow (no stored client on the server).""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -9523,7 +9523,7 @@ async def _exchange_with_upstream_response( mock_async_client.post = AsyncMock(return_value=upstream_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): return await exchange_token_with_server( @@ -9671,10 +9671,10 @@ async def test_token_exchange_relays_rejection_when_http_client_raises(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -9694,7 +9694,7 @@ async def test_token_exchange_relays_rejection_when_http_client_raises(): mock_request.headers = {} with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=raising_client, ): response = await exchange_token_with_server( @@ -9720,7 +9720,7 @@ async def test_register_relays_rejection_when_http_client_raises(): so the register relay must catch it there, not only from the explicit raise_for_status.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -9740,11 +9740,11 @@ async def test_register_relays_rejection_when_http_client_raises(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=raising_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -9783,7 +9783,7 @@ async def test_register_never_relays_out_of_contract_body_to_client(): client detail names only the status.""" import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) @@ -9801,11 +9801,11 @@ async def test_register_never_relays_out_of_contract_body_to_client(): with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=raising_client, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", + "litellm.proxy.mcp_server.discoverable_endpoints._reuse_persisted_dcr_client_if_available", new_callable=AsyncMock, return_value=False, ), @@ -9854,13 +9854,13 @@ async def test_persist_dcr_client_for_config_server_uses_side_store(): server so refresh can authenticate this process, and never call update_server(None) (which previously raised AttributeError on .approval_status, was swallowed, and reported a 200 that persisted nothing).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer config_server = MCPServer( @@ -9883,19 +9883,19 @@ async def test_persist_dcr_client_for_config_server_uses_side_store(): patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.update_mcp_server", + "litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(return_value=None), ), patch( - "litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=mock_upsert, ), patch.object(global_mcp_server_manager, "update_server", new=mock_update_server), @@ -9935,11 +9935,11 @@ async def test_hydrate_config_server_applies_stored_dcr_client(monkeypatch, lega refresh_token grant can authenticate as the registered client instead of re-authenticating.""" import litellm.proxy.common_utils.encrypt_decrypt_utils as enc from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.discoverable_endpoints import ( hydrate_config_server_dcr_client, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -9975,7 +9975,7 @@ async def test_hydrate_config_server_applies_stored_dcr_client(monkeypatch, lega with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=AsyncMock(return_value=stored_blob), ), ): @@ -9994,14 +9994,14 @@ async def test_reuse_config_server_reads_store_with_real_crypto(monkeypatch): a re-authorize reuses the client instead of re-minting one.""" import litellm.proxy.common_utils.encrypt_decrypt_utils as enc from litellm.litellm_core_utils.safe_json_dumps import safe_dumps - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.discoverable_endpoints import ( _reuse_persisted_dcr_client_if_available, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -10033,9 +10033,9 @@ async def test_reuse_config_server_reads_store_with_real_crypto(monkeypatch): with ( patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=True), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_lookup, ), ): @@ -10051,14 +10051,14 @@ async def test_temp_server_is_not_persisted_to_store(): """A rowless server that is NOT config-declared (a throwaway /server/oauth/session server) must not leave a permanent store row on persist, and the read must never consult the store for it. Its minted client is overlaid in memory for the session only.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _persist_dcr_client_registration, _reuse_persisted_dcr_client_if_available, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer temp = MCPServer( @@ -10078,11 +10078,11 @@ async def test_temp_server_is_not_persisted_to_store(): with ( patch.object(global_mcp_server_manager, "is_config_declared_server", return_value=False), patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), - patch("litellm.proxy._experimental.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=upsert), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=None)), + patch("litellm.proxy.mcp_server.db.upsert_mcp_server_oauth_client_credentials", new=upsert), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_read, ), patch.object(global_mcp_server_manager, "update_server", new=AsyncMock()), @@ -10113,10 +10113,10 @@ async def test_temp_server_is_not_persisted_to_store(): async def test_hydrate_does_not_overwrite_explicit_config_client_id(): """An explicit client_id set in config.yaml wins: hydration must not overwrite it with a stale persisted store client, and must not even read the store when config already supplied a client.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( hydrate_config_server_dcr_client, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -10131,7 +10131,7 @@ async def test_hydrate_does_not_overwrite_explicit_config_client_id(): with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_read, ), ): @@ -10149,10 +10149,10 @@ async def test_reuse_does_not_inherit_store_client_when_a_row_exists(): server whose id collides with a config-declared server must not be able to load that config server's client from the store and send it to its own token endpoint. A row that exists but has no client_id yields no reusable client and must not fall back to the store.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.discoverable_endpoints import ( _reuse_persisted_dcr_client_if_available, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer submitted = MCPServer( @@ -10173,11 +10173,11 @@ async def test_reuse_does_not_inherit_store_client_when_a_row_exists(): with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server", + "litellm.proxy.mcp_server.db.get_mcp_server", new=AsyncMock(return_value=row_without_client), ), patch( - "litellm.proxy._experimental.mcp_server.db.get_mcp_server_oauth_client_credentials", + "litellm.proxy.mcp_server.db.get_mcp_server_oauth_client_credentials", new=store_lookup, ), ): @@ -10193,7 +10193,7 @@ async def test_load_servers_from_config_hydrates_dcr_clients(): """load_servers_from_config must invoke DCR-client hydration so config servers pick up their persisted client on startup; deleting the call site leaves a restarted server with no client_id and forces re-authentication on every token expiry.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10210,7 +10210,7 @@ async def test_reload_servers_from_database_hydrates_dcr_clients(): reload_servers_from_database runs after the DB connects and must hydrate config servers' persisted DCR clients too, or a fresh pod has no client_id for a config server and forces re-authentication on the first token refresh.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10240,8 +10240,8 @@ def test_aggregate_wellknown_routes_serve_gateway_metadata(): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10273,8 +10273,8 @@ def test_as_aggregate_route_reserves_mcp_for_the_aggregate(): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10311,7 +10311,7 @@ def test_well_known_root_suffix_reflects_server_root_path(): import os from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.oauth_utils import well_known_root_suffix + from litellm.proxy.mcp_server.oauth_utils import well_known_root_suffix with patch.dict(os.environ, {"SERVER_ROOT_PATH": ""}): assert well_known_root_suffix() == "" @@ -10325,11 +10325,11 @@ def test_well_known_root_suffix_reflects_server_root_path(): async def test_root_resource_uses_gateway_without_changing_authorization_relay(): from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10360,11 +10360,11 @@ async def test_named_discovery_issuer_matches_protected_resource_authorization_s resolved the metadata from, which is the protected-resource authorization_servers entry.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_oauth_authorization_server_response, _build_oauth_protected_resource_response, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10395,10 +10395,10 @@ async def test_openid_configuration_issuer_stays_bare_origin_for_single_oauth2_s bare origin even when root discovery resolves the one configured OAuth2 server.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( openid_configuration, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10424,8 +10424,8 @@ def test_gateway_dcr_flow_routing_engages_only_for_llm_dcrc_clients(monkeypatch) from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -10481,7 +10481,7 @@ async def test_authorize_wall_names_the_fix_for_urlless_servers(): """LIT-4629: the authorize wall previously said only "authorization url is not set" with no hint that spec-only servers never discover; the detail must now name both remedies (manual Authorization URL + Token URL, or an Issuer for RFC 8414 discovery).""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10518,7 +10518,7 @@ async def test_token_wall_names_the_fix_for_urlless_servers(): """The /token wall is the second stop on the same misconfiguration (LIT-4629): after an admin fills only the Authorization URL, the code exchange dies here; the detail must name the remedies like the authorize wall does.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10559,7 +10559,7 @@ async def test_token_wall_names_the_fix_for_urlless_servers(): async def test_register_wall_names_the_fix_for_urlless_servers(): """The /register wall serves the same missing-authorization-url 400 as authorize; its detail must carry the same actionable remedies.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( register_client_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10599,7 +10599,7 @@ async def test_authorize_wall_points_at_discovery_failure_for_url_servers(): discovery against that url failed (typically a misconfigured url); the old detail blamed "servers with no url", sending the operator down the wrong path. The detail must now name the discovery failure and point at the proxy logs where LIT-4658's warnings carry the reason.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10634,7 +10634,7 @@ async def test_authorize_wall_points_at_discovery_failure_for_url_servers(): @pytest.mark.asyncio async def test_token_wall_points_at_discovery_failure_for_url_servers(): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10673,7 +10673,7 @@ async def test_token_wall_points_at_discovery_failure_for_url_servers(): @pytest.mark.asyncio async def test_authorize_wall_names_the_issuer_for_anchored_servers(): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10713,7 +10713,7 @@ async def test_authorize_uses_admin_entered_github_oauth_urls_after_issuer_yield the resolved authorization_url when a leftover issuer is treated as a pin (RFC 8414 yield). The UI authorize must still redirect to the admin-entered GitHub authorize URL instead of 400ing that discovery against api.githubcopilot.com failed.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10757,7 +10757,7 @@ async def test_authorize_uses_admin_entered_github_oauth_urls_after_issuer_yield def test_oauth_endpoints_count_admin_entered_urls_as_resolved(): """A leftover issuer empties the resolved authorize/token fields but must not keep the server on the deferred-discovery retry path when the admin already stored those URLs.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( oauth_endpoints_unresolved, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10783,11 +10783,11 @@ async def test_token_exchange_with_configured_token_url_never_joins_discovery(mo """A server can hold an admin-entered Token URL while its Authorization URL is absent. The token exchange must post to that stored endpoint without awaiting deferred discovery, which can 503 against an unreachable issuer even though nothing it resolves is needed here.""" - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( discoverable_endpoints, mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10852,7 +10852,7 @@ async def test_root_token_route_with_configured_token_url_never_joins_discovery( """A root POST /token that falls back to the sole OAuth2 server must reach the exchange's endpoint-gated discovery join instead of awaiting full discovery at the route: with the token url admin-entered, a failing or slow discovery must not turn the exchange into a 503.""" - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( discoverable_endpoints, mcp_server_manager, ) @@ -10917,8 +10917,8 @@ async def test_bridge_authorize_relays_with_registration_url_resolved_by_deferre relay-vs-short-circuit call must read the resolved server: a client that registered itself through the front door keeps its own redirect binding instead of being routed through the gateway callback the upstream never granted it.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) from litellm.types.mcp import MCPAuth, MCPTransport @@ -10978,7 +10978,7 @@ def test_passthrough_authorization_code_round_trips_and_rejects_hostile_input(): and is total over hostile input: a raw upstream code opens to None, and a tampered or non-gateway value opens to None rather than raising, so every existing caller-supplied-client flow is untouched.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( open_passthrough_authorization_code, seal_passthrough_authorization_code, ) @@ -11001,7 +11001,7 @@ def test_passthrough_authorization_code_round_trips_and_rejects_hostile_input(): assert open_passthrough_authorization_code("raw-upstream-code") is None assert open_passthrough_authorization_code(sealed[:-4] + "aaaa") is None - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _BRIDGE_AUTH_CODE_PREFIX, _PASSTHROUGH_AUTH_CODE_PREFIX, open_bridge_authorization_code, @@ -11022,7 +11022,7 @@ async def test_authorize_with_ephemeral_dcr_client_seals_client_into_state(): """When mcp_authorize fell through to a gateway-side DCR mint, authorize_with_server seals the minted client and the target server into the encrypted OAuth state, so the callback can bind them into the forwarded authorization code while the gateway stores nothing.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, authorize_with_server, ) @@ -11036,7 +11036,7 @@ async def test_authorize_with_ephemeral_dcr_client_seals_client_into_state(): return "mocked_encrypted_state" with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.encode_state_with_base_url", + "litellm.proxy.mcp_server.discoverable_endpoints.encode_state_with_base_url", side_effect=_capture, ): response = await authorize_with_server( @@ -11067,7 +11067,7 @@ async def test_callback_wraps_code_into_passthrough_code_for_ephemeral_dcr_state gateway never stored.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( callback, open_passthrough_authorization_code, ) @@ -11083,15 +11083,15 @@ async def test_callback_wraps_code_into_passthrough_code_for_ephemeral_dcr_state } with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", + "litellm.proxy.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", return_value="enc", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash", + "litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash", return_value=state_data, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", + "litellm.proxy.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", return_value="http://127.0.0.1:60108/cb", ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -11117,7 +11117,7 @@ async def test_authorize_bridge_server_with_ephemeral_client_takes_short_circuit to an IdP that has the gateway callback registered, stranding the flow.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, authorize_with_server, ) @@ -11151,7 +11151,7 @@ async def test_callback_forwards_raw_code_when_dcr_state_lacks_server_binding(): one.""" from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import callback + from litellm.proxy.mcp_server.discoverable_endpoints import callback state_data = { "original_state": "client-state", @@ -11161,15 +11161,15 @@ async def test_callback_forwards_raw_code_when_dcr_state_lacks_server_binding(): } with ( patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", + "litellm.proxy.mcp_server.discoverable_endpoints._resolve_encoded_oauth_state", return_value="enc", ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.decode_state_hash", + "litellm.proxy.mcp_server.discoverable_endpoints.decode_state_hash", return_value=state_data, ), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", + "litellm.proxy.mcp_server.discoverable_endpoints._get_validated_client_redirect_uri", return_value="http://127.0.0.1:60108/cb", ), patch("litellm.proxy.proxy_server.master_key", _BRIDGE_MASTER_KEY), @@ -11206,7 +11206,7 @@ async def test_resolve_ephemeral_dcr_client_mint_set_is_exact(auth_type_value, d oauth_delegate dcr_bridge sign-in is left to its own browser-front-door flow. The UI gatewayMintsClientFor helper mirrors this exact set; ui/.../mcp_tools/types.test.tsx pins the frontend side against the same table, so a divergence fails on one side or the other.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( EphemeralDcrClient, resolve_ephemeral_dcr_client, ) @@ -11222,7 +11222,7 @@ async def test_resolve_ephemeral_dcr_client_mint_set_is_exact(auth_type_value, d mint_mock = AsyncMock(return_value=EphemeralDcrClient(client_id="minted", client_secret=None)) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.mint_ephemeral_dcr_client", mint_mock, ): result = await resolve_ephemeral_dcr_client( @@ -11245,7 +11245,7 @@ async def test_resolve_ephemeral_dcr_client_mint_set_is_exact(auth_type_value, d async def test_mint_ephemeral_dcr_client_returns_none_without_registration_endpoint(): """A server whose upstream exposes no RFC 7591 registration endpoint cannot mint, so the fall-through reports None and the caller keeps its existing missing_client_id failure.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11258,7 +11258,7 @@ async def test_mint_ephemeral_dcr_client_returns_none_without_registration_endpo async def test_mint_ephemeral_dcr_client_posts_rfc7591_and_returns_client(): """The mint POSTs a public-client RFC 7591 registration bound to the gateway /callback and hands back the upstream's client without persisting it anywhere.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11275,7 +11275,7 @@ async def test_mint_ephemeral_dcr_client_posts_rfc7591_and_returns_client(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): minted = await mint_ephemeral_dcr_client(_bridge_mock_request(), server) @@ -11295,7 +11295,7 @@ async def test_mint_ephemeral_dcr_client_reuses_minted_client_within_flow_ttl(): """Reloading the authorize page must not spam the upstream registration endpoint with orphan clients: within the OAuth state's lifetime a second mint for the same server and gateway origin reuses the cached client and performs no second upstream POST.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11310,7 +11310,7 @@ async def test_mint_ephemeral_dcr_client_reuses_minted_client_within_flow_ttl(): mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): first = await mint_ephemeral_dcr_client(_bridge_mock_request(), server) @@ -11328,7 +11328,7 @@ async def test_mint_ephemeral_dcr_client_single_flights_concurrent_mints(): POST happens.""" import asyncio - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11351,7 +11351,7 @@ async def test_mint_ephemeral_dcr_client_single_flights_concurrent_mints(): mock_async_client.post = AsyncMock(side_effect=_slow_post) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): first, second = await asyncio.gather( @@ -11376,7 +11376,7 @@ async def test_mint_ephemeral_dcr_client_unusable_registration_response_is_502(p """An upstream registration response without a usable client_id, whether the field is missing or an empty string, surfaces as a loud 502 instead of letting the authorize proceed with an empty client and fail opaquely at the IdP.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, ) from litellm.types.mcp import MCPAuth @@ -11391,7 +11391,7 @@ async def test_mint_ephemeral_dcr_client_unusable_registration_response_is_502(p mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): with pytest.raises(HTTPException) as exc: @@ -11420,7 +11420,7 @@ async def test_token_exchange_authenticates_with_the_sealed_clients_own_auth_met import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) from litellm.types.mcp import MCPAuth @@ -11434,7 +11434,7 @@ async def test_token_exchange_authenticates_with_the_sealed_clients_own_auth_met mock_async_client.post = AsyncMock(return_value=upstream_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): await exchange_token_with_server( @@ -11529,7 +11529,7 @@ def test_resolve_upstream_resource_tristate_and_canonicalization(url, configured hygiene), and drop a trailing slash, while preserving a non-default port and the path case. An explicit value is never canonicalized, because it has to match what the authorization server expects byte for byte.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import resolve_upstream_resource + from litellm.proxy.mcp_server.oauth_utils import resolve_upstream_resource assert resolve_upstream_resource(_resource_server(url=url, upstream_resource=configured)) == expected @@ -11548,7 +11548,7 @@ def test_build_upstream_oauth2_token_request_bundles_resource_with_client_auth(c mandatory client authentication and no leg can authenticate without also naming the resource its sibling legs named. A leg that reverted to hand-building its body would drop the resource and diverge from the authorize leg, which a strict authorization server rejects as invalid_target.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request + from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request req = build_upstream_oauth2_token_request( _resource_server(url=url, upstream_resource=configured), @@ -11566,7 +11566,7 @@ def test_build_upstream_oauth2_token_request_client_secret_basic_keeps_secret_ou also appear in the body, while the RFC 8707 resource still rides in the body.""" import base64 - from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request + from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request req = build_upstream_oauth2_token_request( _resource_server(upstream_resource="api://audience"), @@ -11585,7 +11585,7 @@ async def _authorize_query(server) -> dict: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( authorize_with_server, ) @@ -11593,7 +11593,7 @@ async def _authorize_query(server) -> dict: mock_request.base_url = "https://litellm.example.com/" mock_request.headers = {} - with patch("litellm.proxy._experimental.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: + with patch("litellm.proxy.mcp_server.discoverable_endpoints.encrypt_value_helper") as mock_encrypt: mock_encrypt.return_value = "encrypted_state" response = await authorize_with_server( request=mock_request, @@ -11612,7 +11612,7 @@ async def _authorize_query(server) -> dict: async def _token_body(server, grant_type: str) -> dict: from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( exchange_token_with_server, ) @@ -11627,7 +11627,7 @@ async def _token_body(server, grant_type: str) -> dict: mock_async_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=mock_async_client, ): await exchange_token_with_server( @@ -11711,7 +11711,7 @@ def test_upstream_resource_auto_keeps_the_path_because_it_identifies_the_server( it would collide them onto one resource identifier and bind each token to the wrong audience, which is the exact confusion RFC 8707 exists to prevent. An operator whose path embeds a secret sets ``upstream_resource`` explicitly instead of using ``auto``.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import resolve_upstream_resource + from litellm.proxy.mcp_server.oauth_utils import resolve_upstream_resource first = resolve_upstream_resource( _resource_server(url="https://gw.example.com/team-a/mcp", upstream_resource="auto") @@ -11740,7 +11740,7 @@ async def test_upstream_resource_sent_on_dcr_bridge_relay_authorize(): """The DCR-bridge relay arm builds its own upstream authorize params, so it needs the resource too. Without it the relayed authorize would omit the resource while the gateway's token leg still sent one, which is itself an invalid_target.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _dcr_bridge_relays_client_registration, ) from litellm.types.mcp import MCPAuth @@ -11781,7 +11781,7 @@ def _no_proxy_base_url(monkeypatch): def _isolated_mcp_registry(): """Fixture-owned registry state: snapshot the shared registry, hand the test an empty one, restore afterwards so nothing leaks between cases.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -11798,7 +11798,7 @@ def _prefixed_discovery_client(prefixes): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.discoverable_endpoints import router from litellm.proxy.middleware.per_request_root_path_middleware import ( PerRequestRootPathMiddleware, ) @@ -11817,7 +11817,7 @@ class TestPerRequestRootPathDiscovery: from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.discoverable_endpoints import router server = _create_oauth2_server(server_id="srv_a", name="server_a", server_name="server_a", alias="server_a") _isolated_mcp_registry[server.server_id] = server @@ -11891,7 +11891,7 @@ class TestPerRequestRootPathDiscovery: """The WWW-Authenticate resource_metadata URL a 401 advertises must land under the request's prefix, or the client is bounced to a document whose ``resource`` cannot match the URL it called.""" - from litellm.proxy._experimental.mcp_server.oauth_utils import ( + from litellm.proxy.mcp_server.oauth_utils import ( get_passthrough_resource_metadata_url, ) @@ -11935,8 +11935,8 @@ class TestPerRequestRootPathDiscovery: from fastapi import FastAPI, HTTPException, Request from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import ( + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.outbound_credentials.adapter import ( raise_user_oauth_challenge, ) from litellm.proxy.middleware.per_request_root_path_middleware import ( @@ -12083,9 +12083,9 @@ def _native_client_app(monkeypatch): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("LITELLM_SALT_KEY", _NATIVE_CLIENT_MASTER_KEY) monkeypatch.setattr("litellm.proxy.proxy_server.master_key", _NATIVE_CLIENT_MASTER_KEY, raising=False) @@ -12099,10 +12099,10 @@ def _native_client_app(monkeypatch): return (ConsentTeam(team_id="team-a", team_alias="Team A"), ConsentTeam(team_id="team-b")) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.mint_proxy_credential", fake_mint + "litellm.proxy.mcp_server.discoverable_endpoints.mint_proxy_credential", fake_mint ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.lookup_consent_teams", fake_lookup + "litellm.proxy.mcp_server.discoverable_endpoints.lookup_consent_teams", fake_lookup ) global_mcp_server_manager.registry.clear() app = FastAPI() @@ -12215,9 +12215,9 @@ def test_gateway_authorize_routes_forward_server_scope(monkeypatch: pytest.Monke from http.cookies import SimpleCookie from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import CONNECT_FLOW_COOKIE_PREFIX - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper + from litellm.proxy.mcp_server.gateway_dcr_flow import CONNECT_FLOW_COOKIE_PREFIX + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setattr( global_mcp_server_manager, @@ -12553,8 +12553,8 @@ def test_introspect_route_requires_virtual_key_auth_and_is_advertised(): from fastapi.routing import APIRoute from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + from litellm.proxy.mcp_server.discoverable_endpoints import router route = next(r for r in router.routes if isinstance(r, APIRoute) and r.path == "/introspect") assert route.methods == {"POST"} @@ -12584,16 +12584,16 @@ def test_introspect_route_answers_for_authenticated_caller(monkeypatch): from fastapi import FastAPI from fastapi.testclient import TestClient - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.auth.user_api_key_auth import user_api_key_auth + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( session_keys_from_master_key, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( + from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SessionPrincipal, mint_session_token, ) - from litellm.proxy._types import UserAPIKeyAuth - from litellm.proxy.auth.user_api_key_auth import user_api_key_auth introspect_master_key = "sk-introspect-route-test" monkeypatch.setattr("litellm.proxy.proxy_server.master_key", introspect_master_key, raising=False) @@ -12602,7 +12602,7 @@ def test_introspect_route_answers_for_authenticated_caller(monkeypatch): return None monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.reload_active_user_by_id", fake_reload + "litellm.proxy.mcp_server.discoverable_endpoints.reload_active_user_by_id", fake_reload ) app = FastAPI() app.include_router(router) @@ -12631,7 +12631,7 @@ async def test_identity_bound_authorization_carries_nonce_and_caller_through_cal from fastapi import Request - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _oauth_state_cookie_name, authorize_with_server, callback, @@ -12667,11 +12667,11 @@ async def test_identity_bound_authorization_carries_nonce_and_caller_through_cal ) with ( patch( # test-quality-ok: isolate authenticated request resolution from the real encrypted OAuth round trip - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", + "litellm.proxy.mcp_server.discoverable_endpoints.authorize_oauth_credential_request", new=AsyncMock(return_value="alice"), ), patch( # test-quality-ok: isolate user access lookup while testing nonce and caller preservation - "litellm.proxy._experimental.mcp_server.discoverable_endpoints._user_can_reach_mcp_server", + "litellm.proxy.mcp_server.discoverable_endpoints._user_can_reach_mcp_server", new=AsyncMock(return_value=True), ), ): @@ -12708,18 +12708,18 @@ async def test_enforced_login_warms_verified_token_readable_without_database_loo from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db, mcp_server_manager - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _store_per_user_token_server_side - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import mcp_per_user_token_cache - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import current_binding_proof - from litellm.proxy._experimental.mcp_server.outbound_credentials.dual_cache_token_backend import ( + from litellm.proxy.mcp_server import db, mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import _store_per_user_token_server_side + from litellm.proxy.mcp_server.oauth2_token_cache import mcp_per_user_token_cache + from litellm.proxy.mcp_server.oauth_identity_binding import current_binding_proof + from litellm.proxy.mcp_server.outbound_credentials.dual_cache_token_backend import ( DualCacheTokenCacheBackend, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import CachedOAuthTokenStore - from litellm.proxy._experimental.mcp_server.outbound_credentials.per_user_oauth_store import ( + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import CachedOAuthTokenStore + from litellm.proxy.mcp_server.outbound_credentials.per_user_oauth_store import ( LazyPerUserOAuthTokenStore, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore + from litellm.proxy.mcp_server.outbound_credentials.v2_token_store import V2PerUserTokenStore from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -12778,7 +12778,7 @@ async def test_dcr_refusal_is_actionable_without_upstream_body( import httpx - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( mint_ephemeral_dcr_client, register_client_with_server, ) @@ -12873,7 +12873,7 @@ def _gateway_root_path_discovery_router(monkeypatch: pytest.MonkeyPatch) -> "Ite (a second reload would hand earlier importers a different ``router`` object).""" import importlib - from litellm.proxy._experimental.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server import discoverable_endpoints snapshot: Final = dict(vars(discoverable_endpoints)) monkeypatch.setenv("SERVER_ROOT_PATH", "/gateway") @@ -12991,13 +12991,13 @@ async def test_oauth_exchange_stores_token_for_validated_jwt_user( ) -> None: import httpx - from litellm.proxy._experimental.mcp_server import discoverable_endpoints from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints from litellm.types.mcp_server.mcp_server_manager import MCPServer handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.custom_validate = lambda claims: policy_allowed - from litellm.proxy._experimental.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server import mcp_server_manager manager: Final = MagicMock() manager.get_allowed_mcp_servers = AsyncMock(return_value=["jwt-oauth-server"] if server_allowed else []) @@ -13112,8 +13112,8 @@ async def test_oauth_jwt_identity_rejects_untrusted_or_inactive_owner( from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.bridge_token_flow import ( + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.bridge_token_flow import ( authorize_oauth_credential_request, extract_user_id_from_request, ) @@ -13159,8 +13159,8 @@ async def test_oauth_jwt_cannot_override_explicit_litellm_key( jwt_oauth_identity: tuple["JWTHandler", "RSAPrivateKey"], blocked: bool, ) -> None: - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy._types import UserAPIKeyAuth, hash_token + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity key: Final = "sk-explicit-key" @@ -13183,9 +13183,9 @@ async def test_oauth_jwt_uses_configured_virtual_key_owner( mapping: str, ) -> None: from litellm.models.user import LiteLLM_UserTable - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy._types import UnregisteredJWTClientBehavior, UserAPIKeyAuth, hash_token from litellm.proxy.auth.auth_checks import jwt_key_mapping_cache_key + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.virtual_key_claim_field = "sub" @@ -13220,7 +13220,7 @@ async def test_oauth_jwt_respects_custom_validation_and_email_policy( jwt_oauth_identity: tuple["JWTHandler", "RSAPrivateKey"], allowed_domain: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.custom_validate = lambda claims: True @@ -13237,9 +13237,9 @@ async def test_oauth_jwt_identity_preserves_separate_mcp_route_authorization( route_allowed: bool, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy._types import LitellmUserRoles, RoleBasedPermissions, RoleMapping from litellm.proxy.auth.handle_jwt import JWTAuthManager + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.user_id_jwt_field = "sub" @@ -13298,8 +13298,8 @@ async def test_oauth_jwt_resolves_canonical_owner_without_cached_identity( ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request from litellm.proxy.auth.handle_jwt import JWTAuthManager + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity external_id: Final = f"external-{identity}-{inactive}-{admin}" @@ -13345,7 +13345,7 @@ async def test_oauth_jwt_identity_does_not_provision_or_synchronize_teams( ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import extract_user_id_from_request + from litellm.proxy.mcp_server.bridge_token_flow import extract_user_id_from_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.enforce_team_based_model_access = True @@ -13373,7 +13373,7 @@ async def test_oauth_refresh_revalidates_the_same_active_user_rule( ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.bridge_token_flow import reload_active_user_by_id + from litellm.proxy.mcp_server.bridge_token_flow import reload_active_user_by_id handler, _ = jwt_oauth_identity user_id: Final = f"jwt-owner-{state}" @@ -13402,10 +13402,10 @@ async def test_oauth_credential_write_keeps_virtual_key_permissions( ) -> None: import asyncio - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.bridge_token_flow import authorize_oauth_credential_request from litellm.proxy._types import UserAPIKeyAuth, hash_token from litellm.proxy.auth.auth_checks import OrganizationNotFoundError, jwt_key_mapping_cache_key + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.bridge_token_flow import authorize_oauth_credential_request handler, signing_key = jwt_oauth_identity monkeypatch.setattr( @@ -13471,9 +13471,9 @@ async def test_oauth_writer_preserves_claimed_team_instead_of_expanding_user_ros ) -> None: from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.bridge_token_flow import authorize_oauth_credential_request from litellm.proxy._types import LiteLLM_TeamTable, Member + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.bridge_token_flow import authorize_oauth_credential_request handler, signing_key = jwt_oauth_identity handler.litellm_jwtauth.team_id_jwt_field = "team" @@ -13509,8 +13509,8 @@ async def test_oauth_write_denial_does_not_erase_identity_binding( jwt_oauth_identity: tuple["JWTHandler", "RSAPrivateKey"], monkeypatch: pytest.MonkeyPatch, ) -> None: - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer _, signing_key = jwt_oauth_identity @@ -13570,8 +13570,8 @@ async def test_signed_oauth_callback_honors_credential_write_policy( from litellm.caching.llm_caching_handler import LLMClientCache from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -13689,9 +13689,9 @@ async def test_identity_bound_authorize_preserves_presented_jwt_permissions( from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import JWTIssuerConfig, MCPTransport, UserAPIKeyAuth, hash_token from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer handler, signing_key = jwt_oauth_identity @@ -13825,8 +13825,8 @@ async def test_identity_bound_authorize_unrelated_bearer_uses_browser_session( from litellm.models.user import LiteLLM_UserTable from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints, mcp_server_manager from litellm.types.mcp_server.mcp_server_manager import MCPOAuthIdentityBinding, MCPServer handler, signing_key = jwt_oauth_identity @@ -13909,9 +13909,9 @@ async def test_authorize_observes_committed_peer_server_changes(monkeypatch, cha from fastapi import HTTPException, Request from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager monkeypatch.setenv("LITELLM_SALT_KEY", "catalog-consistency-test-key") stamp = datetime.now(timezone.utc) @@ -13966,9 +13966,9 @@ async def test_authorize_observes_committed_peer_server_changes(monkeypatch, cha @pytest.mark.asyncio async def test_update_server_drops_cached_upstream_oauth_metadata(): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LiteLLM_MCPServerTable, MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer manager = MCPServerManager() @@ -14003,12 +14003,12 @@ async def test_update_server_drops_cached_upstream_oauth_metadata(): async def test_metadata_fetched_before_invalidation_does_not_repopulate_the_cache(): import asyncio - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.discoverable_endpoints import ( fetch_upstream_oauth_protected_resource, invalidate_oauth_metadata_cache, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -14028,7 +14028,7 @@ async def test_metadata_fetched_before_invalidation_does_not_repopulate_the_cach discoverable_endpoints._OAUTH_METADATA_CACHE.pop(cache_key, None) try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ): in_flight: Final = asyncio.create_task(fetch_upstream_oauth_protected_resource(server)) @@ -14048,12 +14048,12 @@ async def test_metadata_fetched_before_invalidation_does_not_repopulate_the_cach async def test_fetch_waiting_on_a_lock_handoff_stays_tracked_through_invalidation(): import asyncio - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.discoverable_endpoints import ( fetch_upstream_oauth_protected_resource, invalidate_oauth_metadata_cache, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -14073,7 +14073,7 @@ async def test_fetch_waiting_on_a_lock_handoff_stays_tracked_through_invalidatio discoverable_endpoints._OAUTH_METADATA_CACHE.pop(cache_key, None) try: with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client", + "litellm.proxy.mcp_server.discoverable_endpoints.get_async_httpx_client", return_value=client, ): async with discoverable_endpoints._oauth_metadata_fetch_slot(cache_key): @@ -14099,8 +14099,8 @@ async def test_fetch_waiting_on_a_lock_handoff_stays_tracked_through_invalidatio def test_invalidating_an_idle_server_leaves_no_generation_behind(): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import invalidate_oauth_metadata_cache + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.discoverable_endpoints import invalidate_oauth_metadata_cache server_ids: Final = tuple(f"churned-server-{i}" for i in range(50)) try: @@ -14129,7 +14129,7 @@ async def test_callback_rejects_missing_advertised_issuer(monkeypatch): ], ) def test_persisted_client_is_not_applied_to_another_upstream(issuer, url): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _apply_persisted_dcr_credentials, _PersistedDcrCredentials, ) @@ -14154,7 +14154,7 @@ async def test_registration_does_not_write_client_after_upstream_edit(monkeypatc from prisma import models from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _persist_dcr_client_registration + from litellm.proxy.mcp_server.discoverable_endpoints import _persist_dcr_client_registration server = _issuer_anchored_oauth_server().model_copy( update={"url": "https://resource.example/mcp", "client_id": None} @@ -14187,7 +14187,7 @@ async def test_registration_does_not_write_client_after_upstream_edit(monkeypatc "response_issuer", ["https://IDP.example.com", "https://idp.example.com/", "https://idp.example.com:443"] ) def test_issuer_validation_uses_exact_identifier(response_issuer): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import _authorization_response_issuer_is_trusted + from litellm.proxy.mcp_server.discoverable_endpoints import _authorization_response_issuer_is_trusted assert ( _authorization_response_issuer_is_trusted(response_issuer, {"expected_issuer": "https://idp.example.com"}) @@ -14203,7 +14203,7 @@ def test_issuer_validation_uses_exact_identifier(response_issuer): ], ) def test_persisted_client_remains_usable_for_its_issuer(issuer, url, monkeypatch): - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _apply_persisted_dcr_credentials, _PersistedDcrCredentials, ) @@ -14240,7 +14240,7 @@ async def test_callback_does_not_forward_error_from_another_issuer(monkeypatch): async def test_bound_client_cannot_be_sent_to_a_different_issuer(monkeypatch, operation): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -14287,7 +14287,7 @@ async def test_bound_client_cannot_be_sent_to_a_different_issuer(monkeypatch, op async def test_failed_registration_preserves_cached_credentials(monkeypatch): from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints server = _dcr_redirect_test_server("old-client").model_copy( update={ @@ -14333,7 +14333,7 @@ async def test_registration_without_database_keeps_client_in_temporary_server(mo from fastapi import Request from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setattr(proxy_server, "prisma_client", None) server = _dcr_redirect_test_server(None).model_copy( @@ -14367,9 +14367,9 @@ async def test_registration_without_database_keeps_client_in_temporary_server(mo @pytest.mark.parametrize("config_store", [False, True]) async def test_registration_does_not_overwrite_credentials_after_failed_identity_read(monkeypatch, config_store): from litellm.proxy import utils - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _dcr_redirect_test_server(None) monkeypatch.setattr(utils, "get_prisma_client_or_throw", lambda _: MagicMock()) @@ -14399,9 +14399,9 @@ async def test_registration_does_not_overwrite_credentials_after_failed_identity @pytest.mark.parametrize("winner_available", [False, True]) async def test_registration_losing_conditional_write_reuses_only_a_matching_winner(monkeypatch, winner_available): from litellm.proxy import utils - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints server = _dcr_redirect_test_server(None).model_copy(update={"url": "https://upstream.example/mcp"}) row = LiteLLM_MCPServerTable.model_validate(server.model_dump(exclude_none=True)) @@ -14444,8 +14444,8 @@ async def test_register_preserves_client_application_type_only_for_bridge_relay( import respx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = _bridge_server(auth_type=auth_type, server_id="application-client", alias="application-client") app: Final = FastAPI() @@ -14487,8 +14487,8 @@ async def test_register_rejects_invalid_application_type_before_upstream( import respx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = _bridge_server(server_id="invalid-application-client", alias="invalid-application-client") app: Final = FastAPI() @@ -14520,8 +14520,8 @@ async def test_register_application_type_keeps_no_registration_endpoint_fallback import respx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import router - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import router + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server: Final = _bridge_server( auth_type=MCPAuth.oauth2, @@ -14586,7 +14586,7 @@ def _cimd_request(): @pytest.mark.asyncio async def test_cimd_registration_returns_https_identity_without_dcr(monkeypatch, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") response = await endpoints.register_client_with_server( @@ -14602,7 +14602,7 @@ async def test_cimd_registration_returns_https_identity_without_dcr(monkeypatch, async def test_cimd_authorization_uses_metadata_identity_and_s256(monkeypatch): from urllib.parse import parse_qs, urlparse - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "cimd-test-state-signing-key") @@ -14624,7 +14624,7 @@ async def test_cimd_authorization_uses_metadata_identity_and_s256(monkeypatch): async def test_cimd_authorization_rejects_missing_pkce(monkeypatch): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "cimd-test-state-signing-key") @@ -14636,7 +14636,7 @@ async def test_cimd_authorization_rejects_missing_pkce(monkeypatch): def test_cimd_refresh_request_uses_same_identity_without_caller_secret(monkeypatch): - from litellm.proxy._experimental.mcp_server.oauth_utils import build_upstream_oauth2_token_request + from litellm.proxy.mcp_server.oauth_utils import build_upstream_oauth2_token_request monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") request = build_upstream_oauth2_token_request( @@ -14654,7 +14654,7 @@ def test_cimd_refresh_request_uses_same_identity_without_caller_secret(monkeypat async def test_cimd_without_stable_https_origin_reports_actionable_error(monkeypatch, base, respx_mock): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.delenv("PROXY_BASE_URL", raising=False) if base is not None: @@ -14669,7 +14669,7 @@ async def test_cimd_without_stable_https_origin_reports_actionable_error(monkeyp @pytest.mark.parametrize("base", [None, "http://gateway.example.com"]) @pytest.mark.asyncio async def test_cimd_without_https_origin_falls_back_to_available_dcr(monkeypatch, base, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.delenv("PROXY_BASE_URL", raising=False) if base is not None: @@ -14684,8 +14684,8 @@ async def test_cimd_without_https_origin_falls_back_to_available_dcr(monkeypatch @pytest.mark.asyncio async def test_cimd_yields_to_dynamic_registration_when_the_authorization_server_offers_both(monkeypatch, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.oauth_utils import get_cimd_client_id + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.oauth_utils import get_cimd_client_id monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") @@ -14700,7 +14700,7 @@ async def test_cimd_yields_to_dynamic_registration_when_the_authorization_server @pytest.mark.asyncio async def test_cimd_is_preferred_over_dynamic_registration_when_the_deployment_opts_in(monkeypatch, respx_mock): from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") @@ -14729,7 +14729,7 @@ async def test_cimd_is_preferred_over_dynamic_registration_when_the_deployment_o ], ) def test_cimd_preserves_existing_identity_and_other_auth_modes(monkeypatch, updates): - from litellm.proxy._experimental.mcp_server.oauth_utils import get_cimd_client_id + from litellm.proxy.mcp_server.oauth_utils import get_cimd_client_id monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") assert get_cimd_client_id(_cimd_oauth_server().model_copy(update=updates)) is None @@ -14740,7 +14740,7 @@ async def test_cimd_document_is_public_and_binds_configured_origin(monkeypatch): import httpx from fastapi import FastAPI - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com/proxy") app = FastAPI() @@ -14760,7 +14760,7 @@ async def test_cimd_document_is_public_and_binds_configured_origin(monkeypatch): async def test_cimd_document_is_unavailable_without_configured_https_origin(monkeypatch, base): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.delenv("PROXY_BASE_URL", raising=False) if base is not None: @@ -14772,7 +14772,7 @@ async def test_cimd_document_is_unavailable_without_configured_https_origin(monk @pytest.mark.asyncio async def test_cimd_upstream_client_rejection_is_gateway_fault(monkeypatch, respx_mock): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") @@ -14803,8 +14803,8 @@ async def test_optional_cimd_discovery_preserves_the_callers_configured_endpoint ) -> None: from urllib.parse import parse_qs - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import mcp_server_manager as manager_module monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_MCP_OAUTH_DISCOVERY_ON_STARTUP", "0") @@ -14874,8 +14874,8 @@ async def test_token_route_preserves_saved_cimd_grant_after_origin_change( from urllib.parse import parse_qs from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db, mcp_server_manager - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import db, mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_SALT_KEY", "saved-cimd-route-test-salt") @@ -14946,8 +14946,8 @@ async def test_saved_refresh_metadata_is_bound_to_the_callers_stored_grant( from types import SimpleNamespace from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("LITELLM_SALT_KEY", "saved-cimd-owner-test-salt") server: Final = _cimd_oauth_server() @@ -15007,9 +15007,9 @@ async def test_managed_authorize_retains_the_callers_previous_grant( from urllib.parse import parse_qs, urlsplit from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "scope-grant-test-salt") @@ -15053,9 +15053,9 @@ async def test_managed_code_exchange_preserves_requested_scope_only_when_omitted from urllib.parse import parse_qs, urlsplit from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "requested-scope-test-salt") @@ -15117,7 +15117,7 @@ async def test_managed_authorize_requests_only_selected_scope_and_supported_refr from mcp.shared.auth import OAuthMetadata - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints monkeypatch.setenv("LITELLM_SALT_KEY", "metadata-scope-test-salt") metadata = OAuthMetadata( @@ -15143,7 +15143,7 @@ async def test_managed_authorize_requests_only_selected_scope_and_supported_refr @pytest.mark.asyncio @pytest.mark.parametrize("mismatch", ["server", "issuer", "user", "mode", "tampered", "invalid_payload"]) async def test_managed_scope_code_cannot_cross_oauth_boundaries(jwt_oauth_identity, monkeypatch, respx_mock, mismatch): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "scope-boundary-test-salt") @@ -15198,9 +15198,9 @@ async def test_managed_refresh_retains_only_the_actual_grant( from types import SimpleNamespace from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager _, signing_key = jwt_oauth_identity monkeypatch.setenv("LITELLM_SALT_KEY", "refresh-scope-test-salt") @@ -15256,8 +15256,8 @@ async def test_managed_refresh_retains_only_the_actual_grant( @pytest.mark.asyncio @pytest.mark.parametrize("per_server_relay", [False, True]) async def test_managed_resource_metadata_excludes_refresh_permission(monkeypatch, per_server_relay): - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _cimd_oauth_server().model_copy( update={ @@ -15281,8 +15281,8 @@ async def test_managed_resource_metadata_excludes_refresh_permission(monkeypatch ], ) async def test_connect_requires_the_requested_vendor_grant(monkeypatch, granted, required, expected): - from litellm.proxy._experimental.mcp_server import db - from litellm.proxy._experimental.mcp_server import discoverable_endpoints as endpoints + from litellm.proxy.mcp_server import db + from litellm.proxy.mcp_server import discoverable_endpoints as endpoints credential = {**_stored_grant(), "scopes": granted} read = AsyncMock(return_value=credential) @@ -15308,8 +15308,8 @@ def test_aggregate_protected_resource_advertises_header_server_scopes( ) -> None: """A client that re-authenticates from cached discovery never sees the 401 challenge, so the aggregate PRM carries the x-mcp-servers selection as scopes_supported instead.""" - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_aggregate_protected_resource_response, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -15351,9 +15351,9 @@ async def test_token_endpoint_routes_the_jwt_bearer_grant_to_the_aggregate_gatew """A requesting app presents its identity provider's client_id, never a gateway DCR one, so the aggregate dispatch keys on the grant type for RFC 7523 and hands the assertion to the ID-JAG redeemer. A per-server token endpoint never serves that grant.""" - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE - from litellm.proxy._experimental.mcp_server.id_jag_grant import IdJagPrerequisites + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server.id_jag_grant import IdJagPrerequisites request = _mock_callback_request("https://litellm.example.com/") with patch("litellm.proxy.proxy_server.master_key", "sk-test-salt-for-lit9670"): @@ -15395,8 +15395,8 @@ async def test_token_endpoint_takes_the_client_id_from_http_basic_when_the_form_ header the request is a 400 invalid_request, not a 422.""" from base64 import b64encode - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE request = _mock_callback_request("https://litellm.example.com/") request.headers = {"authorization": "Basic " + b64encode(b"0oa-requesting-app:app-secret").decode()} @@ -15427,9 +15427,9 @@ def test_root_metadata_is_the_gateways_own_and_lists_the_jwt_bearer_grant_when_i exactly when the gateway serves it, under the same gates as the aggregate ``/mcp`` document.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager global_mcp_server_manager.registry.clear() request = MagicMock(spec=Request) @@ -15455,9 +15455,9 @@ def test_root_metadata_owned_by_a_resolved_oauth2_server_never_lists_the_gateway ``/.well-known/oauth-authorization-server/mcp`` document in that deployment.""" from fastapi import Request - from litellm.proxy._experimental.mcp_server import discoverable_endpoints - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server import discoverable_endpoints + from litellm.proxy.mcp_server.gateway_dcr_flow import JWT_BEARER_GRANT_TYPE + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager server = _create_oauth2_server() global_mcp_server_manager.registry.clear() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py b/tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py rename to tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py index 530667fdfdd..a426cea131a 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_gateway_dcr_flow.py +++ b/tests/unit/proxy/mcp_server/test_gateway_dcr_flow.py @@ -14,7 +14,8 @@ from starlette.requests import Request from starlette.responses import Response from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper +from litellm.proxy.mcp_server.gateway_dcr_flow import ( _AUTH_CODE_DEBUG_KEY, ACCESS_TOKEN_TOKEN_TYPE, CONNECT_FLOW_COOKIE_PREFIX, @@ -48,21 +49,20 @@ from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( revoke_refresh_token, supported_grant_types, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_credentials import ( +from litellm.proxy.mcp_server.outbound_credentials.session_credentials import ( SessionBearerAdmitted, SessionRefreshOpened, open_session_refresh_bearer, resolve_session_bearer, session_keys_from_master_key, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( +from litellm.proxy.mcp_server.outbound_credentials.session_token import ( SESSION_ISSUER, SESSION_REFRESH_PREFIX, SessionPrincipal, mint_session_refresh_token, mint_session_token, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper MASTER_KEY = "sk-gateway-dcr-flow-tests" REDIRECT_URI = "https://claude.ai/api/mcp/auth_callback" @@ -205,7 +205,7 @@ def test_pkce_mismatched_challenge_returns_false_never_raises(code_challenge): two str with non-ASCII content, but on bytes of unequal length it simply returns False. A review flagged this as an unhandled 500 on length mismatch; encoding both sides to bytes is exactly what makes that impossible, so the claim is pinned here rather than in a comment.""" - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _pkce_verifier_matches + from litellm.proxy.mcp_server.gateway_dcr_flow import _pkce_verifier_matches assert _pkce_verifier_matches("a" * 43, code_challenge) is False @@ -563,7 +563,7 @@ def test_permanent_db_fault_503_does_not_promise_a_retry_will_help(): """Both DB failures are 503 temporarily_unavailable (the only OAuth error a client reads as a server-side outage), so the description is the one place the two are told apart: a transient outage says retry, a fault that never heals must say retrying will not help and point at the deployment.""" - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( + from litellm.proxy.mcp_server.gateway_dcr_flow import ( _consent_lookup_failure_response, _mint_failure_response, _reload_failure_response, @@ -682,7 +682,7 @@ async def test_non_ascii_code_challenge_fails_grant_not_500(): async def test_single_use_guard_in_memory_is_single_use_within_process(): """No Redis configured (single-replica): the in-memory increment is authoritative — the first claim wins, a replay of the same id loses.""" - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard guard = _SingleUseGuard(DualCache()) # redis_cache is None assert await guard.claim("jti-inmem", 60) == "first" @@ -695,7 +695,7 @@ async def test_single_use_guard_uses_redis_as_sole_authority_when_configured(): first caller, >1 → replay), and the per-worker in-memory count is never consulted.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard cache = DualCache() cache.redis_cache = MagicMock() @@ -716,7 +716,7 @@ async def test_single_use_guard_fails_closed_when_redis_errors(): Cursor/Veria replay-across-workers finding).""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard cache = DualCache() cache.redis_cache = MagicMock() @@ -734,7 +734,7 @@ async def test_single_use_guard_peek_fails_closed_when_redis_errors(): look unclaimed for exactly as long as Redis is down.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard cache = DualCache() cache.redis_cache = MagicMock() @@ -756,7 +756,7 @@ async def test_single_use_guard_peek_reads_the_key_under_the_namespace_claim_wro peeked at the bare key would never be seen, and the revoked chain would keep renewing.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import _SingleUseGuard + from litellm.proxy.mcp_server.gateway_dcr_flow import _SingleUseGuard stored: dict[str, int] = {} # mutable-ok: the fake Redis store the test inspects @@ -1003,7 +1003,7 @@ def _scoped_mcp_server(name="github", auth_type="oauth2", **kw): SCOPED_RESOURCE = "https://llm.example.com/mcp/github" -_MANAGER_PATCH = "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" +_MANAGER_PATCH = "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" def _scoped_authorize( @@ -1475,7 +1475,7 @@ async def test_unknown_server_scope_redirects_with_invalid_scope_and_state() -> ], ) def test_gateway_server_scope_accepts_only_rfc6749_scope_tokens(server_name: str, expected: str | None) -> None: - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import gateway_server_scope + from litellm.proxy.mcp_server.gateway_dcr_flow import gateway_server_scope assert gateway_server_scope(server_name) == expected @@ -1728,7 +1728,7 @@ async def test_resolve_scoped_resource_server_matrix(): modes all return None so nothing outside the served set can enter the scoped flow.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server + from litellm.proxy.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server request = _request() github = _scoped_mcp_server() @@ -1757,7 +1757,7 @@ async def test_resource_resolution_is_identity_not_ip_filtered_access(): between authorize and token would turn a matching redemption into invalid_target.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server + from litellm.proxy.mcp_server.gateway_dcr_flow import resolve_scoped_resource_server with patch(_MANAGER_PATCH) as manager: manager.get_mcp_server_by_identifier.return_value = _scoped_mcp_server() @@ -2666,7 +2666,7 @@ async def test_introspect_accepts_rs256_signed_tokens_under_configured_signing(m from pydantic import SecretStr from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import AsymmetricSessionKeys + from litellm.proxy.mcp_server.outbound_credentials.session_token import AsymmetricSessionKeys private_pem = ( rsa.generate_private_key(public_exponent=65537, key_size=2048) @@ -3024,7 +3024,7 @@ async def test_aggregate_step_up_rejects_malformed_permissions(scope): async def test_step_up_validates_every_target_before_credential_reads_and_preserves_each_grant(): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] first, second = _scoped_mcp_server("first"), _scoped_mcp_server("second") @@ -3075,7 +3075,7 @@ async def test_step_up_validates_every_target_before_credential_reads_and_preser async def test_named_resource_rejects_another_upstreams_permission_before_consent(): from unittest.mock import patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] with patch(_MANAGER_PATCH) as manager: @@ -3094,7 +3094,7 @@ async def test_named_resource_rejects_another_upstreams_permission_before_consen ], ) def test_upstream_permission_scope_round_trip_preserves_identity_and_permission(identity, permission): - from litellm.proxy._experimental.mcp_server.oauth_utils import decode_upstream_scope, encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import decode_upstream_scope, encode_upstream_scope encoded = encode_upstream_scope(identity, permission) decoded = decode_upstream_scope(encoded) @@ -3108,7 +3108,7 @@ def test_upstream_permission_scope_round_trip_preserves_identity_and_permission( async def test_upstream_step_up_cannot_finish_with_an_unproven_grant(state, expected): from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] server = _scoped_mcp_server() @@ -3133,11 +3133,11 @@ async def test_sdk_completes_aggregate_step_up_discovery_consent_and_pkce(route) from mcp.client.auth import OAuthClientProvider from mcp.shared.auth import AuthorizationCodeResult, OAuthClientMetadata - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_aggregate_authorization_server_response, oauth_protected_resource_root, ) - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError server = _scoped_mcp_server() storage = AsyncMock() @@ -3209,7 +3209,7 @@ async def test_sdk_completes_aggregate_step_up_discovery_consent_and_pkce(route) ["tools.write", "litellm:mcp_scope::7772697465", "litellm:mcp_scope:6964:5A", "litellm:mcp_scope:6964:7772 697465"], ) def test_upstream_permission_rejects_noncanonical_tokens(scope): - from litellm.proxy._experimental.mcp_server.oauth_utils import decode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import decode_upstream_scope assert decode_upstream_scope(scope) is None @@ -3218,7 +3218,7 @@ def test_upstream_permission_rejects_noncanonical_tokens(scope): async def test_named_step_up_finish_describes_and_retains_its_single_server_ceiling(): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id = (await _register([REDIRECT_URI]))["client_id"] server = _scoped_mcp_server() @@ -3244,7 +3244,7 @@ async def test_named_step_up_finish_describes_and_retains_its_single_server_ceil async def test_upstream_step_up_inside_multi_server_scope_describes_every_sealed_server() -> None: from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.oauth_utils import encode_upstream_scope + from litellm.proxy.mcp_server.oauth_utils import encode_upstream_scope client_id: Final = (await _register([REDIRECT_URI]))["client_id"] alpha: Final = _scoped_mcp_server(name="alpha") @@ -3490,7 +3490,7 @@ def test_aggregate_metadata_advertises_basic_client_auth_only_with_the_grant_tha ``client_secret`` from the form, so ``client_secret_basic`` is advertised only when that grant is on. A client following the document otherwise sends Basic alone and authenticates with no secret.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _build_aggregate_authorization_server_response, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_id_jag_grant.py b/tests/unit/proxy/mcp_server/test_id_jag_grant.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_id_jag_grant.py rename to tests/unit/proxy/mcp_server/test_id_jag_grant.py index f4fa51d57ba..f5d7a07ddb4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_id_jag_grant.py +++ b/tests/unit/proxy/mcp_server/test_id_jag_grant.py @@ -10,14 +10,22 @@ import pytest from fastapi import HTTPException from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ( +from litellm.proxy._types import IdJagRequestingApp, LiteLLM_JWTAuth, LiteLLMRoutes +from litellm.proxy.auth.handle_jwt import ( + ID_JAG_TYP, + AssertionRejection, + JWKSUnreachableError, + JWTHandler, + jwks_unavailable_exception, +) +from litellm.proxy.mcp_server.gateway_dcr_flow import ( AssertionIdentity, ConsentTeam, ReloadUserFailure, SubjectIdentity, SubjectTokenRefusal, ) -from litellm.proxy._experimental.mcp_server.id_jag_grant import ( +from litellm.proxy.mcp_server.id_jag_grant import ( ID_JAG_REQUIRED_CLAIMS, REJECTED_ASSERTION, TEAM_HEADER, @@ -37,14 +45,6 @@ from litellm.proxy._experimental.mcp_server.id_jag_grant import ( select_team, subject_resolver, ) -from litellm.proxy._types import IdJagRequestingApp, LiteLLM_JWTAuth, LiteLLMRoutes -from litellm.proxy.auth.handle_jwt import ( - ID_JAG_TYP, - AssertionRejection, - JWKSUnreachableError, - JWTHandler, - jwks_unavailable_exception, -) ISSUER = "https://idp.example.com" GATEWAY = "https://gateway.example.com" diff --git a/tests/unit/proxy/_experimental/mcp_server/test_idp_token_exchange.py b/tests/unit/proxy/mcp_server/test_idp_token_exchange.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_idp_token_exchange.py rename to tests/unit/proxy/mcp_server/test_idp_token_exchange.py index e94371a6056..036ee4a332b 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_idp_token_exchange.py +++ b/tests/unit/proxy/mcp_server/test_idp_token_exchange.py @@ -7,8 +7,10 @@ from prisma.engine.errors import BinaryNotFoundError from prisma.errors import DataError from litellm.caching.caching import DualCache -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal -from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( +from litellm.proxy._types import JWTIssuerConfig, LiteLLM_JWTAuth, ProxyException +from litellm.proxy.auth.handle_jwt import JWKSUnreachableError, JWTHandler, jwks_unavailable_exception +from litellm.proxy.mcp_server.gateway_dcr_flow import SubjectIdentity, SubjectTokenRefusal +from litellm.proxy.mcp_server.idp_token_exchange import ( REJECTED_SUBJECT_TOKEN, SUBJECT_TOKEN_CHECK_FAULTED, SUBJECT_TOKEN_CHECK_UNAVAILABLE, @@ -16,8 +18,6 @@ from litellm.proxy._experimental.mcp_server.idp_token_exchange import ( identity_from_subject_token, token_exchange_available, ) -from litellm.proxy._types import JWTIssuerConfig, LiteLLM_JWTAuth, ProxyException -from litellm.proxy.auth.handle_jwt import JWKSUnreachableError, JWTHandler, jwks_unavailable_exception IDP_JWT = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ1MSJ9.idp-signature" REQUEST_HEADERS = {"x-litellm-team-id": "team-b", "user-agent": "lite/0.1"} diff --git a/tests/unit/proxy/_experimental/mcp_server/test_interactions.py b/tests/unit/proxy/mcp_server/test_interactions.py similarity index 94% rename from tests/unit/proxy/_experimental/mcp_server/test_interactions.py rename to tests/unit/proxy/mcp_server/test_interactions.py index 8286269525a..aa4c00b1f07 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_interactions.py +++ b/tests/unit/proxy/mcp_server/test_interactions.py @@ -4,9 +4,9 @@ import pytest from mcp import MCPError from mcp.types import CallToolRequest, CallToolRequestParams, InputRequiredResult -from litellm.proxy._experimental.mcp_server.contracts import OperationContext -from litellm.proxy._experimental.mcp_server.interactions import bind_target, open_continuation, seal_continuation from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.contracts import OperationContext +from litellm.proxy.mcp_server.interactions import bind_target, open_continuation, seal_continuation from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -130,7 +130,8 @@ def test_altered_continuations_are_rejected(change: str, monkeypatch: pytest.Mon def test_input_responses_without_state_and_unbound_results_are_rejected(monkeypatch: pytest.MonkeyPatch) -> None: from mcp.types import ElicitResult - from litellm.proxy._experimental.mcp_server.interactions import BoundInputRequiredResult + + from litellm.proxy.mcp_server.interactions import BoundInputRequiredResult monkeypatch.setenv("LITELLM_SALT_KEY", "test-salt") context: Final = OperationContext(_caller=UserAPIKeyAuth(user_id="alice")) @@ -144,8 +145,8 @@ def test_input_responses_without_state_and_unbound_results_are_rejected(monkeypa def test_authenticated_but_invalid_state_payload_is_rejected(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.state_tokens import seal_state - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.state_tokens import seal_state monkeypatch.setenv("LITELLM_SALT_KEY", "test-salt") sealed: Final = seal_state( @@ -169,7 +170,8 @@ async def test_modern_sampling_errors_abort_without_relaying_form_input() -> Non ElicitRequestFormParams, ErrorData, ) - from litellm.proxy._experimental.mcp_server.interactions import ModernClientInteraction + + from litellm.proxy.mcp_server.interactions import ModernClientInteraction async def sampling(context: object, params: CreateMessageRequestParams) -> ErrorData: return ErrorData(code=-32603, message="Sampling refused by gateway policy") @@ -204,10 +206,12 @@ async def test_gateway_rejects_invalid_interaction_boundaries( invalid_response: Literal["legacy_state", "gateway_override", "unbound_result"], monkeypatch: pytest.MonkeyPatch ) -> None: from unittest.mock import AsyncMock, patch + from mcp.types import CreateMessageResult, ElicitResult, TextContent - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.contracts import WireCompat - from litellm.proxy._experimental.mcp_server.interactions import BoundInputRequiredResult + + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.contracts import WireCompat + from litellm.proxy.mcp_server.interactions import BoundInputRequiredResult monkeypatch.setenv("LITELLM_SALT_KEY", "test-salt") context: Final = OperationContext( diff --git a/tests/unit/proxy/_experimental/mcp_server/test_is_tool_name_prefixed.py b/tests/unit/proxy/mcp_server/test_is_tool_name_prefixed.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_is_tool_name_prefixed.py rename to tests/unit/proxy/mcp_server/test_is_tool_name_prefixed.py index 8f09e2410c4..f8dea399067 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_is_tool_name_prefixed.py +++ b/tests/unit/proxy/mcp_server/test_is_tool_name_prefixed.py @@ -6,8 +6,7 @@ Verifies fix for https://github.com/BerriAI/litellm/issues/25081 import pytest -from litellm.proxy._experimental.mcp_server.utils import is_tool_name_prefixed - +from litellm.proxy.mcp_server.utils import is_tool_name_prefixed # --------------------------------------------------------------------------- # Legacy behaviour (no known_server_prefixes passed) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_enforcement.py b/tests/unit/proxy/mcp_server/test_jwt_mcp_enforcement.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_enforcement.py rename to tests/unit/proxy/mcp_server/test_jwt_mcp_enforcement.py index eddfdc4f884..ea275373f2f 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_enforcement.py +++ b/tests/unit/proxy/mcp_server/test_jwt_mcp_enforcement.py @@ -8,20 +8,21 @@ Scenario: 4. EXPECTED: Team MCP permissions should be enforced """ -import pytest from unittest.mock import AsyncMock, MagicMock, patch +import pytest + from litellm.proxy._types import ( LiteLLM_JWTAuth, - LiteLLM_TeamTable, LiteLLM_ObjectPermissionTable, + LiteLLM_TeamTable, UserAPIKeyAuth, ) from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager @pytest.mark.asyncio diff --git a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_simple.py b/tests/unit/proxy/mcp_server/test_jwt_mcp_simple.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_simple.py rename to tests/unit/proxy/mcp_server/test_jwt_mcp_simple.py index 7ee340a69f4..f258ba8b7e9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_jwt_mcp_simple.py +++ b/tests/unit/proxy/mcp_server/test_jwt_mcp_simple.py @@ -2,13 +2,14 @@ Simple test to validate MCP permissions are enforced when calling MCP routes with JWT. """ -import pytest from unittest.mock import AsyncMock, MagicMock, patch +import pytest + from litellm.proxy._types import ( LiteLLM_JWTAuth, - LiteLLM_TeamTable, LiteLLM_ObjectPermissionTable, + LiteLLM_TeamTable, UserAPIKeyAuth, ) @@ -24,7 +25,7 @@ async def test_simple_jwt_mcp_permissions_enforced(): Expected: Only ["github-mcp", "slack-mcp"] should be allowed """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -86,7 +87,7 @@ async def test_simple_jwt_no_team_no_mcp_servers(): """ Simple test: JWT user with no team should get no MCP servers. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -111,7 +112,7 @@ async def test_simple_jwt_team_id_required_for_mcp_permissions(): This is the key insight - if JWT auth doesn't set team_id, team MCP permissions won't be enforced. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -176,8 +177,8 @@ async def test_jwt_auth_sets_team_id_for_mcp_route(): This is the critical test - when user calls /mcp/tools/list with JWT, the team_id from JWT groups must be set on UserAPIKeyAuth. """ - from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.caching import DualCache + from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.proxy.utils import ProxyLogging # Setup @@ -245,8 +246,8 @@ async def test_mcp_route_without_model_still_returns_team_id(): 4. Route check passes because "mcp_routes" is in team_allowed_routes 5. team_id is returned and set on UserAPIKeyAuth """ - from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.caching import DualCache + from litellm.proxy.auth.handle_jwt import JWTAuthManager, JWTHandler from litellm.proxy.utils import ProxyLogging # Setup diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.py b/tests/unit/proxy/mcp_server/test_mcp_auth_header_extraction.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.py rename to tests/unit/proxy/mcp_server/test_mcp_auth_header_extraction.py index b652a6d457e..bb47c1fdfe3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_header_extraction.py +++ b/tests/unit/proxy/mcp_server/test_mcp_auth_header_extraction.py @@ -6,14 +6,15 @@ Tests the fixes for: 2. Case-insensitive matching for server-specific auth headers in _call_regular_mcp_tool """ -import pytest from unittest.mock import AsyncMock, MagicMock + +import pytest from starlette.datastructures import Headers -from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( +from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.py b/tests/unit/proxy/mcp_server/test_mcp_auth_priority.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.py rename to tests/unit/proxy/mcp_server/test_mcp_auth_priority.py index 21a89d7ffcc..675848b0869 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_auth_priority.py +++ b/tests/unit/proxy/mcp_server/test_mcp_auth_priority.py @@ -7,8 +7,9 @@ Validates that: """ import pytest -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager -from litellm.types.mcp import MCPAuth, MCPTransport, MCPSpecVersion + +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager +from litellm.types.mcp import MCPAuth, MCPSpecVersion, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -53,7 +54,7 @@ async def test_mcp_server_config_auth_value_header_used(token_key, config_only_m """ import httpx2 - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_block_recording.py b/tests/unit/proxy/mcp_server/test_mcp_block_recording.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_block_recording.py rename to tests/unit/proxy/mcp_server/test_mcp_block_recording.py index 746130fb892..c59c37b2f37 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_block_recording.py +++ b/tests/unit/proxy/mcp_server/test_mcp_block_recording.py @@ -1,6 +1,7 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """Tests for guardrail-block recording in -``litellm.proxy._experimental.mcp_server.operations.call_mcp_tool``. +``litellm.proxy.mcp_server.operations.call_mcp_tool``. A pre-call MCP guardrail block *raises* into ``call_mcp_tool``'s ``except Exception``. The failure spend-log row that the Guardrails Monitor's @@ -34,7 +35,7 @@ from unittest import mock import pytest from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server import server +from litellm.proxy.mcp_server import server class _RecordingLoggingObj: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.py b/tests/unit/proxy/mcp_server/test_mcp_chat_completions.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.py rename to tests/unit/proxy/mcp_server/test_mcp_chat_completions.py index 32cd883c1f7..e5fd50e832e 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_chat_completions.py +++ b/tests/unit/proxy/mcp_server/test_mcp_chat_completions.py @@ -206,7 +206,7 @@ async def test_completion_mcp_with_streaming_no_timeout_error(monkeypatch): ) # Create a mock streaming response - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} @@ -281,18 +281,18 @@ async def test_completion_mcp_with_streaming_no_timeout_error(monkeypatch): acompletion_calls = [] # Create mock streaming response for initial call - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} logging_obj.async_failure_handler = AsyncMock() from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) # Create initial streaming chunks with tool_calls @@ -471,19 +471,19 @@ async def test_mcp_metadata_in_streaming_final_chunk(monkeypatch): from types import SimpleNamespace from unittest.mock import patch + from litellm.litellm_core_utils.litellm_logging import Logging from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) from litellm.responses.utils import ResponsesAPIRequestUtils - from litellm.utils import CustomStreamWrapper from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) - from litellm.litellm_core_utils.litellm_logging import Logging + from litellm.utils import CustomStreamWrapper dummy_tool = SimpleNamespace( name="local_search", @@ -568,7 +568,7 @@ async def test_mcp_metadata_in_streaming_final_chunk(monkeypatch): ] # Create a proper CustomStreamWrapper with logging_obj - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} @@ -831,14 +831,14 @@ async def test_mcp_streaming_metadata_ordering(monkeypatch): LiteLLM_Proxy_MCP_Handler, ) from litellm.responses.utils import ResponsesAPIRequestUtils - from litellm.utils import CustomStreamWrapper from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) + from litellm.utils import CustomStreamWrapper dummy_tool = SimpleNamespace( name="local_search", @@ -923,7 +923,7 @@ async def test_mcp_streaming_metadata_ordering(monkeypatch): ] # Create a proper CustomStreamWrapper with logging_obj - from unittest.mock import MagicMock, AsyncMock + from unittest.mock import AsyncMock, MagicMock logging_obj = MagicMock() logging_obj.model_call_details = {} diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.py b/tests/unit/proxy/mcp_server/test_mcp_client_unit.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.py rename to tests/unit/proxy/mcp_server/test_mcp_client_unit.py index a270ea16a39..1f804f3b425 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_client_unit.py +++ b/tests/unit/proxy/mcp_server/test_mcp_client_unit.py @@ -3,22 +3,22 @@ Unit tests for the MCPClient class - critical functionality only. """ import base64 +from unittest.mock import ANY, AsyncMock, MagicMock, patch + import pytest -from unittest.mock import AsyncMock, MagicMock, patch, ANY - -# Add the project root to the path - -import litellm.experimental_mcp_client.client as mcp_client_module -from litellm.experimental_mcp_client.client import MCPClient -from litellm.types.mcp import MCPAuth, MCPTransport from mcp.types import CallToolResult as MCPCallToolResult from mcp.types import Implementation, InitializeResult, ListToolsResult, PaginatedRequestParams, ServerCapabilities from mcp.types import Tool as MCPTool +# Add the project root to the path +import litellm.mcp_client.client as mcp_client_module +from litellm.mcp_client.client import MCPClient +from litellm.types.mcp import MCPAuth, MCPTransport + def test_mcp_client_uses_configurable_default_timeout(): """MCPClient should use MCP_CLIENT_TIMEOUT constant when no timeout is passed.""" - with patch("litellm.experimental_mcp_client.client.MCP_CLIENT_TIMEOUT", 120.0): + with patch("litellm.mcp_client.client.MCP_CLIENT_TIMEOUT", 120.0): # Client reads constant at runtime when timeout is None client = MCPClient( server_url="http://example.com", diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_cost_calculator.py b/tests/unit/proxy/mcp_server/test_mcp_cost_calculator.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_cost_calculator.py rename to tests/unit/proxy/mcp_server/test_mcp_cost_calculator.py index 5357e0dce9e..368080f55a5 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_cost_calculator.py +++ b/tests/unit/proxy/mcp_server/test_mcp_cost_calculator.py @@ -6,8 +6,7 @@ import pytest from fastapi import Request from fastapi.testclient import TestClient - -from litellm.proxy._experimental.mcp_server.cost_calculator import MCPCostCalculator +from litellm.proxy.mcp_server.cost_calculator import MCPCostCalculator class TestMCPCostCalculator: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_custom_fields.py b/tests/unit/proxy/mcp_server/test_mcp_custom_fields.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_custom_fields.py rename to tests/unit/proxy/mcp_server/test_mcp_custom_fields.py index e3437bf16f6..78dde8f75df 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_custom_fields.py +++ b/tests/unit/proxy/mcp_server/test_mcp_custom_fields.py @@ -4,15 +4,16 @@ Test suite for MCP server custom fields functionality. Tests that mcp_info can accept arbitrary custom fields in addition to predefined ones. """ -import pytest +from typing import Any, Dict from unittest.mock import Mock, patch -from typing import Dict, Any + +import pytest + +from litellm.proxy._types import LiteLLM_MCPServerTable # Add the path to find the modules - -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPAuth -from litellm.proxy._types import LiteLLM_MCPServerTable class TestMCPCustomFields: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_debug.py b/tests/unit/proxy/mcp_server/test_mcp_debug.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_debug.py rename to tests/unit/proxy/mcp_server/test_mcp_debug.py index ed1ae0bb4fe..4f88aaa1d67 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_debug.py +++ b/tests/unit/proxy/mcp_server/test_mcp_debug.py @@ -9,13 +9,13 @@ import httpx import pytest from starlette.types import Message -from litellm.proxy._experimental.mcp_server.mcp_debug import ( +from litellm.proxy.mcp_server.mcp_debug import ( MCP_DEBUG_REQUEST_HEADER, MCPAuthDiagnostics, MCPDebug, describe_upstream_http_failure, ) -from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution +from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution class TestIsDebugEnabled: @@ -290,7 +290,7 @@ def test_failure_log_omits_unstructured_body(): @pytest.mark.asyncio @pytest.mark.parametrize("mode", ["error", "empty", "large", "timeout", "read_failure", "closed", "success", "cancel"]) async def test_error_capture_is_bounded_and_preserves_success_and_cancellation(mode): - from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response + from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response class Stream(httpx.AsyncByteStream): def __init__(self): @@ -349,7 +349,7 @@ def test_failure_preview_handles_empty_scalar_control_and_long_bodies(body): @pytest.mark.asyncio @pytest.mark.parametrize("slow_error", [False, True]) async def test_error_capture_preserves_httpx_auth_retry(slow_error): - from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response + from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response class RetryAuth(httpx.Auth): def auth_flow(self, request): @@ -467,8 +467,8 @@ async def test_concurrent_mcp_messages_record_on_their_own_http_scope(_mcp_reque from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.mcp_debug import ( + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_debug import ( MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, record_auth_resolution, ) @@ -540,7 +540,8 @@ def test_oversized_request_omits_potentially_reflected_response_credentials(): @pytest.mark.asyncio async def test_streamed_error_redacts_reflected_credentials_before_capture(): import json - from litellm.proxy._experimental.mcp_server.mcp_debug import capture_upstream_error_response + + from litellm.proxy.mcp_server.mcp_debug import capture_upstream_error_response secret = "generic-credential-123" request = httpx.Request("POST", "https://upstream/token", data={"client_secret":secret}) @@ -566,7 +567,7 @@ def test_failure_diagnostics_omit_credential_bearing_url_paths(path): def test_deep_request_omits_response_when_credentials_cannot_be_inspected(): - from litellm.proxy._experimental.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH + from litellm.proxy.mcp_server.utils import MAX_STRUCTURED_CONTENT_SCAN_DEPTH raw = "[" * (MAX_STRUCTURED_CONTENT_SCAN_DEPTH + 1) + '{"client_secret":"nested-credential"}' + "]" * (MAX_STRUCTURED_CONTENT_SCAN_DEPTH + 1) request = httpx.Request("POST", "https://upstream/token", content=raw, headers={"Content-Type": "application/json"}) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_discovery.py b/tests/unit/proxy/mcp_server/test_mcp_discovery.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_discovery.py rename to tests/unit/proxy/mcp_server/test_mcp_discovery.py index d35cb7234dc..35fc7440f99 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_discovery.py +++ b/tests/unit/proxy/mcp_server/test_mcp_discovery.py @@ -5,7 +5,6 @@ from typing import Final import pytest - class TestMCPRegistryFile: """Tests for the curated MCP registry JSON file.""" @@ -17,7 +16,6 @@ class TestMCPRegistryFile: "..", "..", "..", - "..", "litellm", "proxy", "mcp_registry.json", diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py b/tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py rename to tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py index dd8dddf106e..08e3903ece4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_elicitation_handler.py +++ b/tests/unit/proxy/mcp_server/test_mcp_elicitation_handler.py @@ -12,21 +12,20 @@ from types import SimpleNamespace from unittest.mock import AsyncMock import pytest - from mcp.types import ( + REQUEST_TIMEOUT, ClientCapabilities, ElicitationCapability, - FormElicitationCapability, - UrlElicitationCapability, - REQUEST_TIMEOUT, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, ErrorData, + FormElicitationCapability, + UrlElicitationCapability, ) -from litellm.proxy._experimental.mcp_server import elicitation_handler -from litellm.proxy._experimental.mcp_server.elicitation_handler import ( +from litellm.proxy.mcp_server import elicitation_handler +from litellm.proxy.mcp_server.elicitation_handler import ( _relay_elicitation_to_downstream, handle_elicitation_request, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_env_vars.py b/tests/unit/proxy/mcp_server/test_mcp_env_vars.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_env_vars.py rename to tests/unit/proxy/mcp_server/test_mcp_env_vars.py index 807061c946f..57ac6c0be2d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_env_vars.py +++ b/tests/unit/proxy/mcp_server/test_mcp_env_vars.py @@ -1,7 +1,7 @@ """Tests for MCP env-var interpolation utilities. These cover the pure helpers in -``litellm.proxy._experimental.mcp_server.utils`` and do not require a DB +``litellm.proxy.mcp_server.utils`` and do not require a DB connection. The DB-backed per-user flow is exercised in higher-level tests in tests/integration/mcp. """ @@ -12,8 +12,6 @@ from unittest.mock import AsyncMock import pytest from respx import MockRouter -from litellm.types.mcp_server.mcp_server_manager import MCPServer - # Look up these names lazily on every access. Tests in this directory call # ``importlib.reload`` on the utils module to exercise registration logic, # which replaces ``MCPMissingUserEnvVarsError`` with a freshly-constructed @@ -21,7 +19,8 @@ from litellm.types.mcp_server.mcp_server_manager import MCPServer # old class object and ``pytest.raises(_u("MCPMissingUserEnvVarsError"))`` would # stop matching the new class. Accessing the attribute through the module # always picks up the current version. -import litellm.proxy._experimental.mcp_server.utils as _mcp_utils +import litellm.proxy.mcp_server.utils as _mcp_utils +from litellm.types.mcp_server.mcp_server_manager import MCPServer def _u(name: str): @@ -191,7 +190,7 @@ def mock_server(): async def test_resolve_static_headers_interpolates_globals_and_user( mock_server, monkeypatch ): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -216,7 +215,7 @@ async def test_resolve_static_headers_interpolates_globals_and_user( async def test_resolve_static_headers_raises_when_user_vars_missing( mock_server, monkeypatch ): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -250,7 +249,7 @@ async def test_resolve_static_headers_rechecks_db_before_raising_412( MCPMissingUserEnvVarsError the resolver must re-read with force_refresh and honor the fresh DB values. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -288,7 +287,7 @@ async def test_resolve_static_headers_missing_is_non_blocking_for_listing( """With raise_on_missing=False (the tool-list path), missing per-user vars must NOT raise. Available vars interpolate; unfilled ${NAME} refs are left untouched so the server's tools still appear in the listing.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -317,7 +316,7 @@ async def test_resolve_static_headers_propagates_db_error_on_tool_call( ): """A DB failure on the tool-call path must surface as a real error, not be masked as a "missing credentials" MCPMissingUserEnvVarsError (412).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -340,7 +339,7 @@ async def test_resolve_static_headers_swallows_db_error_on_listing( ): """On the listing path a DB failure is non-blocking: globals interpolate and unfilled per-user ${NAME} refs are left untouched.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -363,7 +362,7 @@ async def test_resolve_static_headers_swallows_db_error_on_listing( @pytest.mark.asyncio async def test_resolve_static_headers_passthrough_when_no_env_vars(): """Servers without env_vars should keep static_headers untouched.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -388,7 +387,7 @@ async def test_resolve_static_headers_unreferenced_user_var_is_not_blocking( """A per-user var declared by the admin but never referenced in static_headers must not block the request — only blocking-by-use is enforced.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -423,7 +422,7 @@ async def test_resolve_static_headers_stale_user_value_cannot_override_global( """A var that used to be user-scoped (so the user has a stored value) but is now global must resolve to the admin's global value, not the stale per-user row. Otherwise a user could override admin-configured headers indefinitely.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -460,7 +459,7 @@ async def test_resolve_static_headers_dual_scope_var_uses_global_without_412( global value (globals win in the merge), so the tool-call path must resolve it from the global instead of raising a 412 when the user hasn't filled it in. This happens during a global-to-user (or user-to-global) migration.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -504,7 +503,7 @@ async def test_resolve_static_headers_empty_global_does_not_cover_user_var( global carries no usable value, so the tool-call path still raises a 412 when the user hasn't supplied one, instead of silently interpolating an empty string into the header.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -543,7 +542,7 @@ async def test_resolve_static_headers_user_value_wins_over_empty_global( """When a global is empty, a value the user did supply must win the merge rather than being clobbered by the empty global. The header resolves to the user's value, not an empty string.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -603,7 +602,7 @@ def test_references_per_user_env_var(static_headers, env_vars, expected): """Only headers that actually reference a *per-user* var count: globals and declared-but-unreferenced user vars do not, since the userless probe can still resolve (or simply not need) them.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -624,7 +623,7 @@ def test_references_per_user_env_var(static_headers, env_vars, expected): async def test_health_check_reaches_servers_without_forwarding_per_user_env_vars( mock_server: MCPServer, monkeypatch: pytest.MonkeyPatch, respx_mock: MockRouter ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -650,7 +649,7 @@ async def test_health_check_reaches_servers_without_forwarding_per_user_env_vars @pytest.mark.asyncio async def test_load_user_env_vars_returns_empty_without_user(): """No user auth → no per-user lookup is attempted.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -667,7 +666,7 @@ async def test_load_user_env_vars_returns_empty_without_user_id(): """User auth without a user_id (e.g. anonymous virtual key) → empty dict.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -689,7 +688,7 @@ async def test_load_user_env_vars_raises_when_db_unavailable(monkeypatch): satisfy (per-user env vars are unusable without a DB).""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -715,7 +714,7 @@ async def test_resolve_static_headers_db_unavailable_is_not_missing_412( was None, making a DB outage look like "user has no credentials".""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -736,8 +735,8 @@ async def test_load_user_env_vars_caches_within_ttl(env_vars_salt_key, monkeypat keeping the hot tool-call/tool-listing path off the DB.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server import mcp_server_manager as mgr_mod - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import mcp_server_manager as mgr_mod + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -773,8 +772,8 @@ async def test_load_user_env_vars_force_refresh_bypasses_cache( process-local stale value cannot mask credentials stored on another worker.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server import mcp_server_manager as mgr_mod - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import mcp_server_manager as mgr_mod + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -818,8 +817,8 @@ async def test_load_user_env_vars_invalidation_forces_refetch( instead of serving the stale cached value.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server import mcp_server_manager as mgr_mod - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server import mcp_server_manager as mgr_mod + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, invalidate_user_env_vars_cache, ) @@ -973,7 +972,7 @@ def _transactional_env_vars_prisma(read_delay: float = 0.0): async def test_merge_user_env_vars_does_not_persist_plaintext(env_vars_salt_key): """The per-user write path must encrypt values at rest; ``values_b64`` must never hold plaintext personal credentials, but must still round-trip.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( _decode_user_env_vars, merge_user_env_vars, ) @@ -997,7 +996,7 @@ async def test_merge_user_env_vars_does_not_persist_plaintext(env_vars_salt_key) async def test_get_user_env_vars_round_trip(env_vars_salt_key): from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars + from litellm.proxy.mcp_server.db import get_user_env_vars payload = {"CORP_USERNAME": "alice", "CORP_PASSWORD": "s3cret"} row = MagicMock() @@ -1010,7 +1009,7 @@ async def test_get_user_env_vars_round_trip(env_vars_salt_key): @pytest.mark.asyncio async def test_get_user_env_vars_returns_empty_for_missing_row(): - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars + from litellm.proxy.mcp_server.db import get_user_env_vars prisma = _mock_env_vars_prisma(row=None) assert await get_user_env_vars(prisma, "alice", "srv-1") == {} @@ -1020,7 +1019,7 @@ async def test_get_user_env_vars_returns_empty_for_missing_row(): async def test_get_user_env_vars_stringifies_non_string_json_values(env_vars_salt_key): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars + from litellm.proxy.mcp_server.db import get_user_env_vars row: Final = SimpleNamespace(values_b64=_encrypted_user_env_blob({"PORT": 8080, "DEBUG": True, "EMPTY": None})) @@ -1036,8 +1035,8 @@ async def test_get_user_env_vars_stringifies_non_string_json_values(env_vars_sal async def test_get_user_env_vars_treats_a_blob_that_is_not_a_json_object_as_unset(env_vars_salt_key, stored_json): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper + from litellm.proxy.mcp_server.db import get_user_env_vars row: Final = SimpleNamespace(values_b64=encrypt_value_helper(stored_json)) @@ -1054,8 +1053,8 @@ async def test_decode_user_env_vars_warns_when_undecryptable( credentials" 412 for values they already stored.""" from unittest.mock import MagicMock - import litellm.proxy._experimental.mcp_server.db as mcp_db - from litellm.proxy._experimental.mcp_server.db import _decode_user_env_vars + import litellm.proxy.mcp_server.db as mcp_db + from litellm.proxy.mcp_server.db import _decode_user_env_vars blob = _encrypted_user_env_blob({"CORP_PASSWORD": "s3cret"}) @@ -1071,7 +1070,7 @@ async def test_decode_user_env_vars_warns_when_undecryptable( async def test_get_user_env_vars_bulk_distributes_results(env_vars_salt_key): from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars_bulk + from litellm.proxy.mcp_server.db import get_user_env_vars_bulk blob1 = _encrypted_user_env_blob({"A": "1"}) blob2 = _encrypted_user_env_blob({"B": "2"}) @@ -1091,7 +1090,7 @@ async def test_get_user_env_vars_bulk_distributes_results(env_vars_salt_key): @pytest.mark.asyncio async def test_get_user_env_vars_bulk_empty_ids_short_circuits(): - from litellm.proxy._experimental.mcp_server.db import get_user_env_vars_bulk + from litellm.proxy.mcp_server.db import get_user_env_vars_bulk prisma = _mock_env_vars_prisma() assert await get_user_env_vars_bulk(prisma, "alice", []) == {} @@ -1103,7 +1102,7 @@ async def test_get_user_env_vars_bulk_empty_ids_short_circuits(): async def test_delete_user_env_vars_is_idempotent_delete_many(): """Delete must use ``delete_many`` so a missing row is a no-op rather than raising RecordNotFound; real DB errors are left to propagate.""" - from litellm.proxy._experimental.mcp_server.db import delete_user_env_vars + from litellm.proxy.mcp_server.db import delete_user_env_vars prisma = _mock_env_vars_prisma() await delete_user_env_vars(prisma, "alice", "srv-1") @@ -1118,7 +1117,7 @@ async def test_merge_user_env_vars_preserves_existing_and_prunes_disallowed( ): """Merging one update keeps the user's other stored values and drops any name the admin no longer declares as user-scoped.""" - from litellm.proxy._experimental.mcp_server.db import merge_user_env_vars + from litellm.proxy.mcp_server.db import merge_user_env_vars prisma = _transactional_env_vars_prisma() await merge_user_env_vars( @@ -1149,7 +1148,7 @@ async def test_merge_user_env_vars_serializes_concurrent_writes(env_vars_salt_ke both distinct values survive.""" import asyncio - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( get_user_env_vars, merge_user_env_vars, ) @@ -1178,7 +1177,7 @@ async def test_merge_user_env_vars_acquires_lock_without_deserializing_void( from prisma.errors import RawQueryError - from litellm.proxy._experimental.mcp_server.db import merge_user_env_vars + from litellm.proxy.mcp_server.db import merge_user_env_vars class _Tx: def __init__(self): @@ -1231,7 +1230,7 @@ async def test_delete_mcp_server_removes_orphaned_user_env_vars(): it; there is no FK cascade, so skipping this leaves orphaned credentials.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=object()) @@ -1248,7 +1247,7 @@ async def test_delete_mcp_server_skips_env_var_cleanup_when_server_missing(): """A no-op delete (server not found) must not touch the env var table.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=None) @@ -1267,7 +1266,7 @@ async def test_delete_mcp_server_succeeds_when_orphan_cleanup_fails(): is already gone.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server deleted = object() prisma = _mock_env_vars_prisma() @@ -1289,7 +1288,7 @@ async def test_delete_mcp_server_removes_orphaned_user_credentials(): pointing at a now-missing server.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=object()) @@ -1306,7 +1305,7 @@ async def test_delete_mcp_server_skips_credential_cleanup_when_server_missing(): """A no-op delete (server not found) must not touch the credential table.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server prisma = _mock_env_vars_prisma() prisma.db.litellm_mcpservertable.delete = AsyncMock(return_value=None) @@ -1324,7 +1323,7 @@ async def test_delete_mcp_server_credential_cleanup_failure_still_cleans_env_var still succeed for the caller.""" from unittest.mock import AsyncMock - from litellm.proxy._experimental.mcp_server.db import delete_mcp_server + from litellm.proxy.mcp_server.db import delete_mcp_server deleted = object() prisma = _mock_env_vars_prisma() @@ -1361,11 +1360,11 @@ def test_prepare_mcp_server_data_encrypts_global_env_var_values(env_vars_salt_ke column, while ``scope="user"`` placeholders (not secrets) stay verbatim.""" import json - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, decrypt_global_env_var_values, ) - from litellm.proxy._types import MCPEnvVar req = _global_env_var_server_request( [ @@ -1400,8 +1399,8 @@ def test_prepare_mcp_server_data_skips_unset_env_vars_on_partial_update(): be written, even when the request object carries a non-None env_vars that was never marked as set. Otherwise a partial update could silently overwrite the stored values.""" - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data from litellm.proxy._types import MCPEnvVar, UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data data = UpdateMCPServerRequest.model_construct( _fields_set={"server_id"}, @@ -1420,8 +1419,8 @@ def test_prepare_mcp_server_data_writes_env_vars_when_set_on_partial_update( """A partial update that does set env_vars must serialize and encrypt them.""" import json - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data from litellm.proxy._types import MCPEnvVar, UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data data = UpdateMCPServerRequest( server_id="srv-1", @@ -1443,11 +1442,11 @@ async def test_build_mcp_server_from_table_decrypts_global_env_vars(env_vars_sal headers interpolate to the real secret instead of forwarding ciphertext.""" import json - from litellm.proxy._experimental.mcp_server.db import _prepare_mcp_server_data - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar + from litellm.proxy.mcp_server.db import _prepare_mcp_server_data + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1481,14 +1480,14 @@ async def test_add_server_does_not_double_decrypt_global_env_vars(env_vars_salt_ upstream instead of the interpolated secret.""" import json - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, decrypt_global_env_var_values, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import LiteLLM_MCPServerTable, MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1529,16 +1528,16 @@ async def test_create_mcp_server_decrypts_env_vars_when_prisma_returns_json_stri (timestamps match), so headers forward ciphertext upstream.""" from unittest.mock import AsyncMock, MagicMock - from litellm.proxy._experimental.mcp_server.db import ( - _prepare_mcp_server_data, - create_mcp_server, - update_mcp_server, - ) from litellm.proxy._types import ( MCPEnvVar, NewMCPServerRequest, UpdateMCPServerRequest, ) + from litellm.proxy.mcp_server.db import ( + _prepare_mcp_server_data, + create_mcp_server, + update_mcp_server, + ) req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1598,11 +1597,11 @@ def test_reencrypt_global_env_var_values_handles_json_string(env_vars_salt_key): helper must parse it instead of failing on ``dict(v)`` over a string.""" import json - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, _reencrypt_global_env_var_values, ) - from litellm.proxy._types import MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] @@ -1630,11 +1629,11 @@ async def test_rotate_mcp_user_env_vars_logs_rotated_and_skipped_counts( left untouched and counted as skipped.""" from unittest.mock import AsyncMock, MagicMock - import litellm.proxy._experimental.mcp_server.db as mcp_db - from litellm.proxy._experimental.mcp_server.db import ( + import litellm.proxy.mcp_server.db as mcp_db + from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper + from litellm.proxy.mcp_server.db import ( rotate_mcp_user_env_vars_master_key, ) - from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper def _row(user_id, server_id, blob): row = MagicMock() @@ -1693,12 +1692,12 @@ def test_decrypt_global_env_var_drops_undecryptable_value( import json from unittest.mock import MagicMock - import litellm.proxy._experimental.mcp_server.db as mcp_db - from litellm.proxy._experimental.mcp_server.db import ( + import litellm.proxy.mcp_server.db as mcp_db + from litellm.proxy._types import MCPEnvVar + from litellm.proxy.mcp_server.db import ( _prepare_mcp_server_data, decrypt_global_env_var_values, ) - from litellm.proxy._types import MCPEnvVar req = _global_env_var_server_request( [MCPEnvVar(name="DB_PASSWORD", value="s3cr3t-p@ss", scope="global")] diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_guardrail_usage_monitor.py b/tests/unit/proxy/mcp_server/test_mcp_guardrail_usage_monitor.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_guardrail_usage_monitor.py rename to tests/unit/proxy/mcp_server/test_mcp_guardrail_usage_monitor.py index 8d5e36e9795..765771de633 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_guardrail_usage_monitor.py +++ b/tests/unit/proxy/mcp_server/test_mcp_guardrail_usage_monitor.py @@ -21,7 +21,7 @@ from unittest import mock import pytest from litellm.exceptions import GuardrailRaisedException -from litellm.proxy._experimental.mcp_server import mcp_server_manager as MOD +from litellm.proxy.mcp_server import mcp_server_manager as MOD class _FakeLoggingObj: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_header_alias_utils.py b/tests/unit/proxy/mcp_server/test_mcp_header_alias_utils.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_header_alias_utils.py rename to tests/unit/proxy/mcp_server/test_mcp_header_alias_utils.py index 6c24205c258..80c79505205 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_header_alias_utils.py +++ b/tests/unit/proxy/mcp_server/test_mcp_header_alias_utils.py @@ -1,6 +1,6 @@ """Tests for MCP header alias sanitization and auth header lookup.""" -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.utils import ( lookup_mcp_server_auth_in_headers, sanitize_mcp_alias_for_header, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_hook_extra_headers.py b/tests/unit/proxy/mcp_server/test_mcp_hook_extra_headers.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_hook_extra_headers.py rename to tests/unit/proxy/mcp_server/test_mcp_hook_extra_headers.py index c477a8d34cb..d0cf0199233 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_hook_extra_headers.py +++ b/tests/unit/proxy/mcp_server/test_mcp_hook_extra_headers.py @@ -19,8 +19,8 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest from mcp.types import CallToolResult -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.utils import ProxyLogging from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -412,7 +412,7 @@ class TestCallToolFlowsHookHeaders: new_callable=AsyncMock, return_value=CallToolResult(content=[], isError=False), ): - import litellm.proxy._experimental.mcp_server.mcp_server_manager as mgr_mod + import litellm.proxy.mcp_server.mcp_server_manager as mgr_mod proxy_logging = MagicMock(spec=ProxyLogging) @@ -1059,7 +1059,7 @@ class TestOpenApiByokCallTool: @pytest.mark.asyncio async def test_call_tool_openapi_byok_injects_request_auth_contextvar(self): """Playground/responses call call_tool directly; BYOK must reach OpenAPI handlers.""" - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_auth_header, ) @@ -1083,7 +1083,7 @@ class TestOpenApiByokCallTool: with patch.object(manager, "_resolve_mcp_server_for_tool_call", return_value=server): with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager._resolve_byok_mcp_auth_header", + "litellm.proxy.mcp_server.mcp_server_manager._resolve_byok_mcp_auth_header", new=AsyncMock(return_value="fc-test-key"), ): with patch.object( @@ -1113,21 +1113,21 @@ class TestFormatByokOpenapiAuthHeader: ) def test_api_key_auth_type(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) assert _format_byok_openapi_auth_header(self._server(MCPAuth.api_key), "secret") == "ApiKey secret" def test_basic_auth_type(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) assert _format_byok_openapi_auth_header(self._server(MCPAuth.basic), "secret") == "Basic secret" def test_defaults_to_bearer(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _format_byok_openapi_auth_header, ) @@ -1146,7 +1146,7 @@ class TestOpenapiForwardedExtraHeaders: ) def test_returns_none_without_extra_headers_config(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1154,7 +1154,7 @@ class TestOpenapiForwardedExtraHeaders: assert _openapi_forwarded_extra_headers(server, {"X-Custom": "v"}, None) is None def test_returns_none_without_raw_headers(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1162,7 +1162,7 @@ class TestOpenapiForwardedExtraHeaders: assert _openapi_forwarded_extra_headers(server, None, None) is None def test_forwards_configured_header_case_insensitively(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1171,7 +1171,7 @@ class TestOpenapiForwardedExtraHeaders: assert result == {"X-Custom": "v"} def test_returns_none_when_no_configured_header_is_present(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1179,7 +1179,7 @@ class TestOpenapiForwardedExtraHeaders: assert _openapi_forwarded_extra_headers(server, {"x-custom": "v"}, None) is None def test_skips_authorization_when_caller_header_must_be_stripped(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1189,7 +1189,7 @@ class TestOpenapiForwardedExtraHeaders: assert result is None def test_skips_non_string_header_entries(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _openapi_forwarded_extra_headers, ) @@ -1212,7 +1212,7 @@ class TestResolveByokMcpAuthHeader: @pytest.mark.asyncio async def test_non_byok_server_passes_header_through_unchanged(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1222,7 +1222,7 @@ class TestResolveByokMcpAuthHeader: @pytest.mark.asyncio async def test_byok_server_uses_stored_credential_when_no_header_supplied(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1230,7 +1230,7 @@ class TestResolveByokMcpAuthHeader: user_auth = UserAPIKeyAuth(user_id="user-1", api_key="sk-dashboard") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_byok_credential", + "litellm.proxy.mcp_server.operations._get_byok_credential", new=AsyncMock(return_value="stored-cred"), ): result = await _resolve_byok_mcp_auth_header(server, user_auth, None) @@ -1241,7 +1241,7 @@ class TestResolveByokMcpAuthHeader: async def test_byok_server_raises_401_when_no_credential_stored(self, monkeypatch): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1250,7 +1250,7 @@ class TestResolveByokMcpAuthHeader: user_auth = UserAPIKeyAuth(user_id="user-1", api_key="sk-dashboard") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_byok_credential", + "litellm.proxy.mcp_server.operations._get_byok_credential", new=AsyncMock(return_value=None), ): with pytest.raises(HTTPException) as exc_info: @@ -1264,7 +1264,7 @@ class TestResolveByokMcpAuthHeader: @pytest.mark.asyncio async def test_byok_server_checks_credential_and_keeps_caller_header_when_supplied(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _resolve_byok_mcp_auth_header, ) @@ -1273,7 +1273,7 @@ class TestResolveByokMcpAuthHeader: check_mock = AsyncMock(return_value=None) with patch( - "litellm.proxy._experimental.mcp_server.operations._check_byok_credential", + "litellm.proxy.mcp_server.operations._check_byok_credential", new=check_mock, ): result = await _resolve_byok_mcp_auth_header(server, user_auth, "caller-header") @@ -1304,13 +1304,13 @@ class TestOpenApiResolvedUpstreamAuth: async def test_call_tool_openapi_injects_v2_resolved_token_contextvar(self): """The managed spec_path arm resolves the v2 credential and sets the ContextVar; kills the mutant that drops the resolve_openapi_upstream_auth call in call_tool.""" - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_resolved_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok manager = MCPServerManager() server = self._oauth_server() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.py b/tests/unit/proxy/mcp_server/test_mcp_logging.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.py rename to tests/unit/proxy/mcp_server/test_mcp_logging.py index 44ba40afdd1..9548135b530 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_logging.py +++ b/tests/unit/proxy/mcp_server/test_mcp_logging.py @@ -11,14 +11,14 @@ from mcp.types import Tool as MCPTool import litellm from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( +from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth +from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) -from litellm.proxy._experimental.mcp_server.server import ( +from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth from litellm.types.mcp import MCPPostCallResponseObject @@ -111,7 +111,7 @@ async def test_mcp_cost_tracking(): local_mcp_server_manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load the server config @@ -138,11 +138,11 @@ async def test_mcp_cost_tracking(): # Patch the global manager in both modules where it's used with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", local_mcp_server_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", local_mcp_server_manager, ), ): @@ -244,7 +244,7 @@ async def test_mcp_cost_tracking_per_tool(): local_mcp_server_manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load the server config with per-tool costs @@ -289,11 +289,11 @@ async def test_mcp_cost_tracking_per_tool(): # Patch the global manager in both modules where it's used with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", local_mcp_server_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", local_mcp_server_manager, ), ): @@ -417,7 +417,7 @@ async def test_mcp_tool_call_hook(): local_mcp_server_manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load the server config @@ -447,11 +447,11 @@ async def test_mcp_tool_call_hook(): # Patch the global manager in both modules where it's used with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", local_mcp_server_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", local_mcp_server_manager, ), ): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py b/tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py rename to tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py index 8497d7bb7c4..f1896757874 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_max_concurrent_requests.py +++ b/tests/unit/proxy/mcp_server/test_mcp_max_concurrent_requests.py @@ -2,16 +2,16 @@ import asyncio from collections.abc import Awaitable, Callable from typing import Dict, Final, Optional, TypeVar, cast from unittest.mock import AsyncMock, patch + +import pytest from mcp import ClientSession from mcp.server.context import ServerRequestContext from mcp.types import CallToolRequestParams as MCPCallToolRequestParams -from litellm.experimental_mcp_client.client import MCPClient, PersistentMCPSession -from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - -import pytest from mcp.types import CallToolResult, TextContent -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager +from litellm.mcp_client.client import MCPClient, PersistentMCPSession +from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_metadata_preservation.py b/tests/unit/proxy/mcp_server/test_mcp_metadata_preservation.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_metadata_preservation.py rename to tests/unit/proxy/mcp_server/test_mcp_metadata_preservation.py index 86748d99063..118a4a9f17b 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_metadata_preservation.py +++ b/tests/unit/proxy/mcp_server/test_mcp_metadata_preservation.py @@ -9,11 +9,10 @@ which is critical for ChatGPT UI widget rendering. import pytest # Add the parent directory to the path so we can import litellm - from mcp.types import Tool as MCPTool -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough.py b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough.py rename to tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough.py index 1c59b7b87e0..80b4ea3c287 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough.py +++ b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough.py @@ -15,15 +15,13 @@ import httpx import pytest from fastapi import HTTPException, Request - - -from litellm.proxy._experimental.mcp_server import discoverable_endpoints -from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server import discoverable_endpoints +from litellm.proxy.mcp_server.discoverable_endpoints import ( _OAUTH_METADATA_CACHE, _OAUTH_METADATA_FETCH_LOCKS, _build_oauth_protected_resource_response, ) -from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -32,7 +30,7 @@ from litellm.types.mcp_server.mcp_server_manager import MCPServer def _mock_mcp_client_ip(): """Bypass IP-based access control in tests.""" with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.discoverable_endpoints.IPAddressUtils.get_mcp_client_ip", return_value=None, ): yield @@ -208,7 +206,7 @@ def test_is_oauth_passthrough_false_when_only_delegate_auth_to_upstream_set(): @pytest.mark.asyncio async def test_oauth_protected_resource_passthrough_proxies_upstream_metadata(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -253,7 +251,7 @@ async def test_oauth_protected_resource_passthrough_proxies_upstream_metadata(): @pytest.mark.asyncio async def test_oauth_protected_resource_passthrough_cache_hit(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -380,7 +378,7 @@ async def test_oauth_metadata_cache_expired_entry_is_refetched(): @pytest.mark.asyncio async def test_oauth_protected_resource_passthrough_network_error_returns_502(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -444,7 +442,7 @@ async def test_oauth_protected_resource_gateway_managed_unchanged(): never fetch upstream metadata. Since LIT-4864 the advertised document is the gateway's own aggregate authorization server ({base}/mcp), which serves the keyless DCR flow for per-server URLs; the per-server relay endpoints remain for the keyed flow.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -505,7 +503,7 @@ async def test_oauth_protected_resource_oauth_delegate_returns_upstream_metadata gateway would make a strict IdP refuse to mint it or the upstream reject it. A regression that dropped oauth_delegate from the pass-through predicate would fall through to the gateway-AS branch and advertise LiteLLM as the AS.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -543,7 +541,7 @@ async def test_oauth_protected_resource_true_passthrough_returns_upstream_metada resource included, so the client treats the upstream as the resource and authorizes directly against it. A regression that rewrote resource (the gateway-proxied behavior) would break the transparent-proxy contract.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -582,7 +580,7 @@ async def test_oauth_protected_resource_dcr_bridge_returns_gateway_facade(auth_t facade: resource is the gateway URL the client dialed and authorization_servers names the gateway's per-server AS, so DCR-only clients (which enforce the RFC 9728 resource match) can register and sign in through the gateway. No upstream metadata fetch happens.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_cold_start.py b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_cold_start.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_cold_start.py rename to tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_cold_start.py index 67663448d65..3f6a44b0300 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_cold_start.py +++ b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_cold_start.py @@ -3,7 +3,6 @@ import pytest - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -40,11 +39,11 @@ def test_passthrough_cold_start_emits_401_with_matching_resource_metadata( route, expected_metadata_path ): """No auth headers on a passthrough server route emits matching metadata.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_mcp_passthrough_cold_start, _parse_mcp_server_names_from_path, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -93,10 +92,10 @@ def test_passthrough_cold_start_emits_401_with_matching_resource_metadata( def test_is_mcp_passthrough_cold_start_false_for_oauth2_server(): """Gateway-managed OAuth2 servers must not trigger the cold-start bypass.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_mcp_passthrough_cold_start, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -122,7 +121,7 @@ def test_is_mcp_passthrough_cold_start_false_for_oauth2_server(): def test_is_mcp_passthrough_cold_start_false_for_empty_servers(): """Aggregate /mcp route (no server list) must not trigger bypass.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _is_mcp_passthrough_cold_start, ) @@ -147,7 +146,7 @@ def test_is_mcp_passthrough_cold_start_false_for_empty_servers(): ], ) def test_parse_mcp_server_names_from_path(path, expected): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( _parse_mcp_server_names_from_path, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py rename to tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py index 34b021df2b9..03a7373c908 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_oauth_passthrough_tools.py +++ b/tests/unit/proxy/mcp_server/test_mcp_oauth_passthrough_tools.py @@ -1,4 +1,4 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations """Unit tests for MCP OAuth passthrough tool-fetch behavior.""" @@ -11,21 +11,20 @@ from unittest.mock import AsyncMock, MagicMock import httpx import pytest - if sys.version_info < (3, 11): from exceptiongroup import ExceptionGroup -from litellm.proxy._experimental.mcp_server.exceptions import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.exceptions import ( TOKEN_EXCHANGE_SUBJECT_ERROR, MCPServerListError, MCPUpstreamAuthError, ) -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( +from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, _extract_upstream_auth_failure, ) -from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -341,8 +340,8 @@ async def test_aggregate_list_tools_absorbs_one_unauthenticated_server(): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_server delegate = _http_server( "s1", "delegate_docs", auth_type=MCPAuth.oauth2, delegate_auth_to_upstream=True @@ -384,9 +383,9 @@ async def test_single_server_route_also_absorbs_upstream_auth_error(): re-auth surfacing is handled by a request-scope preemptive check, tracked separately.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.mcp_context import mcp_gateway_server_name from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.mcp_context import mcp_gateway_server_name delegate = _http_server( "s1", "delegate_docs", auth_type=MCPAuth.oauth2, delegate_auth_to_upstream=True @@ -425,8 +424,8 @@ async def test_aggregate_with_single_accessible_server_still_absorbs(): permission sets.""" from unittest.mock import patch - from litellm.proxy._experimental.mcp_server import server as mcp_server from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import server as mcp_server delegate = _http_server( "s1", "delegate_docs", auth_type=MCPAuth.oauth2, delegate_auth_to_upstream=True @@ -506,7 +505,7 @@ async def test_client_creation_failure_logs_sanitized_exchange(monkeypatch, capl ], ) def test_passthrough_admission_recognizes_only_matching_authorization(oauth_headers, server_headers, authorized): - from litellm.proxy._experimental.mcp_server.operations import _client_has_passthrough_authorization + from litellm.proxy.mcp_server.operations import _client_has_passthrough_authorization from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -528,7 +527,7 @@ def test_managed_step_up_challenge_uses_only_the_gateway_metadata(base_url, requ @pytest.mark.asyncio async def test_scope_challenge_replaces_pending_stream_headers_once(): - from litellm.proxy._experimental.mcp_server.scope_challenge import OAuthScopeResponse + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse send = AsyncMock() response = OAuthScopeResponse(send, "https://gateway.example", "/docs/mcp") @@ -554,14 +553,13 @@ async def test_scope_authorization_releases_progress_without_waiting_for_tool_re from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import ( + from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import ( SCOPE_RESPONSE_KEY, OAuthScopeResponse, ) - from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization - send = AsyncMock() gate = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") request = Request({"type": "http", SCOPE_RESPONSE_KEY: gate}) @@ -578,7 +576,7 @@ async def test_scope_authorization_releases_progress_without_waiting_for_tool_re await record_upstream_tool_authorization(httpx2.Response(200, request=unread), pending=get_scope_response()) assert gate.pending # Use the actual HTTP response hook contract, before reading the tool response body. - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient upstream = MCPClient(server_url="https://upstream.example/mcp") async with upstream._create_httpx_client_factory(transport=httpx2.MockTransport(lambda request: httpx2.Response(200, content=b"tool result")))() as client: @@ -602,7 +600,7 @@ async def test_scope_middleware_releases_waiting_response_on_validation_or_cance from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response send: Final = AsyncMock(side_effect=BrokenPipeError("peer disconnected") if fail_send else None) gate: Final = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") @@ -627,8 +625,8 @@ async def test_scope_transport_owns_header_send_cancellation_and_errors(fail_sen import httpx2 from starlette.types import Message - from litellm.proxy._experimental.mcp_server.legacy_callbacks import record_upstream_tool_authorization - from litellm.proxy._experimental.mcp_server.scope_challenge import OAuthScopeResponse + from litellm.proxy.mcp_server.legacy_callbacks import record_upstream_tool_authorization + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse send_started: Final = asyncio.Event() send_stopped: Final = asyncio.Event() @@ -677,7 +675,7 @@ async def test_scope_transport_owns_header_send_cancellation_and_errors(fail_sen async def test_scope_authorization_sends_stream_headers_before_the_first_body_chunk(allowed_before_start: bool) -> None: from starlette.types import Message - from litellm.proxy._experimental.mcp_server.scope_challenge import OAuthScopeResponse + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse send: Final = AsyncMock() gate: Final = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") @@ -698,7 +696,7 @@ async def test_scope_authorization_sends_stream_headers_before_the_first_body_ch @pytest.mark.asyncio async def test_scope_response_preserves_transport_validation_errors(): - from litellm.proxy._experimental.mcp_server.scope_challenge import OAuthScopeResponse + from litellm.proxy.mcp_server.scope_challenge import OAuthScopeResponse send = AsyncMock() gate = OAuthScopeResponse(send, "https://gateway.example", "/mcp/docs") @@ -718,9 +716,9 @@ async def test_streamable_sdk_relays_scope_challenge_before_committing_http_resp from mcp.server.streamable_http_manager import StreamableHTTPSessionManager from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response + from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse, finish_scope_response async def call_tool(context, params): token = active_mcp_request_ctx_var.set(context) @@ -772,9 +770,9 @@ async def test_scope_challenges_are_isolated_between_concurrent_requests(): from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + from litellm.proxy.mcp_server.legacy_callbacks import get_scope_response, record_upstream_tool_authorization + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse async def request_scope(denied): send = AsyncMock() @@ -801,7 +799,7 @@ async def test_scope_challenges_are_isolated_between_concurrent_requests(): @pytest.mark.parametrize("body", [b"", b"{", b"[]", b'{"method":"initialize"}']) def test_non_tool_payloads_do_not_hold_response_headers(body): - from litellm.proxy._experimental.mcp_server.scope_challenge import is_tool_call_request, scope_response_from_request + from litellm.proxy.mcp_server.scope_challenge import is_tool_call_request, scope_response_from_request assert not is_tool_call_request(body) assert scope_response_from_request(None) is None @@ -812,7 +810,7 @@ async def test_scope_middleware_preserves_non_http_requests(): from mcp.server.context import ServerRequestContext from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.scope_challenge import finish_scope_response + from litellm.proxy.mcp_server.scope_challenge import finish_scope_response context = ServerRequestContext(session=MagicMock(), lifespan_context={}, protocol_version="2025-11-25", method="tools/call") async def call_next(request): @@ -824,9 +822,10 @@ async def test_scope_middleware_preserves_non_http_requests(): @pytest.mark.parametrize("path", ["/mcp", "/toolset/demo/mcp"]) def test_managed_step_up_metadata_matches_the_sdk_configured_resource(path): - from mcp.shared.auth_utils import check_resource_allowed from urllib.parse import urlsplit + from mcp.shared.auth_utils import check_resource_allowed + error = MCPUpstreamAuthError(403, None, "docs", required_scope="tools.write") response = error.to_http_exception("https://gateway.test", path) challenge = response.headers["www-authenticate"] diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_partial_update.py b/tests/unit/proxy/mcp_server/test_mcp_partial_update.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_partial_update.py rename to tests/unit/proxy/mcp_server/test_mcp_partial_update.py index d6894979906..8e24e4fca80 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_partial_update.py +++ b/tests/unit/proxy/mcp_server/test_mcp_partial_update.py @@ -12,16 +12,16 @@ import json from unittest.mock import AsyncMock, MagicMock import pytest -from prisma import Json, models from fastapi import HTTPException +from prisma import Json, models -from litellm.proxy._experimental.mcp_server.db import ( +from litellm.proxy._types import NewMCPServerRequest, UpdateMCPServerRequest +from litellm.proxy.mcp_server.db import ( create_mcp_server, decrypt_credentials, set_mcp_server_pinned_tools, update_mcp_server, ) -from litellm.proxy._types import NewMCPServerRequest, UpdateMCPServerRequest from litellm.types.mcp_server.mcp_server_manager import PinnedMCPTool @@ -883,7 +883,7 @@ def _mock_toolset_prisma(): async def _run_toolset_update(payload: dict) -> dict: """The columns PUT /v1/mcp/toolset writes for this payload, minus the audit stamp every write carries. The prisma double is injected, so nothing is patched.""" - from litellm.proxy._experimental.mcp_server.toolset_db import update_mcp_toolset + from litellm.proxy.mcp_server.toolset_db import update_mcp_toolset from litellm.types.mcp_server.mcp_toolset import UpdateMCPToolsetRequest mock_prisma = _mock_toolset_prisma() @@ -943,7 +943,7 @@ async def test_find_identifier_conflict_reports_alias_hit(): Case-insensitive and cross-field matching is exercised end to end against real Postgres by test_duplicate_alias_is_rejected_so_tool_prefixes_cannot_collide. """ - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( find_mcp_server_identifier_conflict, ) @@ -964,7 +964,7 @@ async def test_find_identifier_conflict_reports_alias_hit(): async def test_find_identifier_conflict_reports_server_name_when_alias_is_free(): """alias is checked first so the reported field is deterministic; a clean alias does not mask a colliding server_name.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( find_mcp_server_identifier_conflict, ) @@ -981,7 +981,7 @@ async def test_find_identifier_conflict_reports_server_name_when_alias_is_free() @pytest.mark.asyncio async def test_find_identifier_conflict_returns_none_when_free(): - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( find_mcp_server_identifier_conflict, ) @@ -994,7 +994,7 @@ async def test_find_identifier_conflict_returns_none_when_free(): @pytest.mark.asyncio async def test_update_writing_alias_returns_conflict_instead_of_row(): - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict mock_prisma = _mock_prisma() mock_prisma.db.litellm_mcpservertable.find_first = AsyncMock(return_value=_conflict_row()) @@ -1038,7 +1038,7 @@ async def test_update_writing_free_alias_returns_the_row(): async def test_clearing_alias_conflicts_on_the_fallback_server_name(): """alias: null drops the tool prefix to the stored server_name, which may already belong to another row, so that name goes through the conflict check.""" - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict mock_prisma = _mock_prisma() existing = MagicMock() @@ -1061,7 +1061,7 @@ async def test_clearing_alias_conflicts_on_the_fallback_server_name(): async def test_clearing_alias_to_empty_string_conflicts_on_the_fallback_server_name(): """alias: "" publishes the stored server_name as the tool prefix, just like alias: null, so the fallback name must go through the conflict check too.""" - from litellm.proxy._experimental.mcp_server.db import McpIdentifierConflict + from litellm.proxy.mcp_server.db import McpIdentifierConflict mock_prisma = _mock_prisma() existing = MagicMock() @@ -1254,7 +1254,8 @@ async def test_url_edit_preserves_client_bound_to_previous_known_issuer_without_ @pytest.mark.parametrize("changed", [0, 1]) async def test_registration_write_requires_unchanged_server_revision(changed): from datetime import datetime, timezone - from litellm.proxy._experimental.mcp_server.db import _update_mcp_server_row + + from litellm.proxy.mcp_server.db import _update_mcp_server_row prisma = _mock_prisma() table = prisma.db.litellm_mcpservertable diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_proxy_mode.py b/tests/unit/proxy/mcp_server/test_mcp_proxy_mode.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_proxy_mode.py rename to tests/unit/proxy/mcp_server/test_mcp_proxy_mode.py index 7dadfc6493a..8d6a92a12a7 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_proxy_mode.py +++ b/tests/unit/proxy/mcp_server/test_mcp_proxy_mode.py @@ -1,4 +1,3 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations import asyncio import json import logging @@ -14,15 +13,16 @@ from pydantic import AnyUrl import litellm from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server import server -from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller -from litellm.proxy._experimental.mcp_server.tool_search import ( +from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth +from litellm.proxy.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import server +from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller +from litellm.proxy.mcp_server.tool_search import ( handle_mcp_proxy_tool, mcp_proxy_tool_id, with_mcp_proxy_identity, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_completion_flow.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_completion_flow.py similarity index 85% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_completion_flow.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_completion_flow.py index d17b407a1be..e838b8b088d 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_completion_flow.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_completion_flow.py @@ -11,10 +11,9 @@ from types import SimpleNamespace from unittest.mock import AsyncMock, MagicMock, patch import pytest - from mcp.types import CreateMessageResult, ErrorData -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _build_completion_kwargs, _run_guardrails_and_call_llm, handle_sampling_create_message, @@ -146,26 +145,26 @@ class TestHandleSamplingCreateMessagePipeline: ) with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._build_completion_kwargs", + "litellm.proxy.mcp_server.sampling_handler._build_completion_kwargs", new_callable=AsyncMock, return_value={"model": "gpt-4o", "messages": []}, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_guardrails_and_call_llm", + "litellm.proxy.mcp_server.sampling_handler._run_guardrails_and_call_llm", new_callable=AsyncMock, return_value=response, ), @@ -187,21 +186,21 @@ class TestHandleSamplingCreateMessagePipeline: auth = SimpleNamespace(user_id="u1", api_key="sk-test", token="tok") with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._build_completion_kwargs", + "litellm.proxy.mcp_server.sampling_handler._build_completion_kwargs", new_callable=AsyncMock, side_effect=RateLimitError( "rate limited", llm_provider="openai", model="gpt-4o" @@ -220,21 +219,21 @@ class TestHandleSamplingCreateMessagePipeline: auth = SimpleNamespace(user_id="u1", api_key="sk-test", token="tok") with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._build_completion_kwargs", + "litellm.proxy.mcp_server.sampling_handler._build_completion_kwargs", new_callable=AsyncMock, side_effect=RuntimeError("kaboom"), ), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_access.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_access.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_access.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_model_access.py index 8975f42387b..7111638da29 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_access.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_access.py @@ -7,10 +7,11 @@ calls, preventing a malicious upstream MCP server from requesting inference on models the caller's API key is not authorized to use. """ -import pytest from unittest.mock import AsyncMock, MagicMock, patch -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +import pytest + +from litellm.proxy.mcp_server.sampling_handler import ( _check_model_access, ) @@ -207,7 +208,7 @@ class TestSamplingAuthAndBudgetGating: @pytest.mark.asyncio async def test_should_deny_when_no_auth_context(self): """Sampling must reject calls with no user_api_key_auth.""" - from litellm.proxy._experimental.mcp_server.sampling_handler import ( + from litellm.proxy.mcp_server.sampling_handler import ( handle_sampling_create_message, ) @@ -236,7 +237,7 @@ class TestSamplingAuthAndBudgetGating: @pytest.mark.asyncio async def test_should_run_budget_checks(self): """Sampling must call _run_budget_checks after model access check.""" - from litellm.proxy._experimental.mcp_server.sampling_handler import ( + from litellm.proxy.mcp_server.sampling_handler import ( handle_sampling_create_message, ) @@ -254,17 +255,17 @@ class TestSamplingAuthAndBudgetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=None, ) as mock_budget, patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), patch( @@ -298,7 +299,8 @@ class TestSamplingAuthAndBudgetGating: async def test_should_deny_over_budget_caller(self): """When _run_budget_checks returns ErrorData, sampling must return it.""" from mcp.types import ErrorData - from litellm.proxy._experimental.mcp_server.sampling_handler import ( + + from litellm.proxy.mcp_server.sampling_handler import ( handle_sampling_create_message, ) @@ -318,17 +320,17 @@ class TestSamplingAuthAndBudgetGating: with ( patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._check_model_access", + "litellm.proxy.mcp_server.sampling_handler._check_model_access", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._run_budget_checks", + "litellm.proxy.mcp_server.sampling_handler._run_budget_checks", new_callable=AsyncMock, return_value=budget_error, ), patch( - "litellm.proxy._experimental.mcp_server.sampling_handler._resolve_model_from_preferences", + "litellm.proxy.mcp_server.sampling_handler._resolve_model_from_preferences", return_value="gpt-4o", ), ): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_resolution.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_resolution.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_resolution.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_model_resolution.py index 0c8f7bd4814..a0280abbae7 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_model_resolution.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_model_resolution.py @@ -12,7 +12,7 @@ from unittest.mock import MagicMock, patch import pytest -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _resolve_model_from_preferences, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_priority_selection.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_priority_selection.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_priority_selection.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_priority_selection.py index 24309ed0460..b6426ca88d6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_priority_selection.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_priority_selection.py @@ -9,7 +9,7 @@ per the MCP spec. from types import SimpleNamespace from unittest.mock import patch -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _has_priorities, _resolve_model_from_preferences, _select_model_by_priority, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_request_builder.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_request_builder.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_request_builder.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_request_builder.py index d5c636baead..3d1b2072ae5 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_request_builder.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_request_builder.py @@ -7,7 +7,7 @@ so that header-dependent guardrails, routing hooks, and trace correlation function correctly. """ -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _build_sampling_request, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_response_conversion.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_response_conversion.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_response_conversion.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_response_conversion.py index ba130f34964..de9c600b5c4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_response_conversion.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_response_conversion.py @@ -18,7 +18,7 @@ from mcp.types import ( ToolUseContent, ) -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _convert_mcp_content_to_openai, _convert_mcp_tool_choice_to_openai, _convert_mcp_tools_to_openai, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_tool_conversion.py b/tests/unit/proxy/mcp_server/test_mcp_sampling_tool_conversion.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_tool_conversion.py rename to tests/unit/proxy/mcp_server/test_mcp_sampling_tool_conversion.py index 167847afe1f..e537f03aeff 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sampling_tool_conversion.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sampling_tool_conversion.py @@ -12,12 +12,11 @@ from typing import Any, Dict from mcp.types import TextContent, ToolResultContent -from litellm.proxy._experimental.mcp_server.sampling_handler import ( +from litellm.proxy.mcp_server.sampling_handler import ( _convert_mcp_messages_to_openai, _convert_single_content, ) - # --------------------------------------------------------------------------- # Helpers — lightweight MCP type stand-ins # --------------------------------------------------------------------------- diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server.py b/tests/unit/proxy/mcp_server/test_mcp_server.py similarity index 92% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server.py rename to tests/unit/proxy/mcp_server/test_mcp_server.py index de711d737d0..884c82760ea 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server.py @@ -2,24 +2,21 @@ import asyncio import json import os +from contextlib import asynccontextmanager, nullcontext from typing import Final +from unittest.mock import ANY, AsyncMock, MagicMock, patch import pytest -from unittest.mock import ANY, AsyncMock, MagicMock, patch -from contextlib import asynccontextmanager, nullcontext - +from mcp.types import CallToolResult, ListToolsResult, TextContent +from mcp.types import Tool as MCPTool from starlette.types import Receive, Scope, Send - -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - MCPServerManager, +from litellm.proxy._types import LiteLLM_ObjectPermissionTable +from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServer, + MCPServerManager, MCPTransport, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable -from mcp.types import Tool as MCPTool, CallToolResult, ListToolsResult -from mcp.types import TextContent - mcp_server_manager = MCPServerManager() @@ -77,7 +74,7 @@ async def test_mcp_server_manager_https_server(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): await mcp_server_manager.load_servers_from_config( @@ -185,7 +182,7 @@ async def test_mcp_http_transport_list_tools_mock(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load server config with HTTP transport @@ -262,7 +259,7 @@ async def test_mcp_http_transport_call_tool_mock(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load server config with HTTP transport @@ -328,7 +325,7 @@ async def test_mcp_http_transport_call_tool_error_mock(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Load server config with HTTP transport @@ -426,26 +423,26 @@ async def test_streamable_http_mcp_handler_mock(): with ( patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", mock_session_manager_stateless, ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", mock_session_manager_stateful, ), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", AsyncMock(return_value=mock_auth_context), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), ): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -495,32 +492,32 @@ async def test_sse_mcp_handler_mock(): ) with ( - patch("litellm.proxy._experimental.mcp_server.server.serve_loop", serve), + patch("litellm.proxy.mcp_server.server.serve_loop", serve), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.sse", + "litellm.proxy.mcp_server.server.sse", mock_sse, ), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new=AsyncMock(return_value=mock_auth_result), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new=AsyncMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new=AsyncMock(), ), ): - from litellm.proxy._experimental.mcp_server.server import handle_sse_mcp + from litellm.proxy.mcp_server.server import handle_sse_mcp # Call the handler await handle_sse_mcp(mock_scope, mock_receive, mock_send) @@ -560,33 +557,33 @@ async def test_sse_mcp_handler_propagates_passthrough_401(): with ( patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.sse", + "litellm.proxy.mcp_server.server.sse", ) as transport, patch( - "litellm.proxy._experimental.mcp_server.server.server.run", + "litellm.proxy.mcp_server.server.server.run", AsyncMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new=AsyncMock(return_value=mock_auth_result), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new=AsyncMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new=AsyncMock(side_effect=challenge), ), ): - from litellm.proxy._experimental.mcp_server.server import handle_sse_mcp + from litellm.proxy.mcp_server.server import handle_sse_mcp with pytest.raises(HTTPException) as excinfo: await handle_sse_mcp(mock_scope, mock_receive, mock_send) @@ -751,12 +748,13 @@ def test_generate_stable_server_id(): @pytest.mark.asyncio async def test_list_tools_rest_api_server_not_found(): """Test the list_tools REST API when server is not found""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( - list_tool_rest_api, - global_mcp_server_manager, - ) from fastapi import Query + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import ( + global_mcp_server_manager, + list_tool_rest_api, + ) # Mock UserAPIKeyAuth with explicit permission to access the requested server id mock_user_auth = UserAPIKeyAuth( @@ -776,7 +774,7 @@ async def test_list_tools_rest_api_server_not_found(): # Mock the global_mcp_server_manager to allow the server ID but return None for the server with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: # Allow the server ID in permissions mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -805,14 +803,15 @@ async def test_list_tools_rest_api_server_not_found(): @pytest.mark.asyncio async def test_list_tools_rest_api_success(): """Test the list_tools REST API successful case""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from fastapi import Query + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import ( list_tool_rest_api, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) - from fastapi import Query - from litellm.proxy._types import UserAPIKeyAuth # Mock successful tools mock_tools = [ @@ -849,7 +848,7 @@ async def test_list_tools_rest_api_success(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_allowed_mcp_servers = AsyncMock( return_value=["test-server-123"] @@ -862,7 +861,7 @@ async def test_list_tools_rest_api_success(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: mock_get_tools.return_value = mock_tools @@ -881,14 +880,14 @@ async def test_list_tools_rest_api_success(): @pytest.mark.asyncio async def test_get_tools_from_mcp_servers(): """Test _get_tools_from_mcp_servers function with both specific and no server filters""" - from litellm.proxy._experimental.mcp_server.server import ( - _get_tools_from_mcp_servers, - ) from litellm.proxy._types import UserAPIKeyAuth - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServer, MCPTransport, ) + from litellm.proxy.mcp_server.server import ( + _get_tools_from_mcp_servers, + ) # Mock data mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -946,7 +945,7 @@ async def test_get_tools_from_mcp_servers(): ) with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): # Test with specific servers @@ -995,7 +994,7 @@ async def test_get_tools_from_mcp_servers(): ) with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager_2, ): result = await _get_tools_from_mcp_servers( @@ -1028,11 +1027,11 @@ async def test_get_tools_from_mcp_servers(): ) with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_mcp_servers_from_access_groups", AsyncMock(return_value=["server3_id"]), ): # Test with specific servers @@ -1112,7 +1111,7 @@ async def test_list_tools_only_returns_allowed_servers(monkeypatch): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call list_tools @@ -1158,13 +1157,12 @@ async def test_mcp_server_manager_access_groups_from_config(config_only_mcp_mana assert config_server is not None assert set(config_server.access_groups) == {"group-a", "group-b"} # Check that the lookup logic finds the correct server ids - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) - # Patch global_mcp_server_manager for this test and restore afterwards to # avoid leaking state into other tests (e.g. the proxy MCP e2e suite). - import litellm.proxy._experimental.mcp_server.mcp_server_manager as mcp_server_manager_mod + import litellm.proxy.mcp_server.mcp_server_manager as mcp_server_manager_mod + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) original_manager = mcp_server_manager_mod.global_mcp_server_manager mcp_server_manager_mod.global_mcp_server_manager = test_manager @@ -1204,6 +1202,7 @@ async def test_mcp_server_manager_config_integration_with_database(config_only_m specifically testing access_groups and description fields. """ import datetime + from litellm.proxy._types import LiteLLM_MCPServerTable test_manager = config_only_mcp_manager_factory() @@ -1310,7 +1309,7 @@ def test_get_server_prefix_with_alias(): """ Test that get_server_prefix returns alias when present. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server with alias mock_server = MagicMock() @@ -1326,7 +1325,7 @@ def test_get_server_prefix_without_alias(): """ Test that get_server_prefix falls back to server_name when alias is not present. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server without alias mock_server = MagicMock() @@ -1342,7 +1341,7 @@ def test_get_server_prefix_fallback_to_server_id(): """ Test that get_server_prefix falls back to server_id when neither alias nor server_name are present. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server without alias or server_name mock_server = MagicMock() @@ -1358,7 +1357,7 @@ def test_get_server_prefix_empty_strings(): """ Test that get_server_prefix handles empty strings correctly. """ - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix # Create a mock server with empty strings mock_server = MagicMock() @@ -1409,7 +1408,7 @@ async def test_mcp_server_manager_alias_tool_prefixing(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Get tools from server @@ -1469,7 +1468,7 @@ async def test_mcp_server_manager_server_name_tool_prefixing(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Get tools from server @@ -1529,7 +1528,7 @@ async def test_mcp_server_manager_server_id_tool_prefixing(): return mock_client with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Get tools from server @@ -1748,7 +1747,7 @@ def test_normalize_server_name(): """ Test that normalize_server_name correctly replaces spaces with underscores. """ - from litellm.proxy._experimental.mcp_server.utils import normalize_server_name + from litellm.proxy.mcp_server.utils import normalize_server_name # Test basic space replacement assert normalize_server_name("My Server Name") == "My_Server_Name" @@ -1768,7 +1767,7 @@ def test_normalize_server_name(): def test_add_server_prefix_to_name(): """Ensure add_server_prefix_to_name correctly formats resource names.""" - from litellm.proxy._experimental.mcp_server.utils import add_server_prefix_to_name + from litellm.proxy.mcp_server.utils import add_server_prefix_to_name # Test basic prefixing result = add_server_prefix_to_name("send_email", "My Server") @@ -1789,7 +1788,7 @@ def test_add_server_prefix_to_name(): def test_get_server_auth_header_with_alias(): """Test _get_server_auth_header function with server alias.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1824,7 +1823,7 @@ def test_get_server_auth_header_with_alias(): def test_get_server_auth_header_with_server_name(): """Test _get_server_auth_header function with server name (no alias).""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1859,7 +1858,7 @@ def test_get_server_auth_header_with_server_name(): def test_get_server_auth_header_fallback_to_default(): """Test _get_server_auth_header function fallback to default auth header.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1887,7 +1886,7 @@ def test_get_server_auth_header_fallback_to_default(): def test_get_server_auth_header_hyphenated_alias_sanitized_header_key(): """Header keys use sanitized alias; lookup must match legacy hyphenated aliases.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1907,7 +1906,7 @@ def test_get_server_auth_header_hyphenated_alias_sanitized_header_key(): def test_get_server_auth_header_no_auth_headers(): """Test _get_server_auth_header function with no auth headers.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_server_auth_header, ) @@ -1926,11 +1925,12 @@ def test_get_server_auth_header_no_auth_headers(): def test_create_tool_response_objects(): """Test _create_tool_response_objects enriches mcp_info with server_id and alias.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy.mcp_server.rest_endpoints import ( _create_tool_response_objects, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer - from mcp.types import Tool as MCPTool # Create mock tools mock_tools = [ @@ -1977,10 +1977,11 @@ def test_create_tool_response_objects(): @pytest.mark.asyncio async def test_get_tools_for_single_server(): """Test _get_tools_for_single_server function.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) - from mcp.types import Tool as MCPTool # Create a mock server (pin allowlist fields; MagicMock auto-attrs are truthy) mock_server = MagicMock() @@ -2001,7 +2002,7 @@ async def test_get_tools_for_single_server(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_tools_from_server = AsyncMock(return_value=mock_tools) @@ -2033,10 +2034,11 @@ async def test_get_tools_for_single_server(): @pytest.mark.asyncio async def test_get_tools_for_single_server_applies_disallowed_tools_without_allowlist(): """REST listing must honor disallowed_tools even when no allowlist is set.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) - from mcp.types import Tool as MCPTool mock_server = MagicMock() mock_server.mcp_info = {"server_name": "zapier"} @@ -2062,7 +2064,7 @@ async def test_get_tools_for_single_server_applies_disallowed_tools_without_allo ] with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_tools_from_server = AsyncMock(return_value=mock_tools) @@ -2080,14 +2082,15 @@ async def test_rest_listing_hides_key_grants_dispatch_would_refuse(): therefore grants nothing, and REST listing that matched the prefixed spelling would advertise a tool the very next call refuses. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool server_id = "3c6f6617-d23c-4f48-bfb0-f205e3b27bab" mock_server = MagicMock() @@ -2110,9 +2113,9 @@ async def test_rest_listing_hides_key_grants_dispatch_would_refuse(): ] with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_server_manager, patch.object( MCPRequestHandler, "get_allowed_tools_for_server", @@ -2133,11 +2136,11 @@ async def test_rest_listing_hides_key_grants_dispatch_would_refuse(): @pytest.mark.asyncio async def test_list_tool_rest_api_with_server_specific_auth(): """Test list_tool_rest_api with server-specific auth headers.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import list_tool_rest_api - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import list_tool_rest_api # Create mock request with server-specific auth headers mock_request = MagicMock() @@ -2162,7 +2165,7 @@ async def test_list_tool_rest_api_with_server_specific_auth(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_allowed_mcp_servers = AsyncMock( return_value=["test-server-123"] @@ -2191,9 +2194,9 @@ async def test_list_tool_rest_api_with_server_specific_auth(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) @@ -2231,11 +2234,11 @@ async def test_list_tool_rest_api_with_server_specific_auth(): @pytest.mark.asyncio async def test_list_tool_rest_api_with_default_auth(): """Test list_tool_rest_api with default auth header when no server-specific header is found.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import list_tool_rest_api - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import list_tool_rest_api # Create mock request with default auth header only mock_request = MagicMock() @@ -2256,7 +2259,7 @@ async def test_list_tool_rest_api_with_default_auth(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: mock_manager.get_allowed_mcp_servers = AsyncMock( return_value=["test-server-123"] @@ -2285,9 +2288,9 @@ async def test_list_tool_rest_api_with_default_auth(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) @@ -2325,11 +2328,11 @@ async def test_list_tool_rest_api_with_default_auth(): @pytest.mark.asyncio async def test_list_tool_rest_api_all_servers_with_auth(): """Test list_tool_rest_api for all servers with server-specific auth headers.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import list_tool_rest_api - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.rest_endpoints import list_tool_rest_api # Create mock request with server-specific auth headers mock_request = MagicMock() @@ -2354,7 +2357,7 @@ async def test_list_tool_rest_api_all_servers_with_auth(): # Mock the global_mcp_server_manager with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager" + "litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager" ) as mock_manager: # Create mock servers mock_zapier_server = MagicMock() @@ -2395,9 +2398,9 @@ async def test_list_tool_rest_api_all_servers_with_auth(): # Mock the _get_tools_for_single_server function with patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server" + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server" ) as mock_get_tools: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( ListMCPToolsRestAPIResponseObject, ) @@ -2452,11 +2455,12 @@ async def test_list_tool_rest_api_all_servers_with_auth(): @pytest.mark.asyncio async def test_filter_tools_by_allowed_tools_integration(): """Test that filter_tools_by_allowed_tools works correctly via _get_tools_from_mcp_servers""" - from litellm.proxy._experimental.mcp_server.server import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool # Create a mock user auth mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -2509,7 +2513,7 @@ async def test_filter_tools_by_allowed_tools_integration(): # Mock the global MCP server manager with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_manager: # Mock manager methods mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -2526,7 +2530,7 @@ async def test_filter_tools_by_allowed_tools_integration(): # Mock the MCPClient constructor with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call _get_tools_from_mcp_servers which should apply the filtering @@ -2567,11 +2571,12 @@ async def test_filter_tools_by_allowed_tools_integration(): @pytest.mark.asyncio async def test_filter_tools_by_disallowed_tools_integration(): """Test that filter_tools_by_allowed_tools works correctly with disallowed_tools via _get_tools_from_mcp_servers""" - from litellm.proxy._experimental.mcp_server.server import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool # Create a mock user auth mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -2624,7 +2629,7 @@ async def test_filter_tools_by_disallowed_tools_integration(): # Mock the global MCP server manager with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_manager: # Mock manager methods mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -2640,7 +2645,7 @@ async def test_filter_tools_by_disallowed_tools_integration(): # Mock the MCPClient constructor with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call _get_tools_from_mcp_servers which should apply the filtering @@ -2681,11 +2686,12 @@ async def test_filter_tools_by_disallowed_tools_integration(): @pytest.mark.asyncio async def test_filter_tools_no_restrictions_integration(): """Test that filter_tools_by_allowed_tools returns all tools when no restrictions are set""" - from litellm.proxy._experimental.mcp_server.server import ( + from mcp.types import Tool as MCPTool + + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth - from mcp.types import Tool as MCPTool # Create a mock user auth mock_user_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") @@ -2725,7 +2731,7 @@ async def test_filter_tools_no_restrictions_integration(): # Mock the global MCP server manager with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager" + "litellm.proxy.mcp_server.operations.global_mcp_server_manager" ) as mock_manager: # Mock manager methods mock_manager.get_allowed_mcp_servers = AsyncMock( @@ -2742,7 +2748,7 @@ async def test_filter_tools_no_restrictions_integration(): # Mock the MCPClient constructor with patch( - "litellm.proxy._experimental.mcp_server.upstream.MCPClient", + "litellm.proxy.mcp_server.upstream.MCPClient", mock_client_constructor, ): # Call _get_tools_from_mcp_servers which should apply the filtering @@ -2766,10 +2772,10 @@ async def test_filter_tools_no_restrictions_integration(): @pytest.mark.asyncio async def test_mcp_access_group_permission_inheritance_integration(): """Integration test for MCP access group permission inheritance""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth # Test scenario: team has access groups, key has no permissions -> should inherit # Use direct mocking of the helper functions instead of complex database mocking @@ -2806,10 +2812,10 @@ async def test_mcp_access_group_permission_inheritance_integration(): @pytest.mark.asyncio async def test_mcp_access_group_permission_intersection_integration(): """Integration test for MCP access group permission intersection""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth # Test scenario: both team and key have access groups -> should intersect # Use direct mocking of the helper functions instead of complex database mocking @@ -2849,11 +2855,11 @@ async def test_mcp_access_group_permission_intersection_integration(): @pytest.mark.asyncio async def test_mcp_server_manager_with_access_groups_integration(config_only_mcp_manager_factory): """Integration test for MCPServerManager with access group filtering""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) - from litellm.proxy._types import UserAPIKeyAuth # Create a test manager test_manager = config_only_mcp_manager_factory() @@ -2901,7 +2907,7 @@ async def test_mcp_server_manager_with_access_groups_integration(config_only_mcp @pytest.mark.asyncio async def test_get_allowed_mcp_servers_returns_registry_for_admin(config_only_mcp_manager_factory): from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -2936,7 +2942,7 @@ async def test_get_allowed_mcp_servers_returns_registry_for_admin(config_only_mc @pytest.mark.asyncio async def test_get_allowed_mcp_servers_returns_empty_for_non_admin_without_permissions(config_only_mcp_manager_factory): from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) @@ -2972,7 +2978,7 @@ async def test_get_allowed_mcp_servers_returns_empty_for_non_admin_without_permi @pytest.mark.asyncio async def test_call_mcp_tool_uses_manager_permission_lookup(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) @@ -3002,14 +3008,14 @@ async def test_call_mcp_tool_uses_manager_permission_lookup(): ), patch.object(global_mcp_server_manager, "server_exposes_tool", return_value=True), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_tool_registry" + "litellm.proxy.mcp_server.operations.global_mcp_tool_registry" ) as mock_tool_registry, patch( - "litellm.proxy._experimental.mcp_server.operations._handle_managed_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_managed_mcp_tool", new_callable=AsyncMock, ) as mock_handle_managed, patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -3038,7 +3044,7 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission Ensure `call_mcp_tool` resolves an unprefixed tool name on a request scoped to one server against that server and enforces server-level permissions with it. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) @@ -3068,14 +3074,14 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission ), patch.object(global_mcp_server_manager, "server_exposes_tool", return_value=True), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_tool_registry" + "litellm.proxy.mcp_server.operations.global_mcp_tool_registry" ) as mock_tool_registry, patch( - "litellm.proxy._experimental.mcp_server.operations._handle_managed_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_managed_mcp_tool", new_callable=AsyncMock, ) as mock_handle_managed, patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ) as mock_is_allowed, ): @@ -3103,7 +3109,7 @@ async def test_call_mcp_tool_resolves_unprefixed_tool_name_and_checks_permission @pytest.mark.asyncio async def test_mcp_admission_body_peek_times_out_without_losing_the_body(monkeypatch: pytest.MonkeyPatch) -> None: try: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server except ImportError: pytest.skip("MCP server not available") @@ -3127,16 +3133,16 @@ async def test_mcp_admission_body_peek_times_out_without_losing_the_body(monkeyp @pytest.mark.parametrize("method", ["tools/list", "tools/call", ["tools/list"]]) async def test_mcp_routing_stashes_only_method_for_auth_and_replays_full_body(method: str | list[str]): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.common_utils.http_parsing_utils import _read_request_body + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCP_PEEKED_BODY_SCOPE_KEY, _admission_request, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, ) - from litellm.proxy.common_utils.http_parsing_utils import _read_request_body except ImportError: pytest.skip("MCP server not available") @@ -3172,17 +3178,17 @@ async def test_mcp_routing_stashes_only_method_for_auth_and_replays_full_body(me with ( patch( # test-quality-ok: the ASGI handler reads auth from a module-level helper; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(MagicMock(), None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.server._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.server._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: init flag is a module global; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: session managers are module-level singletons; the suite's only seam @@ -3206,15 +3212,15 @@ async def test_mcp_routing_stashes_only_method_for_auth_and_replays_full_body(me @pytest.mark.asyncio async def test_mcp_routing_batch_body_is_not_stashed_for_auth(): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.common_utils.http_parsing_utils import _read_request_body + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCP_PEEKED_BODY_SCOPE_KEY, _admission_request, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) - from litellm.proxy.common_utils.http_parsing_utils import _read_request_body except ImportError: pytest.skip("MCP server not available") @@ -3233,17 +3239,17 @@ async def test_mcp_routing_batch_body_is_not_stashed_for_auth(): with ( patch( # test-quality-ok: the ASGI handler reads auth from a module-level helper; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(MagicMock(), None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.server._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.server._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: init flag is a module global; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: session managers are module-level singletons; the suite's only seam @@ -3262,15 +3268,15 @@ async def test_mcp_routing_batch_body_is_not_stashed_for_auth(): @pytest.mark.asyncio async def test_mcp_routing_truncated_json_body_is_not_stashed_for_auth(): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.common_utils.http_parsing_utils import _read_request_body + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCP_PEEKED_BODY_SCOPE_KEY, _admission_request, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) - from litellm.proxy.common_utils.http_parsing_utils import _read_request_body except ImportError: pytest.skip("MCP server not available") @@ -3289,17 +3295,17 @@ async def test_mcp_routing_truncated_json_body_is_not_stashed_for_auth(): with ( patch( # test-quality-ok: the ASGI handler reads auth from a module-level helper; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(MagicMock(), None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.server._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.server._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: init flag is a module global; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: session managers are module-level singletons; the suite's only seam diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_identity_env.py b/tests/unit/proxy/mcp_server/test_mcp_server_identity_env.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server_identity_env.py rename to tests/unit/proxy/mcp_server/test_mcp_server_identity_env.py index 1c65adac4c6..7b3472d32c2 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_identity_env.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server_identity_env.py @@ -2,7 +2,7 @@ ``LITELLM_MCP_SERVER_NAME`` and ``LITELLM_MCP_SERVER_DESCRIPTION`` are read from the environment at import time in -``litellm.proxy._experimental.mcp_server.utils`` and must flow through to every +``litellm.proxy.mcp_server.utils`` and must flow through to every consumer, including the well-known registry entry built in ``mcp_management_endpoints``. The env values are reloaded into the modules and restored afterwards so the override does not leak into other tests. @@ -16,7 +16,7 @@ import pytest pytest.importorskip("mcp") -UTILS_MODULE = "litellm.proxy._experimental.mcp_server.utils" +UTILS_MODULE = "litellm.proxy.mcp_server.utils" MGMT_MODULE = "litellm.proxy.management_endpoints.mcp_management_endpoints" diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/unit/proxy/mcp_server/test_mcp_server_manager.py similarity index 96% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py rename to tests/unit/proxy/mcp_server/test_mcp_server_manager.py index ecd08e17cda..c76326c51f6 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server_manager.py @@ -1,13 +1,14 @@ -from litellm.proxy._experimental.mcp_server.upstream import resolve_upstream_auth -import importlib import asyncio + +# Add the parent directory to the path so we can import litellm +import contextlib import functools +import importlib import json import logging import os import sys import time -import anyio from collections.abc import AsyncIterator, Awaitable, Callable, Iterator from datetime import datetime from pathlib import Path @@ -15,27 +16,17 @@ from types import SimpleNamespace from typing import Any, Dict, Final, Literal, Optional, TypeVar, cast from unittest.mock import AsyncMock, MagicMock, patch -import pytest -from fastapi import HTTPException -from respx import MockRouter - -from litellm.proxy._experimental.mcp_server.exceptions import ( - MCPServerListError, - MCPUpstreamAuthError, -) -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListFault - -# Add the parent directory to the path so we can import litellm - - -import contextlib - +import anyio import httpx import httpx2 +import pytest +from fastapi import HTTPException from mcp import ClientSession, ReadResourceResult, Resource from mcp.server.context import ServerRequestContext from mcp.types import ( CallToolRequestParams as MCPCallToolRequestParams, +) +from mcp.types import ( CallToolResult, GetPromptResult, ListToolsResult, @@ -46,30 +37,17 @@ from mcp.types import ( ) from mcp.types import Tool as MCPTool from pydantic import AnyUrl, TypeAdapter +from respx import MockRouter +import litellm +import litellm.llms as litellm_llms +from litellm.caching.caching import DualCache +from litellm.caching.llm_caching_handler import LLMClientCache from litellm.constants import MCP_METADATA_TIMEOUT, MCP_UPSTREAM_RATE_LIMIT_MAX_RETRIES -from litellm.proxy._experimental.mcp_server import discoverable_endpoints -from litellm.proxy._experimental.mcp_server.legacy_callbacks import ElicitationCallback -from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var -from litellm.proxy._experimental.mcp_server.tool_outcome import TextResult -from litellm.experimental_mcp_client.client import MCPClient, PersistentMCPSession -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - ListedToolsCaller, - MCPServerManager, - global_mcp_server_manager, - _deserialize_json_dict, - _flow_endpoints_missing, - _mcp_oauth_discovery_on_startup_enabled, - oauth_endpoints_unresolved, - _deserialize_json_list, - _normalize_mcp_server_cost_info, - _obo_retry_applies, - resolve_openapi_tool_auth, - should_strip_caller_authorization, - listed_tools_caller_for, -) +from litellm.integrations.custom_guardrail import CustomGuardrail +from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.mcp_client.client import MCPClient, PersistentMCPSession from litellm.proxy import proxy_server -from litellm.proxy.auth import auth_checks from litellm.proxy._types import ( LiteLLM_MCPServerTable, LiteLLM_ObjectPermissionTable, @@ -82,25 +60,45 @@ from litellm.proxy._types import ( MCPTransport, UserAPIKeyAuth, ) -from litellm.types.llms.custom_http import httpxSpecialProvider -from litellm.types.mcp import MCPAuth, MCPAuthType, MCPUpstreamProtocol -from litellm.types.mcp_server.mcp_server_manager import MCPOAuthMetadata, MCPServer, PinnedMCPTool -from litellm.caching.caching import DualCache -from litellm.caching.llm_caching_handler import LLMClientCache -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler -import litellm -from litellm.integrations.custom_guardrail import CustomGuardrail -import litellm.llms as litellm_llms +from litellm.proxy.auth import auth_checks +from litellm.proxy.mcp_server import discoverable_endpoints +from litellm.proxy.mcp_server.exceptions import ( + MCPServerListError, + MCPUpstreamAuthError, +) +from litellm.proxy.mcp_server.faults.list_outcomes import ServerListFault +from litellm.proxy.mcp_server.legacy_callbacks import ElicitationCallback +from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var +from litellm.proxy.mcp_server.mcp_server_manager import ( + ListedToolsCaller, + MCPServerManager, + _deserialize_json_dict, + _deserialize_json_list, + _flow_endpoints_missing, + _mcp_oauth_discovery_on_startup_enabled, + _normalize_mcp_server_cost_info, + _obo_retry_applies, + global_mcp_server_manager, + listed_tools_caller_for, + oauth_endpoints_unresolved, + resolve_openapi_tool_auth, + should_strip_caller_authorization, +) +from litellm.proxy.mcp_server.tool_outcome import TextResult +from litellm.proxy.mcp_server.upstream import resolve_upstream_auth from litellm.proxy.utils import ProxyLogging from litellm.types.guardrails import GuardrailEventHooks from litellm.types.integrations.slack_alerting import AlertType +from litellm.types.llms.custom_http import httpxSpecialProvider +from litellm.types.mcp import MCPAuth, MCPAuthType, MCPUpstreamProtocol +from litellm.types.mcp_server.mcp_server_manager import MCPOAuthMetadata, MCPServer, PinnedMCPTool _TSessionResult = TypeVar("_TSessionResult") @pytest.mark.asyncio async def test_manager_sampling_preserves_explicit_headers_without_ambient_context(): - from litellm.proxy._experimental.mcp_server import server as legacy_server + from litellm.proxy.mcp_server import server as legacy_server caller = UserAPIKeyAuth(user_id="sampling-caller") upstream = MCPServer( @@ -115,8 +113,8 @@ async def test_manager_sampling_preserves_explicit_headers_without_ambient_conte client.call_tool = AsyncMock(return_value=CallToolResult(content=[])) assert legacy_server.get_active_auth_context() is None with ( - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient", return_value=client) as factory, - patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", sampling), + patch("litellm.proxy.mcp_server.upstream.MCPClient", return_value=client) as factory, + patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", sampling), ): await MCPServerManager()._call_regular_mcp_tool( mcp_server=upstream, @@ -140,8 +138,8 @@ async def test_manager_sampling_preserves_explicit_headers_without_ambient_conte async def test_sampling_callback_keeps_creation_context_after_caller_switch(): from mcp.server.auth.middleware.auth_context import auth_context_var - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_sampling_callback + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.mcp_server_manager import _create_sampling_callback token = auth_context_var.set(None) recorder = AsyncMock() @@ -154,7 +152,7 @@ async def test_sampling_callback_keeps_creation_context_after_caller_switch(): original.models.append("bravo-model") headers["x-caller"] = "bravo" legacy_server.set_auth_context(UserAPIKeyAuth(user_id="bravo"), raw_headers={"x-caller": "bravo"}) - with patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", recorder): + with patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", recorder): await callback(None, None) observed = recorder.await_args.kwargs assert observed["user_api_key_auth"].user_id == "alpha" @@ -168,18 +166,19 @@ async def test_sampling_callback_keeps_creation_context_after_caller_switch(): @pytest.mark.asyncio async def test_elicitation_callback_keeps_initiating_session(): - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_elicitation_callback - from types import SimpleNamespace + from mcp.types import ( ClientCapabilities, ElicitationCapability, - FormElicitationCapability, ElicitRequestFormParams, ElicitResult, + FormElicitationCapability, ) - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_server_manager import _create_elicitation_callback capabilities = ClientCapabilities(elicitation=ElicitationCapability(form=FormElicitationCapability())) accepted = ElicitResult(action="accept") @@ -206,7 +205,7 @@ async def test_elicitation_callback_keeps_initiating_session(): async def test_sampling_callbacks_isolate_callers_and_cancellation(): from mcp.types import ErrorData - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_sampling_callback + from litellm.proxy.mcp_server.mcp_server_manager import _create_sampling_callback started = asyncio.Event() cancelled = asyncio.Event() @@ -230,7 +229,7 @@ async def test_sampling_callbacks_isolate_callers_and_cancellation(): for label in ("alpha", "bravo", "cancelled") ) with patch( - "litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", record_sampling + "litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", record_sampling ): tasks = tuple(asyncio.create_task(callback(None, None)) for callback in callbacks) await asyncio.wait_for(started.wait(), timeout=2) @@ -243,12 +242,12 @@ async def test_sampling_callbacks_isolate_callers_and_cancellation(): def _reload_mcp_manager_module(): - utils_module = sys.modules["litellm.proxy._experimental.mcp_server.utils"] - manager_module = sys.modules["litellm.proxy._experimental.mcp_server.mcp_server_manager"] + utils_module = sys.modules["litellm.proxy.mcp_server.utils"] + manager_module = sys.modules["litellm.proxy.mcp_server.mcp_server_manager"] importlib.reload(utils_module) reloaded = importlib.reload(manager_module) for name, module in tuple(sys.modules.items()): - if name.startswith("litellm.proxy._experimental.mcp_server.") and hasattr(module, "global_mcp_server_manager"): + if name.startswith("litellm.proxy.mcp_server.") and hasattr(module, "global_mcp_server_manager"): module.global_mcp_server_manager = reloaded.global_mcp_server_manager return reloaded @@ -265,7 +264,7 @@ def restore_mcp_manager_singleton(): bound: Final = tuple( (module, module.global_mcp_server_manager) for name, module in tuple(sys.modules.items()) - if name.startswith("litellm.proxy._experimental.mcp_server.") and hasattr(module, "global_mcp_server_manager") + if name.startswith("litellm.proxy.mcp_server.") and hasattr(module, "global_mcp_server_manager") ) yield for module, manager in bound: @@ -285,8 +284,8 @@ def restore_mcp_manager_singleton(): ) @pytest.mark.parametrize("explicit_key", [False, True]) def test_validated_admission_jwt_is_not_forwarded_as_an_extra_header(auth_type: MCPAuth, explicit_key: bool) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers server: Final = MCPServer( server_id="header-boundary", @@ -325,8 +324,8 @@ def test_admission_authorization_is_not_forwarded_for_any_auth_type( auth_type: MCPAuth, monkeypatch: pytest.MonkeyPatch ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", "test-master-key") server: Final = MCPServer( @@ -379,8 +378,8 @@ def test_no_master_key_preserves_caller_authorization_unless_auth_is_enabled( auth_type: MCPAuth, monkeypatch: pytest.MonkeyPatch ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", None) monkeypatch.setattr(proxy_server, "general_settings", {}) @@ -423,8 +422,8 @@ def test_custom_auth_is_stripped_in_no_auth_dev_mode( auth_type: MCPAuth, monkeypatch: pytest.MonkeyPatch ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", None) monkeypatch.setattr(proxy_server, "general_settings", {}) @@ -489,8 +488,8 @@ def test_custom_admission_header_controls_authorization_forwarding( monkeypatch: pytest.MonkeyPatch, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers - from litellm.proxy._experimental.mcp_server.operations import _prepare_mcp_server_headers + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_forwarded_extra_headers + from litellm.proxy.mcp_server.operations import _prepare_mcp_server_headers monkeypatch.setattr(proxy_server, "master_key", "test-master-key") monkeypatch.setattr(proxy_server, "general_settings", {"litellm_key_header_name": "x-company-key"}) @@ -639,10 +638,10 @@ class TestMCPServerManager: """A caller-supplied per-request override must not substitute the stored authorization_code token: _create_mcp_client keeps the v2 spec and resolves through the injected provider rather than deferring to the v1 caller-override path.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( + from litellm.proxy.mcp_server.outbound_credentials.result import ( Ok, ) from litellm.types.mcp import MCPAuth @@ -674,10 +673,10 @@ class TestMCPServerManager: """A caller-supplied per-request override must not disable the ID-JAG exchange and forward an arbitrary bearer upstream: _create_mcp_client keeps the v2 spec and resolves through the injected provider rather than deferring to the v1 caller-override path.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( + from litellm.proxy.mcp_server.outbound_credentials.result import ( Ok, ) from litellm.types.mcp import MCPAuth @@ -1226,7 +1225,7 @@ class TestMCPServerManager: patch.object(manager, "_discover_oauth_metadata_for_server", new=discovery), patch.object(manager, "initialize_tool_name_to_mcp_server_name_mapping"), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager._oauth_discovery_now", + "litellm.proxy.mcp_server.mcp_server_manager._oauth_discovery_now", new=discovery_clock, ), ): @@ -1279,7 +1278,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", + "litellm.proxy.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", 0.01, ), patch.object(manager, "_discover_oauth_metadata_for_server", side_effect=never_returns) as discovery, @@ -1446,7 +1445,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -1509,7 +1508,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -1651,7 +1650,7 @@ class TestMCPServerManager: "ensure_oauth_metadata_discovered", new=ensure_oauth_metadata_discovered, ), - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient"), + patch("litellm.proxy.mcp_server.upstream.MCPClient"), ): await manager._create_mcp_client(server) @@ -2568,7 +2567,7 @@ class TestMCPServerManager: won't help) and a genuine non-auth failure (e.g. 503) both keep the default isError degradation and stay a visible warning, mirroring the list path, rather than being relayed as a re-auth challenge.""" - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient server = self._passthrough_call_server(MCPAuth.true_passthrough, server_id=f"pt-{status_code}") manager = MCPServerManager() @@ -2577,7 +2576,7 @@ class TestMCPServerManager: mock_client.error_tool_result = MCPClient.error_tool_result manager.create_mcp_client = AsyncMock(return_value=mock_client) - import litellm.proxy._experimental.mcp_server.mcp_server_manager as _mgr_mod + import litellm.proxy.mcp_server.mcp_server_manager as _mgr_mod with patch.object(_mgr_mod, "verbose_logger") as mock_log: result = await self._run_call_regular(manager, server) @@ -2637,8 +2636,8 @@ class TestMCPServerManager: # must reconstruct it onto the MCPServer, and the v2 adapter must map it onto the resolver # config. Without threading it through, an entra_obo server persisted via the API silently # falls back to rfc8693 and posts the wrong grant to the IdP. - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import TokenExchangeConfig + from litellm.proxy.mcp_server.outbound_credentials.adapter import to_server_spec + from litellm.proxy.mcp_server.outbound_credentials.types import TokenExchangeConfig manager = MCPServerManager() row = LiteLLM_MCPServerTable( @@ -3239,10 +3238,10 @@ class TestMCPServerManager: """A caller-supplied per-server header (x-mcp-*) must NOT disable the OBO exchange: _create_mcp_client keeps the v2 spec and runs the resolver (which exchanges the subject), rather than deferring to v1 and forwarding the caller's header verbatim upstream.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok exchanged_subjects = [] @@ -3269,10 +3268,10 @@ class TestMCPServerManager: """A guardrail/static Authorization (e.g. MCPJWTSigner) must NOT shadow the exchanged OBO token. The resolver-owned credential is authoritative: the conflicting header is dropped and the minted token is what reaches the upstream, not the injected JWT.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3297,10 +3296,10 @@ class TestMCPServerManager: the gateway-minted client_credentials bearer. Dropping the resolved auth here would also drop the one-shot 401 refetch that rides on it, so the resolver-owned credential is authoritative exactly as for token_exchange and authorization_code.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3348,10 +3347,10 @@ class TestMCPServerManager: """The dual-credential case: an ESB wants the gateway-minted token on its own header while a separate static Authorization passes through to the origin. Dropping Authorization here (the old name-blind behavior) deletes the second credential and the upstream 401s.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3371,10 +3370,10 @@ class TestMCPServerManager: """The negative class of the test above: when the two DO collide the resolver-owned credential is still authoritative, so the knob cannot be used to smuggle a second credential into the same slot.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3399,10 +3398,10 @@ class TestMCPServerManager: downstream consumer of that dict. httpx happens to collapse the two on the wire, which is exactly why this needs pinning rather than being left to luck. """ - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3430,8 +3429,8 @@ class TestMCPServerManager: """A subject the IdP rejects must raise the RFC 9728 401 challenge from the preflight, so a single-server route fails observably at the transport edge instead of the old behavior of the session opening and list_tools masking the failed exchange as an empty tool list.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3455,8 +3454,8 @@ class TestMCPServerManager: async def test_preflight_token_exchange_maps_gateway_fault_to_public_status(self): """A gateway-fault CredError (e.g. invalid_client) must surface its public status (500) from the preflight, not the OBO 401 challenge and not an empty-success session.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3477,10 +3476,10 @@ class TestMCPServerManager: async def test_preflight_token_exchange_noop_on_success_and_without_subject(self): """A successful exchange returns without raising, and a request with no bearer never reaches the resolver (the no-subject case is the existing preemptive challenge's job).""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok resolved = [] @@ -3525,8 +3524,8 @@ class TestMCPServerManager: gets a 200 with an empty tool list and then 'tool not found', which is not what happened. 412 is a precondition, not an RFC 9728 discovery challenge, so it carries no WWW-Authenticate: there is nothing for the client to discover and retry against.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError summary = ( "ID-JAG requires an IdP identity assertion for this user and none is stored. " @@ -3553,8 +3552,8 @@ class TestMCPServerManager: async def test_preflight_id_jag_surfaces_assertion_store_outage_as_503(self): """A store outage is the other failure the session would swallow, and it is a different answer than 412: the user has nothing to fix by signing in again.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError class _FakeProvider: async def resolve_credentials(self, subject, server): @@ -3574,10 +3573,10 @@ class TestMCPServerManager: async def test_preflight_id_jag_preflights_litellm_key_and_skips_identity_bearer(self): """ID-JAG preflights when Authorization carries a LiteLLM key, but skips a caller identity bearer that the session passes through unchanged.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok subjects = [] @@ -3635,8 +3634,8 @@ class TestMCPServerManager: other mode itself. The single-server call site no longer tests the mode before calling, so a mode that falls through here would start resolving its credential a second time, at connect, for flows that never had a connect-time resolution at all.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError calls = [] @@ -3677,11 +3676,11 @@ class TestMCPServerManager: ) async def test_preflight_token_exchange_strips_inbound_authorization_scheme(self, authorization): """The resolver posts inbound_token verbatim as subject_token.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject resolved: Final[list[str | None]] = [] @@ -3705,11 +3704,11 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_preflight_token_exchange_preserves_authorization_without_separator(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject + from litellm.proxy.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject resolved: Final[list[str | None]] = [] @@ -4320,10 +4319,10 @@ class TestMCPServerManager: ) with ( patch( - "litellm.proxy._experimental.mcp_server.upstream.resolve_mcp_auth", + "litellm.proxy.mcp_server.upstream.resolve_mcp_auth", new_callable=AsyncMock, ) as mock_resolve, - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as mock_client_cls, + patch("litellm.proxy.mcp_server.upstream.MCPClient") as mock_client_cls, ): await manager._create_mcp_client(server=server, extra_headers={"Authorization": "Bearer upstream-token"}) mock_resolve.assert_not_awaited() @@ -4340,13 +4339,13 @@ class TestMCPServerManager: """A configured OBO server is owned end to end by the v2 token_exchange arm, even when the caller supplies an x-mcp-* override. This is what makes the v1 OBO handler unreachable, so if it ever defers to v1 again the deleted handler is silently needed back.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import ( + from litellm.proxy.mcp_server.outbound_credentials.resolver import ( UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _StubExchanger: def __init__(self): @@ -4373,10 +4372,10 @@ class TestMCPServerManager: ) with ( patch( - "litellm.proxy._experimental.mcp_server.upstream.resolve_mcp_auth", + "litellm.proxy.mcp_server.upstream.resolve_mcp_auth", new_callable=AsyncMock, ) as mock_resolve, - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as mock_client_cls, + patch("litellm.proxy.mcp_server.upstream.MCPClient") as mock_client_cls, ): await manager._create_mcp_client( server=server, @@ -4416,10 +4415,10 @@ class TestMCPServerManager: ) with ( patch( - "litellm.proxy._experimental.mcp_server.upstream.resolve_mcp_auth", + "litellm.proxy.mcp_server.upstream.resolve_mcp_auth", new_callable=AsyncMock, ) as mock_resolve, - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as mock_client_cls, + patch("litellm.proxy.mcp_server.upstream.MCPClient") as mock_client_cls, ): await manager._create_mcp_client( server=server, @@ -4432,7 +4431,7 @@ class TestMCPServerManager: assert not kwargs["extra_headers"] or "authorization" not in {k.lower() for k in kwargs["extra_headers"]} def test_consumes_caller_authorization_per_mode(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _consumes_caller_authorization, ) @@ -4468,7 +4467,7 @@ class TestMCPServerManager: ) def test_caller_authorization_fans_out_only_with_second_consumer(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( caller_authorization_fans_out, ) @@ -4743,7 +4742,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -4778,7 +4777,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ) as get_client, patch.object( @@ -4833,7 +4832,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ), patch.object( @@ -4880,7 +4879,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(side_effect=build_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): # The Azure issuer is cross-origin against the server_url — use @@ -4930,7 +4929,7 @@ class TestMCPServerManager: mock_client = MagicMock() mock_client.get = AsyncMock(side_effect=build_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata(issuer, issuer, require_issuer=issuer) @@ -4967,7 +4966,7 @@ class TestMCPServerManager: mock_client = MagicMock() mock_client.get = AsyncMock(side_effect=build_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata(issuer, issuer, require_issuer=issuer) @@ -4992,7 +4991,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata(issuer, issuer) @@ -5020,7 +5019,7 @@ class TestMCPServerManager: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): azure = await manager._fetch_single_authorization_server_metadata(issuer, issuer, require_issuer=issuer) @@ -5061,7 +5060,7 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ), patch.object( @@ -5155,9 +5154,9 @@ class TestMCPServerManager: assert server.scopes is None # And the exchange precondition now fails closed before any IdP call. - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.token_exchanger import ( + from litellm.proxy.mcp_server.outbound_credentials.adapter import to_server_spec + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.token_exchanger import ( OboTokenExchanger, ) @@ -5220,7 +5219,7 @@ class TestMCPServerManager: assert minimal.subject_token_type == DEFAULT_SUBJECT_TOKEN_TYPE assert minimal.token_exchange_profile == "rfc8693" - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import to_server_spec + from litellm.proxy.mcp_server.outbound_credentials.adapter import to_server_spec spec = to_server_spec(full) assert spec is not None @@ -5390,7 +5389,7 @@ class TestMCPServerManager: @pytest.mark.asyncio @pytest.mark.parametrize("cancel", [False, True]) async def test_openapi_health_timeout_and_cancellation_cleanup(self, respx_mock, monkeypatch, cancel): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _openapi_spec_health + from litellm.proxy.mcp_server.mcp_server_manager import _openapi_spec_health monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") started = asyncio.Event() @@ -5742,7 +5741,7 @@ class TestMCPServerManager: self, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch, cancel: bool ) -> None: monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_HEALTH_CHECK_TIMEOUT", 0.1) + monkeypatch.setattr("litellm.proxy.mcp_server.mcp_server_manager.MCP_HEALTH_CHECK_TIMEOUT", 0.1) manager: Final = MCPServerManager() server: Final = MCPServer( server_id="slow-health", @@ -6154,15 +6153,15 @@ class TestMCPServerManager: with ( patch( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.create_tool_function", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.create_tool_function", side_effect=fake_create_tool_function, ), patch( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.build_input_schema", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.build_input_schema", return_value={"type": "object", "properties": {}, "required": []}, ), patch( - "litellm.proxy._experimental.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", + "litellm.proxy.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", return_value=None, ), ): @@ -6244,15 +6243,15 @@ class TestMCPServerManager: return tool_func monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.create_tool_function", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.create_tool_function", fake_create_tool_function, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.build_input_schema", + "litellm.proxy.mcp_server.openapi_to_mcp_generator.build_input_schema", lambda *args, **kwargs: {"type": "object", "properties": {}, "required": []}, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", + "litellm.proxy.mcp_server.tool_registry.global_mcp_tool_registry.register_tool", lambda *args, **kwargs: None, ) await manager._register_openapi_tools( @@ -6851,7 +6850,7 @@ class TestMCPServerManager: stored = {"Authorization": "Bearer stored-user-token"} with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(return_value=stored), ) as mock_lookup: result = await manager._resolve_oauth2_headers_for_tool_call( @@ -6878,7 +6877,7 @@ class TestMCPServerManager: user_auth = UserAPIKeyAuth(api_key="sk-test", user_id="alice") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(return_value={"Authorization": "Bearer should-not-be-used"}), ) as mock_lookup: result = await manager._resolve_oauth2_headers_for_tool_call( @@ -6904,7 +6903,7 @@ class TestMCPServerManager: user_auth = UserAPIKeyAuth(api_key="sk-test", user_id="alice") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(side_effect=RuntimeError("redis down")), ): result = await manager._resolve_oauth2_headers_for_tool_call( @@ -7060,7 +7059,7 @@ class TestMCPServerManager: user_auth = UserAPIKeyAuth(api_key="sk-test") with patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new=AsyncMock(return_value={"Authorization": "Bearer x"}), ) as mock_lookup: result = await manager._resolve_oauth2_headers_for_tool_call( @@ -7139,7 +7138,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_rest_endpoint_filters_by_allowed_tools(self): """Test that REST endpoint _get_tools_for_single_server respects allowed_tools configuration""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) @@ -7160,7 +7159,7 @@ class TestMCPServerManager: tool3 = MCPTool(name="allowed_tool_2", description="This tool is also allowed", inputSchema={}) # Mock the global_mcp_server_manager._get_tools_from_server - from litellm.proxy._experimental.mcp_server import rest_endpoints + from litellm.proxy.mcp_server import rest_endpoints with patch.object( rest_endpoints.global_mcp_server_manager, @@ -7180,7 +7179,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_rest_endpoint_shows_all_when_allowed_tools_is_none(self): """Test that REST endpoint shows all tools when allowed_tools is None (backwards compatibility)""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) @@ -7201,7 +7200,7 @@ class TestMCPServerManager: tool3 = MCPTool(name="tool_3", description="Tool 3", inputSchema={}) # Mock the global_mcp_server_manager._get_tools_from_server - from litellm.proxy._experimental.mcp_server import rest_endpoints + from litellm.proxy.mcp_server import rest_endpoints with patch.object( rest_endpoints.global_mcp_server_manager, @@ -7221,7 +7220,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_rest_endpoint_shows_all_when_allowed_tools_is_empty_list(self): """Test that REST endpoint shows all tools when allowed_tools is empty list (backwards compatibility)""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import ( + from litellm.proxy.mcp_server.rest_endpoints import ( _get_tools_for_single_server, ) @@ -7240,7 +7239,7 @@ class TestMCPServerManager: tool2 = MCPTool(name="tool_2", description="Tool 2", inputSchema={}) # Mock the global_mcp_server_manager._get_tools_from_server - from litellm.proxy._experimental.mcp_server import rest_endpoints + from litellm.proxy.mcp_server import rest_endpoints with patch.object( rest_endpoints.global_mcp_server_manager, @@ -7656,8 +7655,8 @@ class TestMCPServerManager: from mcp.server.context import ServerRequestContext from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse auth = self._unrestricted_auth() manager, logging = self._manager_ready_for_call_tool( @@ -8130,7 +8129,7 @@ class TestMCPServerManager: with ( patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_user_credential", + "litellm.proxy.mcp_server.db.get_user_credential", AsyncMock(side_effect=RuntimeError("DB DOWN")), ), ): @@ -8156,11 +8155,11 @@ class TestMCPServerManager: """A REST listing records under the header the client sent (none here). tools/call then swaps the stored credential in, either before reaching ``call_tool`` (``execute_mcp_tool``) or inside it (the Responses API), and must still read that slot rather than one keyed by the credential.""" - from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( + from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache_key, cache_byok_credential, ) - from litellm.proxy._experimental.mcp_server.operations import byok_credential_cache + from litellm.proxy.mcp_server.operations import byok_credential_cache manager = MCPServerManager() server = MCPServer( @@ -8264,11 +8263,11 @@ class TestMCPServerManager: reads, even with the stored BYOK secret at hand in the cache, and tools/list sends upstream exactly what the caller supplied, so the static token, the M2M mint and MCPJWTSigner all behave as they did before the catalog existed, whatever the auth_type.""" - from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( + from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache_key, cache_byok_credential, ) - from litellm.proxy._experimental.mcp_server.operations import byok_credential_cache + from litellm.proxy.mcp_server.operations import byok_credential_cache manager = MCPServerManager() server = MCPServer( @@ -8531,7 +8530,7 @@ class TestMCPServerManager: ) def test_per_caller_listed_tools_evict_oldest_caller_and_keep_shared(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _LISTED_TOOLS_CALLERS_PER_SERVER + from litellm.proxy.mcp_server.mcp_server_manager import _LISTED_TOOLS_CALLERS_PER_SERVER manager = MCPServerManager() server = MCPServer( @@ -8566,7 +8565,7 @@ class TestMCPServerManager: @pytest.mark.asyncio @pytest.mark.parametrize("add_prefix", [True, False]) async def test_openapi_listing_records_listed_tools(self, add_prefix): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry server = MCPServer( server_id="petstore-id", @@ -8601,7 +8600,7 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_openapi_listing_ignores_overlapping_server_prefix(self): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry server = MCPServer( server_id="pet-id", @@ -8647,7 +8646,7 @@ class TestMCPServerManager: async def test_get_tools_from_server_records_the_catalog_only_when_asked_to(self, openapi): """The startup fill, the implicit pre-call listing and the pin snapshot reuse this fetch without serving its result, so only a listing that asks to be recorded sets what tools/call hooks see.""" - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry if openapi: server = MCPServer( @@ -8720,11 +8719,11 @@ class TestMCPServerManager: when called. This verifies the fix where user_api_key_auth is passed through litellm_metadata from responses API. """ - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth manager = MCPServerManager() @@ -8777,10 +8776,10 @@ class TestMCPServerManager: async def test_no_mcp_servers_sentinel_blocks_allow_all_keys(self): """A key scoped to no-mcp-servers gets zero servers even when allow_all_keys servers exist, and the inner resolver is never consulted.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth manager = MCPServerManager() object_permission = LiteLLM_ObjectPermissionTable( @@ -8812,10 +8811,10 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_no_mcp_servers_sentinel_excludes_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth class _Cache: async def async_get_cache(self, key: str): @@ -8860,10 +8859,10 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_explicitly_scoped_key_excludes_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth cache = MagicMock() cache.async_get_cache = AsyncMock(return_value=["submitted-server"]) @@ -8912,14 +8911,14 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_toolset_scope_excludes_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, MCPServerAccess, ) - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_active_toolset_id, ) - from litellm.proxy._types import UserAPIKeyAuth cache = MagicMock() cache.async_get_cache = AsyncMock(return_value=["submitted-server"]) @@ -8998,7 +8997,7 @@ class TestMCPServerManager: patch.object(proxy_server_module, "user_api_key_cache", cache), patch.object(proxy_server_module, "prisma_client", MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", + "litellm.proxy.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", AsyncMock(return_value=["submitted-server", "unknown-server"]), ), ): @@ -9014,10 +9013,10 @@ class TestMCPServerManager: @pytest.mark.asyncio async def test_get_allowed_mcp_servers_fallback_keeps_submitted_byom_servers(self): from litellm.proxy import proxy_server as proxy_server_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._types import UserAPIKeyAuth class _Cache: async def async_get_cache(self, key: str): @@ -9099,7 +9098,7 @@ class TestMCPServerManager: submitted_server_ids, expected_server_ids, ): # test-quality-ok: parameterized matrix covers the scope state machine - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess manager = MCPServerManager() auth = UserAPIKeyAuth(api_key="sk-test", user_id="user-123") @@ -9131,7 +9130,7 @@ class TestMCPServerManager: when extracting server name from prefixed tool name (second case). This ensures the fix for using server_name instead of name works correctly. """ - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, ) @@ -9317,9 +9316,9 @@ class TestMCPServerTimestamps: repo_instance = MagicMock() repo_instance.table.update = AsyncMock() with ( - patch("litellm.proxy._experimental.mcp_server.db.update_mcp_server", new=update_mcp_server_mock), + patch("litellm.proxy.mcp_server.db.update_mcp_server", new=update_mcp_server_mock), patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repo_instance, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -9493,7 +9492,7 @@ class TestMCPServerTimestamps: build_mock = AsyncMock(return_value=previous_entry) with ( patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repo_instance, ), patch( @@ -9585,7 +9584,7 @@ class TestMCPServerTimestamps: def test_carry_forward_skips_when_url_or_auth_type_changed(self): """Stale endpoints from a different upstream or auth mode must not carry forward.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9624,7 +9623,7 @@ class TestMCPServerTimestamps: this, re-pointing authorize to server B while the same MCP url keeps serving A's token endpoint recreates the RFC 9700 mix-up, durably, and the discovery gate alone cannot catch it because the stale endpoint comes from the registry, not from discovery.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9658,7 +9657,7 @@ class TestMCPServerTimestamps: endpoint) adopts the previous authorize endpoint AND its token endpoint together as a consistent group, and a rebuild that re-pins the same authorize endpoint (formatting aside) keeps carrying the corroborated token endpoint.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9720,7 +9719,7 @@ class TestMCPServerTimestamps: endpoint the issuer anchor distrusts would keep being served across rebuilds. Resource-driven scopes still carry as last-known-good. Anchoring is keyed on the explicit issuer_is_anchored flag, not on issuer truthiness, so a discovered issuer does not trip this fail-closed branch.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9760,7 +9759,7 @@ class TestMCPServerTimestamps: must still carry forward as last-known-good, the same as any resource-rooted server. This is the regression the explicit issuer_is_anchored flag prevents: keying fail-closed on issuer truthiness alone would drop the working endpoints the moment the server learned its issuer.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( carry_forward_resolved_oauth_endpoints, ) @@ -9799,7 +9798,7 @@ class TestMCPServerTimestamps: """The corroboration check must not fail on formatting-only differences an IdP legitimately emits: default port, trailing slash, host case, and query string are not identity, but a non-default port is.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _normalized_authorize_endpoint, ) @@ -9813,7 +9812,7 @@ class TestMCPServerTimestamps: """Issuer equality tolerates only URL-insignificant differences (scheme/host case, default port, a trailing slash). A different host, a non-string, an empty string, or a None issuer never matches, so a document that omits issuer fails closed under issuer-anchored discovery.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _issuer_matches + from litellm.proxy.mcp_server.mcp_server_manager import _issuer_matches assert _issuer_matches("https://mcp.slack.com", "https://mcp.slack.com") assert not _issuer_matches("https://MCP.slack.com/", "https://mcp.slack.com") @@ -10340,7 +10339,7 @@ class TestLegacyDelegateAuthWarningLog: def test_warn_skipped_for_client_credentials(self, caplog): caplog.set_level(logging.WARNING, logger="LiteLLM") - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _warn_legacy_delegate_auth_if_applicable, ) @@ -10795,7 +10794,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata( @@ -10823,7 +10822,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10846,7 +10845,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10865,7 +10864,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10893,7 +10892,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10916,7 +10915,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10942,7 +10941,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): servers, scopes = await manager._fetch_oauth_metadata_from_resource( @@ -10973,7 +10972,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(return_value=redirect_response) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata( @@ -11007,7 +11006,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(side_effect=fake_get) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): await manager._fetch_oauth_metadata_from_resource( @@ -11038,7 +11037,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock(side_effect=fake_get) with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): await manager._fetch_single_authorization_server_metadata( @@ -11057,7 +11056,7 @@ class TestOAuthDiscoverySSRFGuard: mock_client.get = AsyncMock() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ): result = await manager._fetch_single_authorization_server_metadata( @@ -11130,10 +11129,10 @@ class TestApprovalStatusGate: async def test_update_server_eviction_clears_openapi_routing_artifacts(self, tmp_path): """Rejecting a server must remove its OpenAPI tools and name mappings.""" - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -11315,7 +11314,7 @@ class TestUserEnvVarsCacheEviction: @staticmethod def _patch_cache(monkeypatch, max_size): - from litellm.proxy._experimental.mcp_server import mcp_server_manager as m + from litellm.proxy.mcp_server import mcp_server_manager as m cache: Dict[Any, Any] = {} monkeypatch.setattr(m, "_user_env_vars_cache", cache) @@ -11553,7 +11552,7 @@ class TestCreateMcpClientV2Graft: return MCPServer(**base) async def test_none_mode_resolves_to_noop_auth(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, ) @@ -11590,7 +11589,7 @@ class TestCreateMcpClientV2Graft: ], ) async def test_static_family_emits_expected_header(self, auth_type, token, expected_name, expected_value): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) @@ -11606,7 +11605,7 @@ class TestCreateMcpClientV2Graft: async def test_basic_mode_base64_encodes(self): import base64 - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) @@ -11622,16 +11621,16 @@ class TestCreateMcpClientV2Graft: async def test_m2m_client_credentials_resolves_via_v2(self): # M2M (oauth2 client_credentials) is migrated: to_server_spec owns the server and the # v2 arm mints the token through the injected source; nothing flows to v1's auth_value. - from litellm.proxy._experimental.mcp_server.outbound_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials import ( UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import ( + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import ( OAuthToken, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok class _FakeM2MSource: async def get(self, server_id, config): @@ -11699,8 +11698,8 @@ class TestCreateMcpClientV2Graft: assert client._mcp_auth_value == "k-stdio" async def test_resolver_error_maps_to_http_exception(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials import Error + from litellm.proxy.mcp_server.outbound_credentials.types import ( CredError, ) @@ -11740,7 +11739,7 @@ class TestCreateMcpClientV2Graft: assert client._get_auth_headers()["Authorization"] == "Bearer hook-jwt" async def test_none_with_extra_header_stays_v2_without_clobbering(self): - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, ) @@ -11780,7 +11779,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_fetch_tools_with_timeout_surfaces_upstream_401(self): - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -11832,7 +11831,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_get_tools_from_server_surfaces_unusable_user_token(self): - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -11884,7 +11883,7 @@ class TestMCPToolsListAuthSurfacing: answered 401 without the WWW-Authenticate the client needs to start the OAuth flow.""" import httpx - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -11916,7 +11915,7 @@ class TestMCPToolsListAuthSurfacing: would fail the RFC 9728 resource match against the gateway URL it dialed.""" import httpx - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) from litellm.types.mcp import MCPAuth @@ -11954,7 +11953,7 @@ class TestMCPToolsListAuthSurfacing: clients at the upstream protected-resource metadata, which fails the RFC 9728 resource match against the gateway URL they dialed. Stripping it makes the single-server route fabricate the gateway well-known challenge, whose content is the bridge facade.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) from litellm.types.mcp import MCPAuth @@ -11982,7 +11981,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_get_tools_from_server_suppresses_resolver_challenge_for_dcr_bridge(self): """The client-build-time HTTPException conversion path applies the same suppression.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) from litellm.types.mcp import MCPAuth @@ -12011,7 +12010,7 @@ class TestMCPToolsListAuthSurfacing: @pytest.mark.asyncio async def test_aggregate_list_tools_absorbs_unauthenticated_server(self): - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -12096,7 +12095,7 @@ class _RetryFakeClient: """A fake MCPClient whose call_tool fails on the first attempt and (optionally) succeeds after.""" def __init__(self, *, raises=None, result=None) -> None: - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient self._raises = raises self._result = result @@ -12175,7 +12174,7 @@ class TestOBOCallToolRetry: async def test_upstream_401_on_id_jag_evicts_the_cached_bearer_and_retries(self): """The retry path must invalidate the ID-JAG leg-2 bearer too: without eviction the rebuilt client resolves the same rejected token from the cache and the retry 401s identically.""" - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials.types import ( IdJagConfig, ) @@ -12300,7 +12299,7 @@ class TestOBOCallToolRetry: @pytest.mark.asyncio async def test_session_closed_by_a_peers_refresh_retries_on_a_fresh_session_without_invalidating(self) -> None: - from litellm.experimental_mcp_client.client import UpstreamSessionClosedError + from litellm.mcp_client.client import UpstreamSessionClosedError manager: Final = self._manager() success: Final = CallToolResult(content=[], isError=False) @@ -12608,7 +12607,7 @@ class TestOBOEndpointDiscovery: with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=mock_client, ), patch.object(manager, "_fetch_oauth_metadata_from_resource", AsyncMock(return_value=([], None))), @@ -12633,8 +12632,8 @@ async def test_preflight_challenge_carries_step_up_error_and_claims(): claims in the single-server 401 challenge, so an MSAL-family client can drive the step-up and retry.""" import base64 - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError + from litellm.proxy.mcp_server.outbound_credentials.result import Error + from litellm.proxy.mcp_server.outbound_credentials.types import CredError claims = '{"access_token":{"acrs":{"essential":true,"value":"c1"}}}' @@ -12671,7 +12670,7 @@ async def test_preflight_challenge_carries_step_up_error_and_claims(): async def test_aggregate_list_still_absorbs_step_up_challenged_server(): """A step-up (claims-bearing) 401 from one server must not change the aggregate contract: the multi-server listing still absorbs it and returns the healthy servers' tools.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError manager = MCPServerManager() good = MCPServer(server_id="good", name="good", transport=MCPTransport.http) @@ -13093,7 +13092,7 @@ async def test_resolve_toolset_tool_permissions_single_db_fetch_across_checks(): key's toolsets during one request; the shared cache must dedupe the DB fetch so the request costs a single toolset query however many checks run""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -13104,7 +13103,7 @@ async def test_resolve_toolset_tool_permissions_single_db_fetch_across_checks(): with ( patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", list_toolsets_mock, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -13124,7 +13123,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_sees_writer_revocat request even though the legacy cache still holds the old grant, and the fresh read must go to the writer, not the replica""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -13137,7 +13136,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_sees_writer_revocat with ( patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", list_toolsets_mock, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -13162,7 +13161,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_propagates_db_fault """A fresh read that fails must raise so the managed-agent boundary fails closed; the legacy path keeps its swallow-to-empty behaviour""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -13171,7 +13170,7 @@ async def test_resolve_toolset_tool_permissions_fresh_policy_propagates_db_fault with ( patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", list_toolsets_mock, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), @@ -13191,10 +13190,10 @@ class TestMaterializeAuthHeaders: @pytest.mark.asyncio async def test_static_header_auth_materializes_its_header(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) @@ -13203,13 +13202,13 @@ class TestMaterializeAuthHeaders: @pytest.mark.asyncio async def test_client_credentials_bearer_auth_materializes_bearer(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, ) @@ -13224,13 +13223,13 @@ class TestMaterializeAuthHeaders: async def test_materialize_follows_the_minted_token_to_a_custom_header(self): # The OpenAPI arm reads header_name off the auth object rather than assuming Authorization, # so it carries the knob with no per-arm change. This pins that it stays that way. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.client_credentials import ( + from litellm.proxy.mcp_server.outbound_credentials.client_credentials import ( ClientCredentialsBearerAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( + from litellm.proxy.mcp_server.outbound_credentials.types import ( ClientCredentialsConfig, ) @@ -13243,10 +13242,10 @@ class TestMaterializeAuthHeaders: @pytest.mark.asyncio async def test_noop_and_none_materialize_to_none(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _materialize_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( NoOpAuth, ) @@ -13367,7 +13366,7 @@ class TestDiscoveryFailureLogging: secret_url = "https://typo-host.example.com/mcp/s/PATHSECRET/mcp" with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=self._connect_error_client(secret_url), ), caplog.at_level(logging.WARNING, logger="LiteLLM"), @@ -13387,7 +13386,7 @@ class TestDiscoveryFailureLogging: url = "https://typo-host.example.com/mcp" with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=self._connect_error_client(url), ), caplog.at_level(logging.WARNING, logger="LiteLLM"), @@ -13404,7 +13403,7 @@ class TestDiscoveryFailureLogging: client.get = AsyncMock(return_value=httpx.Response(404, request=httpx.Request("GET", url))) with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + "litellm.proxy.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=client, ), caplog.at_level(logging.WARNING, logger="LiteLLM"), @@ -13731,7 +13730,7 @@ class TestServerToolListsHonorThePrefixBoundary: @pytest.mark.asyncio async def test_wire_form_allowlist_entry_follows_a_non_default_separator(self): - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils server = self._aliased_server(allowed_tools=["petstore__getpetbyid"]) @@ -13885,7 +13884,7 @@ class TestOpenAPIRegistryKeyMatchesRegistration: @staticmethod def _register(server: MCPServer, base_tool_name: str) -> str: - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -13893,7 +13892,7 @@ class TestOpenAPIRegistryKeyMatchesRegistration: return add_server_prefix_to_name(base_tool_name, get_server_prefix(server)) async def _call(self, server: MCPServer, registered_key: str, bare_tool_name: str) -> CallToolResult: - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -13967,7 +13966,7 @@ class TestOpenAPIRegistryKeyMatchesRegistration: @pytest.mark.asyncio async def test_dispatch_follows_a_non_default_prefix_separator(self): - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils server = MCPServer( server_id="dd7f2b9e-2c4a-4f1b-9e0a-8d3c6b5a4f21", @@ -14092,20 +14091,20 @@ class TestSessionResourceScopeIntersect: return auth def test_scope_reader_is_none_for_keys_and_unscoped_subjects(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager assert MCPServerManager._admitted_session_resource_scope(None) is None assert MCPServerManager._admitted_session_resource_scope(UserAPIKeyAuth(user_id="u")) is None assert MCPServerManager._admitted_session_resource_scope(self._admitted_auth(None)) is None def test_scope_reader_returns_sealed_scope_for_admitted_subjects(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager assert MCPServerManager._admitted_session_resource_scope(self._admitted_auth("b")) == frozenset({"b"}) def test_scope_reader_returns_all_sealed_server_ids(self): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager auth = self._admitted_auth("first") auth.mcp_session_resource_server_ids = ("first", "second") @@ -14119,8 +14118,8 @@ class TestSessionResourceScopeIntersect: single-exit shape, the old early return would hand a per-server bearer the registry.""" from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -14148,8 +14147,8 @@ class TestSessionResourceScopeIntersect: async def test_admin_registry_seed_keeps_both_servers_in_a_multi_server_session(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -14184,14 +14183,14 @@ class TestSessionResourceScopeIntersect: than the whole set.""" from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() auth = self._admitted_auth("granted-id") with ( patch.object(MCPServerManager, "get_allow_all_keys_server_ids", return_value=["open-id", "granted-id"]), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", new_callable=AsyncMock, return_value=["granted-id", "other-id"], ), @@ -14208,7 +14207,7 @@ class TestSessionResourceScopeIntersect: with ( patch.object(MCPServerManager, "get_allow_all_keys_server_ids", return_value=["open-id", "granted-id"]), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", new_callable=AsyncMock, side_effect=RuntimeError("resolver down"), ), @@ -14281,7 +14280,7 @@ class TestClientForwardedDiscoveryFailureIsNotFatal: {"new": AsyncMock(return_value=None)} if failure == "incomplete" else {"side_effect": never_returns} ) with ( - patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", 0.01), + patch("litellm.proxy.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", 0.01), patch.object(manager, "_discover_oauth_metadata_for_server", **discovery_patch), ): if not serves_without_endpoints: @@ -14506,8 +14505,8 @@ class TestOpenApiHandlerRelaysUpstreamAuth: @pytest.mark.asyncio async def test_upstream_auth_error_keeps_its_type(self): - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() server = self._server() @@ -14526,7 +14525,7 @@ class TestOpenApiHandlerRelaysUpstreamAuth: @pytest.mark.asyncio async def test_other_failures_still_become_an_error_result(self): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() @@ -14556,8 +14555,8 @@ class TestOpenApiHandlerRelaysUpstreamAuth: async def test_json_bodies_keep_verbatim_text_and_gain_structured_content(self, body, compat, expected_structured): """The OpenAPI arm used to stringify the response; now the text block is the upstream body byte for byte, exactly once, and JSON bodies carry structuredContent when the caller's revision admits it.""" - from litellm.proxy._experimental.mcp_server.tool_outcome import WireCompat, parse_http_body - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_outcome import WireCompat, parse_http_body + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() @@ -14747,7 +14746,7 @@ class TestConfigServerIdPinning: ) with ( patch( # test-quality-ok: the db reload path has no seam but its own repository - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( # test-quality-ok: same, the prisma client is fetched inside the reload @@ -15203,8 +15202,8 @@ class TestLitellmAdmissionKeyIsNeverTheSubjectToken: @staticmethod def _recording_provider() -> MagicMock: - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.result import Ok provider: Final = MagicMock() provider.resolve_credentials = AsyncMock( @@ -15504,8 +15503,7 @@ async def test_pre_call_tool_check_honors_guardrail_attached_to_key(monkeypatch, @pytest.mark.asyncio async def test_pre_call_tool_check_stamps_personal_key_team_rpm_limits(monkeypatch: pytest.MonkeyPatch) -> None: import litellm - - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler manager: Final = MCPServerManager() server: Final = MCPServer( @@ -15544,7 +15542,7 @@ async def test_pre_call_tool_check_stamps_personal_key_team_rpm_limits(monkeypat @pytest.mark.asyncio async def test_pre_call_tool_check_uses_inherited_team_auth_for_guardrails(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler server: Final = MCPServer( server_id="srv-guardrails", @@ -15610,7 +15608,7 @@ async def test_pre_call_tool_check_uses_inherited_team_auth_for_guardrails(monke @pytest.mark.asyncio async def test_pre_call_tool_check_keeps_native_name_for_team_attribution(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler server: Final = MCPServer( server_id="math-a", @@ -15711,10 +15709,10 @@ async def test_pre_call_tool_check_keeps_original_auth_for_team_key(monkeypatch: @pytest.mark.asyncio async def test_call_tool_passes_attributed_auth_to_guardrail_hooks(monkeypatch: pytest.MonkeyPatch) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.operations import _run_post_mcp_call_guardrails - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.operations import _run_post_mcp_call_guardrails original_auth: Final = UserAPIKeyAuth(api_key="sk-personal", user_id="alice") team: Final = LiteLLM_TeamTable( @@ -15826,13 +15824,12 @@ async def test_call_tool_passes_attributed_auth_to_guardrail_hooks(monkeypatch: async def test_virtual_mcp_calls_use_attributed_auth_for_logging_and_hooks(monkeypatch: pytest.MonkeyPatch) -> None: from mcp.types import CallToolResult, Tool - from litellm.proxy._experimental.mcp_server import operations, tool_search - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry from litellm.proxy import proxy_server + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable from litellm.proxy.auth import auth_checks - from litellm.proxy._types import LiteLLM_ObjectPermissionTable - from litellm.proxy._types import LiteLLM_TeamTable, LiteLLM_UserTable + from litellm.proxy.mcp_server import operations, tool_search + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry from litellm.types.mcp_server.tool_registry import MCPTool original_auth: Final = UserAPIKeyAuth( @@ -15971,13 +15968,13 @@ async def test_debug_resolution_matches_final_header_conflict_winner( expected_source: str, expected_authorization: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var - from starlette.requests import Request from pydantic import SecretStr + from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.auth.litellm_auth_handler import MCPAuthenticatedUser - from litellm.proxy._experimental.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics - from litellm.proxy._experimental.mcp_server.outbound_credentials import ( + from litellm.proxy.mcp_server.auth.litellm_auth_handler import MCPAuthenticatedUser + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics + from litellm.proxy.mcp_server.outbound_credentials import ( ApiKeyConfig, AuthorizationCodeConfig, NoneConfig, @@ -15985,7 +15982,7 @@ async def test_debug_resolution_matches_final_header_conflict_winner( SharedKey, UpstreamCredentialProvider, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import OAuthToken + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import OAuthToken from litellm.types.mcp_server.mcp_server_manager import MCPServer class Store: @@ -16041,10 +16038,10 @@ async def test_debug_reports_legacy_signing_and_non_http_transport( _mcp_request_ctx, monkeypatch, transport: Literal["http", "stdio"] ) -> None: monkeypatch.setenv("LITELLM_ENABLE_MCP_STDIO", "true") - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server.mcp_debug import MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics from litellm.types.mcp_server.mcp_server_manager import MCPServer diagnostics = MCPAuthDiagnostics() @@ -16255,7 +16252,7 @@ async def test_openapi_health_coalesces_concurrent_checks_and_reuses_results(res @pytest.mark.asyncio async def test_openapi_health_cache_expires_at_thirty_seconds(respx_mock, monkeypatch): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _OpenAPIHealthProbe + from litellm.proxy.mcp_server.mcp_server_manager import _OpenAPIHealthProbe monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") clock = iter([0.0, 29.0, 30.0, 30.0]) @@ -16350,8 +16347,8 @@ class _DiscoveryClock: return self.now -from pydantic import TypeAdapter from mcp.types import JSONRPCMessage, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult +from pydantic import TypeAdapter _JSONRPC_ADAPTER = TypeAdapter(JSONRPCMessage) @@ -16359,7 +16356,7 @@ _JSONRPC_ADAPTER = TypeAdapter(JSONRPCMessage) @contextlib.contextmanager def _mcp_upstream(respond): """Drive the SDK's streamable-HTTP transport off an httpx2 MockTransport; respx only sees httpx.""" - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient def make_client(self, *args, **kwargs): return httpx2.AsyncClient( @@ -16792,7 +16789,7 @@ async def test_discovery_cache_can_be_disabled(monkeypatch: pytest.MonkeyPatch) "value,expected", (("invalid", 60.0), ("nan", 60.0), ("inf", 60.0), ("-1", 60.0), ("12.5", 12.5)) ) def test_discovery_cache_ttl_validation(value: str, expected: float, monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _mcp_discovery_cache_ttl + from litellm.proxy.mcp_server.mcp_server_manager import _mcp_discovery_cache_ttl monkeypatch.setenv("LITELLM_MCP_DISCOVERY_CACHE_TTL", value) assert _mcp_discovery_cache_ttl() == expected @@ -16811,7 +16808,7 @@ def test_discovery_cache_keys_isolate_user_dependent_auth(auth_type: MCPAuth) -> def _register_local_tool(name: str, description: str) -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry async def _handler(**kwargs): return None @@ -16829,7 +16826,7 @@ def _openapi_server(name: str) -> MCPServer: @pytest.mark.asyncio async def test_openapi_listing_ignores_overlapping_server_prefix() -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager: Final = MCPServerManager() manager.create_mcp_client = AsyncMock(return_value=AsyncMock()) @@ -16850,7 +16847,7 @@ async def test_openapi_listing_ignores_overlapping_server_prefix() -> None: @pytest.mark.asyncio async def test_openapi_listing_finds_tools_registered_under_the_normalized_prefix() -> None: - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager: Final = MCPServerManager() manager.create_mcp_client = AsyncMock(return_value=AsyncMock()) @@ -16866,7 +16863,7 @@ async def test_openapi_listing_finds_tools_registered_under_the_normalized_prefi @pytest.mark.asyncio async def test_discovery_cache_retries_cancelled_fetches() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) @@ -16883,7 +16880,7 @@ async def test_discovery_cache_retries_cancelled_fetches() -> None: @pytest.mark.asyncio async def test_discovery_cache_cancels_fetch_when_last_waiter_leaves() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) entered: Final = asyncio.Event() @@ -16912,7 +16909,7 @@ async def test_discovery_cache_cancels_fetch_when_last_waiter_leaves() -> None: @pytest.mark.asyncio async def test_discovery_cache_bounds_detached_fetches_without_dropping_results() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) entered: Final[asyncio.Queue[None]] = asyncio.Queue() @@ -16944,10 +16941,11 @@ async def test_discovery_cache_bounds_detached_fetches_without_dropping_results( @pytest.mark.asyncio async def test_discovery_cache_tracks_resolved_credentials_across_workers() -> None: import respx - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth - from litellm.proxy._experimental.mcp_server.outbound_credentials.resolver import UpstreamCredentialProvider - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok, Result - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject + + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import StaticHeaderAuth + from litellm.proxy.mcp_server.outbound_credentials.resolver import UpstreamCredentialProvider + from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok, Result + from litellm.proxy.mcp_server.outbound_credentials.types import CredError, ServerSpec, Subject class CredentialSource(UpstreamCredentialProvider): def __init__(self) -> None: @@ -17020,7 +17018,8 @@ async def test_discovery_cache_tracks_resolved_credentials_across_workers() -> N @pytest.mark.asyncio async def test_discovery_resolves_stored_oauth_for_the_requesting_user() -> None: import respx - from litellm.proxy._experimental.mcp_server.outbound_credentials.oauth_token_store import OAuthToken + + from litellm.proxy.mcp_server.outbound_credentials.oauth_token_store import OAuthToken class TokenStore: def __init__(self) -> None: @@ -17058,7 +17057,7 @@ async def test_discovery_resolves_stored_oauth_for_the_requesting_user() -> None @pytest.mark.asyncio async def test_discovery_cache_evicts_results_at_capacity() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) @@ -17076,7 +17075,7 @@ async def test_discovery_cache_evicts_results_at_capacity() -> None: @pytest.mark.asyncio async def test_discovery_cache_invalidation_preserves_other_servers_and_pending_fetches() -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) entered: Final = asyncio.Event() @@ -17108,7 +17107,7 @@ async def test_discovery_cache_invalidation_preserves_other_servers_and_pending_ @pytest.mark.asyncio @pytest.mark.parametrize("description", ("x" * 96_000, "é" * 40_000), ids=("ascii", "unicode")) async def test_discovery_cache_returns_oversized_results_without_retaining_them(description: str) -> None: - from litellm.proxy._experimental.mcp_server.catalog import _DiscoveryCache + from litellm.proxy.mcp_server.catalog import _DiscoveryCache cache: Final = _DiscoveryCache[ListPromptsResult](60, _DiscoveryClock(), TypeAdapter(ListPromptsResult)) fetch: Final = AsyncMock( @@ -17141,9 +17140,9 @@ class TestProtectedCredentialPreparation: credential: str | None, dispatch: str, ) -> None: - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.server import _handle_local_mcp_tool - from litellm.proxy._experimental.mcp_server.utils import add_server_prefix_to_name, get_server_prefix + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.server import _handle_local_mcp_tool + from litellm.proxy.mcp_server.utils import add_server_prefix_to_name, get_server_prefix spec_path: Final = tmp_path / "openapi.json" spec_path.write_text( @@ -17433,7 +17432,7 @@ class TestProtectedCredentialPreparation: forwarded: dict[str, str] | None, caller: str | None, ) -> None: - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( create_tool_function, request_auth_header, request_extra_headers, @@ -17465,8 +17464,9 @@ class TestProtectedCredentialPreparation: @pytest.mark.asyncio async def test_static_resolution_cancellation_closes_flow(self) -> None: from collections.abc import AsyncGenerator - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.outbound_credentials.adapter import prepare_mcp_client + + from litellm.mcp_client.client import MCPClient + from litellm.proxy.mcp_server.outbound_credentials.adapter import prepare_mcp_client class CancelledAuth(httpx.Auth): closed = False @@ -17730,8 +17730,8 @@ class TestProtectedCredentialPreparation: @pytest.mark.asyncio @pytest.mark.parametrize("selected", [False, True]) async def test_request_selected_during_guardrail_runs_concurrently_with_tool(monkeypatch, selected): + from litellm.proxy.mcp_server import tool_registry from litellm.responses.mcp.request_context import MCPRequestContext - from litellm.proxy._experimental.mcp_server import tool_registry tool_started = asyncio.Event() guardrail_started = asyncio.Event() @@ -17809,8 +17809,9 @@ async def test_server_response_identifies_read_only_config(in_config, in_db, exp @pytest.mark.parametrize("with_caller,legacy_factory", [(True, False), (False, False), (True, True)]) async def test_client_sampling_does_not_fill_explicit_context_from_another_ambient_caller(with_caller, legacy_factory): from mcp.server.auth.middleware.auth_context import auth_context_var - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import _create_sampling_callback + + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.mcp_server_manager import _create_sampling_callback upstream = MCPServer( server_id="explicit-empty", @@ -17828,8 +17829,8 @@ async def test_client_sampling_does_not_fill_explicit_context_from_another_ambie client_ip="192.0.2.99", ) with ( - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient") as factory, - patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", sampling), + patch("litellm.proxy.mcp_server.upstream.MCPClient") as factory, + patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", sampling), ): if legacy_factory: callback = _create_sampling_callback(user_api_key_auth=UserAPIKeyAuth(user_id="explicit")) @@ -18106,6 +18107,7 @@ async def test_catalog_delete_drops_derived_tool_mapping(monkeypatch): @pytest.mark.parametrize("rediscover", [False, True]) async def test_catalog_publishes_rediscovered_routes_despite_concurrent_owner_change(monkeypatch, rediscover): from mcp.types import Tool + from litellm.proxy import proxy_server monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -18165,7 +18167,7 @@ async def test_catalog_reload_preserves_concurrent_config_discovery_and_routes(a with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", side_effect=hydrate, ), ): @@ -18247,7 +18249,7 @@ async def test_catalog_operation_retains_routes_only_for_same_configured_target( @pytest.mark.parametrize("change", ["concurrent", "staged", "deleted", "staged_after_delete", "staged_with_concurrent"]) @pytest.mark.parametrize("mapped", [False, True]) async def test_catalog_reload_keeps_new_route_owner_over_earlier_route(change, mapped, monkeypatch): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry manager: Final = MCPServerManager() registry: Final = tool_registry.MCPToolRegistry() @@ -18377,7 +18379,8 @@ async def test_catalog_reload_retains_routes_discovered_for_a_late_server(change from datetime import timedelta from mcp.types import Tool - from litellm.proxy._experimental.mcp_server import tool_registry + + from litellm.proxy.mcp_server import tool_registry row: Final = LiteLLM_MCPServerTable( server_id="late-routes", @@ -18453,7 +18456,7 @@ async def test_catalog_reload_retains_routes_discovered_for_a_late_server(change async def test_catalog_openapi_refresh_does_not_restore_removed_operations( tmp_path, monkeypatch, respx_mock, retain_operation ): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") manager: Final = MCPServerManager() @@ -18493,7 +18496,7 @@ async def test_catalog_openapi_refresh_does_not_restore_removed_operations( if retain_operation: assert manager.server_exposes_tool(manager.registry[row.server_id], "spec_refresh-retained") assert retained is not None - from litellm.proxy._experimental.mcp_server.tool_outcome import JsonResult + from litellm.proxy.mcp_server.tool_outcome import JsonResult retained_result = await retained.handler() assert isinstance(retained_result, JsonResult) @@ -18609,7 +18612,8 @@ async def test_catalog_background_lookup_after_operation_exit_observes_deletion( @pytest.mark.asyncio async def test_catalog_cancelled_openapi_refresh_retains_tools_and_discovery(monkeypatch): from datetime import timedelta - from litellm.proxy._experimental.mcp_server import tool_registry + + from litellm.proxy.mcp_server import tool_registry manager: Final = MCPServerManager() stamp: Final = datetime.now() @@ -18697,7 +18701,7 @@ async def test_catalog_snapshot_identity_is_independent_of_worker_oauth_discover @pytest.mark.asyncio async def test_catalog_failed_openapi_row_does_not_publish_partial_handlers(monkeypatch): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry manager: Final = MCPServerManager() registry: Final = tool_registry.MCPToolRegistry() @@ -18744,7 +18748,7 @@ async def test_catalog_unchanged_read_preserves_derived_initialize_instructions( @pytest.mark.asyncio async def test_catalog_reuses_openapi_tools_until_configuration_or_background_refresh(monkeypatch, tmp_path): - from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator, tool_registry + from litellm.proxy.mcp_server import openapi_to_mcp_generator, tool_registry registry = tool_registry.MCPToolRegistry() monkeypatch.setattr(tool_registry, "global_mcp_tool_registry", registry) @@ -18793,7 +18797,7 @@ async def test_catalog_rejects_configuration_switch_before_client_creation(monke admitted = manager.get_mcp_server_by_id("catalog-server") read_rows.return_value = [_catalog_row("updated")] if change == "edit" else [] await asyncio.create_task(manager.reload_servers_from_database()) - with patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPClient") as factory: + with patch("litellm.proxy.mcp_server.mcp_server_manager.MCPClient") as factory: with pytest.raises(HTTPException) as exc: await manager._create_mcp_client(admitted) assert exc.value.status_code == 503 @@ -18804,8 +18808,8 @@ async def test_catalog_rejects_configuration_switch_before_client_creation(monke @pytest.mark.asyncio @pytest.mark.parametrize("dispatch", ["managed", "local"]) async def test_catalog_changed_openapi_handler_never_dispatches(monkeypatch, tmp_path, respx_mock, dispatch): - from litellm.proxy._experimental.mcp_server import operations, tool_registry - from litellm.proxy._experimental.mcp_server.utils import add_server_prefix_to_name, get_server_prefix + from litellm.proxy.mcp_server import operations, tool_registry + from litellm.proxy.mcp_server.utils import add_server_prefix_to_name, get_server_prefix registry = tool_registry.MCPToolRegistry() monkeypatch.setattr(tool_registry, "global_mcp_tool_registry", registry) @@ -18912,7 +18916,7 @@ async def test_catalog_cancelled_config_hydration_preserves_published_credential raise asyncio.CancelledError() with patch( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", + "litellm.proxy.mcp_server.discoverable_endpoints.hydrate_config_server_dcr_client", side_effect=cancelled_hydration, ): with pytest.raises(asyncio.CancelledError): @@ -19029,7 +19033,7 @@ async def test_catalog_fresh_lookup_does_not_fall_back_to_stale_grants_when_data @pytest.mark.asyncio async def test_catalog_cancelled_registration_does_not_publish_partial_handlers(monkeypatch): - from litellm.proxy._experimental.mcp_server import tool_registry + from litellm.proxy.mcp_server import tool_registry manager = MCPServerManager() registry = tool_registry.MCPToolRegistry() @@ -19681,7 +19685,7 @@ async def test_close_all_upstream_sessions_logs_when_waiting_times_out( await self._never_close.wait() monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_UPSTREAM_SESSION_SHUTDOWN_TIMEOUT_SECONDS", + "litellm.proxy.mcp_server.mcp_server_manager.MCP_UPSTREAM_SESSION_SHUTDOWN_TIMEOUT_SECONDS", 0.05, ) caplog.set_level(logging.WARNING, logger="LiteLLM") @@ -19776,7 +19780,7 @@ class TestSharedIdentifierPrefixWarning: with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -19826,7 +19830,7 @@ async def test_reload_warns_once_about_a_blocked_stdio_row_that_is_rebuilt_every with ( patch("litellm.proxy.proxy_server.prisma_client", prisma), patch( - "litellm.proxy._experimental.mcp_server.db.MCPServerRepository", + "litellm.proxy.mcp_server.db.MCPServerRepository", return_value=repository, ), patch( @@ -20378,7 +20382,7 @@ class TestToolCatalogGuard: @pytest.mark.asyncio @pytest.mark.parametrize("add_prefix", [False, True]) async def test_openapi_catalog_is_scanned_and_pinned_like_an_upstream_listing(self, catalog_guardrail, add_prefix): - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry _, proxy_logging_obj = catalog_guardrail server = MCPServer( @@ -20495,7 +20499,7 @@ async def test_upstream_preparation_preserves_windows_command_and_caller_environ @pytest.mark.asyncio async def test_upstream_preparation_honors_case_sensitive_extra_command(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server import upstream + from litellm.proxy.mcp_server import upstream monkeypatch.setenv("LITELLM_ENABLE_MCP_STDIO", "true") monkeypatch.setattr(upstream, "MCP_STDIO_ALLOWED_COMMANDS", frozenset({"CustomRunner"})) @@ -20560,8 +20564,8 @@ async def test_cached_discovery_cannot_authorize_another_servers_local_handler(m from fastapi import HTTPException from mcp.types import Tool - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry _catalog_database(monkeypatch, AsyncMock(return_value=[]), AsyncMock(return_value=_revision_row(7))) manager = MCPServerManager() @@ -20600,7 +20604,7 @@ async def test_cached_discovery_cannot_authorize_another_servers_local_handler(m def test_discovery_preserves_registered_tool_namespaces(monkeypatch, local_handler): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() allowed = MCPServer(server_id="allowed", name="allowed", transport=MCPTransport.http) @@ -20644,8 +20648,8 @@ async def test_overlapping_server_prefix_cannot_authorize_registered_openapi_han from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry manager = MCPServerManager() private = MCPServer(server_id="private", name="billing", alias="billing", transport=MCPTransport.http) @@ -20735,8 +20739,8 @@ async def test_catalog_revision_failure_preserves_state_and_recovers(monkeypatch @pytest.mark.asyncio @pytest.mark.parametrize("groups", [[], ["catalog-group"]]) async def test_access_group_resolution_uses_the_operation_catalog(monkeypatch, groups): - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler row = _catalog_row().model_copy(update={"mcp_access_groups": groups}) _catalog_database(monkeypatch, AsyncMock(return_value=[row])) @@ -20771,9 +20775,9 @@ async def test_empty_access_group_scope_cannot_inherit_unrelated_server( ): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server import mcp_server_manager - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server import mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler row = _catalog_row() _catalog_database(monkeypatch, AsyncMock(return_value=[row])) @@ -20935,7 +20939,7 @@ async def test_paginated_listing_keeps_earlier_tool_metadata_and_caller_isolatio from mcp.types import ListToolsResult, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations + from litellm.proxy.mcp_server import catalog, operations monkeypatch.setenv("LITELLM_SALT_KEY", "listed-tools-test") monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -21026,9 +21030,9 @@ async def test_aggregate_bounds_each_paginated_server_by_its_own_listing_deadlin from mcp.types import JSONRPCRequest, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix + from litellm.proxy.mcp_server import catalog, operations + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.utils import MCP_TOOL_PREFIX_SEPARATOR, get_server_prefix monkeypatch.setenv("LITELLM_SALT_KEY", "paginated-listing-deadline-test") monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -21093,7 +21097,7 @@ async def test_failed_aggregate_continuation_preserves_only_delivered_tool_metad from mcp.types import ListToolsResult, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations + from litellm.proxy.mcp_server import catalog, operations monkeypatch.setenv("LITELLM_SALT_KEY", "failed-listing-test") monkeypatch.setattr(proxy_server, "prisma_client", None) @@ -21136,7 +21140,7 @@ async def test_aggregate_publishes_complete_bare_routes_only_after_delivering_a_ from mcp.types import ListToolsResult, PaginatedRequestParams from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations + from litellm.proxy.mcp_server import catalog, operations monkeypatch.delenv("LITELLM_SALT_KEY", raising=False) if can_seal: @@ -21202,7 +21206,7 @@ def test_discovery_keys_bind_static_auth_to_caller_and_configuration() -> None: @pytest.mark.parametrize("advertised", [False, True]) def test_untrusted_metadata_cannot_enable_cimd_without_matching_authorization_endpoint(advertised): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( _restrict_discovery_to_corroborated_authorization_server, ) @@ -21224,8 +21228,8 @@ async def test_manual_oauth_endpoints_discover_client_metadata_once( ) -> None: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server import mcp_server_manager as manager_module - from litellm.proxy._experimental.mcp_server.oauth_utils import get_cimd_client_id + from litellm.proxy.mcp_server import mcp_server_manager as manager_module + from litellm.proxy.mcp_server.oauth_utils import get_cimd_client_id monkeypatch.setenv("PROXY_BASE_URL", "https://gateway.example.com") monkeypatch.setenv("LITELLM_MCP_OAUTH_DISCOVERY_ON_STARTUP", "1" if startup else "0") @@ -21347,7 +21351,7 @@ async def test_optional_client_metadata_discovery_failure_preserves_manual_endpo @pytest.mark.parametrize("capability", [True, False]) @pytest.mark.parametrize("rebuild", ["same", "repointed", "fresh_discovery", "anchored"]) def test_oauth_rebuild_retains_only_corroborated_cimd_capability(capability: bool, rebuild: str) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import carry_forward_resolved_oauth_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import carry_forward_resolved_oauth_endpoints previous: Final = MCPServer( server_id="cimd-rebuild", @@ -21437,10 +21441,12 @@ def test_openapi_extra_headers_exclude_gateway_admission_key(header_name: str) - @pytest.mark.asyncio async def test_legacy_upstream_elicitation_rejects_modern_downstream_without_consent() -> None: from types import SimpleNamespace + from mcp.types import ElicitRequestFormParams, ErrorData - from litellm.proxy._experimental.mcp_server import server as legacy_server - from litellm.proxy._experimental.mcp_server.legacy_callbacks import create_elicitation_callback - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + + from litellm.proxy.mcp_server import server as legacy_server + from litellm.proxy.mcp_server.legacy_callbacks import create_elicitation_callback + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var session: Final = SimpleNamespace(client_params=None) session_token: Final = legacy_server.active_mcp_session_var.set(session) @@ -21450,7 +21456,7 @@ async def test_legacy_upstream_elicitation_rejects_modern_downstream_without_con relay: Final = AsyncMock() try: callback: Final = create_elicitation_callback() - with patch("litellm.proxy._experimental.mcp_server.elicitation_handler.handle_elicitation_request", relay): + with patch("litellm.proxy.mcp_server.elicitation_handler.handle_elicitation_request", relay): result: Final = await callback( None, ElicitRequestFormParams(message="Confirm", requested_schema={"type": "object"}) ) @@ -21536,7 +21542,7 @@ class TestMCPUpstreamRateLimitRetry: self, monkeypatch: pytest.MonkeyPatch ) -> None: monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.5 + "litellm.proxy.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.5 ) manager: Final = MCPServerManager() client: Final = MagicMock() @@ -21579,7 +21585,7 @@ class TestMCPUpstreamRateLimitRetry: self, monkeypatch: pytest.MonkeyPatch ) -> None: monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.05 + "litellm.proxy.mcp_server.mcp_server_manager.MCP_TOOL_LISTING_TIMEOUT", 0.05 ) manager: Final = MCPServerManager() server: Final = MCPServer(server_id="notes", name="notes", transport=MCPTransport.http) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py b/tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py rename to tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py index a873e2ab1ae..aa61deaf554 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_tool_calls_and_headers.py +++ b/tests/unit/proxy/mcp_server/test_mcp_server_tool_calls_and_headers.py @@ -1,4 +1,3 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations import asyncio import contextlib import contextvars @@ -33,14 +32,15 @@ from mcp_types.version import HANDSHAKE_PROTOCOL_VERSIONS, LATEST_HANDSHAKE_VERS from pydantic import JsonValue, TypeAdapter from starlette.types import Message, Receive, Scope, Send -from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing from litellm.proxy._types import ( LiteLLM_MCPServerTable, MCPTransport, UserAPIKeyAuth, ) +from litellm.proxy.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing +from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPOAuthMetadata, MCPServer, PinnedMCPTool @@ -50,7 +50,7 @@ def test_mcp_available_on_sdk2(): from packaging.version import Version - from litellm.proxy._experimental.mcp_server.server import MCP_AVAILABLE + from litellm.proxy.mcp_server.server import MCP_AVAILABLE assert Version("2.2.0") <= Version(version("mcp")) < Version("3") assert MCP_AVAILABLE is True @@ -71,7 +71,7 @@ def cleanup_mcp_global_state(): can leak between tests causing mock assertion failures. """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -109,7 +109,7 @@ def _paged_params(): async def test_mcp_server_tool_call_body_contains_request_data(_mcp_request_ctx): """Test that proxy_server_request body contains name and arguments""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -147,7 +147,7 @@ async def test_mcp_server_tool_call_body_contains_request_data(_mcp_request_ctx) mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch( @@ -171,7 +171,7 @@ async def test_mcp_server_tool_call_forwards_client_headers_to_logging(_mcp_requ """The MCP protocol path must hand the connection's client headers to the pre-call pipeline, so logging callbacks and guardrails see them the way the REST path does.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -203,7 +203,7 @@ async def test_mcp_server_tool_call_forwards_client_headers_to_logging(_mcp_requ mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch("litellm.proxy.proxy_server.proxy_config", MagicMock()): @@ -221,11 +221,11 @@ async def test_mcp_server_tool_call_strips_custom_litellm_key_header(_mcp_reques The pre-call pipeline only knows that name if it is passed in, so without it the virtual key reaches metadata.headers and proxy_server_request.headers in plaintext.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) - from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_request except ImportError: pytest.skip("MCP server not available") @@ -250,7 +250,7 @@ async def test_mcp_server_tool_call_strips_custom_litellm_key_header(_mcp_reques capturing_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch("litellm.proxy.proxy_server.proxy_config", MagicMock()): @@ -274,7 +274,7 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( ): from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse + from litellm.proxy.mcp_server.scope_challenge import SCOPE_RESPONSE_KEY, OAuthScopeResponse status_code = 403 if required_scope is not None else 401 send = AsyncMock() @@ -282,8 +282,8 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( request = Request({"type": "http", "headers": [], SCOPE_RESPONSE_KEY: response}) headers: Final = asyncio.create_task(response({"type": "http.response.start", "status": 200, "headers": []})) try: - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -306,11 +306,11 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch("litellm.proxy.proxy_server.proxy_config", MagicMock()): - with patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger", mock_logger): + with patch("litellm.proxy.mcp_server.operations.verbose_logger", mock_logger): result = await mcp_server_tool_call( _mcp_request_ctx(request=request if http_transport else None), _call_tool_params("test_tool", {"param": "value"}), @@ -338,7 +338,7 @@ async def test_mcp_server_tool_call_relays_upstream_auth_error_as_iserror( def test_prepare_mcp_server_headers_case_insensitive_extra_headers(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -368,7 +368,7 @@ def test_prepare_mcp_server_headers_case_insensitive_extra_headers(): def test_prepare_mcp_server_headers_group_header_defaults_for_members_only(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -405,7 +405,7 @@ def test_prepare_mcp_server_headers_group_header_defaults_for_members_only(): def test_prepare_mcp_server_headers_passthrough_strips_authorization_without_admission_header(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -441,7 +441,7 @@ def test_prepare_mcp_server_headers_passthrough_forwards_authorization_for_anony (``user_api_key_auth.api_key is None``) and the ``Authorization`` bearer is the upstream OAuth token — it must be forwarded, not stripped.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -483,7 +483,7 @@ def test_prepare_mcp_server_headers_passthrough_strips_authorization_for_authent the bearer must still be stripped to avoid leaking the gateway key upstream.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -519,7 +519,7 @@ def test_prepare_mcp_server_headers_passthrough_strips_authorization_for_authent def test_prepare_mcp_server_headers_oauth2_m2m_omits_litellm_caller_authorization(): """M2M OAuth must not put caller Bearer (LiteLLM API key) into extra_headers (#23652).""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -553,7 +553,7 @@ def test_prepare_mcp_server_headers_oauth2_interactive_drops_caller_authorizatio caller-supplied bearer must not override another user's stored credential. Non-auth headers are still carried; only the credential is dropped.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -583,10 +583,10 @@ def test_prepare_mcp_server_headers_oauth2_interactive_drops_caller_authorizatio def test_prepare_mcp_server_headers_legacy_delegate_strips_admission_authorization(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="legacy-delegate-admission", @@ -610,10 +610,10 @@ def test_prepare_mcp_server_headers_legacy_delegate_strips_admission_authorizati def test_prepare_mcp_server_headers_legacy_delegate_preserves_separate_upstream_authorization(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="legacy-delegate-dual-credential", @@ -640,10 +640,10 @@ def test_prepare_mcp_server_headers_legacy_delegate_preserves_separate_upstream_ def test_prepare_mcp_server_headers_legacy_delegate_strips_repeated_admission_key(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="legacy-delegate-repeated-key", @@ -672,7 +672,7 @@ def test_prepare_mcp_server_headers_legacy_delegate_strips_repeated_admission_ke def test_prepare_mcp_server_headers_m2m_skips_authorization_from_raw_extra_headers(): """M2M must not merge caller Authorization from raw_headers when extra_headers lists it.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) except ImportError: @@ -715,7 +715,7 @@ def _client_forwarded_mode_server(server_id: str, auth_type) -> MCPServer: def _prepare_headers_in_scope(server: MCPServer, scope_servers): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _prepare_mcp_server_headers, ) @@ -825,7 +825,7 @@ def test_prepare_mcp_server_headers_sole_consumer_still_forwards_via_extra_heade async def test_call_tool_m2m_skips_authorization_headers(): """M2M call_tool must not forward caller Authorization in oauth2/raw headers.""" try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -870,7 +870,7 @@ async def test_call_tool_m2m_skips_authorization_headers(): @pytest.mark.asyncio async def test_get_prompts_from_mcp_servers_success(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_prompts_from_mcp_servers, ) except ImportError: @@ -896,15 +896,15 @@ async def test_get_prompts_from_mcp_servers_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server_a, server_b]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_prompts_from_server = AsyncMock( @@ -930,7 +930,7 @@ async def test_get_prompts_from_mcp_servers_success(): @pytest.mark.asyncio async def test_get_resources_from_mcp_servers_success(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_resources_from_mcp_servers, ) except ImportError: @@ -956,15 +956,15 @@ async def test_get_resources_from_mcp_servers_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server_a, server_b]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_resources_from_server = AsyncMock( @@ -1003,7 +1003,7 @@ async def test_get_resources_from_mcp_servers_success(): @pytest.mark.asyncio async def test_get_resource_templates_from_mcp_servers_success(): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_resource_templates_from_mcp_servers, ) except ImportError: @@ -1021,15 +1021,15 @@ async def test_get_resource_templates_from_mcp_servers_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_resource_templates_from_server = AsyncMock( @@ -1058,7 +1058,7 @@ async def test_get_resource_templates_from_mcp_servers_success(): @pytest.mark.asyncio async def test_mcp_get_prompt_success(): try: - from litellm.proxy._experimental.mcp_server.server import mcp_get_prompt + from litellm.proxy.mcp_server.server import mcp_get_prompt except ImportError: pytest.skip("MCP server not available") @@ -1071,15 +1071,15 @@ async def test_mcp_get_prompt_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=({"Authorization": "token"}, {"X-Test": "1"}), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.get_prompt_from_server = AsyncMock(return_value=prompt_result) @@ -1118,7 +1118,7 @@ async def test_mcp_get_prompt_success(): @pytest.mark.asyncio async def test_mcp_read_resource_success(): try: - from litellm.proxy._experimental.mcp_server.server import mcp_read_resource + from litellm.proxy.mcp_server.server import mcp_read_resource except ImportError: pytest.skip("MCP server not available") @@ -1139,15 +1139,15 @@ async def test_mcp_read_resource_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server]), ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=({"Authorization": "token"}, {"X-Test": "1"}), ) as mock_headers, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, ): mock_manager.read_resource_from_server = AsyncMock(return_value=read_result) @@ -1188,7 +1188,8 @@ async def test_mcp_read_resource_success(): ) async def test_read_resource_preserves_content_metadata(_mcp_request_ctx, kind, metadata): from mcp.types import ReadResourceRequestParams - from litellm.proxy._experimental.mcp_server import operations, server + + from litellm.proxy.mcp_server import operations, server uri: Final = "https://example.com/resource" caller: Final = UserAPIKeyAuth(user_id="resource-caller") @@ -1231,7 +1232,7 @@ async def test_read_resource_preserves_content_metadata(_mcp_request_ctx, kind, @pytest.mark.asyncio async def test_mcp_read_resource_multiple_servers_error(): try: - from litellm.proxy._experimental.mcp_server.server import mcp_read_resource + from litellm.proxy.mcp_server.server import mcp_read_resource except ImportError: pytest.skip("MCP server not available") @@ -1243,7 +1244,7 @@ async def test_mcp_read_resource_multiple_servers_error(): server_b.name = "server_b" with patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[server_a, server_b]), ) as mock_allowed: with pytest.raises(HTTPException) as exc_info: @@ -1261,7 +1262,7 @@ async def test_mcp_read_resource_multiple_servers_error(): async def test_get_tools_from_mcp_servers_continues_when_one_server_fails(): """Test that _get_tools_from_mcp_servers continues when one server fails""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -1333,14 +1334,14 @@ async def test_get_tools_from_mcp_servers_continues_when_one_server_fails(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): with ( patch( - "litellm.proxy._experimental.mcp_server.catalog.verbose_logger", + "litellm.proxy.mcp_server.catalog.verbose_logger", ) as mock_logger, - patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger", mock_logger), + patch("litellm.proxy.mcp_server.operations.verbose_logger", mock_logger), ): # Test with server-specific auth headers mcp_server_auth_headers = { @@ -1374,7 +1375,7 @@ async def test_get_tools_from_mcp_servers_continues_when_one_server_fails(): async def test_get_tools_from_mcp_servers_handles_all_servers_failing(): """Test that _get_tools_from_mcp_servers handles all servers failing gracefully""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -1432,14 +1433,14 @@ async def test_get_tools_from_mcp_servers_handles_all_servers_failing(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): with ( patch( - "litellm.proxy._experimental.mcp_server.catalog.verbose_logger", + "litellm.proxy.mcp_server.catalog.verbose_logger", ) as mock_logger, - patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger", mock_logger), + patch("litellm.proxy.mcp_server.operations.verbose_logger", mock_logger), ): # Test with server-specific auth headers mcp_server_auth_headers = { @@ -1505,15 +1506,15 @@ async def _denied_scoped_list( mock_manager: MagicMock, resolver: AsyncMock, ) -> HTTPException: - from litellm.proxy._experimental.mcp_server.server import _get_tools_from_mcp_servers + from litellm.proxy.mcp_server.server import _get_tools_from_mcp_servers with ( patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", resolver, ), patch( # test-quality-ok: the server registry is a module-level singleton; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ), ): @@ -1529,7 +1530,7 @@ async def _denied_scoped_list( @pytest.mark.asyncio async def test_scoped_list_denied_by_agent_binding_raises_403_naming_agent(): """The agent-binding veto must raise a 403 naming the agent, never a silent 200 with no tools.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") resolver = _scope_resolver(resolved_without_agent={"github": "srv-github"}) @@ -1552,19 +1553,19 @@ async def test_scoped_list_denied_by_agent_binding_raises_403_naming_agent(): @pytest.mark.asyncio async def test_empty_scope_lists_nothing_instead_of_raising_a_nameless_denial(): """An empty ``x-mcp-servers`` header scopes to no servers; that is an empty listing, not a 403.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") - from litellm.proxy._experimental.mcp_server.server import _get_tools_from_mcp_servers + pytest.importorskip("litellm.proxy.mcp_server.server") + from litellm.proxy.mcp_server.server import _get_tools_from_mcp_servers user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") resolver = AsyncMock(return_value=[]) with ( patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", resolver, ), patch( # test-quality-ok: the server registry is a module-level singleton; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", _denied_scope_manager({"github": "srv-github"}), ), ): @@ -1579,7 +1580,7 @@ async def test_empty_scope_lists_nothing_instead_of_raising_a_nameless_denial(): @pytest.mark.asyncio async def test_scoped_list_denied_for_non_agent_key_raises_generic_403(): """A denial for a key with no agent binding stays generic and skips the agent-stripped rerun.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") resolver = AsyncMock(return_value=[]) @@ -1599,7 +1600,7 @@ async def test_scoped_list_denied_for_non_agent_key_raises_generic_403(): async def test_scoped_list_unknown_name_raises_same_generic_403_as_unauthorized(): """Unknown and registered-but-unauthorized names raise byte-identical generic 403s, so a caller cannot probe which server names exist.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1623,7 +1624,7 @@ async def test_scoped_list_unknown_name_raises_same_generic_403_as_unauthorized( async def test_scoped_list_access_group_vetoed_by_agent_names_agent_and_group(): """An access-group scope vetoed by the agent binding raises the 403 naming the agent and the group instead of the silent empty list.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1646,7 +1647,7 @@ async def test_scoped_list_mixed_unknown_and_vetoed_group_names_the_group_that_r """With an unknown name ahead of the agent-vetoed group in the scope, the 403 must name the group whose servers the key can reach, never the unknown name, or the admin is told to grant a group that does not exist.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1668,7 +1669,7 @@ async def test_scoped_list_mixed_unknown_and_vetoed_group_names_the_group_that_r async def test_scoped_list_agent_key_denied_by_key_grants_raises_generic_403(): """When the agent-stripped rerun still resolves nothing, the 403 stays generic instead of blaming the agent binding.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") resolver = _scope_resolver(resolved_without_agent={}) @@ -1688,7 +1689,7 @@ async def test_scoped_list_agent_key_denied_by_key_grants_raises_generic_403(): async def test_scoped_list_agent_veto_attributed_for_differently_cased_server_name(): """The scope filter matches `/mcp/GitHub` to a server named `github` case-insensitively, so the agent-attributed 403 must match the same way instead of falling back to the generic denial.""" - pytest.importorskip("litellm.proxy._experimental.mcp_server.server") + pytest.importorskip("litellm.proxy.mcp_server.server") user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user", agent_id="agent-123") @@ -1711,7 +1712,7 @@ async def test_handle_list_tools_converts_permission_httpexception_to_mcp_error( """The MCP protocol handler surfaces a permission HTTPException as a clean JSON-RPC error (MCPError, INVALID_REQUEST) carrying the denial message, instead of a raw 500.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_list_tools + from litellm.proxy.mcp_server.server import handle_list_tools except ImportError: pytest.skip("MCP server not available") @@ -1723,13 +1724,13 @@ async def test_handle_list_tools_converts_permission_httpexception_to_mcp_error( with ( patch( # test-quality-ok: the protocol handler reads auth from module context; no injection seam - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock( return_value=(None, None, None, None, None, None, None), side_effect=denial if denial_at_auth else None ), ), patch( # test-quality-ok: the listing helper is the handler's only collaborator; the suite's seam - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new=AsyncMock(side_effect=denial), ), ): @@ -1793,7 +1794,7 @@ async def test_rate_limited_catalog_lists_return_mcp_errors(handler_name): @pytest.mark.asyncio async def test_mcp_server_tool_call_renders_denial_message_not_detail_dict(_mcp_request_ctx): try: - from litellm.proxy._experimental.mcp_server.server import mcp_server_tool_call + from litellm.proxy.mcp_server.server import mcp_server_tool_call except ImportError: pytest.skip("MCP server not available") @@ -1802,11 +1803,11 @@ async def test_mcp_server_tool_call_renders_denial_message_not_detail_dict(_mcp_ with ( patch( # test-quality-ok: the protocol handler reads auth from module context; no injection seam - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock(return_value=(None, None, None, None, None, None, None)), ), patch( # test-quality-ok: the tool-call helper is the handler's only collaborator; the suite's seam - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", new=AsyncMock(side_effect=denial), ), ): @@ -1820,7 +1821,7 @@ async def test_mcp_server_tool_call_renders_denial_message_not_detail_dict(_mcp_ async def test_mcp_server_tool_call_body_with_none_arguments(_mcp_request_ctx): """Test that proxy_server_request body handles None arguments correctly""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_server_tool_call, set_auth_context, ) @@ -1857,7 +1858,7 @@ async def test_mcp_server_tool_call_body_with_none_arguments(_mcp_request_ctx): mock_add_litellm_data_to_request, ): with patch( - "litellm.proxy._experimental.mcp_server.operations.call_mcp_tool", + "litellm.proxy.mcp_server.operations.call_mcp_tool", mock_call_mcp_tool, ): with patch( @@ -1880,14 +1881,14 @@ async def test_mcp_server_tool_call_body_with_none_arguments(_mcp_request_ctx): async def test_concurrent_initialize_session_managers(): """Test that concurrent calls to initialize_session_managers don't cause race conditions.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( initialize_session_managers, ) except ImportError: pytest.skip("MCP server not available") # Import the module to reset state - import litellm.proxy._experimental.mcp_server.server as mcp_server + import litellm.proxy.mcp_server.server as mcp_server # Reset state before test original_initialized = mcp_server._SESSION_MANAGERS_INITIALIZED @@ -1920,7 +1921,7 @@ async def test_concurrent_initialize_session_managers(): "run", return_value=mock_cm_stateful, ) as mock_stateful_run, - patch("litellm.proxy._experimental.mcp_server.operations.verbose_logger"), + patch("litellm.proxy.mcp_server.operations.verbose_logger"), ): # Create multiple concurrent tasks that call initialize_session_managers async def init_task(): @@ -1981,7 +1982,7 @@ async def test_streamable_http_session_manager_is_stateless(): - stateful manager for clients with session IDs (Claude Code, Cursor, VSCode) """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( session_manager_stateful, session_manager_stateless, ) @@ -2021,9 +2022,9 @@ async def test_mcp_routing_initialize_to_stateful_no_session_to_stateless( from starlette.requests import Request from starlette.types import Message, Receive, Scope, Send - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.mcp_debug import record_auth_resolution - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.mcp_debug import record_auth_resolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution scope: Final[Scope] = {"type": "http", "method": method, "path": "/mcp", "headers": []} receive: Final = AsyncMock(return_value={"type": "http.request", "body": request_body, "more_body": False}) @@ -2046,7 +2047,7 @@ async def test_mcp_routing_initialize_to_stateful_no_session_to_stateless( stateful_handle: Final = AsyncMock(side_effect=handle_request) with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( UserAPIKeyAuth(user_id="debug-user"), @@ -2057,13 +2058,13 @@ async def test_mcp_routing_initialize_to_stateful_no_session_to_stateless( {"x-litellm-mcp-debug": "true"} if debug else {}, ), ), - patch("litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), + patch("litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), ): @@ -2114,14 +2115,14 @@ def _client_allowlist_patches( stack: Final = contextlib.ExitStack() stack.enter_context( patch( # test-quality-ok: the ASGI handler resolves auth through a module-level function; no injection seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(user_id="allowlist-user", jwt_claims=jwt_claims), None, None, None, None, {}), ) ) stack.enter_context( patch( # test-quality-ok: module flag guarding lazy session-manager startup; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True ) ) stack.enter_context( @@ -2154,7 +2155,7 @@ async def test_streamable_http_rejects_unlisted_client_before_any_session_work( request_body: bytes, expected_fragment: str, ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp", "headers": headers} receive: Final = AsyncMock(return_value={"type": "http.request", "body": request_body, "more_body": False}) @@ -2166,15 +2167,15 @@ async def test_streamable_http_rejects_unlisted_client_before_any_session_work( with ( _client_allowlist_patches(_ALLOWLIST_SETTINGS, jwt_claims), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), patch( # test-quality-ok: module-level cap check; asserting it is never reached is the point - "litellm.proxy._experimental.mcp_server.server._enforce_stateful_session_cap_for_owner", session_cap + "litellm.proxy.mcp_server.server._enforce_stateful_session_cap_for_owner", session_cap ), pytest.raises(HTTPException) as denied, ): @@ -2206,7 +2207,7 @@ async def test_streamable_http_rejects_unlisted_client_before_any_session_work( async def test_streamable_http_admits_listed_or_unrestricted_clients_and_hands_the_body_downstream( settings: dict[str, object], jwt_claims: dict[str, object] | None, headers: list[tuple[bytes, bytes]] ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp", "headers": headers} receive: Final = AsyncMock( @@ -2227,11 +2228,11 @@ async def test_streamable_http_admits_listed_or_unrestricted_clients_and_hands_t with ( _client_allowlist_patches(settings, jwt_claims), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), ): @@ -2256,7 +2257,7 @@ async def test_streamable_http_admits_listed_or_unrestricted_clients_and_hands_t async def test_sse_endpoint_applies_the_same_client_allowlist( jwt_claims: dict[str, object] | None, headers: list[tuple[bytes, bytes]], admitted: bool ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp/sse", "headers": headers} receive: Final = AsyncMock(return_value={"type": "http.request", "body": _INITIALIZE, "more_body": False}) @@ -2269,11 +2270,11 @@ async def test_sse_endpoint_applies_the_same_client_allowlist( with ( _client_allowlist_patches(_ALLOWLIST_SETTINGS, jwt_claims), patch( # test-quality-ok: module-level pre-auth probe unrelated to the allowlist under test; no injection seam - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new_callable=AsyncMock, ), patch( # test-quality-ok: module-level upstream auth probe unrelated to the allowlist under test; no injection seam - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch.object( # test-quality-ok: SSE manager is a module singleton; the downstream call is the observable @@ -2302,7 +2303,7 @@ async def test_mcp_routing_chunked_initialize_to_stateful(): Test that chunked initialize requests route to the stateful manager. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2344,20 +2345,20 @@ async def test_mcp_routing_chunked_initialize_to_stateful(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, ["progress_test"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -2398,8 +2399,8 @@ async def test_mcp_routing_caps_body_peek_for_oversized_chunked_body(): receive into the downstream handler. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2456,13 +2457,13 @@ async def test_mcp_routing_caps_body_peek_for_oversized_chunked_body(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, ["progress_test"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateless, "handle_request", side_effect=stateless_handle), @@ -2496,8 +2497,8 @@ async def test_mcp_routing_peek_survives_multibyte_char_split_at_cap( ) -> None: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.scope_challenge import finish_scope_response + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.scope_challenge import finish_scope_response params: Final = ( { @@ -2538,11 +2539,11 @@ async def test_mcp_routing_peek_survives_multibyte_char_split_at_cap( with ( _client_allowlist_patches({}, None), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), patch( - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), ): @@ -2562,8 +2563,8 @@ async def test_enforce_stateful_session_cap_evicts_oldest_idle_then_rejects(): every one of its sessions is in flight (nothing safe to evict). """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( session_manager_stateful, ) except ImportError: @@ -2635,8 +2636,8 @@ async def test_mcp_routing_initialize_rejected_when_owner_at_session_cap(): and must not reach the stateful session manager. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2675,13 +2676,13 @@ async def test_mcp_routing_initialize_rejected_when_owner_at_session_cap(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, ["progress_test"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(mcp_server, "_owner_fingerprint_for", return_value="owner-X"), @@ -2715,8 +2716,8 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): stored auth object must be refreshed for each mcp-session-id request. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( get_auth_context, handle_streamable_http_mcp, session_manager_stateful, @@ -2767,7 +2768,7 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( current_auth, @@ -2779,7 +2780,7 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): ), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -2810,7 +2811,7 @@ async def test_stateful_mcp_requests_refresh_session_auth_context(): @pytest.mark.asyncio async def test_initialize_response_capture_accepts_str_headers_and_sets_auth_context(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -2858,8 +2859,8 @@ async def test_initialize_response_capture_accepts_str_headers_and_sets_auth_con @pytest.mark.asyncio async def test_initialize_request_tracks_active_session_after_response_header(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -2907,17 +2908,17 @@ async def test_initialize_request_tracks_active_session_after_response_header(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -2960,7 +2961,7 @@ _INITIALIZE_WITH_CLIENT_INFO: Final = ( ) def test_extract_initialize_client_info_reads_client_name_and_version(body, expected_name, expected_version): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -2982,7 +2983,7 @@ def test_extract_initialize_client_info_reads_client_name_and_version(body, expe ) def test_extract_initialize_client_info_returns_none_without_client_info(body): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -2994,7 +2995,7 @@ def test_oversized_initialize_peek_neither_routes_stateful_nor_attributes_client an initialize larger than the peek can never become a tracked session that then reports an unknown client.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3016,8 +3017,8 @@ async def test_initialize_request_records_client_name_in_gateway_sessions_report """The real initialize body's clientInfo is attributed to the session the stateful manager creates, together with the authenticated user.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -3060,17 +3061,17 @@ async def test_initialize_request_records_client_name_in_gateway_sessions_report try: with ( patch( # test-quality-ok: admission auth is resolved by a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( # test-quality-ok: session manager init is a module-level flag; the suite's only seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( # test-quality-ok: the transports are module-level singletons; the suite's only seam @@ -3117,8 +3118,8 @@ async def test_initialize_request_records_client_name_in_gateway_sessions_report def test_gateway_sessions_report_groups_live_sessions_by_client_and_user(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") from mcp.types import Implementation @@ -3187,7 +3188,7 @@ def test_gateway_sessions_report_groups_live_sessions_by_client_and_user(): def test_remove_stateful_session_tracking_drops_client_info(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") from mcp.types import Implementation @@ -3225,8 +3226,8 @@ def _admin_terminate_fixture(mcp_server): @pytest.mark.asyncio async def test_terminate_mcp_gateway_sessions_by_user_closes_every_live_session_of_that_user(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3284,8 +3285,8 @@ async def test_terminate_mcp_gateway_sessions_by_user_closes_every_live_session_ @pytest.mark.asyncio async def test_terminate_mcp_gateway_sessions_prefix_and_user_must_both_match(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3322,8 +3323,8 @@ async def test_admin_terminated_session_id_gets_404_instead_of_a_fresh_stateless try: from starlette.types import Scope - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3388,8 +3389,8 @@ async def test_admin_terminated_session_id_stays_refused_while_replayed_and_is_f try: from starlette.types import Scope - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import session_manager_stateful + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import session_manager_stateful except ImportError: pytest.skip("MCP server not available") @@ -3454,8 +3455,8 @@ async def test_admin_terminated_session_id_stays_refused_while_replayed_and_is_f @pytest.mark.asyncio async def test_initialize_request_with_existing_session_tracks_new_session(): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -3528,7 +3529,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( owner_auth, @@ -3540,7 +3541,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): ), ), patch( # test-quality-ok: registry is empty in unit tests; key owns one server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[ MCPServer( @@ -3553,7 +3554,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): ], ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -3589,7 +3590,7 @@ async def test_initialize_request_with_existing_session_tracks_new_session(): async def test_stateful_mcp_auth_contexts_expire_with_idle_sessions(): """Expired session auth contexts should not remain in memory indefinitely.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3620,7 +3621,7 @@ async def test_stateful_mcp_auth_contexts_expire_with_idle_sessions(): async def test_stateful_mcp_auth_contexts_do_not_expire_active_sessions(): """Active stateful sessions should not be terminated by idle cleanup.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3657,7 +3658,7 @@ async def test_stateful_mcp_auth_contexts_do_not_expire_active_sessions(): async def test_stateful_mcp_auth_context_cleanup_respects_zero_now(): """Explicit now=0 should be used as-is instead of falling back to monotonic.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3696,7 +3697,7 @@ async def test_stateful_mcp_auth_context_cleanup_respects_zero_now(): async def test_stateful_mcp_cleanup_loop_survives_purge_errors(): """Cleanup loop should keep running after one purge attempt fails.""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server except ImportError: pytest.skip("MCP server not available") @@ -3721,7 +3722,7 @@ async def test_owner_fingerprint_distinguishes_oauth_callers(): user could hijack another's mcp-session-id. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _owner_fingerprint_for, ) except ImportError: @@ -3757,7 +3758,7 @@ async def test_owner_fingerprint_distinguishes_oauth_callers(): async def test_owner_fingerprint_hashes_custom_api_keys(): """Custom API key formats should not appear in owner fingerprints.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _owner_fingerprint_for, ) except ImportError: @@ -3788,8 +3789,8 @@ async def test_stateful_mcp_session_owner_mismatch_returns_403(body: bytes): with 403, and the stateful manager must never be invoked. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -3829,12 +3830,12 @@ async def test_stateful_mcp_session_owner_mismatch_returns_403(body: bytes): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(intruder_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -3866,8 +3867,8 @@ async def test_stateful_mcp_session_serializes_concurrent_requests(): MCPAuthenticatedUser while in-flight callbacks are still running. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -3912,12 +3913,12 @@ async def test_stateful_mcp_session_serializes_concurrent_requests(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=slow_handle), @@ -3949,8 +3950,8 @@ async def test_stateful_mcp_lock_does_not_leak_when_auth_context_missing(): leaked lock would otherwise live forever. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -3980,12 +3981,12 @@ async def test_stateful_mcp_lock_does_not_leak_when_auth_context_missing(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=handle), @@ -4016,8 +4017,8 @@ async def test_stateful_mcp_get_stream_does_not_block_post(): same mcp-session-id hang for the lifetime of the stream. """ try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -4059,12 +4060,12 @@ async def test_stateful_mcp_get_stream_does_not_block_post(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=handle), @@ -4099,7 +4100,7 @@ def test_jsonrpc_text_has_top_level_method_ignores_nested_method(): """The top-level-key scan must not be fooled by a ``method`` field nested inside a JSON-RPC response's ``result`` payload — a flat substring search would, and that misread is what deadlocks the session lock.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _jsonrpc_text_has_top_level_method, ) @@ -4131,8 +4132,8 @@ async def test_truncated_jsonrpc_response_with_nested_method_skips_lock( deadlock behind the in-flight request POST that is holding the lock while it awaits this very response (e.g. sampling/createMessage).""" try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -4207,12 +4208,12 @@ async def test_truncated_jsonrpc_response_with_nested_method_skips_lock( try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(owner_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object(session_manager_stateful, "handle_request", side_effect=handle), @@ -4265,14 +4266,14 @@ async def test_mcp_routing_with_conflicting_alias_and_group_name(): conflicts with an access group name (e.g., "group"). """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_mcp_servers_in_path, _get_tools_from_mcp_servers, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4310,15 +4311,15 @@ async def test_mcp_routing_with_conflicting_alias_and_group_name(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", mock_get_allowed, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.get_mcp_servers_from_access_groups", + "litellm.proxy.mcp_server.server.MCPRequestHandler.get_mcp_servers_from_access_groups", mock_db_lookup, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_tools_from_server", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_tools_from_server", mock_get_tools_spy, ), ): @@ -4346,14 +4347,14 @@ async def test_oauth2_caller_headers_not_forwarded_for_migrated_server(): caller's oauth2 Authorization to the MCP client — the resolver injects the stored per-user token, so a caller-supplied bearer cannot override another user's credential.""" try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: @@ -4427,16 +4428,16 @@ async def test_oauth2_caller_headers_not_forwarded_for_migrated_server(): side_effect=mock_fetch_tools_with_timeout, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[oauth2_server]), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prefetch_oauth_creds_for_user", + "litellm.proxy.mcp_server.operations._prefetch_oauth_creds_for_user", new_callable=AsyncMock, return_value={}, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new_callable=AsyncMock, return_value=None, ), @@ -4469,7 +4470,7 @@ async def test_oauth2_caller_headers_not_forwarded_for_migrated_server(): async def test_list_tools_single_server_unprefixed_names(): """When only one MCP server is allowed, list tools should return prefixed names (server prefix is always added).""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -4518,7 +4519,7 @@ async def test_list_tools_single_server_unprefixed_names(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -4537,7 +4538,7 @@ async def test_list_tools_single_server_unprefixed_names(): async def test_list_tools_multiple_servers_prefixed_names(): """When multiple MCP servers are allowed, list tools should return prefixed names.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -4597,7 +4598,7 @@ async def test_list_tools_multiple_servers_prefixed_names(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -4615,10 +4616,10 @@ async def test_list_tools_multiple_servers_prefixed_names(): @pytest.mark.asyncio async def test_mcp_manager_allows_public_servers_without_permissions(): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4638,7 +4639,7 @@ async def test_mcp_manager_allows_public_servers_without_permissions(): return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=[]), ), ): @@ -4650,10 +4651,10 @@ async def test_mcp_manager_allows_public_servers_without_permissions(): @pytest.mark.asyncio async def test_mcp_manager_returns_public_when_permission_lookup_fails(): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4673,7 +4674,7 @@ async def test_mcp_manager_returns_public_when_permission_lookup_fails(): return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(side_effect=Exception("boom")), ), ): @@ -4685,11 +4686,11 @@ async def test_mcp_manager_returns_public_when_permission_lookup_fails(): @pytest.mark.asyncio async def test_mcp_manager_merges_public_and_restricted_servers(): try: - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPServerAccess + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -4717,7 +4718,7 @@ async def test_mcp_manager_merges_public_and_restricted_servers(): return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCPRequestHandler.get_mcp_server_access", + "litellm.proxy.mcp_server.mcp_server_manager.MCPRequestHandler.get_mcp_server_access", AsyncMock(return_value=MCPServerAccess(server_ids=("restricted",), scope="scoped")), ), ): @@ -4731,8 +4732,8 @@ async def test_call_mcp_tool_user_unauthorized_access(): """Test that a user cannot call a tool from a server they don't have access to""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool # Create a mock user without access to the server mock_user_auth = UserAPIKeyAuth( @@ -4773,11 +4774,11 @@ async def test_call_mcp_tool_user_unauthorized_access(): with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=["allowed_server", "another_server"]), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", side_effect=mock_get_server_by_id, ), ): @@ -4801,17 +4802,17 @@ async def test_call_mcp_tool_user_unauthorized_access(): @pytest.mark.asyncio async def test_call_mcp_tool_scoped_denial_names_the_binding_agent(): - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool + from litellm.proxy.mcp_server.server import call_mcp_tool agent_bound_key = UserAPIKeyAuth(api_key="test-key", user_id="test-user", agent_id="agent-123") with ( patch( # test-quality-ok: the server registry is a module-level singleton; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_allowed_mcp_servers", AsyncMock(return_value=[]), ), patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", _scope_resolver({"github": "srv-github"}), ), ): @@ -4840,8 +4841,8 @@ async def test_call_mcp_tool_unauthorized_403_does_not_leak_server_credentials() """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp_server.mcp_server_manager import MCPServer mock_user_auth = UserAPIKeyAuth( @@ -4879,11 +4880,11 @@ async def test_call_mcp_tool_unauthorized_403_does_not_leak_server_credentials() with ( patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=["allowed_server"]), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_id", side_effect=mock_get_server_by_id, ), ): @@ -4947,11 +4948,11 @@ def test_mcpserver_repr_and_str_mask_credentials(): async def test_list_tools_filters_by_key_team_permissions(): """Test that list_tools filters tools based on key/team mcp_tool_permissions""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5026,7 +5027,7 @@ async def test_list_tools_filters_by_key_team_permissions(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -5046,14 +5047,14 @@ async def test_list_tools_filters_by_key_team_permissions(): async def test_list_tools_with_team_tool_permissions_inheritance(): """Test that list_tools correctly applies key/team tool permissions inheritance logic""" try: - from litellm.proxy._experimental.mcp_server.server import ( - _get_tools_from_mcp_servers, - set_auth_context, - ) from litellm.proxy._types import ( LiteLLM_ObjectPermissionTable, UserAPIKeyAuth, ) + from litellm.proxy.mcp_server.server import ( + _get_tools_from_mcp_servers, + set_auth_context, + ) except ImportError: pytest.skip("MCP server not available") @@ -5137,12 +5138,12 @@ async def test_list_tools_with_team_tool_permissions_inheritance(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): # Mock the team object permission retrieval with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_team_object_permission", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler._get_team_object_permission", AsyncMock(return_value=team_object_permission), ): listing = await _get_tools_from_mcp_servers( @@ -5162,11 +5163,11 @@ async def test_list_tools_with_team_tool_permissions_inheritance(): async def test_list_tools_with_no_tool_permissions_shows_all(): """Test that list_tools shows all tools when no mcp_tool_permissions are set""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5229,7 +5230,7 @@ async def test_list_tools_with_no_tool_permissions_shows_all(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -5255,11 +5256,11 @@ async def test_list_tools_strips_prefix_when_matching_permissions(): The filtering should strip the prefix before comparing. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) - from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5335,7 +5336,7 @@ async def test_list_tools_strips_prefix_when_matching_permissions(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -5359,7 +5360,7 @@ def test_filter_tools_by_allowed_tools(): """Test that filter_tools_by_allowed_tools filters tools correctly""" from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp import MCPTransport @@ -5431,7 +5432,7 @@ def test_filter_tools_by_allowed_tools(): def test_apply_display_name_overrides_leaves_descriptions_to_the_catalog_guard(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import apply_display_name_overrides + from litellm.proxy.mcp_server.server import apply_display_name_overrides from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5472,7 +5473,7 @@ def test_apply_display_name_overrides_leaves_descriptions_to_the_catalog_guard() def test_apply_display_name_overrides_no_overrides(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import apply_display_name_overrides + from litellm.proxy.mcp_server.server import apply_display_name_overrides from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -5514,7 +5515,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_reuses_existing_server_when_updated_at_matches(self): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5551,7 +5552,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_rebuilds_server_when_updated_at_changes(self): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5599,7 +5600,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_skips_server_when_build_from_database_fails(self, caplog): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5660,7 +5661,7 @@ class TestMCPServerManagerReload: @pytest.mark.asyncio async def test_skips_server_when_openapi_registration_fails(self, caplog): try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) except ImportError: @@ -5744,11 +5745,11 @@ async def test_call_mcp_tool_logs_failure_via_post_call_failure_hook(): Ensure proxy-side `call_mcp_tool` logs failures via `proxy_logging_obj.post_call_failure_hook`. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport, UserAPIKeyAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -5781,12 +5782,12 @@ async def test_call_mcp_tool_logs_failure_via_post_call_failure_hook(): return_value=mock_server, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new_callable=AsyncMock, return_value=[mock_server], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, side_effect=Exception("boom"), ), @@ -5816,10 +5817,10 @@ async def test_get_tools_from_mcp_servers_logs_list_tools_to_spendlogs_when_enab try: from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -5850,26 +5851,26 @@ async def test_get_tools_from_mcp_servers_logs_list_tools_to_spendlogs_when_enab with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server_a]), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), patch( - "litellm.proxy._experimental.mcp_server.operations.function_setup", + "litellm.proxy.mcp_server.operations.function_setup", side_effect=_capture_function_setup, ), ): @@ -5928,21 +5929,21 @@ async def test_get_tools_from_mcp_servers_all_failed_listing_never_runs_proxy_fa with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=servers), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), - patch("litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", manager), - patch("litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", return_value=[]), + patch("litellm.proxy.mcp_server.operations.global_mcp_server_manager", manager), + patch("litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", return_value=[]), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(return_value=[]), ), patch( - "litellm.proxy._experimental.mcp_server.operations.function_setup", + "litellm.proxy.mcp_server.operations.function_setup", return_value=(logging_obj, None), ), patch("litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging_obj), @@ -5974,10 +5975,10 @@ async def test_get_tools_from_mcp_servers_returns_tools_when_success_logging_fai async_success_handler raises (e.g. serialization errors in logging path). """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth except ImportError: pytest.skip("MCP server not available") @@ -6002,26 +6003,26 @@ async def test_get_tools_from_mcp_servers_returns_tools_when_success_logging_fai with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server_a]), ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), patch( - "litellm.proxy._experimental.mcp_server.operations.function_setup", + "litellm.proxy.mcp_server.operations.function_setup", return_value=(dummy_logging_obj, None), ), ): @@ -6051,7 +6052,7 @@ def test_tool_name_matches_case_insensitive(): Without case-insensitive matching, all tools would be filtered out. """ try: - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.server import _tool_name_matches except ImportError: pytest.skip("MCP server not available") @@ -6095,7 +6096,7 @@ def test_filter_tools_by_allowed_tools_case_insensitive(): camelCase allowed_tools configuration from the OpenAPI spec. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp_server.tool_registry import MCPTool @@ -6158,7 +6159,7 @@ def test_filter_tools_by_allowed_tools_case_insensitive(): def test_filter_tools_by_allowed_tools_no_filter(): """Test that filter_tools_by_allowed_tools returns all tools when no filter is set.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp_server.tool_registry import MCPTool @@ -6201,7 +6202,7 @@ def test_filter_tools_by_allowed_tools_no_filter(): def test_filter_tools_enforced_empty_allowlist_blocks_all(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp import MCPTransport @@ -6231,7 +6232,7 @@ def test_filter_tools_enforced_empty_allowlist_blocks_all(): def test_filter_tools_legacy_empty_allowlist_allows_all(): from mcp.types import Tool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) from litellm.types.mcp import MCPTransport @@ -6259,7 +6260,7 @@ def test_filter_tools_legacy_empty_allowlist_allows_all(): def test_check_allowed_or_banned_tools_enforced_empty_denies_calls(): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPTransport @@ -6292,10 +6293,10 @@ async def test_get_tools_from_mcp_servers_injects_stored_oauth2_token(): API because the stored credential was never injected. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.types.mcp import MCPAuth except ImportError: pytest.skip("MCP server not available") @@ -6322,23 +6323,23 @@ async def test_get_tools_from_mcp_servers_injects_stored_oauth2_token(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[oauth2_server]), ), patch( # Patch the bulk prefetch so no real DB connection is needed - "litellm.proxy._experimental.mcp_server.operations._prefetch_oauth_creds_for_user", + "litellm.proxy.mcp_server.operations._prefetch_oauth_creds_for_user", new=AsyncMock(return_value=prefetched_creds), ) as mock_prefetch, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), ): @@ -6395,7 +6396,7 @@ class TestMergeGatewayInitializeInstructions: def _merge(self, servers): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _merge_gateway_initialize_instructions, ) except ImportError: @@ -6418,7 +6419,7 @@ class TestMergeGatewayInitializeInstructions: def test_yaml_override_beats_upstream_cache(self): """YAML/DB instructions take precedence over upstream cache.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6431,7 +6432,7 @@ class TestMergeGatewayInitializeInstructions: def test_upstream_cache_used_when_no_yaml(self): """Upstream cached instructions are used when no YAML override is set.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6471,7 +6472,7 @@ class TestMergeGatewayInitializeInstructions: def test_mixed_yaml_cache_specpath(self): """YAML, upstream-cache, and spec_path servers are handled correctly together.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6493,7 +6494,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_skips_when_yaml_instructions_set(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6506,7 +6507,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_skips_when_already_cached(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6523,7 +6524,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_skips_when_spec_path_set(self): from unittest.mock import AsyncMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6536,7 +6537,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: async def test_runs_upstream_session_and_caches(self): from unittest.mock import AsyncMock, MagicMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6565,7 +6566,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: """Upstream returns no instructions → next call within cooldown must not reconnect.""" from unittest.mock import AsyncMock, MagicMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6590,7 +6591,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: """run_with_session raises → cooldown applies, no immediate retry.""" from unittest.mock import AsyncMock, MagicMock, patch - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6613,7 +6614,7 @@ class TestEnsureUpstreamInitializeInstructionsCached: @pytest.mark.asyncio async def test_reload_resets_probe_cooldown(self): """load_servers_from_config clears the negative-cache map so reloads re-probe.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -6631,11 +6632,11 @@ class TestGatewayCreateInitializationOptions: def test_no_contextvar_returns_default_options(self): """When ContextVar is None, instructions are absent.""" try: - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_gateway_initialize_instructions, mcp_gateway_server_name, ) - from litellm.proxy._experimental.mcp_server.server import server + from litellm.proxy.mcp_server.server import server except ImportError: pytest.skip("MCP server not available") @@ -6652,7 +6653,7 @@ class TestGatewayCreateInitializationOptions: @pytest.mark.asyncio async def test_scoped_request_uses_configured_server_alias(self): try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, global_mcp_server_manager, server, @@ -6670,7 +6671,7 @@ class TestGatewayCreateInitializationOptions: with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[scoped_server], ), @@ -6694,13 +6695,13 @@ class TestGatewayCreateInitializationOptions: async def test_initialize_with_no_granted_servers_returns_403(self): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, ) - from litellm.proxy._types import UserAPIKeyAuth with patch( # test-quality-ok: grant resolution is the input under test - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ): @@ -6720,13 +6721,13 @@ class TestGatewayCreateInitializationOptions: async def test_initialize_with_no_granted_scoped_servers_returns_scoped_denial(self): from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, ) - from litellm.proxy._types import UserAPIKeyAuth with patch( # test-quality-ok: grant resolution is the input under test - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ): @@ -6744,14 +6745,14 @@ class TestGatewayCreateInitializationOptions: @pytest.mark.asyncio async def test_non_initialize_request_with_no_granted_servers_is_not_rejected_here(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _gateway_initialize_instructions_request_scope, mcp_gateway_initialize_instructions, ) - from litellm.proxy._types import UserAPIKeyAuth with patch( # test-quality-ok: grant resolution is the input under test - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ): @@ -6765,8 +6766,8 @@ class TestGatewayCreateInitializationOptions: @pytest.mark.asyncio async def test_sse_handler_scopes_server_name_from_single_server_path(self): try: - from litellm.proxy._experimental.mcp_server import server as mcp_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.server import ( global_mcp_server_manager, handle_sse_mcp, server, @@ -6807,7 +6808,7 @@ class TestGatewayCreateInitializationOptions: with ( patch.object(mcp_server.sse, "connect_sse", connect_sse), patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( UserAPIKeyAuth(api_key="sk-test"), @@ -6819,7 +6820,7 @@ class TestGatewayCreateInitializationOptions: ), ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[scoped_server], ), @@ -6829,15 +6830,15 @@ class TestGatewayCreateInitializationOptions: new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -6854,10 +6855,10 @@ class TestGatewayCreateInitializationOptions: def test_contextvar_set_injects_instructions(self): """When ContextVar has a value, it appears in InitializationOptions.""" try: - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_gateway_initialize_instructions, ) - from litellm.proxy._experimental.mcp_server.server import server + from litellm.proxy.mcp_server.server import server except ImportError: pytest.skip("MCP server not available") @@ -6871,10 +6872,10 @@ class TestGatewayCreateInitializationOptions: def test_contextvar_reset_removes_instructions(self): """After resetting the ContextVar, instructions disappear.""" try: - from litellm.proxy._experimental.mcp_server.mcp_context import ( + from litellm.proxy.mcp_server.mcp_context import ( mcp_gateway_initialize_instructions, ) - from litellm.proxy._experimental.mcp_server.server import server + from litellm.proxy.mcp_server.server import server except ImportError: pytest.skip("MCP server not available") @@ -6894,10 +6895,10 @@ async def test_list_tools_with_legacy_db_m2m_server_resolves_oauth2_flow(): Authorization header is forwarded upstream instead of being blocked. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, ) - from litellm.proxy._types import UserAPIKeyAuth from litellm.types.mcp import MCPAuth except ImportError: pytest.skip("MCP server not available") @@ -6954,14 +6955,14 @@ async def test_list_tools_with_legacy_db_m2m_server_resolves_oauth2_flow(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_allowed_tools", + "litellm.proxy.mcp_server.operations.filter_tools_by_allowed_tools", side_effect=lambda tools, _server: tools, ), patch( - "litellm.proxy._experimental.mcp_server.operations.filter_tools_by_key_team_permissions", + "litellm.proxy.mcp_server.operations.filter_tools_by_key_team_permissions", new=AsyncMock(side_effect=lambda tools, **_: tools), ), ): @@ -6998,7 +6999,7 @@ async def test_call_tool_empty_extra_headers_returns_none(): differently if an empty dict is passed instead. """ try: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp import MCPAuth @@ -7073,7 +7074,7 @@ async def test_call_tool_empty_extra_headers_returns_none(): @pytest.mark.asyncio async def test_probe_upstream_auth_returns_upstream_status(): """_probe_upstream_auth forwards the status code from the upstream server.""" - from litellm.proxy._experimental.mcp_server.server import _probe_upstream_auth + from litellm.proxy.mcp_server.server import _probe_upstream_auth mock_response = MagicMock() mock_response.status_code = 401 @@ -7083,7 +7084,7 @@ async def test_probe_upstream_auth_returns_upstream_status(): mock_client.post = AsyncMock(return_value=mock_response) with patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=mock_client, ): status, www_auth = await _probe_upstream_auth("http://upstream/mcp", "Bearer some-token") @@ -7106,7 +7107,7 @@ async def test_probe_upstream_auth_surfaces_httpx_status_error(): fail-open `except Exception`) so the auth check is not silently defeated. """ - from litellm.proxy._experimental.mcp_server.server import _probe_upstream_auth + from litellm.proxy.mcp_server.server import _probe_upstream_auth mock_response = MagicMock() mock_response.status_code = 401 @@ -7118,7 +7119,7 @@ async def test_probe_upstream_auth_surfaces_httpx_status_error(): mock_client.post = AsyncMock(side_effect=error) with patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=mock_client, ): status, www_auth = await _probe_upstream_auth("http://upstream/mcp", "Bearer some-token") @@ -7130,13 +7131,13 @@ async def test_probe_upstream_auth_surfaces_httpx_status_error(): @pytest.mark.asyncio async def test_probe_upstream_auth_fails_open_on_network_error(): """_probe_upstream_auth returns (200, None) when the network call fails.""" - from litellm.proxy._experimental.mcp_server.server import _probe_upstream_auth + from litellm.proxy.mcp_server.server import _probe_upstream_auth mock_client = MagicMock() mock_client.post = AsyncMock(side_effect=Exception("connection refused")) with patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=mock_client, ): status, www_auth = await _probe_upstream_auth("http://upstream/mcp", "Bearer some-token") @@ -7147,7 +7148,7 @@ async def test_probe_upstream_auth_fails_open_on_network_error(): def test_get_forwarded_auth_from_scope_extracts_header(): """Returns Authorization value when x-litellm-api-key is also present.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_forwarded_auth_from_scope, ) @@ -7162,7 +7163,7 @@ def test_get_forwarded_auth_from_scope_extracts_header(): def test_get_forwarded_auth_from_scope_returns_none_when_missing(): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_forwarded_auth_from_scope, ) @@ -7177,7 +7178,7 @@ def test_get_forwarded_auth_from_scope_skips_when_no_litellm_key_header(): leak the proxy key, so the helper must return None and the probe must not fire. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_forwarded_auth_from_scope, ) @@ -7223,7 +7224,7 @@ def _patch_delegate_resolver(server: MCPServer, *resolvable_names: str): return server if name in resolvable_names else None return patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", side_effect=_resolve, ) @@ -7231,10 +7232,10 @@ def _patch_delegate_resolver(server: MCPServer, *resolvable_names: str): @pytest.mark.asyncio async def test_legacy_delegate_bare_token_is_not_probed_upstream(): # test-quality-ok: this removed security-sensitive egress has no return value; non-invocation is the contract """A bare bearer is an admission credential and must never reach upstream.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server() scope = _delegate_scope([(b"authorization", b"Bearer bogus-token")]) @@ -7242,11 +7243,11 @@ async def test_legacy_delegate_bare_token_is_not_probed_upstream(): # test-qual with ( _patch_delegate_resolver(server, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, 'Bearer realm="upstream", error="invalid_token"')), ) as probe, ): @@ -7266,10 +7267,10 @@ async def test_legacy_delegate_bare_token_is_not_probed_upstream(): # test-qual @pytest.mark.asyncio async def test_legacy_delegate_dual_credentials_are_not_probed_upstream(): # test-quality-ok: this removed security-sensitive egress has no return value; non-invocation is the contract """A separate upstream bearer never triggers the removed legacy probe.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server() scope = _delegate_scope( @@ -7281,11 +7282,11 @@ async def test_legacy_delegate_dual_credentials_are_not_probed_upstream(): # te with ( patch( # test-quality-ok: isolate authorized-server resolution so this test targets the preflight boundary - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( # test-quality-ok: the removed probe call is the security regression under test - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(), ) as probe, ): @@ -7308,10 +7309,10 @@ async def test_legacy_delegate_dual_credentials_are_not_probed_upstream(): # te ) @pytest.mark.asyncio async def test_oauth_passthrough_preflight_preserves_status_contract(probe_status, expected_status): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id="passthrough-id", @@ -7331,11 +7332,11 @@ async def test_oauth_passthrough_preflight_preserves_status_contract(probe_statu with ( patch( # test-quality-ok: isolate authorized-server resolution so this test exercises the preflight contract - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( # test-quality-ok: the upstream transport boundary is the behavior being mapped to an HTTP response - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(probe_status, None)), ) as probe, ): @@ -7372,10 +7373,10 @@ async def test_oauth_passthrough_preflight_preserves_status_contract(probe_statu async def test_delegate_tokenless_request_not_probed(): """Tokenless delegate requests are the preemptive challenge's job; the preflight must not probe upstream with an empty credential.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server() scope = _delegate_scope([(b"content-type", b"application/json")]) @@ -7383,11 +7384,11 @@ async def test_delegate_tokenless_request_not_probed(): with ( _patch_delegate_resolver(server, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7408,10 +7409,10 @@ async def test_delegate_tokenless_request_not_probed(): async def test_delegate_preflight_skipped_on_multi_server_routes(): """The delegate probe is gated to single-server routes so one rejected token cannot 401 a multi-server aggregate connect (matching the OBO preflight).""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth servers = [_delegate_auth_mcp_server("delegate-1"), _delegate_auth_mcp_server("delegate-2")] scope = _delegate_scope([(b"authorization", b"Bearer bogus-token")]) @@ -7419,11 +7420,11 @@ async def test_delegate_preflight_skipped_on_multi_server_routes(): with ( _patch_delegate_resolver(servers[0], "delegate_test", "other_server"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=servers), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7446,10 +7447,10 @@ async def test_bare_authorization_never_probes_passthrough_servers(): only delegate servers (where admission classified it as an upstream token) may be probed with it; ``is_oauth_passthrough`` servers still require the unambiguous ``x-litellm-api-key`` + ``Authorization`` pair.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth passthrough_server = MCPServer( server_id="pt-1", @@ -7465,11 +7466,11 @@ async def test_bare_authorization_never_probes_passthrough_servers(): with ( _patch_delegate_resolver(passthrough_server, "pt_server"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[passthrough_server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7494,10 +7495,10 @@ async def test_delegate_not_probed_when_named_only_via_server_id(): so the bare ``Authorization`` header is that LiteLLM key. The probe must resolve the target through the SAME resolver and therefore skip it, never forwarding the key upstream, even though the widened allowed-server set still contains it.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth server = _delegate_auth_mcp_server(server_id="delegate-secret-id") # Admission's resolver matches alias/server_name/name only, never server_id: the @@ -7514,11 +7515,11 @@ async def test_delegate_not_probed_when_named_only_via_server_id(): with ( _patch_delegate_resolver(server, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[server]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7540,21 +7541,21 @@ async def test_delegate_probe_not_fanned_out_to_access_group_members(): """A single access-group name passes the one-target route gate but must not fan the delegate probe out to group-expanded member servers; the group name resolves to no server under admission's resolver, so no probe fires.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import ( _check_passthrough_upstream_auth, ) - from litellm.proxy._types import UserAPIKeyAuth group_member = _delegate_auth_mcp_server() with ( _patch_delegate_resolver(group_member, "delegate_test"), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(return_value=[group_member]), ), patch( - "litellm.proxy._experimental.mcp_server.server._probe_upstream_auth", + "litellm.proxy.mcp_server.server._probe_upstream_auth", new=AsyncMock(return_value=(401, None)), ) as probe, ): @@ -7574,7 +7575,7 @@ async def test_delegate_probe_not_fanned_out_to_access_group_members(): @pytest.mark.asyncio async def test_create_mcp_client_sampling_disabled_by_default(): """Sampling callback must be None when allow_sampling is not set (default False).""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -7593,7 +7594,7 @@ async def test_create_mcp_client_sampling_disabled_by_default(): @pytest.mark.asyncio async def test_create_mcp_client_sampling_enabled(): """Sampling callback must be set when allow_sampling=True.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -7615,7 +7616,7 @@ async def test_execute_mcp_tool_rest_server_id_authoritative_for_unprefixed_tool """REST server_id + unprefixed tool name must not use global tool-name mapping.""" from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -7712,7 +7713,7 @@ def _worker_that_never_listed(server: MCPServer, upstream_tools: tuple[str, ...] tools/list with ``upstream_tools`` and a managed dispatch that records what reaches it.""" from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module mcp_operations.global_mcp_server_manager.registry[server.server_id] = server dispatched: dict[str, object] = {} @@ -7746,7 +7747,7 @@ def _worker_that_never_listed(server: MCPServer, upstream_tools: tuple[str, ...] async def test_execute_mcp_tool_lists_never_listed_passthrough_server_with_caller_token_first(): """A prefixed tools/call on a worker that has not served tools/list must list that server once with the caller's own credentials and then dispatch, instead of answering 404.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add",)) as worker: @@ -7767,7 +7768,7 @@ async def test_execute_mcp_tool_lists_never_listed_passthrough_server_with_calle @pytest.mark.asyncio async def test_execute_mcp_tool_rest_server_id_lists_never_listed_server_first(): - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add",)) as worker: @@ -7787,7 +7788,7 @@ async def test_execute_mcp_tool_rest_server_id_lists_never_listed_server_first() @pytest.mark.asyncio async def test_execute_mcp_tool_unknown_tool_on_never_listed_server_lists_once_then_404s(): - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with ( @@ -7811,7 +7812,7 @@ async def test_execute_mcp_tool_unknown_tool_on_never_listed_server_lists_once_t async def test_execute_mcp_tool_does_not_relist_a_server_this_worker_already_listed(): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add",)) as worker: @@ -7834,7 +7835,7 @@ async def test_execute_mcp_tool_lists_a_tool_this_worker_has_not_yet_seen_on_a_l for a different tool it has not cached, so callers with wider upstream catalogs are not 404ed.""" from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() with _worker_that_never_listed(server, upstream_tools=("add", "multiply")) as worker: @@ -7854,7 +7855,7 @@ async def test_execute_mcp_tool_lists_a_tool_this_worker_has_not_yet_seen_on_a_l @pytest.mark.asyncio async def test_execute_mcp_tool_never_lists_a_server_the_caller_cannot_access(): - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server = _never_listed_passthrough_server() other_server = MCPServer(server_id="other-1", name="other", transport=MCPTransport.http) @@ -7885,7 +7886,7 @@ async def test_execute_mcp_tool_strips_a_prefix_that_contains_the_separator(): """ from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server_id = "117c814c-1a2b-4c4d-8e8f-0a1b2c3d4e5f" alias_less_server = MCPServer( @@ -7944,7 +7945,7 @@ async def test_execute_mcp_tool_rest_server_id_injects_requested_server_credenti """REST server_id must inject the requested server's auth, not a URL-collision peer's.""" from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module requested_server = MCPServer( server_id="requested-server-id", @@ -8028,7 +8029,7 @@ async def test_execute_mcp_tool_rest_server_id_injects_requested_server_credenti @pytest.mark.asyncio async def test_execute_mcp_tool_rest_prefixed_tool_still_validates_server_id(): """Prefixed REST tool names must still match the requested server_id.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -8092,7 +8093,7 @@ async def test_execute_mcp_tool_rest_prefixed_tool_still_validates_server_id(): @pytest.mark.asyncio async def test_execute_mcp_tool_rest_unauthorized_prefix_still_mismatches(): """Prefixed name for a registry server the caller cannot access must 403.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -8156,7 +8157,7 @@ async def test_execute_mcp_tool_rest_hyphenated_upstream_tool_name_routes_to_req """REST server_id + hyphenated upstream tool name (no registry prefix) must route, not 400.""" from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module api_key_server = MCPServer( server_id="api-key-server-id", @@ -8227,8 +8228,8 @@ async def test_execute_mcp_tool_sets_model_in_model_call_details(): import uuid from datetime import timezone - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server import server as mcp_module from litellm.utils import Rules, function_setup user = UserAPIKeyAuth( @@ -8282,11 +8283,11 @@ async def test_execute_mcp_tool_sets_model_in_model_call_details(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=AsyncMock(return_value=CallToolResult(content=[], is_error=False)), ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -8309,7 +8310,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_the_listed_entry_and_nothing only, as before this metadata existed, so a pre_mcp_call policy never scans a description the caller was not served. Once the caller has listed, the same call hands the entry that listing served.""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module from litellm.proxy.utils import ProxyLogging petstore = MCPServer( @@ -8369,7 +8370,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_the_listed_entry_and_nothing async def test_execute_mcp_tool_hands_openapi_hooks_the_guarded_catalog_entry_clients_saw(): """When tools/list pinned the schema and masked the description of an OpenAPI tool, the local-registry call path must hand the pre-call hooks that served entry, not the raw registry one.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8423,7 +8424,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_the_guarded_catalog_entry_cl async def test_execute_mcp_tool_hands_openapi_hooks_each_callers_own_listed_entry(): """Two keys can be shown differently guarded OpenAPI catalogs. The call path must evaluate each key against the entry its own tools/list served, not the entry the most recent listing left behind.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8479,7 +8480,7 @@ async def test_execute_mcp_tool_hands_openapi_hooks_each_callers_own_listed_entr async def test_execute_mcp_tool_runs_the_longer_colliding_operation_and_hands_hooks_no_registry_metadata(): """An OpenAPI operation whose name starts with its own server prefix runs instead of the shorter one, and with no prior listing the pre-call hooks get name and arguments only, never either registry entry.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8523,7 +8524,7 @@ async def test_execute_mcp_tool_runs_the_longer_colliding_operation_and_hands_ho async def test_execute_mcp_tool_hands_hooks_nothing_for_a_never_listed_operation_named_after_a_listed_one(): """After the caller listed ``get_pet``, a call to the never-listed ``petstore-get_pet`` operation hands the pre-call hooks name and arguments only, not the listed sibling's description and schema.""" - from litellm.proxy._experimental.mcp_server import operations as mcp_module + from litellm.proxy.mcp_server import operations as mcp_module petstore = MCPServer( server_id="petstore-id", @@ -8613,7 +8614,7 @@ async def test_fetch_pinnable_tool_catalog_records_no_listed_catalog_for_the_adm """The pin snapshot lists the raw upstream catalog, without the catalog guard or the admin's description overrides, so it must not become what the admin's own later tools/call is evaluated against.""" from litellm.caching.caching import DualCache - from litellm.proxy._experimental.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog + from litellm.proxy.mcp_server.rest_endpoints import fetch_pinnable_tool_catalog from litellm.proxy.utils import ProxyLogging manager = mcp_operations.global_mcp_server_manager @@ -8656,7 +8657,7 @@ async def test_execute_mcp_tool_rest_unresolved_prefixed_name_routes_to_requeste """ from mcp.types import TextContent - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module requested_server = MCPServer( server_id="rest-target-id", @@ -8740,7 +8741,7 @@ async def test_execute_mcp_tool_rest_unresolved_prefixed_name_routes_to_requeste @pytest.mark.asyncio async def test_execute_mcp_tool_rest_prefix_retry_resolution_still_enforces_server_id(): """A managed tool resolved via the requested server's prefix must still honor the server_id guard.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module requested_server = MCPServer( server_id="api-key-server-id", @@ -8832,7 +8833,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_unknown_name_fails_ NOT silently fall back to the caller's full allowed-server set. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8844,7 +8845,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_unknown_name_fails_ ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], @@ -8865,7 +8866,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_none_returns_all(): path that the fail-closed fix must not break. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8891,7 +8892,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_known_alias_returns server. Guards against the fix accidentally narrowing the happy path. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8903,7 +8904,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_known_alias_returns ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], @@ -8924,7 +8925,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_mixed_known_and_unk when NOTHING resolves. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8936,7 +8937,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_mixed_known_and_unk ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=[], @@ -8957,7 +8958,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_access_group_resolv as unresolved). """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -8969,7 +8970,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_access_group_resolv ] with patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups", new_callable=AsyncMock, return_value=["id-b"], @@ -8989,7 +8990,7 @@ async def test_get_allowed_mcp_servers_from_mcp_server_names_empty_list_fails_cl explicit filter request. Fail closed rather than returning everything. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_allowed_mcp_servers_from_mcp_server_names, ) except ImportError: @@ -9017,10 +9018,10 @@ class TestProxyExceptionToHttpException: """ def test_preserves_401_status_and_www_authenticate_header(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server.server import ( _proxy_exception_to_http_exception, ) - from litellm.proxy._types import ProxyException exc = ProxyException( message="Authentication Error, invalid token", @@ -9037,10 +9038,10 @@ class TestProxyExceptionToHttpException: assert http_exc.headers["WWW-Authenticate"] == 'Bearer resource_metadata="/x"' def test_preserves_403_status(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server.server import ( _proxy_exception_to_http_exception, ) - from litellm.proxy._types import ProxyException http_exc = _proxy_exception_to_http_exception( ProxyException(message="Forbidden", type="auth_error", param="key", code=403) @@ -9049,10 +9050,10 @@ class TestProxyExceptionToHttpException: assert http_exc.status_code == 403 def test_non_numeric_code_falls_back_to_500(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server.server import ( _proxy_exception_to_http_exception, ) - from litellm.proxy._types import ProxyException # ProxyException normalises code to the string "None" when unset. http_exc = _proxy_exception_to_http_exception( @@ -9070,8 +9071,8 @@ class TestStreamableHttpAuthErrorMapping: @pytest.mark.asyncio async def test_streamable_http_propagates_proxy_exception_as_401(self): - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server import server as mcp_module scope = { "type": "http", @@ -9111,8 +9112,8 @@ class TestStreamableHttpAuthErrorMapping: @pytest.mark.asyncio async def test_sse_propagates_proxy_exception_as_401(self): - from litellm.proxy._experimental.mcp_server import server as mcp_module from litellm.proxy._types import ProxyException + from litellm.proxy.mcp_server import server as mcp_module scope = { "type": "http", @@ -9167,7 +9168,7 @@ class TestMCPMetaTraceCarrier: from mcp.types import CallToolRequestParams - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _mcp_meta_trace_carrier, ) @@ -9195,7 +9196,7 @@ class TestMCPMetaTraceCarrier: from mcp.types import CallToolRequestParams - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _mcp_meta_trace_carrier, ) @@ -9217,15 +9218,15 @@ async def test_stateful_mcp_tool_call_uses_current_requests_otel_destinations(_m reset_request_destinations, set_request_destinations, ) - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _MCP_DESTINATIONS_SCOPE_KEY, mcp_server_tool_call, set_auth_context, ) - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -9271,10 +9272,10 @@ async def test_stateful_mcp_tool_call_uses_current_requests_otel_destinations(_m @pytest.mark.asyncio async def test_get_allowed_mcp_servers_includes_active_servers_submitted_by_user(): """BYOM submitters can see approved servers they submitted without allow_all_keys.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth submitted_server = _make_mcp_server_for_scope_filter("submitted-1", "user_mcp") submitter = UserAPIKeyAuth( @@ -9298,13 +9299,13 @@ async def test_get_allowed_mcp_servers_includes_active_servers_submitted_by_user return_value={"submitted-1": submitted_server}, ), patch( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_allowed_mcp_servers", AsyncMock(return_value=[]), ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), patch( - "litellm.proxy._experimental.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", + "litellm.proxy.mcp_server.db.get_active_submitted_mcp_server_ids_for_user", side_effect=_submitted_ids, ), ): @@ -9317,10 +9318,10 @@ async def test_get_allowed_mcp_servers_includes_active_servers_submitted_by_user @pytest.mark.asyncio async def test_get_active_submitted_mcp_server_ids_for_user_queries_active_rows(): - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy._types import MCPApprovalStatus + from litellm.proxy.mcp_server.db import ( get_active_submitted_mcp_server_ids_for_user, ) - from litellm.proxy._types import MCPApprovalStatus row = MagicMock() row.server_id = "submitted-1" @@ -9341,7 +9342,7 @@ async def test_get_active_submitted_mcp_server_ids_for_user_queries_active_rows( @pytest.mark.asyncio async def test_get_active_submitted_mcp_server_ids_for_user_empty_user_id_skips_db(): - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( get_active_submitted_mcp_server_ids_for_user, ) @@ -9381,7 +9382,7 @@ def _mock_mcp_proxy_logging() -> MagicMock: def test_extract_mcp_tool_result_error_message(): - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( extract_mcp_tool_result_error_message, ) @@ -9404,8 +9405,8 @@ async def test_fire_mcp_tool_call_logging_iserror_logs_failure(): """Regression test: a CallToolResult with is_error=True must go down the failure logging path (async_failure_handler + post_call_failure_hook), never async_success_handler.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPToolResultError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.exceptions import MCPToolResultError + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9443,7 +9444,7 @@ async def test_fire_mcp_tool_call_logging_iserror_logs_failure(): async def test_fire_mcp_tool_call_logging_success_path_unchanged(): """is_error=False must keep today's behavior: success handler fires, no failure logging, no post_call_failure_hook.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9472,7 +9473,7 @@ async def test_fire_mcp_tool_call_logging_success_path_unchanged(): async def test_fire_mcp_tool_call_logging_applies_hook_content(): from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) from litellm.types.mcp import MCPPostCallResponseObject @@ -9530,7 +9531,7 @@ async def test_fire_mcp_tool_call_logging_applies_hook_content(): async def test_fire_mcp_tool_call_logging_iserror_without_auth_skips_failure_hook(): """Without a UserAPIKeyAuth the failure handlers still fire but the proxy post_call_failure_hook (which requires one) is skipped.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9556,7 +9557,7 @@ async def test_fire_mcp_tool_call_logging_strips_credentials_from_failure_hook() """Credential-bearing request_data fields (raw request headers, upstream MCP auth headers, OAuth tokens) must never reach post_call_failure_hook callbacks; non-credential fields must survive untouched.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9622,7 +9623,7 @@ async def test_fire_mcp_tool_call_logging_iserror_builds_failure_payload(monkeyp status='failure' with the tool's error text, so OTel (whose _parse_error keys off status) marks the MCP span ERROR.""" import litellm - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9651,7 +9652,7 @@ async def test_fire_mcp_tool_call_logging_iserror_builds_failure_payload(monkeyp async def test_fire_mcp_tool_call_logging_success_builds_success_payload(monkeypatch): """is_error=False still produces a status='success' payload.""" import litellm - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9688,7 +9689,7 @@ async def test_fire_mcp_tool_call_logging_iserror_emits_otel_error_span(monkeypa from litellm.integrations.otel import OpenTelemetryV2Config from litellm.integrations.otel.logger import OpenTelemetryV2 from litellm.integrations.otel.plumbing import providers - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _fire_mcp_tool_call_logging, ) @@ -9729,8 +9730,8 @@ async def test_call_tool_with_legacy_db_m2m_server_resolves_oauth2_flow(): call path was not). """ try: - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp import MCPAuth except ImportError: pytest.skip("MCP server not available") @@ -9759,14 +9760,14 @@ async def test_call_tool_with_legacy_db_m2m_server_resolves_oauth2_flow(): with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", ) as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", side_effect=capture_execute, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new=AsyncMock(side_effect=lambda mcp_servers, allowed_mcp_servers: allowed_mcp_servers), ), ): @@ -9804,7 +9805,7 @@ def test_redact_mcp_resource_url_strips_credentials(url, expected): """The MCP tool-call log records the upstream resource, so the URL must be redacted to scheme+host+path: userinfo, query string, and fragment (which can carry embedded tokens or secret parameters) must never reach spend-log metadata or logging callbacks.""" - from litellm.proxy._experimental.mcp_server.server import redact_mcp_resource_url + from litellm.proxy.mcp_server.server import redact_mcp_resource_url assert redact_mcp_resource_url(url) == expected @@ -9815,12 +9816,12 @@ async def test_call_mcp_tool_skips_failure_hook_for_upstream_auth_error(): caller-must-reauth signal, not a failed call, so call_mcp_tool must re-raise it WITHOUT firing post_call_failure_hook (which records a failure and can trip LLM exception alerts). The streamable handler downgrades it to an informational isError result afterward.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.server import ( call_mcp_tool, global_mcp_server_manager, ) - from litellm.proxy._types import MCPTransport, UserAPIKeyAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer mock_server = MCPServer( @@ -9844,12 +9845,12 @@ async def test_call_mcp_tool_skips_failure_hook_for_upstream_auth_error(): ), patch.object(global_mcp_server_manager, "get_mcp_server_by_id", return_value=mock_server), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new_callable=AsyncMock, return_value=[mock_server], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, side_effect=MCPUpstreamAuthError(status_code=401, www_authenticate="Bearer", server_name="test_server"), ), @@ -9885,7 +9886,7 @@ def _interim_input_required_result(): @contextlib.contextmanager def _managed_tool_returning(server, upstream_result, proxy_logging_mock): - from litellm.proxy._experimental.mcp_server.server import global_mcp_server_manager + from litellm.proxy.mcp_server.server import global_mcp_server_manager with ( patch.object( @@ -9898,20 +9899,20 @@ def _managed_tool_returning(server, upstream_result, proxy_logging_mock): patch.object(global_mcp_server_manager, "get_mcp_server_from_tool_name", return_value=server), patch.object(global_mcp_server_manager, "server_owning_tool_name_prefix", return_value=server), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers_from_mcp_server_names", new_callable=AsyncMock, return_value=[server], ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_tools_before_first_call", + "litellm.proxy.mcp_server.operations._list_tools_before_first_call", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.operations._prepare_mcp_server_headers", + "litellm.proxy.mcp_server.operations._prepare_mcp_server_headers", return_value=(None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_managed_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_managed_mcp_tool", new_callable=AsyncMock, return_value=upstream_result, ) as managed_call, @@ -9926,12 +9927,12 @@ async def test_call_mcp_tool_legacy_interim_result_is_rejected_into_failure_acco must come back as isError and go through the same failure accounting as any other errored call.""" from mcp.types import CallToolResult - from litellm.proxy._experimental.mcp_server.result_conversion import ( + from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.result_conversion import ( INPUT_REQUIRED_UNSUPPORTED_MESSAGE, WireCompat, ) - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool - from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -9970,9 +9971,9 @@ async def test_call_mcp_tool_modern_interim_result_passes_through_without_comple logged as a completed success nor run through the post-call guardrail and success hooks.""" from mcp.types import InputRequiredResult - from litellm.proxy._experimental.mcp_server.result_conversion import WireCompat - from litellm.proxy._experimental.mcp_server.server import call_mcp_tool from litellm.proxy._types import MCPTransport, UserAPIKeyAuth + from litellm.proxy.mcp_server.result_conversion import WireCompat + from litellm.proxy.mcp_server.server import call_mcp_tool from litellm.types.mcp_server.mcp_server_manager import MCPServer server = MCPServer( @@ -10017,15 +10018,15 @@ async def test_aggregate_listing_reports_per_server_outcomes(): """A failed server must contribute a classified outcome, not just silently shrink the list: without the outcome a broken upstream is indistinguishable from a healthy server with no tools.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) except ImportError: pytest.skip("MCP server not available") - from litellm.proxy._experimental.mcp_server.exceptions import MCPServerListError - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListFault + from litellm.proxy.mcp_server.exceptions import MCPServerListError + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListFault user_api_key_auth = UserAPIKeyAuth(api_key="test_key", user_id="test_user") set_auth_context(user_api_key_auth) @@ -10075,7 +10076,7 @@ async def test_aggregate_listing_reports_per_server_outcomes(): mock_manager.get_tools_from_server = mock_get_tools_from_server with patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ): listing = await _get_tools_from_mcp_servers( @@ -10100,7 +10101,7 @@ async def test_outcome_keys_use_display_prefix_never_canonical_names(): the caller already sees on tool names: keying them by canonical server_name would let any authenticated caller enumerate internal server names the alias scheme deliberately hides.""" try: - from litellm.proxy._experimental.mcp_server.server import _aggregate_server_key + from litellm.proxy.mcp_server.server import _aggregate_server_key except ImportError: pytest.skip("MCP server not available") @@ -10121,13 +10122,13 @@ async def test_handle_list_tools_attaches_outcome_meta(_mcp_request_ctx): """The protocol handler returns a ListToolsResult whose _meta carries the per-server outcomes, so MCP clients can tell a degraded listing from a genuinely empty one.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_list_tools + from litellm.proxy.mcp_server.server import handle_list_tools except ImportError: pytest.skip("MCP server not available") from mcp.types import ListToolsResult, Tool - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10145,11 +10146,11 @@ async def test_handle_list_tools_attaches_outcome_meta(_mcp_request_ctx): with ( patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock(return_value=(None, None, None, None, None, None, None)), ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new=AsyncMock(return_value=listing), ), ): @@ -10168,17 +10169,17 @@ async def _list_tools_with_listing( params: PaginatedRequestParams, ) -> ListToolsResult: try: - from litellm.proxy._experimental.mcp_server.server import handle_list_tools + from litellm.proxy.mcp_server.server import handle_list_tools except ImportError: pytest.skip("MCP server not available") with ( patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new=AsyncMock(return_value=(None, None, None, None, None, None, None)), ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new=AsyncMock(return_value=listing), ), ): @@ -10192,7 +10193,7 @@ async def test_handle_list_tools_errors_when_every_server_failed( from mcp.shared.exceptions import MCPError from mcp.types import INTERNAL_ERROR - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10223,7 +10224,7 @@ async def test_handle_list_tools_auth_fault_keeps_degraded_result( ) -> None: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10248,7 +10249,7 @@ async def test_handle_list_tools_all_faults_on_continuation_stays_degraded( ) -> None: from mcp.types import ListToolsResult, PaginatedRequestParams - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( SERVER_OUTCOMES_META_KEY, AggregateToolListing, ServerListFault, @@ -10275,7 +10276,7 @@ async def test_handle_list_tools_empty_outcomes_is_a_clean_empty_result( ) -> None: from mcp.types import ListToolsResult - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing listing: Final = AggregateToolListing(tools=[], outcomes={}) @@ -10336,7 +10337,7 @@ class TestPreemptive401ModeAware: return {"type": "http", "method": "POST", "path": f"/mcp/{alias}", "headers": []} async def _run(self, server, oauth2_headers, has_stored_token: bool): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module with ( patch.object( @@ -10362,7 +10363,7 @@ class TestPreemptive401ModeAware: @pytest.mark.asyncio async def test_deferred_discovery_runs_before_delegate_challenge(self): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module manager = mcp_operations.global_mcp_server_manager server = _make_oauth2_server( @@ -10394,7 +10395,7 @@ class TestPreemptive401ModeAware: @pytest.mark.asyncio async def test_stamped_m2m_challenge_skips_deferred_discovery(self): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module manager = mcp_operations.global_mcp_server_manager server = _make_oauth2_server("stamped_m2m", oauth2_flow="client_credentials") @@ -10427,7 +10428,7 @@ class TestPreemptive401ModeAware: async def test_gateway_as_metadata_challenge_under_server_root_path(self, original_path, expected_as_path): """Under SERVER_ROOT_PATH the challenge must keep the spelling the client called and point at a route the proxy registered, so it has to compare a route-relative path and carry the root suffix.""" - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module server = _make_oauth2_server("interactive", oauth2_flow="authorization_code") scope = { @@ -10542,7 +10543,7 @@ class TestSingleServerPreflightReachesIdJag: ) async def _run(self, server: MCPServer, mcp_servers: list[str], preflight: AsyncMock) -> None: - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module with ( patch.object( # test-quality-ok: route wiring must use the manager's configured server @@ -10587,7 +10588,7 @@ class TestSingleServerPreflightReachesIdJag: RFC 9728 discovery challenge from the block above and the preflight is never reached; pushing a subject-less exchange through the resolver would turn that challenge into some other status and strand a client that only had to SSO and retry.""" - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module token_exchange = MCPServer( server_id="id-obo", @@ -10666,7 +10667,7 @@ class TestOboPreflightScopedToAllowedServers: SUBJECT_HEADERS = {"Authorization": "Bearer upstream-subject-token"} async def _run(self, requested: MCPServer, allowed: list[MCPServer], user_api_key_auth: UserAPIKeyAuth | None): - from litellm.proxy._experimental.mcp_server import server as server_module + from litellm.proxy.mcp_server import server as server_module allowed_lookup = AsyncMock(return_value=allowed) preflight = AsyncMock() @@ -10720,7 +10721,7 @@ class TestOboPreflightScopedToAllowedServers: @pytest.mark.asyncio async def test_post_mcp_call_guardrails_return_the_rewritten_result(): """The result a post_mcp_call guardrail rewrote must be what the caller sends back.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _run_post_mcp_call_guardrails, ) @@ -10754,7 +10755,7 @@ async def test_post_mcp_call_guardrails_run_without_a_logging_object(): caller that omits it) would otherwise skip the guardrail entirely and return the unscanned tool output to the client. """ - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _run_post_mcp_call_guardrails, ) @@ -10782,7 +10783,7 @@ async def test_post_mcp_call_guardrails_run_without_a_logging_object(): async def test_post_mcp_call_guardrails_propagate_a_block(): """A post_mcp_call guardrail rejection must propagate instead of returning the result.""" from litellm.exceptions import BlockedPiiEntityError - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _run_post_mcp_call_guardrails, ) @@ -10806,8 +10807,8 @@ async def test_post_mcp_call_guardrails_propagate_a_block(): async def test_post_mcp_call_guardrails_preserve_and_deduplicate_mapping_entries( monkeypatch: pytest.MonkeyPatch, ) -> None: - from litellm.proxy._experimental.mcp_server.server import _run_post_mcp_call_guardrails from litellm.proxy import proxy_server + from litellm.proxy.mcp_server.server import _run_post_mcp_call_guardrails monkeypatch.setattr("litellm.proxy.utils.premium_user_check", MagicMock()) monkeypatch.setattr(proxy_server, "premium_user", True, raising=False) @@ -10858,7 +10859,7 @@ class TestListFiltersHonorThePrefixBoundary: @staticmethod def _alias_less_server(**overrides): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServer + from litellm.proxy.mcp_server.mcp_server_manager import MCPServer return MCPServer( server_id=TestListFiltersHonorThePrefixBoundary.SERVER_ID, @@ -10877,7 +10878,7 @@ class TestListFiltersHonorThePrefixBoundary: ] def test_bare_allowlist_entry_keeps_the_published_tool(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) @@ -10889,7 +10890,7 @@ class TestListFiltersHonorThePrefixBoundary: assert [tool.name for tool in kept] == [f"{self.SERVER_ID}-read_wiki_contents"] def test_bare_blocklist_entry_excludes_the_published_tool(self): - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) @@ -10901,7 +10902,7 @@ class TestListFiltersHonorThePrefixBoundary: assert [tool.name for tool in kept] == [f"{self.SERVER_ID}-read_wiki_contents"] def test_unrelated_entry_does_not_match(self): - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.server import _tool_name_matches server = self._alias_less_server() @@ -10912,7 +10913,7 @@ class TestListFiltersHonorThePrefixBoundary: # folding recovers a spec-spelled entry on an OpenAPI server. A native server # gets none of it: routing dispatches two names differing only in case as two # tools, so one policy must not decide both. - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.server import _tool_name_matches native = self._alias_less_server() openapi = self._alias_less_server(spec_path="/specs/petstore.yaml") @@ -10925,8 +10926,8 @@ class TestListFiltersHonorThePrefixBoundary: # Routing accepts the alias form, so an entry stored before short # prefixes were turned on still governs the tool. Matching only the # published spelling left it advertised while dispatch refused it. - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServer - from litellm.proxy._experimental.mcp_server.server import _tool_name_matches + from litellm.proxy.mcp_server.mcp_server_manager import MCPServer + from litellm.proxy.mcp_server.server import _tool_name_matches monkeypatch.setenv("LITELLM_USE_SHORT_MCP_TOOL_PREFIX", "true") server = MCPServer( @@ -10952,11 +10953,11 @@ class TestListFiltersHonorThePrefixBoundary: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServer, MCPServerManager, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_allowed_tools, ) @@ -11017,13 +11018,13 @@ class TestListFiltersHonorThePrefixBoundary: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._types import UserAPIKeyAuth server = MCPServer( server_id=self.SERVER_ID, @@ -11036,7 +11037,7 @@ class TestListFiltersHonorThePrefixBoundary: with ( patch.object(MCPRequestHandler, "get_allowed_tools_for_server", AsyncMock(return_value=grants)), - patch("litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager") as mock_manager, + patch("litellm.proxy.mcp_server.operations.global_mcp_server_manager") as mock_manager, ): mock_manager.get_mcp_server_by_id.return_value = server @@ -11058,7 +11059,7 @@ async def test_list_tools_injects_byok_credential_for_non_oauth2_auth_types(auth """Regression for BYOK servers on a non-oauth2 auth_type: the stored per-user credential must be attached when listing tools, otherwise the upstream 401 is absorbed and the server lists nothing.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _get_tools_from_mcp_servers, set_auth_context, ) @@ -11099,11 +11100,11 @@ async def test_list_tools_injects_byok_credential_for_non_oauth2_auth_types(auth with ( patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", mock_manager, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_byok_credential", + "litellm.proxy.mcp_server.operations._get_byok_credential", AsyncMock(return_value="personal-api-key"), ), ): @@ -11120,7 +11121,7 @@ async def test_list_tools_injects_byok_credential_for_non_oauth2_auth_types(auth @pytest.mark.asyncio async def test_active_request_ctx_var_feeds_get_current_session(_mcp_request_ctx) -> None: - from litellm.proxy._experimental.mcp_server.server import _get_current_session + from litellm.proxy.mcp_server.server import _get_current_session session = SimpleNamespace() ctx = _mcp_request_ctx(session=session) @@ -11171,7 +11172,7 @@ async def test_mcp_origin_admission_precedes_authentication( ) -> None: import httpx - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server authenticate: Final = AsyncMock(side_effect=HTTPException(status_code=401, detail="authentication required")) with ( @@ -11196,12 +11197,12 @@ async def test_mcp_origin_admission_precedes_authentication( async def test_active_request_ctx_var_feeds_auth_resolution_recording(_mcp_request_ctx) -> None: from starlette.requests import Request - from litellm.proxy._experimental.mcp_server.mcp_debug import ( + from litellm.proxy.mcp_server.mcp_debug import ( MCP_AUTH_DIAGNOSTICS_SCOPE_KEY, MCPAuthDiagnostics, record_auth_resolution, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.types import AuthResolution + from litellm.proxy.mcp_server.outbound_credentials.types import AuthResolution diagnostics = MCPAuthDiagnostics() ctx = _mcp_request_ctx(request=Request({"type": "http", MCP_AUTH_DIAGNOSTICS_SCOPE_KEY: diagnostics})) @@ -11228,8 +11229,8 @@ async def test_active_request_ctx_var_feeds_auth_resolution_recording(_mcp_reque async def test_streamable_http_rejects_modern_protocol_version( header_value: str, expected_rejected: bool, handler: str, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.server import unsupported_protocol_version + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.server import unsupported_protocol_version monkeypatch.setattr("litellm.proxy.proxy_server.general_settings", {}) scope: Scope = { @@ -11273,7 +11274,7 @@ async def test_streamable_http_rejects_modern_protocol_version( ], ) async def test_native_listing_preserves_empty_result_on_auth_failure(_mcp_request_ctx, handler_name, field): - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server with patch.object(server, "get_or_extract_auth_context", AsyncMock(side_effect=RuntimeError("auth failure"))): result = await getattr(server, handler_name)(_mcp_request_ctx(), _paged_params()) @@ -11283,8 +11284,8 @@ async def test_native_listing_preserves_empty_result_on_auth_failure(_mcp_reques @pytest.mark.asyncio @pytest.mark.parametrize("failure_hook_raises", [False, True]) async def test_tool_listing_preserves_permission_denial_when_failure_logging_fails(failure_hook_raises): - from litellm.proxy._experimental.mcp_server import operations from litellm.proxy import proxy_server + from litellm.proxy.mcp_server import operations auth = UserAPIKeyAuth(user_id="denied-caller") denial = HTTPException(status_code=403, detail="scope denied") @@ -11320,8 +11321,9 @@ async def test_legacy_sse_mount_emits_message_endpoint( ) -> None: from starlette.applications import Starlette from starlette.routing import Mount - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing - from litellm.proxy._experimental.mcp_server import server as mcp_server + + from litellm.proxy.mcp_server import server as mcp_server + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing app: Final = Starlette(routes=[Mount("/mcp", app=mcp_server.app)]) incoming: Final[asyncio.Queue[Message]] = asyncio.Queue() @@ -11469,7 +11471,7 @@ async def test_legacy_sse_mount_emits_message_endpoint( @pytest.mark.parametrize("revision,rejected", [("2024-11-05", False), ("2025-11-25", True), ("2026-07-28", True)]) def test_protocol_header_respects_configured_advertisement(revision, rejected): from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.server import unsupported_protocol_version + from litellm.proxy.mcp_server.server import unsupported_protocol_version with patch.dict(proxy_server.general_settings, {"mcp_advertised_versions": ["2024-11-05"]}): result = unsupported_protocol_version({"headers": [(b"mcp-protocol-version", revision.encode())]}) @@ -11479,7 +11481,8 @@ def test_protocol_header_respects_configured_advertisement(revision, rejected): @pytest.mark.asyncio async def test_discovery_adapter_preserves_authenticated_context(_mcp_request_ctx): from mcp.types import DiscoverResult, RequestParams, ServerCapabilities - from litellm.proxy._experimental.mcp_server import server + + from litellm.proxy.mcp_server import server expected = DiscoverResult(supported_versions=["2025-11-25"], capabilities=ServerCapabilities()) dispatched = AsyncMock(return_value=expected) @@ -11522,11 +11525,13 @@ async def test_modern_oauth_challenge_follows_continuation_authorization( monkeypatch: pytest.MonkeyPatch, ) -> None: import time - from pydantic import TypeAdapter - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.interactions import InteractionOperation, bind_target, seal_continuation + from mcp.types import InputRequiredResult + from pydantic import TypeAdapter + + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.interactions import InteractionOperation, bind_target, seal_continuation monkeypatch.setenv("LITELLM_SALT_KEY", "challenge-test-salt") monkeypatch.setattr("litellm.proxy.proxy_server.general_settings", {"mcp_advertised_versions": ["2026-07-28"]}) @@ -11674,7 +11679,7 @@ async def test_modern_oauth_challenge_follows_continuation_authorization( async def test_modern_preflight_enforces_sdk_body_limit( method: str, size_delta: int, chunked: bool, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server monkeypatch.setattr("litellm.proxy.proxy_server.general_settings", {"mcp_advertised_versions": ["2026-07-28"]}) limit: Final = server.session_manager_stateless.max_request_body_size @@ -11747,8 +11752,8 @@ async def test_modern_preflight_enforces_sdk_body_limit( async def test_modern_preflight_leaves_invalid_envelopes_to_sdk_without_upstream_work( invalid_request: Literal["malformed", "other_method", "header_mismatch", "duplicate_header"], ) -> None: - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.contracts import OperationContext envelope: Final = { "jsonrpc": "2.0", @@ -11787,9 +11792,10 @@ async def test_modern_preflight_leaves_invalid_envelopes_to_sdk_without_upstream @pytest.mark.parametrize("forwarded_token", (False, True)) async def test_modern_passthrough_probe_uses_scrubbed_server_credential(binding: str, forwarded_token: bool): import respx + from litellm.proxy._types import LiteLLM_ObjectPermissionTable - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.contracts import OperationContext target: Final = MCPServer( server_id="probe-id", @@ -11860,8 +11866,9 @@ async def test_modern_passthrough_probe_uses_scrubbed_server_credential(binding: @pytest.mark.parametrize("header_shape", ("mapping", "non_authorization")) async def test_passthrough_probes_bind_each_token_to_its_authorized_server(allowed: bool, header_shape: str): import respx + from litellm.proxy._types import LiteLLM_ObjectPermissionTable - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server targets: Final = [ MCPServer( @@ -11913,7 +11920,7 @@ async def test_passthrough_probes_bind_each_token_to_its_authorized_server(allow @pytest.mark.asyncio async def test_streamable_http_admission_auth_sees_only_peeked_jsonrpc_method() -> None: from litellm.constants import MCP_PEEKED_BODY_SCOPE_KEY - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module scope: Final[Scope] = {"type": "http", "method": "POST", "path": "/mcp", "headers": []} receive: Final = AsyncMock( @@ -11938,22 +11945,22 @@ async def test_streamable_http_admission_auth_sees_only_peeked_jsonrpc_method() with ( patch( # test-quality-ok: the ASGI handler resolves auth through a module-level function; no injection seam - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, side_effect=extract, ), patch( # test-quality-ok: module flag guarding lazy session-manager startup; no injection seam - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True ), patch( # test-quality-ok: the allowlist is read off this module global; no injection seam "litellm.proxy.proxy_server.general_settings", _ALLOWLIST_SETTINGS ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateful", + "litellm.proxy.mcp_server.server.session_manager_stateful", SimpleNamespace(handle_request=stateful_handle), ), patch( # test-quality-ok: session managers are module singletons; the downstream call is the observable - "litellm.proxy._experimental.mcp_server.server.session_manager_stateless", + "litellm.proxy.mcp_server.server.session_manager_stateless", SimpleNamespace(handle_request=stateless_handle), ), ): @@ -11980,7 +11987,7 @@ async def test_streamable_http_admission_auth_sees_only_peeked_jsonrpc_method() ], ) async def test_stateful_cancellation_does_not_wait_for_call_or_change_its_auth(payload, valid): - from litellm.proxy._experimental.mcp_server import server as mcp_server + from litellm.proxy.mcp_server import server as mcp_server session_id = "cancellation-isolation-session" owner = UserAPIKeyAuth(api_key="owner-key", user_id="owner") @@ -12048,11 +12055,10 @@ async def test_stateful_cancellation_does_not_wait_for_call_or_change_its_auth(p @pytest.mark.parametrize("selected", [False, True]) async def test_progress_text_obeys_request_output_guardrails(monkeypatch, action, message, selected): import litellm - from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.operations import _guarded_progress_callback from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.content_filter import ContentFilterGuardrail + from litellm.proxy.mcp_server.operations import _guarded_progress_callback from litellm.proxy.utils import ProxyLogging from litellm.types.guardrails import BlockedWord, ContentFilterAction, GuardrailEventHooks @@ -12084,7 +12090,7 @@ async def test_progress_text_obeys_request_output_guardrails(monkeypatch, action async def test_progress_callback_preserves_absence_and_cancellation(): import asyncio - from litellm.proxy._experimental.mcp_server.operations import _guarded_progress_callback + from litellm.proxy.mcp_server.operations import _guarded_progress_callback assert _guarded_progress_callback(None, None, None, None, {}) is None callback = _guarded_progress_callback(AsyncMock(side_effect=asyncio.CancelledError), None, None, None, {}) @@ -12098,13 +12104,12 @@ async def test_execute_mcp_tool_derives_team_guardrail_auth_for_personal_keys( monkeypatch: pytest.MonkeyPatch, ) -> None: import litellm - from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix - from litellm.proxy.auth import auth_checks from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable + from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.utils import get_server_prefix from litellm.proxy.utils import ProxyLogging user_api_key_auth: Final = UserAPIKeyAuth(api_key="sk-personal", user_id="owner") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_session_logging.py b/tests/unit/proxy/mcp_server/test_mcp_session_logging.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_session_logging.py rename to tests/unit/proxy/mcp_server/test_mcp_session_logging.py index 790937cc1de..83bd4a29908 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_session_logging.py +++ b/tests/unit/proxy/mcp_server/test_mcp_session_logging.py @@ -1,7 +1,7 @@ """The MCP ``mcp-session-id`` is captured for tool-call logging so the otel span can carry ``mcp.session.id``. Guards the header read against casing and absence.""" -from litellm.proxy._experimental.mcp_server.server import _mcp_session_id_from_headers +from litellm.proxy.mcp_server.server import _mcp_session_id_from_headers def test_reads_session_id_case_insensitively(): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sigv4_auth.py b/tests/unit/proxy/mcp_server/test_mcp_sigv4_auth.py similarity index 93% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_sigv4_auth.py rename to tests/unit/proxy/mcp_server/test_mcp_sigv4_auth.py index 7b9fc17840a..5350e8a9f41 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_sigv4_auth.py +++ b/tests/unit/proxy/mcp_server/test_mcp_sigv4_auth.py @@ -15,7 +15,7 @@ import httpx2 import pytest from prisma import models -from litellm.experimental_mcp_client.client import MCPClient, MCPSigV4Auth +from litellm.mcp_client.client import MCPClient, MCPSigV4Auth from litellm.types.mcp import MCPAuth, MCPTransport _FUTURE_EXPIRATION: Final = datetime.now(timezone.utc) + timedelta(hours=1) @@ -444,7 +444,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_create_mcp_client_with_sigv4(self): """_create_mcp_client creates client with SigV4 auth when auth_type is aws_sigv4.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -471,7 +471,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_create_mcp_client_without_sigv4(self): """_create_mcp_client does not create SigV4 auth for non-SigV4 servers.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -494,7 +494,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_load_config_with_aws_role_name(self): """Config loading correctly parses aws_role_name and aws_session_name.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -519,7 +519,7 @@ class TestMCPServerManagerSigV4: @pytest.mark.asyncio async def test_create_mcp_client_with_role_assumption(self): """_create_mcp_client passes aws_role_name to MCPSigV4Auth.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -555,7 +555,7 @@ class TestMCPServerManagerSigV4: def test_extract_aws_credentials_includes_role_fields(self): """_extract_aws_credentials extracts aws_role_name and aws_session_name.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -577,7 +577,7 @@ class TestSigV4CredentialEncryption: def test_encrypt_credentials_handles_aws_fields(self): """AWS credential fields are encrypted in the credentials dict.""" - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.db import encrypt_credentials creds = { "aws_access_key_id": "AKIAIOSFODNN7EXAMPLE", @@ -588,7 +588,7 @@ class TestSigV4CredentialEncryption: } with patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc:{value}", ): result = encrypt_credentials(credentials=creds, encryption_key="test-key") @@ -603,12 +603,12 @@ class TestSigV4CredentialEncryption: def test_encrypt_credentials_skips_absent_aws_fields(self): """encrypt_credentials does not fail when AWS fields are absent.""" - from litellm.proxy._experimental.mcp_server.db import encrypt_credentials + from litellm.proxy.mcp_server.db import encrypt_credentials creds = {"auth_value": "some-token"} with patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc:{value}", ): result = encrypt_credentials(credentials=creds, encryption_key="test-key") @@ -623,8 +623,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_partial_update_preserves_existing_credentials(self): """Updating only aws_region_name should not wipe aws_secret_access_key.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "aws_sigv4" @@ -648,11 +648,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: value, ), ): @@ -673,8 +673,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_update_without_credentials_preserves_all(self): """Update with no credentials field should not touch existing credentials.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server mock_prisma = MagicMock() mock_prisma.db.litellm_mcpservertable.update = AsyncMock(return_value=_updated_row()) @@ -685,7 +685,7 @@ class TestCredentialMergeOnUpdate: ) with patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ): await update_mcp_server(mock_prisma, data, "test-user") @@ -696,8 +696,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_update_new_server_no_merge(self): """Update with credentials on a server that has no existing credentials.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "aws_sigv4" @@ -715,11 +715,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: value, ), ): @@ -732,8 +732,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_auth_type_change_replaces_credentials_entirely(self): """Switching auth_type should replace credentials, not merge.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "aws_sigv4" @@ -757,11 +757,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc:{value}", ), ): @@ -775,8 +775,8 @@ class TestCredentialMergeOnUpdate: @pytest.mark.asyncio async def test_same_auth_type_merges_credentials(self): """Same auth_type should merge credentials (preserve untouched fields).""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "oauth2" @@ -800,11 +800,11 @@ class TestCredentialMergeOnUpdate: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: value, ), ): @@ -823,7 +823,7 @@ class TestSigV4BuildFromTable: @pytest.mark.asyncio async def test_build_mcp_server_from_table_with_sigv4_credentials(self): """SigV4 credentials from DB are decrypted and mapped to MCPServer fields.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -878,7 +878,7 @@ class TestSigV4BuildFromTable: manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.decrypt_value_helper", + "litellm.proxy.mcp_server.mcp_server_manager.decrypt_value_helper", side_effect=lambda value, key, exception_type, return_original_value: value.replace("enc:", ""), ): server = await manager.build_mcp_server_from_table(table_record) @@ -893,7 +893,7 @@ class TestSigV4BuildFromTable: @pytest.mark.asyncio async def test_build_mcp_server_from_table_without_sigv4_credentials(self): """Non-SigV4 servers still work — AWS fields default to None.""" - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( MCPServerManager, ) @@ -940,7 +940,7 @@ class TestSigV4BuildFromTable: manager = MCPServerManager() with patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.decrypt_value_helper", + "litellm.proxy.mcp_server.mcp_server_manager.decrypt_value_helper", side_effect=lambda value, key, exception_type, return_original_value: value.replace("enc:", ""), ): server = await manager.build_mcp_server_from_table(table_record) @@ -958,7 +958,7 @@ class TestDecryptCredentials: def test_decrypt_credentials_handles_all_secret_fields(self): """All secret fields are decrypted; non-secret fields are left as-is.""" - from litellm.proxy._experimental.mcp_server.db import decrypt_credentials + from litellm.proxy.mcp_server.db import decrypt_credentials creds = { "auth_value": "enc:tok", @@ -972,7 +972,7 @@ class TestDecryptCredentials: } with patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc:", "" ), @@ -991,12 +991,12 @@ class TestDecryptCredentials: def test_decrypt_credentials_skips_absent_fields(self): """Absent fields are not touched.""" - from litellm.proxy._experimental.mcp_server.db import decrypt_credentials + from litellm.proxy.mcp_server.db import decrypt_credentials creds = {"aws_access_key_id": "enc:AKI"} with patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc:", "" ), @@ -1013,7 +1013,7 @@ class TestRotateCredentials: @pytest.mark.asyncio async def test_rotation_decrypts_then_reencrypts(self): """Key rotation should decrypt with old key then encrypt with new key.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( rotate_mcp_server_credentials_master_key, ) @@ -1034,17 +1034,17 @@ class TestRotateCredentials: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value="old-key", ), patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc_old:", "" ), ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc_new:{value}", ), ): @@ -1063,7 +1063,7 @@ class TestRotateCredentials: async def test_rotation_reencrypts_global_env_vars(self): """Global env var values are re-encrypted under the new key; user-scope placeholders are left untouched.""" - from litellm.proxy._experimental.mcp_server.db import ( + from litellm.proxy.mcp_server.db import ( rotate_mcp_server_credentials_master_key, ) @@ -1083,17 +1083,17 @@ class TestRotateCredentials: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value="old-key", ), patch( - "litellm.proxy._experimental.mcp_server.db.decrypt_value_helper", + "litellm.proxy.mcp_server.db.decrypt_value_helper", side_effect=lambda value, key, exception_type="error", return_original_value=False: value.replace( "enc_old:", "" ), ), patch( - "litellm.proxy._experimental.mcp_server.db.encrypt_value_helper", + "litellm.proxy.mcp_server.db.encrypt_value_helper", side_effect=lambda value, new_encryption_key: f"enc_new:{value}", ), ): @@ -1116,8 +1116,8 @@ class TestAuthTypeSwitchClearsCredentials: @pytest.mark.asyncio async def test_auth_type_change_without_credentials_clears_stale(self): """Changing auth_type without providing credentials should clear old ones.""" - from litellm.proxy._experimental.mcp_server.db import update_mcp_server from litellm.proxy._types import UpdateMCPServerRequest + from litellm.proxy.mcp_server.db import update_mcp_server existing_record = MagicMock() existing_record.auth_type = "oauth2" @@ -1134,7 +1134,7 @@ class TestAuthTypeSwitchClearsCredentials: ) with patch( - "litellm.proxy._experimental.mcp_server.db.get_salt_key", + "litellm.proxy.mcp_server.db.get_salt_key", return_value=None, ): await update_mcp_server(mock_prisma, data, "test-user") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_stale_session.py b/tests/unit/proxy/mcp_server/test_mcp_stale_session.py similarity index 84% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_stale_session.py rename to tests/unit/proxy/mcp_server/test_mcp_stale_session.py index 66d853bdd44..88f18b609a4 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_stale_session.py +++ b/tests/unit/proxy/mcp_server/test_mcp_stale_session.py @@ -25,7 +25,7 @@ class TestHandleStaleMcpSession: async def test_strips_stale_session_id_for_non_delete(self): """Non-DELETE requests should have stale session IDs stripped.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -55,7 +55,7 @@ class TestHandleStaleMcpSession: async def test_delete_stale_session_returns_success(self): """DELETE requests for non-existent sessions should return success (idempotent).""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, _stateful_session_active_request_counts, _stateful_session_auth_context_last_seen, @@ -111,7 +111,7 @@ class TestHandleStaleMcpSession: async def test_preserves_valid_session_id(self): """Valid session IDs should not be modified.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -141,7 +141,7 @@ class TestHandleStaleMcpSession: async def test_no_op_when_no_session_header(self): """No session header should result in no-op.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -167,7 +167,7 @@ class TestHandleStaleMcpSession: async def test_no_op_when_server_instances_missing(self): """If _server_instances attr doesn't exist, don't crash.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -194,7 +194,7 @@ class TestHandleStaleMcpSession: async def test_delete_valid_session_not_handled(self): """DELETE requests for existing sessions should not be intercepted.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _handle_stale_mcp_session, ) except ImportError: @@ -227,7 +227,7 @@ async def test_stale_mcp_session_id_is_stripped(): request to the session manager so a fresh session is created. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, session_manager_stateless, @@ -263,15 +263,15 @@ async def test_stale_mcp_session_id_is_stripped(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -312,7 +312,7 @@ async def test_delete_stale_mcp_session_returns_success(): without forwarding to the session manager (idempotent DELETE). """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager, ) @@ -340,15 +340,15 @@ async def test_delete_stale_mcp_session_returns_success(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -378,7 +378,7 @@ async def test_failed_delete_preserves_stateful_session_tracking(): owner/auth tracking so the session cannot be hijacked or hidden from cleanup. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _owner_fingerprint_for, _stateful_session_auth_context_last_seen, _stateful_session_auth_contexts, @@ -419,12 +419,12 @@ async def test_failed_delete_preserves_stateful_session_tracking(): try: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -461,7 +461,7 @@ async def test_valid_mcp_session_id_is_preserved(): handle_streamable_http_mcp should NOT strip the header. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -494,15 +494,15 @@ async def test_valid_mcp_session_id_is_preserved(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -530,7 +530,7 @@ async def test_no_mcp_session_id_header_works_normally(): handle_streamable_http_mcp should work without any issues. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager, ) @@ -557,15 +557,15 @@ async def test_no_mcp_session_id_header_works_normally(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(UserAPIKeyAuth(), None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch.object( @@ -596,7 +596,7 @@ async def test_per_user_oauth_missing_stored_token_returns_preemptive_401(): from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -627,29 +627,29 @@ async def test_per_user_oauth_missing_stored_token_returns_preemptive_401(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["repro_oauth_server"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, return_value=False, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=oauth_server, ), patch.object( @@ -683,7 +683,7 @@ async def test_admitted_subject_missing_stored_token_challenged_with_resource_me from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -715,29 +715,29 @@ async def test_admitted_subject_missing_stored_token_challenged_with_resource_me with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["repro_oauth_server"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, return_value=False, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=oauth_server, ), patch.object( @@ -781,11 +781,11 @@ async def test_client_credentials_server_is_not_preemptively_challenged(m2m_fiel never look for. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) - from litellm.proxy._types import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer except ImportError: pytest.skip("MCP server not available") @@ -826,23 +826,23 @@ async def test_client_credentials_server_is_not_preemptively_challenged(m2m_fiel with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["m2m_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), - patch("litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), + patch("litellm.proxy.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=m2m_server, ), patch.object(session_manager_stateless, "handle_request", new_callable=AsyncMock) as mock_handle_request, @@ -866,10 +866,10 @@ async def test_handle_streamable_http_mcp_delegated_server_surfaces_upstream_cha from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -912,7 +912,7 @@ async def test_handle_streamable_http_mcp_delegated_server_surfaces_upstream_cha with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( user_auth, @@ -923,27 +923,27 @@ async def test_handle_streamable_http_mcp_delegated_server_surfaces_upstream_cha None, ), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_user_oauth_extra_headers_from_db", + "litellm.proxy.mcp_server.operations._get_user_oauth_extra_headers_from_db", new_callable=AsyncMock, return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=delegated_server, ), patch( # test-quality-ok: registry is empty in unit tests; key owns the delegated server - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[delegated_server], ), @@ -973,7 +973,7 @@ async def test_per_user_oauth_with_stored_token_skips_preemptive_401(): 401 and continue to session manager request handling. """ try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1010,29 +1010,29 @@ async def test_per_user_oauth_with_stored_token_skips_preemptive_401(): with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["repro_oauth_server"], None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, return_value=True, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=oauth_server, ), patch.object( @@ -1068,7 +1068,7 @@ async def test_handle_streamable_http_mcp_delegated_server_without_token_returns from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1107,7 +1107,7 @@ async def test_handle_streamable_http_mcp_delegated_server_without_token_returns with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=( user_auth, @@ -1119,23 +1119,23 @@ async def test_handle_streamable_http_mcp_delegated_server_without_token_returns ), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.has_user_oauth_token", new_callable=AsyncMock, ) as mock_has_token, patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=delegated_server, ), patch.object( @@ -1168,7 +1168,7 @@ async def test_handle_streamable_http_mcp_token_exchange_without_subject_returns from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1208,22 +1208,22 @@ async def test_handle_streamable_http_mcp_token_exchange_without_subject_returns with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["obo_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=obo_server, ), patch.object( @@ -1290,7 +1290,7 @@ async def test_handle_streamable_http_mcp_oauth_delegate_without_token_returns_g from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1312,17 +1312,17 @@ async def test_handle_streamable_http_mcp_oauth_delegate_without_token_returns_g with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["od_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=od_server, ), patch.object( @@ -1349,7 +1349,7 @@ async def test_handle_streamable_http_mcp_oauth_delegate_with_forwarded_token_sk re-challenge. Guards the ``_get_forwarded_auth_from_scope(...) is None`` condition: dropping it would 401 even a fully-authenticated request.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1377,26 +1377,26 @@ async def test_handle_streamable_http_mcp_oauth_delegate_with_forwarded_token_sk with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["od_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=od_server, ), patch.object( @@ -1422,7 +1422,7 @@ async def _run_passthrough_connect( challenged (raised) or forwarded to the session manager. Returns (challenged, www_authenticate).""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1442,23 +1442,23 @@ async def _run_passthrough_connect( with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, server_names, mcp_server_auth_headers, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), - patch("litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), + patch("litellm.proxy.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=server, ), patch.object(session_manager_stateless, "handle_request", new_callable=AsyncMock) as mock_handle_request, @@ -1478,7 +1478,7 @@ async def test_handle_streamable_http_mcp_per_server_header_skips_preemptive_cha connect gate must recognize it and forward instead of spuriously 401-ing, since egress already honors it. Without this, the mandatory multi-server binding is unusable at connect.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp # noqa: F401 + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp # noqa: F401 except ImportError: pytest.skip("MCP server not available") @@ -1497,7 +1497,7 @@ async def test_handle_streamable_http_mcp_sanitized_per_server_header_skips_pree alias 'pt-server' arrives as the header key 'pt_server'. Egress resolves that via the sanitized alias, so the connect gate must too, or it 401s a token egress would forward.""" try: - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp # noqa: F401 + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp # noqa: F401 except ImportError: pytest.skip("MCP server not available") @@ -1515,7 +1515,7 @@ async def test_handle_streamable_http_mcp_aggregate_does_not_preemptively_challe """A multi-server aggregate must degrade gracefully: the preemptive 401 is single-server only, so one server missing a token cannot 401 the whole connect (the listing absorbs per-server failures).""" try: - from litellm.proxy._experimental.mcp_server.server import handle_streamable_http_mcp # noqa: F401 + from litellm.proxy.mcp_server.server import handle_streamable_http_mcp # noqa: F401 except ImportError: pytest.skip("MCP server not available") @@ -1536,7 +1536,7 @@ async def test_handle_streamable_http_mcp_true_passthrough_without_token_surface from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1565,21 +1565,21 @@ async def test_handle_streamable_http_mcp_true_passthrough_without_token_surface with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=tp_server, ), patch.object( @@ -1606,7 +1606,7 @@ async def test_handle_streamable_http_mcp_true_passthrough_dcr_bridge_challenges from fastapi import HTTPException try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateful, ) @@ -1633,21 +1633,21 @@ async def test_handle_streamable_http_mcp_true_passthrough_dcr_bridge_challenges with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_bridge_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=bridge_server, ), patch.object( @@ -1674,7 +1674,7 @@ async def test_handle_streamable_http_mcp_true_passthrough_with_token_skips_prob ``not _scope_has_authorization_header(scope)`` condition and the no-probe fast path.""" try: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1702,30 +1702,30 @@ async def test_handle_streamable_http_mcp_true_passthrough_with_token_skips_prob with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ), patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=tp_server, ), patch.object( @@ -1806,7 +1806,7 @@ async def test_streamable_http_skips_preflight_for_disabled_methods( # test-qua monkeypatch: pytest.MonkeyPatch, ) -> None: from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, session_manager_stateless, ) @@ -1838,39 +1838,39 @@ async def test_streamable_http_skips_preflight_for_disabled_methods( # test-qua with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new_callable=AsyncMock, return_value=(user_auth, None, ["tp_server"], None, None, None), ), - patch("litellm.proxy._experimental.mcp_server.server.set_auth_context"), + patch("litellm.proxy.mcp_server.server.set_auth_context"), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new_callable=AsyncMock, return_value=False, ), patch( - "litellm.proxy._experimental.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", + "litellm.proxy.mcp_server.server._raise_preemptive_401_for_unauthenticated_servers", new_callable=AsyncMock, ) as mock_preemptive_401, patch( - "litellm.proxy._experimental.mcp_server.server._check_passthrough_upstream_auth", + "litellm.proxy.mcp_server.server._check_passthrough_upstream_auth", new_callable=AsyncMock, ) as mock_passthrough_auth, patch( - "litellm.proxy._experimental.mcp_server.server._preflight_modern_interaction", + "litellm.proxy.mcp_server.server._preflight_modern_interaction", new_callable=AsyncMock, return_value=None, ) as mock_modern_preflight, patch( - "litellm.proxy._experimental.mcp_server.server.get_async_httpx_client", + "litellm.proxy.mcp_server.server.get_async_httpx_client", return_value=probe_client, ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager.get_mcp_server_by_name", return_value=tp_server, ), patch.object( diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_tool_search.py b/tests/unit/proxy/mcp_server/test_mcp_tool_search.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_tool_search.py rename to tests/unit/proxy/mcp_server/test_mcp_tool_search.py index ea0dd70cd22..b21202ba227 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_tool_search.py +++ b/tests/unit/proxy/mcp_server/test_mcp_tool_search.py @@ -1,4 +1,5 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """ Tests for MCP tool search feature. @@ -20,14 +21,16 @@ from typing import Any, Final from unittest.mock import AsyncMock, MagicMock, patch import pytest -from pydantic import JsonValue from mcp.types import Tool +from pydantic import JsonValue import litellm from litellm.models.object_permission import LiteLLM_ObjectPermissionTable -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller -from litellm.proxy._experimental.mcp_server.tool_search import ( +from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.common_utils.semantic_text_index import EmbeddingFailed, SemanticTextIndex, Vector +from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller +from litellm.proxy.mcp_server.tool_search import ( AGENT_SEARCH_TOOL_NAME, MCP_TOOL_CALL_TOOL_NAME, MCP_TOOL_SEARCH_TOOL_NAME, @@ -41,8 +44,6 @@ from litellm.proxy._experimental.mcp_server.tool_search import ( search_mcp_tools, search_tools, ) -from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth -from litellm.proxy.common_utils.semantic_text_index import EmbeddingFailed, SemanticTextIndex, Vector from litellm.types.mcp import MCPToolSearchSettings, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -97,7 +98,7 @@ SAMPLE_TOOLS = _make_tools( def test_offline_schema_validation_preserves_supported_constraints( schema: Mapping[str, JsonValue], arguments: Mapping[str, JsonValue], error: str | None ) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _validate_tool_arguments + from litellm.proxy.mcp_server.tool_search import _validate_tool_arguments result: Final = _validate_tool_arguments(schema, arguments) if error is None: @@ -108,7 +109,7 @@ def test_offline_schema_validation_preserves_supported_constraints( @pytest.mark.parametrize(("count", "allowed"), ((4_999, True), (5_000, False))) def test_validation_node_limit(count: int, allowed: bool) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _validation_limit_error + from litellm.proxy.mcp_server.tool_search import _validation_limit_error result: Final = _validation_limit_error({}, {str(index): None for index in range(count)}) assert (result is None) is allowed @@ -116,7 +117,7 @@ def test_validation_node_limit(count: int, allowed: bool) -> None: @pytest.mark.parametrize(("size", "allowed"), ((1_048_575, True), (1_048_576, False))) def test_validation_text_limit(size: int, allowed: bool) -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _validation_limit_error + from litellm.proxy.mcp_server.tool_search import _validation_limit_error assert (_validation_limit_error({}, {"x": "a" * size}) is None) is allowed @@ -125,7 +126,7 @@ def test_validation_text_limit(size: int, allowed: bool) -> None: def test_validation_depth_limit(depth: int, allowed: bool) -> None: from functools import reduce - from litellm.proxy._experimental.mcp_server.tool_search import _validation_limit_error + from litellm.proxy.mcp_server.tool_search import _validation_limit_error nested: Final = reduce(lambda value, _: {"x": value}, range(depth), {}) assert (_validation_limit_error({}, nested) is None) is allowed @@ -133,7 +134,7 @@ def test_validation_depth_limit(depth: int, allowed: bool) -> None: @pytest.mark.asyncio async def test_oversized_arguments_are_rejected_before_worker_submission() -> None: - from litellm.proxy._experimental.mcp_server.tool_search import _tool_argument_validation_error + from litellm.proxy.mcp_server.tool_search import _tool_argument_validation_error with patch("anyio.to_process.run_sync", new_callable=AsyncMock) as submit: result: Final = await _tool_argument_validation_error({}, {"value": "x" * 1_048_576}) @@ -145,7 +146,7 @@ async def test_oversized_arguments_are_rejected_before_worker_submission() -> No async def test_failed_validation_worker_returns_tool_error() -> None: from anyio import BrokenWorkerProcess - from litellm.proxy._experimental.mcp_server.tool_search import _tool_argument_validation_error + from litellm.proxy.mcp_server.tool_search import _tool_argument_validation_error with patch("anyio.to_process.run_sync", side_effect=BrokenWorkerProcess): result: Final = await _tool_argument_validation_error({}, {}) @@ -472,7 +473,7 @@ class TestGetVirtualToolDefinitions: class TestListToolRestApiWithToolSearch: @pytest.mark.asyncio async def test_returns_only_virtual_tools_when_flag_enabled(self) -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router user_api_key_dict = UserAPIKeyAuth( api_key="test_key", @@ -509,7 +510,7 @@ class TestListToolRestApiWithToolSearch: @pytest.mark.asyncio async def test_returns_full_catalog_when_flag_disabled(self) -> None: - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router user_api_key_dict = UserAPIKeyAuth( api_key="test_key", @@ -538,32 +539,32 @@ class TestListToolRestApiWithToolSearch: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.build_effective_auth_contexts", + "litellm.proxy.mcp_server.rest_endpoints.build_effective_auth_contexts", new_callable=AsyncMock, return_value=[user_api_key_dict], ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, + patch("litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server", + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server", new_callable=AsyncMock, return_value=fake_tools, ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils"), + patch("litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils"), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._prefetch_user_oauth_creds", + "litellm.proxy.mcp_server.rest_endpoints._prefetch_user_oauth_creds", new_callable=AsyncMock, return_value={}, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", + "litellm.proxy.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", return_value=[], ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_server_auth_header", + "litellm.proxy.mcp_server.rest_endpoints._get_server_auth_header", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_user_oauth_extra_headers", + "litellm.proxy.mcp_server.rest_endpoints._get_user_oauth_extra_headers", new_callable=AsyncMock, return_value=None, ), @@ -587,7 +588,7 @@ class TestListToolRestApiWithToolSearch: """Regression: an admin listing with include_disabled_tools must see the real catalog (to configure allowlists) even when mcp_tool_search_enabled is set, instead of the two virtual tools.""" - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router user_api_key_dict = UserAPIKeyAuth( api_key="admin_key", @@ -617,32 +618,32 @@ class TestListToolRestApiWithToolSearch: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.build_effective_auth_contexts", + "litellm.proxy.mcp_server.rest_endpoints.build_effective_auth_contexts", new_callable=AsyncMock, return_value=[user_api_key_dict], ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, + patch("litellm.proxy.mcp_server.rest_endpoints.global_mcp_server_manager") as mock_manager, patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_tools_for_single_server", + "litellm.proxy.mcp_server.rest_endpoints._get_tools_for_single_server", new_callable=AsyncMock, return_value=fake_tools, ), - patch("litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils"), + patch("litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils"), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._prefetch_user_oauth_creds", + "litellm.proxy.mcp_server.rest_endpoints._prefetch_user_oauth_creds", new_callable=AsyncMock, return_value={}, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", + "litellm.proxy.mcp_server.rest_endpoints._v1_resolved_oauth2_server_ids", return_value=[], ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_server_auth_header", + "litellm.proxy.mcp_server.rest_endpoints._get_server_auth_header", return_value=None, ), patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._get_user_oauth_extra_headers", + "litellm.proxy.mcp_server.rest_endpoints._get_user_oauth_extra_headers", new_callable=AsyncMock, return_value=None, ), @@ -672,7 +673,7 @@ class TestCallToolRestApiVirtualTools: return mock_request def _get_call_fn(self) -> Any: - from litellm.proxy._experimental.mcp_server.rest_endpoints import router + from litellm.proxy.mcp_server.rest_endpoints import router return next( r.endpoint @@ -698,7 +699,7 @@ class TestCallToolRestApiVirtualTools: mock_tool.input_schema = {"type": "object", "properties": {}} with patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new_callable=AsyncMock, return_value=AggregateToolListing(tools=[mock_tool], outcomes={}), ): @@ -742,17 +743,17 @@ class TestCallToolRestApiVirtualTools: with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, return_value=fake_result, ) as mock_execute, patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints._fire_mcp_tool_call_logging", + "litellm.proxy.mcp_server.rest_endpoints._fire_mcp_tool_call_logging", new_callable=AsyncMock, side_effect=RuntimeError("logging failed"), ) as mock_fire_logging, @@ -791,16 +792,16 @@ class TestCallToolRestApiVirtualTools: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.7", ), patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, return_value=fake_result, ), @@ -821,11 +822,11 @@ class TestCallToolRestApiVirtualTools: with ( patch( - "litellm.proxy._experimental.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", + "litellm.proxy.mcp_server.rest_endpoints.IPAddressUtils.get_mcp_client_ip", return_value="203.0.113.7", ), patch( - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new_callable=AsyncMock, return_value=AggregateToolListing(tools=[], outcomes={}), ) as mock_list, @@ -893,7 +894,7 @@ class TestCallToolRestApiVirtualTools: ) fake_result = CallToolResult(content=[TextContent(type="text", text="[]")], isError=False) with patch( # test-quality-ok: the embedding router only resolves via proxy_server globals, no injection seam - "litellm.proxy._experimental.mcp_server.tool_search.handle_skill_search", + "litellm.proxy.mcp_server.tool_search.handle_skill_search", new_callable=AsyncMock, return_value=fake_result, ) as mock_search: @@ -958,7 +959,7 @@ class TestCallToolRestApiVirtualTools: "litellm.proxy.proxy_server.proxy_logging_obj", key_limits ), patch( # test-quality-ok: the authorized catalog is the seam every virtual tool shares; the ranking under test stays real - "litellm.proxy._experimental.mcp_server.operations._list_mcp_tools", + "litellm.proxy.mcp_server.operations._list_mcp_tools", new_callable=AsyncMock, return_value=AggregateToolListing(tools=list(CATALOG), outcomes={}), ) as mock_list, @@ -1027,7 +1028,7 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_returns_none_for_non_virtual_tool(self) -> None: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _dispatch_virtual_mcp_tool, ) @@ -1041,7 +1042,7 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_rejects_when_flag_disabled(self) -> None: - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( _dispatch_virtual_mcp_tool, ) @@ -1057,11 +1058,11 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_routes_search_with_client_ip(self) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_search", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_search", new_callable=AsyncMock, return_value="SEARCH_RESULT", ) as mock_search: @@ -1079,11 +1080,11 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_routes_agent_search_to_its_handler(self) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( # test-quality-ok: dispatch routing is the subject; the handler is faked like its siblings here - "litellm.proxy._experimental.mcp_server.tool_search.handle_agent_search", + "litellm.proxy.mcp_server.tool_search.handle_agent_search", new_callable=AsyncMock, return_value="AGENT_RESULT", ) as mock_agent_search: @@ -1103,7 +1104,7 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_agent_search_rejected_when_flag_disabled(self) -> None: - from litellm.proxy._experimental.mcp_server.server import _dispatch_virtual_mcp_tool + from litellm.proxy.mcp_server.server import _dispatch_virtual_mcp_tool uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=False)) result = await _dispatch_virtual_mcp_tool( @@ -1114,11 +1115,11 @@ class TestDispatchVirtualMcpTool: @pytest.mark.asyncio async def test_routes_call_with_client_ip(self) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_call", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_call", new_callable=AsyncMock, return_value="CALL_RESULT", ) as mock_call: @@ -1147,7 +1148,7 @@ class TestDispatchVirtualMcpTool: """Regression: the SSE dispatch must run the pre-call pipeline and forward the resulting logging object to handle_mcp_tool_call, otherwise mcp_tool_call over /mcp/ skips spend logging and guardrails (unlike the REST path).""" - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) sentinel_logging_obj = object() @@ -1158,7 +1159,7 @@ class TestDispatchVirtualMcpTool: return_value=sentinel_logging_obj, ) as mock_build, patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_call", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_call", new_callable=AsyncMock, return_value="CALL_RESULT", ) as mock_call, @@ -1177,11 +1178,11 @@ class TestDispatchVirtualMcpTool: async def test_search_coerces_non_int_top_k(self) -> None: """Regression: a non-integer top_k from an MCP client must not raise; it falls back to the default instead of ValueError propagating out.""" - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.tool_search.handle_mcp_tool_search", + "litellm.proxy.mcp_server.tool_search.handle_mcp_tool_search", new_callable=AsyncMock, return_value="SEARCH_RESULT", ) as mock_search: @@ -1200,7 +1201,7 @@ class TestDispatchVirtualMcpTool: upstream MCP servers needing pass-through auth can be called.""" from mcp.types import CallToolResult, TextContent - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( handle_mcp_tool_call, ) @@ -1208,12 +1209,12 @@ class TestDispatchVirtualMcpTool: fake = CallToolResult(content=[TextContent(type="text", text="ok")], isError=False) with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[MagicMock()], ) as mock_allowed, patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, return_value=fake, ) as mock_exec, @@ -1248,19 +1249,19 @@ class TestDispatchVirtualMcpTool: run via the local registry without a server permission check.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( handle_mcp_tool_call, ) uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with ( patch( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new_callable=AsyncMock, return_value=[], ), patch( - "litellm.proxy._experimental.mcp_server.operations.execute_mcp_tool", + "litellm.proxy.mcp_server.operations.execute_mcp_tool", new_callable=AsyncMock, ) as mock_exec, ): @@ -1278,7 +1279,7 @@ class TestDispatchVirtualMcpTool: class TestCaptureHostProgressCallback: @pytest.mark.parametrize("meta", [None, {}, {"traceparent": "trace"}]) def test_returns_none_without_progress(self, _mcp_request_ctx, meta) -> None: - from litellm.proxy._experimental.mcp_server.server import _capture_host_progress_callback + from litellm.proxy.mcp_server.server import _capture_host_progress_callback assert _capture_host_progress_callback(_mcp_request_ctx(meta=meta)) is None @@ -1292,7 +1293,7 @@ class TestCaptureHostProgressCallback: from mcp.shared.dispatcher import DispatchContext from mcp.types import CallToolRequestParams - from litellm.proxy._experimental.mcp_server.server import _capture_host_progress_callback + from litellm.proxy.mcp_server.server import _capture_host_progress_callback params = CallToolRequestParams.model_validate( {"name": "tool", "_meta": {"progressToken": token}}, by_name=False @@ -1312,11 +1313,11 @@ class TestHandleListToolsVirtual: @pytest.mark.asyncio async def test_returns_virtual_tools_when_flag_enabled(self, _mcp_request_ctx) -> None: - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new_callable=AsyncMock, return_value=(uak, None, None, None, None, None, None), ): @@ -1338,17 +1339,17 @@ class TestMcpServerToolCallErrorHandling: async def test_virtual_tool_error_returns_iserror_not_raised(self, _mcp_request_ctx) -> None: from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as srv + from litellm.proxy.mcp_server import server as srv uak = UserAPIKeyAuth(api_key="k", object_permission=_make_perm(mcp_tool_search_enabled=True)) with ( patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", new_callable=AsyncMock, return_value=(uak, None, None, None, None, None, None), ), patch( - "litellm.proxy._experimental.mcp_server.operations._dispatch_virtual_mcp_tool", + "litellm.proxy.mcp_server.operations._dispatch_virtual_mcp_tool", new_callable=AsyncMock, side_effect=HTTPException(status_code=403, detail="User not allowed to call this tool"), ), @@ -1371,7 +1372,7 @@ class TestMcpServerToolCallErrorHandling: async def test_handle_mcp_tool_call_scoped_denial_names_the_binding_agent() -> None: from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server.tool_search import handle_mcp_tool_call + from litellm.proxy.mcp_server.tool_search import handle_mcp_tool_call agent_bound_key = UserAPIKeyAuth(api_key="test_key", agent_id="agent-123") @@ -1385,7 +1386,7 @@ async def test_handle_mcp_tool_call_scoped_denial_names_the_binding_agent() -> N ] with patch( # test-quality-ok: the permission resolver is a module-level function; the suite's only seam - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", new=AsyncMock(side_effect=resolve), ): with pytest.raises(HTTPException) as exc_info: @@ -1435,7 +1436,7 @@ async def test_mcp_tool_search_leaves_the_listed_tools_slot_empty(monkeypatch: p async def test_cold_concurrent_schema_validation_accepts_valid_arguments() -> None: import psutil - from litellm.proxy._experimental.mcp_server.tool_search import ( + from litellm.proxy.mcp_server.tool_search import ( _MAX_VALIDATION_WORKERS, _tool_argument_validation_error, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py b/tests/unit/proxy/mcp_server/test_mcp_toolset_scope.py similarity index 88% rename from tests/unit/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py rename to tests/unit/proxy/mcp_server/test_mcp_toolset_scope.py index b9eebca3baa..f3cc38eacf9 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_toolset_scope.py +++ b/tests/unit/proxy/mcp_server/test_mcp_toolset_scope.py @@ -34,7 +34,7 @@ def _make_auth( def _granted_through_team(*team_toolset_ids: str) -> Callable[[UserAPIKeyAuth], Awaitable[frozenset[str]]]: """The real grant resolver over a team that holds ``team_toolset_ids``, with no key access rule.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import granted_toolset_ids + from litellm.proxy.mcp_server.ui_session_utils import granted_toolset_ids async def team_permission(context: UserAPIKeyAuth) -> LiteLLM_ObjectPermissionTable: return LiteLLM_ObjectPermissionTable(object_permission_id="team-op", mcp_toolsets=list(team_toolset_ids)) @@ -50,14 +50,14 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_restricts_to_toolset_servers_and_tools(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope toolset_perms = { "server-a": ["tool1", "tool2"], "server-b": ["tool3"], } with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=AsyncMock(return_value=toolset_perms), ): @@ -73,8 +73,8 @@ class TestApplyToolsetScope: assert set(op.mcp_servers or []) == {"server-a", "server-b"} assert op.mcp_tool_permissions == toolset_perms - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager - from litellm.proxy._experimental.mcp_server.operations import prepare_context + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.operations import prepare_context manager = MCPServerManager() unscoped_open = await manager.operator_open_server_ids( @@ -92,11 +92,11 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_admin_creates_object_permission_when_none(self): """Admin key with object_permission=None can access any toolset.""" - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope toolset_perms = {"server-a": ["tool1"]} with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=AsyncMock(return_value=toolset_perms), ): @@ -116,12 +116,12 @@ class TestApplyToolsetScope: async def test_team_granted_toolset_is_served_to_a_key_without_its_own_grant(self): """A team key whose own row carries no toolset grant is admitted to the toolset its team holds (LIT-6029), scoped to that toolset's servers and tools.""" - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope toolset_perms = {"server-a": ["tool1"]} auth = UserAPIKeyAuth(api_key="sk-test", team_id="team-a", object_permission=None) with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=AsyncMock(return_value=toolset_perms), ): @@ -138,7 +138,7 @@ class TestApplyToolsetScope: team-granted toolset is not capped by the user's own row: the row stays intact and the toolset rides along as mcp_toolset_id (LIT-6029).""" from litellm.constants import UI_SESSION_TOKEN_TEAM_ID - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope session = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-1") own_row = LiteLLM_ObjectPermissionTable(object_permission_id="user-op", mcp_servers=["server-own"]) @@ -147,7 +147,7 @@ class TestApplyToolsetScope: granted = AsyncMock(return_value=frozenset({"toolset-123"})) resolve = AsyncMock(return_value={"server-team": ["tool1"]}) with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): @@ -163,7 +163,7 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_a_gateway_admitted_user_without_the_toolset_in_any_source_is_denied(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope admitted = UserAPIKeyAuth(user_id="user-1", object_permission=None) admitted.mcp_admitted_user_subject = True @@ -178,7 +178,7 @@ class TestApplyToolsetScope: async def test_a_resource_scoped_admitted_user_is_denied_a_team_toolset_on_another_server(self): """A gateway bearer scoped to server-own (RFC 8707 resource) cannot open a team toolset whose servers lie outside that resource, even though the team grants it (Devin Review 4150024267).""" - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope admitted = UserAPIKeyAuth(user_id="user-1", object_permission=None) admitted.mcp_admitted_user_subject = True @@ -187,7 +187,7 @@ class TestApplyToolsetScope: granted = AsyncMock(return_value=frozenset({"toolset-123"})) resolve = AsyncMock(return_value={"server-team": ["tool1"]}) with patch( - "litellm.proxy._experimental.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", + "litellm.proxy.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): with pytest.raises(HTTPException) as exc_info: @@ -198,7 +198,7 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_a_resource_scoped_admitted_user_opens_a_toolset_inside_its_resource(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope admitted = UserAPIKeyAuth(user_id="user-1", object_permission=None) admitted.mcp_admitted_user_subject = True @@ -206,7 +206,7 @@ class TestApplyToolsetScope: granted = AsyncMock(return_value=frozenset({"toolset-123"})) resolve = AsyncMock(return_value={"server-team": ["tool1"], "server-other": ["tool2"]}) with patch( - "litellm.proxy._experimental.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", + "litellm.proxy.mcp_server.server.global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): result = await apply_toolset_scope(admitted, "toolset-123", granted=granted) @@ -217,7 +217,7 @@ class TestApplyToolsetScope: @pytest.mark.asyncio async def test_team_grant_for_another_toolset_does_not_admit_a_key_to_this_one(self): - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope auth = _make_auth(mcp_toolsets=[]) auth.team_id = "team-a" @@ -231,7 +231,7 @@ class TestApplyToolsetScope: """Non-admin key with object_permission=None is denied (no grants configured).""" from starlette.exceptions import HTTPException - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope auth = UserAPIKeyAuth(api_key="sk-test", object_permission=None) with pytest.raises(HTTPException) as exc_info: @@ -246,7 +246,7 @@ class TestApplyToolsetScope: toolset path, which replaces mcp_servers and would drop the sentinel.""" from starlette.exceptions import HTTPException - from litellm.proxy._experimental.mcp_server.server import apply_toolset_scope + from litellm.proxy.mcp_server.server import apply_toolset_scope op = LiteLLM_ObjectPermissionTable( object_permission_id="test", @@ -259,7 +259,7 @@ class TestApplyToolsetScope: resolve = AsyncMock(return_value={"server-a": ["tool1"]}) with patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.resolve_toolset_tool_permissions", new=resolve, ): @@ -382,12 +382,12 @@ class TestFetchMCPToolsetsAccess: @pytest.mark.asyncio async def test_team_granted_toolsets_are_listed_for_a_key_without_its_own_grant(self): """GET /v1/mcp/toolset for a team key lists the team's toolsets (LIT-6029).""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( fetch_mcp_toolsets, ) + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) auth = UserAPIKeyAuth(api_key="sk-test", team_id="team-a", object_permission=None) team_permission = LiteLLM_ObjectPermissionTable(object_permission_id="team-op", mcp_toolsets=["ts-team"]) @@ -417,12 +417,12 @@ class TestFetchMCPToolsetsAccess: @pytest.mark.asyncio async def test_admin_with_own_grants_is_not_narrowed_by_a_team_lookup(self): """An admin's own grant list is the only filter; no team lookup runs for admins.""" - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( fetch_mcp_toolsets, ) + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) auth = _make_auth(mcp_toolsets=["ts-1"]) auth.user_role = LitellmUserRoles.PROXY_ADMIN @@ -454,12 +454,12 @@ class TestFetchMCPToolsetAccess: @staticmethod async def _fetch(auth: UserAPIKeyAuth, toolset_id: str, team_toolsets: list[str] | None): - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( - MCPRequestHandler, - ) from litellm.proxy.management_endpoints.mcp_management_endpoints import ( fetch_mcp_toolset, ) + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( + MCPRequestHandler, + ) team_permission = ( LiteLLM_ObjectPermissionTable(object_permission_id="team-op", mcp_toolsets=team_toolsets) @@ -542,10 +542,10 @@ class TestToolsetPrefixResolution: ): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -564,12 +564,12 @@ class TestToolsetPrefixResolution: with ( patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "MCPRequestHandler.get_allowed_tools_for_server", new=AsyncMock(return_value=allowed), ), patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), @@ -606,7 +606,7 @@ class TestToolsetPrefixResolution: async def test_resolve_keeps_a_name_that_looks_like_its_own_server_prefix( self, alias, server_name, server_id ): - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -624,7 +624,7 @@ class TestToolsetPrefixResolution: async def _resolve(server, server_id, stored): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) @@ -635,14 +635,14 @@ class TestToolsetPrefixResolution: ) with ( patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager." + "litellm.proxy.mcp_server.mcp_server_manager." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), patch("litellm.proxy.proxy_server.prisma_client", MagicMock()), patch("litellm.proxy.proxy_server.user_api_key_cache", cache), patch( - "litellm.proxy._experimental.mcp_server.toolset_db.list_mcp_toolsets", + "litellm.proxy.mcp_server.toolset_db.list_mcp_toolsets", new=AsyncMock(return_value=[toolset]), ), ): @@ -661,10 +661,10 @@ class TestToolsetPrefixResolution: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, strip_known_server_prefix, @@ -691,12 +691,12 @@ class TestToolsetPrefixResolution: with ( patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "MCPRequestHandler.get_allowed_tools_for_server", new=AsyncMock(return_value=resolved["srv-collide"]), ), patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), @@ -725,10 +725,10 @@ class TestToolsetPrefixResolution: """ from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( filter_tools_by_key_team_permissions, ) - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( add_server_prefix_to_name, get_server_prefix, ) @@ -748,12 +748,12 @@ class TestToolsetPrefixResolution: with ( patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "MCPRequestHandler.get_allowed_tools_for_server", new=AsyncMock(return_value=resolved["srv-lonely"]), ), patch( - "litellm.proxy._experimental.mcp_server.server." + "litellm.proxy.mcp_server.server." "global_mcp_server_manager.get_mcp_server_by_id", return_value=server, ), @@ -770,7 +770,7 @@ class TestToolsetPrefixResolution: async def test_bare_stored_name_without_collision_grants_only_that_tool(self): """The ordinary row must stay exact; accepting both readings of an ambiguous row must not widen an unambiguous one.""" - from litellm.proxy._experimental.mcp_server.utils import get_server_prefix + from litellm.proxy.mcp_server.utils import get_server_prefix server = self._server("deepwiki", None, "srv-clean") assert get_server_prefix(server) == "deepwiki" @@ -784,12 +784,12 @@ class TestMCPActiveToolsetContextVar: """Tests for _mcp_active_toolset_id ContextVar — clients cannot inject it.""" def test_contextvar_default_is_none(self): - from litellm.proxy._experimental.mcp_server.server import mcp_active_toolset_id + from litellm.proxy.mcp_server.server import mcp_active_toolset_id assert mcp_active_toolset_id.get() is None def test_contextvar_set_and_reset(self): - from litellm.proxy._experimental.mcp_server.server import mcp_active_toolset_id + from litellm.proxy.mcp_server.server import mcp_active_toolset_id token = mcp_active_toolset_id.set("toolset-abc") assert mcp_active_toolset_id.get() == "toolset-abc" @@ -799,7 +799,7 @@ class TestMCPActiveToolsetContextVar: @pytest.mark.asyncio async def test_client_header_is_stripped_in_scope(self): """handle_streamable_http_mcp strips x-mcp-toolset-id from scope before passing to session manager.""" - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( handle_streamable_http_mcp, ) @@ -824,35 +824,35 @@ class TestMCPActiveToolsetContextVar: with ( patch( - "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + "litellm.proxy.mcp_server.server.extract_mcp_auth_context", new=AsyncMock( return_value=(mock_auth, None, [], {}, {}, scope["headers"]) ), ), patch( - "litellm.proxy._experimental.mcp_server.server.IPAddressUtils", + "litellm.proxy.mcp_server.server.IPAddressUtils", MagicMock(get_mcp_client_ip=MagicMock(return_value="127.0.0.1")), ), patch( - "litellm.proxy._experimental.mcp_server.operations.global_mcp_server_manager", + "litellm.proxy.mcp_server.operations.global_mcp_server_manager", MagicMock(get_mcp_server_by_name=MagicMock(return_value=None)), ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPDebug", + "litellm.proxy.mcp_server.server.MCPDebug", MagicMock( maybe_build_debug_headers=MagicMock(return_value=None), ), ), patch( - "litellm.proxy._experimental.mcp_server.server.set_auth_context", + "litellm.proxy.mcp_server.server.set_auth_context", MagicMock(), ), patch( - "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", + "litellm.proxy.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( - "litellm.proxy._experimental.mcp_server.server._handle_stale_mcp_session", + "litellm.proxy.mcp_server.server._handle_stale_mcp_session", new=AsyncMock(return_value=True), ), ): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_flow_backfill.py b/tests/unit/proxy/mcp_server/test_oauth2_flow_backfill.py similarity index 99% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth2_flow_backfill.py rename to tests/unit/proxy/mcp_server/test_oauth2_flow_backfill.py index ce079878328..7a7e1cf390a 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_flow_backfill.py +++ b/tests/unit/proxy/mcp_server/test_oauth2_flow_backfill.py @@ -17,7 +17,7 @@ from unittest.mock import AsyncMock, MagicMock import pytest -from litellm.proxy._experimental.mcp_server.oauth2_flow_backfill import ( +from litellm.proxy.mcp_server.oauth2_flow_backfill import ( backfill_null_oauth2_flows, classify_null_flow_row, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_mcp_config.yaml b/tests/unit/proxy/mcp_server/test_oauth2_mcp_config.yaml similarity index 100% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth2_mcp_config.yaml rename to tests/unit/proxy/mcp_server/test_oauth2_mcp_config.yaml diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_token_cache.py b/tests/unit/proxy/mcp_server/test_oauth2_token_cache.py similarity index 90% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth2_token_cache.py rename to tests/unit/proxy/mcp_server/test_oauth2_token_cache.py index 6eb93b090e9..f455096d390 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth2_token_cache.py +++ b/tests/unit/proxy/mcp_server/test_oauth2_token_cache.py @@ -10,12 +10,12 @@ from unittest.mock import AsyncMock, MagicMock, patch import httpx import pytest -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( +from litellm.proxy._types import MCPTransport +from litellm.proxy.mcp_server.oauth2_token_cache import ( MCPOAuth2TokenCache, resolve_mcp_auth, resolved_token_header, ) -from litellm.proxy._types import MCPTransport from litellm.types.mcp import MCPAuth from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -55,7 +55,7 @@ async def test_resolve_mcp_auth_fetches_oauth2_token(): mock_client.post.return_value = _token_response("m2m-token-1") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): result = await resolve_mcp_auth(server) @@ -78,11 +78,11 @@ async def test_token_cached_across_calls(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", cache, ), ): @@ -107,11 +107,11 @@ async def test_m2m_token_not_shared_across_server_ids_with_identical_config(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", + "litellm.proxy.mcp_server.oauth2_token_cache.mcp_oauth2_token_cache", cache, ), ): @@ -178,7 +178,7 @@ async def test_http_error_raises_value_error(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), pytest.raises(ValueError, match="failed with status 401"), @@ -198,7 +198,7 @@ async def test_non_dict_response_raises_value_error(): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ), pytest.raises(ValueError, match="non-object JSON"), @@ -217,7 +217,7 @@ async def test_client_credentials_uses_client_secret_basic_when_configured(): mock_client.post.return_value = _token_response("m2m-basic") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): result = await resolve_mcp_auth(server) @@ -236,7 +236,7 @@ def test_storage_ttl_capped_at_token_lifetime(): Redis fast path (which never re-checks expires_at) kept serving the dead token until eviction, while the stored refresh_token sat unused because refresh only runs on the DB read-through.""" from litellm.constants import MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -247,7 +247,7 @@ def test_storage_ttl_capped_at_token_lifetime(): def test_storage_ttl_shorter_than_token_lifetime_wins(): """A configured TTL below the token lifetime is the operative value: the knob's purpose is to force earlier DB re-checks (staleness backstop), so the shorter side must win the min().""" - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -258,7 +258,7 @@ def test_storage_ttl_shorter_than_token_lifetime_wins(): def test_storage_ttl_verbatim_when_token_lifetime_unknown(): """With no expires_in from the upstream there is nothing to cap against, so the configured TTL applies as-is (matching the pre-cap behavior for lifetime-less tokens).""" - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -269,7 +269,7 @@ def test_storage_ttl_verbatim_when_token_lifetime_unknown(): def test_storage_ttl_floors_at_one_second_for_nearly_dead_token(): """A token already inside the expiry buffer yields the 1-second floor, not zero or a negative TTL, mirroring the floor the default (unconfigured) path has always had.""" - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -284,7 +284,7 @@ def test_default_ttl_paths_unchanged_without_storage_ttl(): MCP_PER_USER_TOKEN_DEFAULT_TTL, MCP_PER_USER_TOKEN_EXPIRY_BUFFER_SECONDS, ) - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( + from litellm.proxy.mcp_server.oauth2_token_cache import ( compute_per_user_token_ttl, ) @@ -311,7 +311,7 @@ async def test_client_credentials_sends_rfc8707_resource(configured, expected): mock_client.post.return_value = _token_response("m2m-tok") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): await resolve_mcp_auth(server) @@ -340,7 +340,7 @@ async def test_token_cache_mints_afresh_when_the_token_request_changes(changed): mock_client.post.side_effect = [_token_response("tok-before"), _token_response("tok-after")] with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): before = await cache.async_get_token(_server()) @@ -360,7 +360,7 @@ async def test_token_cache_still_reuses_a_token_when_nothing_changed(): mock_client.post.return_value = _token_response("tok-reused") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): first = await cache.async_get_token(_server(upstream_resource="auto")) @@ -383,7 +383,7 @@ async def test_invalidate_clears_every_identity_for_a_server(): ] with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): await cache.async_get_token(_server()) @@ -399,8 +399,8 @@ async def test_invalidate_clears_every_identity_for_a_server(): async def test_per_user_token_delete_evicts_locally_and_broadcasts_to_peer_workers(): """Revoking a user's OAuth token must not leave peer workers serving it from their in-memory layer.""" from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.oauth2_token_cache import MCPPerUserTokenCache from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.oauth2_token_cache import MCPPerUserTokenCache local_cache = UserApiKeyCache() publish = AsyncMock() @@ -433,7 +433,7 @@ async def test_m2m_mint_uses_admin_entered_token_url_when_issuer_yield_empties_r mock_client.post.return_value = _token_response("m2m-token-configured") with patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth2_token_cache.get_async_httpx_client", return_value=mock_client, ): result = await cache.async_get_token(server) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth_identity_binding.py b/tests/unit/proxy/mcp_server/test_oauth_identity_binding.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth_identity_binding.py rename to tests/unit/proxy/mcp_server/test_oauth_identity_binding.py index 0036035f448..15c80abf576 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth_identity_binding.py +++ b/tests/unit/proxy/mcp_server/test_oauth_identity_binding.py @@ -11,7 +11,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa from fastapi import HTTPException from pydantic import ValidationError -from litellm.proxy._experimental.mcp_server.oauth_identity_binding import ( +from litellm.proxy.mcp_server.oauth_identity_binding import ( RefreshOwnershipProven, RefreshTokenPresented, VerifiedRefreshToken, @@ -101,7 +101,7 @@ async def test_fetch_issuer_jwks_fetches_and_caches_keys(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for JWKS fetching - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): first: Final = await _fetch_issuer_jwks(binding) @@ -121,7 +121,7 @@ async def test_fetch_issuer_jwks_rejects_malformed_document(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for JWKS fetching - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): with pytest.raises(TypeError, match="has no 'keys' array"): @@ -136,7 +136,7 @@ async def test_discover_jwks_url_returns_provider_uri(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for OIDC discovery - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): result: Final = await _discover_jwks_url("https://idp.example.com/") @@ -153,7 +153,7 @@ async def test_discover_jwks_url_rejects_missing_provider_uri(): client.get = AsyncMock(return_value=response) with patch( # test-quality-ok: no HTTP dependency injection seam exists for OIDC discovery - "litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client", + "litellm.proxy.mcp_server.oauth_identity_binding.get_async_httpx_client", return_value=client, ): with pytest.raises(ValueError, match="returned no jwks_uri"): @@ -177,7 +177,7 @@ async def test_load_caller_principal_supports_user_id_and_database_email(): assert await _load_caller_principal("user-a", user_id_binding) == "user-a" with patch( # test-quality-ok: caller loading is a lazy database boundary without injection - "litellm.proxy._experimental.mcp_server.bridge_token_flow.load_active_user_by_id", + "litellm.proxy.mcp_server.bridge_token_flow.load_active_user_by_id", new=AsyncMock(side_effect=["no_active_key", SimpleNamespace(user_email="alice@example.com")]), ): assert await _load_caller_principal("user-a", _server().oauth_identity_binding) is None @@ -191,7 +191,7 @@ async def test_load_stored_refresh_token_returns_credential_and_fails_closed(): get_credential: Final = AsyncMock(return_value={"refresh_token": "rt-1", "identity_binding_proof": proof}) with ( patch( # test-quality-ok: stored-token loading is a lazy database boundary without injection - "litellm.proxy._experimental.mcp_server.db.get_user_oauth_credential", + "litellm.proxy.mcp_server.db.get_user_oauth_credential", new=get_credential, ), patch( # test-quality-ok: stored-token loading is a lazy database boundary without injection @@ -627,7 +627,7 @@ async def test_authorization_code_rejects_missing_or_foreign_nonce(nonce): @pytest.mark.asyncio async def test_binding_proof_rejects_changed_user_or_policy(): - from litellm.proxy._experimental.mcp_server.oauth_identity_binding import credential_binding_matches + from litellm.proxy.mcp_server.oauth_identity_binding import credential_binding_matches binding = _server(caller_field="user_id", principal_claim="sub").oauth_identity_binding proof = await current_binding_proof(binding, "alice", "srv-1") diff --git a/tests/unit/proxy/_experimental/mcp_server/test_oauth_issuer_stamp_backfill.py b/tests/unit/proxy/mcp_server/test_oauth_issuer_stamp_backfill.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_oauth_issuer_stamp_backfill.py rename to tests/unit/proxy/mcp_server/test_oauth_issuer_stamp_backfill.py index a576bcbb3e2..4f0e91a2c1f 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_oauth_issuer_stamp_backfill.py +++ b/tests/unit/proxy/mcp_server/test_oauth_issuer_stamp_backfill.py @@ -9,10 +9,10 @@ import pytest from litellm._service_logger import ServiceTypes from litellm.proxy import proxy_server -from tests.unit.proxy.db.fake_prisma_engine import engine_call -from litellm.proxy._experimental.mcp_server.oauth_issuer_stamp_backfill import ( +from litellm.proxy.mcp_server.oauth_issuer_stamp_backfill import ( backfill_discovery_stamped_issuers, ) +from tests.unit.proxy.db.fake_prisma_engine import engine_call def _row(**overrides): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.py b/tests/unit/proxy/mcp_server/test_openapi_spec_path_url.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.py rename to tests/unit/proxy/mcp_server/test_openapi_spec_path_url.py index 17a0022046e..aac85160eba 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_openapi_spec_path_url.py +++ b/tests/unit/proxy/mcp_server/test_openapi_spec_path_url.py @@ -5,7 +5,7 @@ from typing import Any, Dict import httpx import pytest -from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator as gen +from litellm.proxy.mcp_server import openapi_to_mcp_generator as gen class _FakeAsyncHTTPHandler: diff --git a/tests/unit/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.py b/tests/unit/proxy/mcp_server/test_openapi_to_mcp_generator.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.py rename to tests/unit/proxy/mcp_server/test_openapi_to_mcp_generator.py index 9f3db632db1..adb185e4242 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_openapi_to_mcp_generator.py +++ b/tests/unit/proxy/mcp_server/test_openapi_to_mcp_generator.py @@ -17,12 +17,11 @@ import pytest from fastapi import HTTPException from respx import MockRouter -from litellm.types.mcp import MCPAuth, MCPAuthType - -from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_auth_header, - request_extra_headers, - request_resolved_auth_headers, +from litellm.proxy.mcp_server.exceptions import ( + MCPOpenApiUpstreamError, + MCPUpstreamAuthError, +) +from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _request_upstream_url, _resolve_param_list, _resolve_ref, @@ -30,16 +29,15 @@ from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( create_tool_function, extract_parameters, get_base_url, + request_auth_header, + request_extra_headers, + request_resolved_auth_headers, resolve_operation_params, ) -from litellm.proxy._experimental.mcp_server.tool_outcome import JsonResult, TextResult +from litellm.proxy.mcp_server.tool_outcome import JsonResult, TextResult +from litellm.types.mcp import MCPAuth, MCPAuthType -from litellm.proxy._experimental.mcp_server.exceptions import ( - MCPOpenApiUpstreamError, - MCPUpstreamAuthError, -) - -GET_ASYNC_CLIENT_TARGET = "litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator.get_async_httpx_client" +GET_ASYNC_CLIENT_TARGET = "litellm.proxy.mcp_server.openapi_to_mcp_generator.get_async_httpx_client" @pytest.mark.asyncio @@ -1065,7 +1063,7 @@ class TestResolveOperationParams: class TestSanitizeOpenAPIToolName: def test_replaces_slashes(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) @@ -1075,35 +1073,35 @@ class TestSanitizeOpenAPIToolName: ) def test_replaces_other_punctuation(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("foo.bar:baz qux") == "foo_bar_baz_qux" def test_lowercases(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("Pulls/List-Files") == "pulls_list-files" def test_already_valid_passes_through(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("plain-tool_name") == "plain-tool_name" def test_empty_string(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) assert sanitize_openapi_tool_name("") == "" def test_caps_at_128_chars(self): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( sanitize_openapi_tool_name, ) @@ -1117,7 +1115,7 @@ class TestRegisterToolsFromOpenAPI: def test_github_style_operation_ids_are_sanitized(self, monkeypatch): import re - from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator + from litellm.proxy.mcp_server import openapi_to_mcp_generator registered: list = [] @@ -1165,7 +1163,7 @@ class TestRegisterToolsFromOpenAPI: ): import re - from litellm.proxy._experimental.mcp_server import openapi_to_mcp_generator + from litellm.proxy.mcp_server import openapi_to_mcp_generator registered: list = [] @@ -1561,7 +1559,7 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.asyncio @pytest.mark.parametrize("max_bytes", [12, 13]) async def test_exact_size_and_smaller_specs_load(self, respx_mock, monkeypatch, max_bytes): - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async + from litellm.proxy.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") route = respx_mock.get("https://93.184.216.34/spec.json").respond(200, content=b'{"paths":{}}') @@ -1572,8 +1570,9 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.parametrize("headers", [{"content-length": "1000000"}, {"content-encoding": "gzip"}]) async def test_unsafe_response_headers_reject_before_reading(self, respx_mock, monkeypatch, headers): import httpx + from litellm.llms.custom_httpx.http_handler import HTTPResponseLimitError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( load_openapi_spec_async, ) @@ -1596,8 +1595,9 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.asyncio async def test_chunked_response_is_bounded_and_closed(self, respx_mock, monkeypatch): import httpx + from litellm.llms.custom_httpx.http_handler import HTTPResponseLimitError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( load_openapi_spec_async, ) @@ -1624,7 +1624,7 @@ class TestBoundedOpenAPISpecLoading: @pytest.mark.parametrize("target", ["https://93.184.216.35/final.json", "http://127.0.0.1/private.json"]) async def test_bounded_spec_redirects_preserve_ssrf_protection(self, respx_mock, monkeypatch, target): from litellm.litellm_core_utils.url_utils import SSRFError - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async + from litellm.proxy.mcp_server.openapi_to_mcp_generator import load_openapi_spec_async monkeypatch.setenv("DISABLE_AIOHTTP_TRANSPORT", "True") respx_mock.get("https://93.184.216.34/spec.json").respond(302, headers={"location": target}) @@ -1650,7 +1650,7 @@ def without_mcp(name, *args, **kwargs): raise ModuleNotFoundError('MCP SDK unavailable') return original_import(name, *args, **kwargs) builtins.__import__ = without_mcp -import litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator +import litellm.proxy.mcp_server.openapi_to_mcp_generator """ result = subprocess.run([sys.executable, "-c", script], capture_output=True, text=True) assert result.returncode == 0, result.stderr diff --git a/tests/unit/proxy/_experimental/mcp_server/test_openapi_tool_auth.py b/tests/unit/proxy/mcp_server/test_openapi_tool_auth.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_openapi_tool_auth.py rename to tests/unit/proxy/mcp_server/test_openapi_tool_auth.py index ffa25d63391..3ff925c486b 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_openapi_tool_auth.py +++ b/tests/unit/proxy/mcp_server/test_openapi_tool_auth.py @@ -1,4 +1,5 @@ -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations + """ VERIA-7 regression: OpenAPI-backed (local-registry) MCP tools must run through `pre_call_tool_check` before dispatch, the same as managed @@ -25,7 +26,7 @@ async def test_openapi_local_tool_runs_pre_call_tool_check(): """When `execute_mcp_tool` resolves a local-registry (OpenAPI) tool AND a server, the pre-call hook must fire before the local handler runs. Pre-fix this path skipped the hook entirely.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module user = UserAPIKeyAuth( api_key="sk-user", @@ -70,11 +71,11 @@ async def test_openapi_local_tool_runs_pre_call_tool_check(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -112,7 +113,7 @@ async def test_openapi_local_tool_blocked_when_pre_call_check_raises(): tool), the local handler must NOT be invoked.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module user = UserAPIKeyAuth( api_key="sk-user", @@ -159,11 +160,11 @@ async def test_openapi_local_tool_blocked_when_pre_call_check_raises(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -188,7 +189,7 @@ async def test_openapi_local_tool_denied_when_server_not_resolvable(): rather than dispatched without `pre_call_tool_check`.""" from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module user = UserAPIKeyAuth( api_key="sk-user", @@ -224,11 +225,11 @@ async def test_openapi_local_tool_denied_when_server_not_resolvable(): return_value=fake_tool, ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -256,14 +257,14 @@ async def test_openapi_local_tool_injects_resolved_oauth_token(): user's completed OAuth flow stored a token that never reached the upstream API. The resolved credential must land in the `_request_resolved_auth_headers` ContextVar the tool closure reads. Kills the mutant that deletes the resolve_openapi_upstream_auth call in server.py.""" - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_resolved_auth_headers, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.httpx_auth import ( + from litellm.proxy.mcp_server.outbound_credentials.httpx_auth import ( StaticHeaderAuth, ) - from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Ok + from litellm.proxy.mcp_server.outbound_credentials.result import Ok from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -315,11 +316,11 @@ async def test_openapi_local_tool_injects_resolved_oauth_token(): new=AsyncMock(return_value=Ok(StaticHeaderAuth("Bearer stored-user-token"))), ), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=handle_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -350,10 +351,10 @@ def legacy_local_tool(): Yields the server and the list the handler appends to, so a test can tell "refused" from "dispatched" by whether the handler actually ran. """ - from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + from litellm.proxy.mcp_server.mcp_server_manager import ( global_mcp_server_manager, ) - from litellm.proxy._experimental.mcp_server.tool_registry import ( + from litellm.proxy.mcp_server.tool_registry import ( global_mcp_tool_registry, ) @@ -412,8 +413,8 @@ async def test_legacy_local_tool_fallback_refuses_unentitled_caller(legacy_local """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) @@ -461,7 +462,7 @@ async def test_legacy_local_tool_fallback_still_dispatches_entitled_caller( This is the backwards-compatibility half. Refusing this call would trade an authorization hole for an outage on a configuration that worked before. """ - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module server, executed = legacy_local_tool user = _caller_entitled_to([LEGACY_TOOL]) @@ -491,7 +492,7 @@ async def test_legacy_local_tool_fallback_fails_closed_on_empty_prefix( """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module _server, executed = legacy_local_tool @@ -520,7 +521,7 @@ async def test_legacy_local_tool_fallback_fails_closed_when_prefix_names_no_serv """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module _server, executed = legacy_local_tool other_server = MCPServer( @@ -534,7 +535,7 @@ async def test_legacy_local_tool_fallback_fails_closed_when_prefix_names_no_serv ) with patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ): with pytest.raises(HTTPException) as exc: @@ -558,7 +559,7 @@ async def test_unknown_tool_name_still_reports_not_found(): """ from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import server as mcp_module + from litellm.proxy.mcp_server import server as mcp_module with pytest.raises(HTTPException) as exc: await mcp_operations.execute_mcp_tool( @@ -603,8 +604,8 @@ async def test_per_server_auth_header_reaches_both_openapi_dispatch_arms(dispatc modes the credential has to reach `resolve_openapi_upstream_auth`, whose passthrough arm outranks the ContextVar when it materializes a header. """ - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( request_auth_header, ) @@ -640,11 +641,11 @@ async def test_per_server_auth_header_reaches_both_openapi_dispatch_arms(dispatc patch.object(manager, "get_mcp_server_from_tool_name", return_value=server), patch.object(mcp_operations.global_mcp_tool_registry, "get_tool", return_value=fake_tool), patch( - "litellm.proxy._experimental.mcp_server.operations._handle_local_mcp_tool", + "litellm.proxy.mcp_server.operations._handle_local_mcp_tool", new=capture_local, ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -690,8 +691,8 @@ async def test_local_dispatch_reports_the_outcome_instead_of_success(failure: st `call_tool_rest_api` turns an unrecognized exception into HTTP 500 and an upstream 403 or 429 is not a gateway crash. """ - from litellm.proxy._experimental.mcp_server import server as mcp_module - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server import server as mcp_module + from litellm.proxy.mcp_server.exceptions import ( MCPOpenApiUpstreamError, MCPUpstreamAuthError, ) @@ -732,7 +733,7 @@ async def test_local_dispatch_reports_the_outcome_instead_of_success(failure: st new=AsyncMock(return_value=(None, None)), ), patch( - "litellm.proxy._experimental.mcp_server.server.MCPRequestHandler.is_tool_allowed", + "litellm.proxy.mcp_server.server.MCPRequestHandler.is_tool_allowed", return_value=True, ), ): @@ -797,9 +798,9 @@ def test_the_openapi_arm_installs_the_guard_when_a_credential_rides_a_custom_slo """Pins the wiring, not just the hook: the arm must actually build a guarded client. Testing the hook alone passes even if this arm never installs it. """ - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_resolved_auth_headers, + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _upstream_client, + request_resolved_auth_headers, ) token = request_resolved_auth_headers.set({"esb-oauth": "Bearer minted"}) @@ -815,9 +816,9 @@ def test_the_guarded_client_is_reused_rather_than_built_per_call(): sets upstream_token_header would leak an httpx client and its connection pool. Both variants have to come from the shared cache. """ - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_resolved_auth_headers, + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _upstream_client, + request_resolved_auth_headers, ) token = request_resolved_auth_headers.set({"esb-oauth": "Bearer minted"}) @@ -834,10 +835,10 @@ async def test_the_shared_guard_reads_the_url_from_the_request_context(): """ import httpx - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _drop_credential_across_origin, - request_resolved_auth_headers, _request_upstream_url, + request_resolved_auth_headers, ) creds = request_resolved_auth_headers.set({"esb-oauth": "Bearer minted"}) @@ -859,9 +860,9 @@ async def test_the_shared_guard_reads_the_url_from_the_request_context(): def test_the_openapi_arm_keeps_the_shared_client_when_no_guard_is_needed(resolved): # Authorization is already stripped across origins by the HTTP client, so taking the guarded # path for it would give up the shared connection pool for nothing. - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import ( - request_resolved_auth_headers, + from litellm.proxy.mcp_server.openapi_to_mcp_generator import ( _upstream_client, + request_resolved_auth_headers, ) token = request_resolved_auth_headers.set(resolved) @@ -880,7 +881,7 @@ async def test_openapi_passthrough_preparation_preserves_credential_precedence( ) -> None: from typing import Final - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="openapi-passthrough", name="openapi-passthrough", transport=MCPTransport.http, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_operations.py b/tests/unit/proxy/mcp_server/test_operations.py similarity index 94% rename from tests/unit/proxy/_experimental/mcp_server/test_operations.py rename to tests/unit/proxy/mcp_server/test_operations.py index 6f7437c90dc..497c4482eba 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_operations.py +++ b/tests/unit/proxy/mcp_server/test_operations.py @@ -11,20 +11,21 @@ from mcp.types import Tool as MCPTool import litellm from litellm.caching.dual_cache import DualCache from litellm.integrations.custom_logger import CustomLogger -from litellm.proxy._experimental.mcp_server import operations -from litellm.proxy._experimental.mcp_server import rest_endpoints -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( - HTTPException as MCPServerManagerHTTPException, - ListedToolsCaller, -) -from litellm.proxy._experimental.mcp_server.operations import GatewayOperations, prepare_context -from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry from litellm.proxy._types import UserAPIKeyAuth -from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError +from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache from litellm.proxy.hooks.parallel_request_limiter_v3 import ( PROXY_MaxParallelRequestsHandler_v3, ) +from litellm.proxy.mcp_server import operations, rest_endpoints +from litellm.proxy.mcp_server.mcp_server_manager import ( + HTTPException as MCPServerManagerHTTPException, +) +from litellm.proxy.mcp_server.mcp_server_manager import ( + ListedToolsCaller, +) +from litellm.proxy.mcp_server.operations import GatewayOperations, prepare_context +from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry from litellm.proxy.utils import InternalUsageCache, ProxyLogging, hash_token from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -106,11 +107,11 @@ async def test_mapped_caller_bearer_reaches_agent_evaluation( from starlette.requests import Request from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler - from litellm.proxy._experimental.mcp_server import server as gateway - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler - from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode - from litellm.proxy._experimental.mcp_server.tool_search import mcp_proxy_tool_id, with_mcp_proxy_identity from litellm.proxy.guardrails.guardrail_hooks.agent_365.agent_365 import Agent365Guardrail + from litellm.proxy.mcp_server import server as gateway + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler + from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode + from litellm.proxy.mcp_server.tool_search import mcp_proxy_tool_id, with_mcp_proxy_identity bearer: Final = "signed.caller.assertion" request: Final = Request( @@ -163,7 +164,7 @@ async def test_mapped_caller_bearer_reaches_agent_evaluation( executions: Final[asyncio.Queue[str]] = asyncio.Queue() async def tool() -> str: - from litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator import request_extra_headers + from litellm.proxy.mcp_server.openapi_to_mcp_generator import request_extra_headers assert bearer not in str(request_extra_headers.get()) executions.put_nowait("executed") @@ -313,14 +314,14 @@ async def test_listing_records_only_tools_the_caller_received( @pytest.mark.asyncio async def test_oauth_prefetch_failure_does_not_log_caller_or_exception_text(caplog): - from litellm.proxy._experimental.mcp_server.operations import _prefetch_oauth_creds_for_user + from litellm.proxy.mcp_server.operations import _prefetch_oauth_creds_for_user user_id = "caller\nFORGED-USER-LINE" fetch = AsyncMock(side_effect=RuntimeError("database\nFORGED-ERROR-LINE")) database = object() with ( patch("litellm.proxy.utils.get_prisma_client_or_throw", return_value=database), - patch("litellm.proxy._experimental.mcp_server.db.list_user_oauth_credentials", fetch), + patch("litellm.proxy.mcp_server.db.list_user_oauth_credentials", fetch), caplog.at_level("WARNING", logger="LiteLLM"), ): result = await _prefetch_oauth_creds_for_user(UserAPIKeyAuth(user_id=user_id)) @@ -337,7 +338,7 @@ async def test_oauth_prefetch_failure_does_not_log_caller_or_exception_text(capl async def test_dispatch_uses_explicit_context_when_ambient_caller_differs(): from mcp.server.auth.middleware.auth_context import auth_context_var - from litellm.proxy._experimental.mcp_server.server import set_auth_context + from litellm.proxy.mcp_server.server import set_auth_context context = prepare_context( UserAPIKeyAuth(user_id="alpha"), @@ -349,7 +350,7 @@ async def test_dispatch_uses_explicit_context_when_ambient_caller_differs(): handler = AsyncMock(return_value=GetPromptResult(messages=[])) try: set_auth_context(UserAPIKeyAuth(user_id="bravo"), raw_headers={"x-caller": "bravo"}) - with patch("litellm.proxy._experimental.mcp_server.operations.mcp_get_prompt", handler): + with patch("litellm.proxy.mcp_server.operations.mcp_get_prompt", handler): result = await GatewayOperations().execute( GetPromptRequest(params=GetPromptRequestParams(name="alpha-prompt")), context ) @@ -367,8 +368,8 @@ async def test_dispatch_uses_explicit_context_when_ambient_caller_differs(): async def test_legacy_adapter_cleans_context_after_cancelled_operation(): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var previous_session = server.active_mcp_session_var.get() previous_request = active_mcp_request_ctx_var.get() @@ -382,7 +383,7 @@ async def test_legacy_adapter_cleans_context_after_cancelled_operation(): raise asyncio.CancelledError with patch( - "litellm.proxy._experimental.mcp_server.server.get_or_extract_auth_context", AsyncMock(return_value=auth) + "litellm.proxy.mcp_server.server.get_or_extract_auth_context", AsyncMock(return_value=auth) ): with pytest.raises(asyncio.CancelledError): await cancelled_operation() @@ -394,8 +395,8 @@ async def test_legacy_adapter_cleans_context_after_cancelled_operation(): async def test_legacy_adapter_cleans_context_when_trace_setup_fails(): from types import SimpleNamespace - from litellm.proxy._experimental.mcp_server import server - from litellm.proxy._experimental.mcp_server.mcp_context import active_mcp_request_ctx_var + from litellm.proxy.mcp_server import server + from litellm.proxy.mcp_server.mcp_context import active_mcp_request_ctx_var previous_session = server.active_mcp_session_var.get() previous_request = active_mcp_request_ctx_var.get() @@ -416,7 +417,7 @@ async def test_legacy_adapter_cleans_context_when_trace_setup_fails(): async def test_prompt_sampling_receives_explicit_operation_caller_headers_and_ip(): from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -437,8 +438,8 @@ async def test_prompt_sampling_receives_explicit_operation_caller_headers_and_ip sampling = AsyncMock() with ( patch.object(operations, "_get_allowed_mcp_servers", AsyncMock(return_value=[upstream])), - patch("litellm.proxy._experimental.mcp_server.upstream.MCPClient", return_value=client) as factory, - patch("litellm.proxy._experimental.mcp_server.sampling_handler.handle_sampling_create_message", sampling), + patch("litellm.proxy.mcp_server.upstream.MCPClient", return_value=client) as factory, + patch("litellm.proxy.mcp_server.sampling_handler.handle_sampling_create_message", sampling), ): result = await GatewayOperations().execute( GetPromptRequest(params=GetPromptRequestParams(name="explicit_prompt-prompt")), context @@ -519,7 +520,7 @@ async def test_disabled_capability_never_reaches_upstream( from mcp.types import METHOD_NOT_FOUND from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog + from litellm.proxy.mcp_server import catalog monkeypatch.setitem(proxy_server.general_settings, "mcp_disabled_capabilities", [disabled]) request, _client_method, manager_method, upstream_value, result_field = _catalog_case(operation) @@ -567,8 +568,8 @@ async def test_mcp_server_rpm_limits_every_catalog_operation(operation: str) -> from mcp.shared.exceptions import MCPError from mcp.types import INVALID_REQUEST - from litellm.proxy._experimental.mcp_server import catalog - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk + from litellm.proxy.mcp_server import catalog + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk server: Final = MCPServer( server_id="catalog-rpm", @@ -712,7 +713,7 @@ def _scoped_rig( from mcp.types import CallToolResult, TextContent from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() memory: Final = MCPServer( @@ -787,7 +788,7 @@ async def test_bare_tool_name_without_a_single_server_scope_is_still_unresolved_ @pytest.mark.asyncio async def test_tools_call_pre_call_check_enforces_mcp_server_rpm() -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="catalog-call", @@ -822,7 +823,7 @@ async def test_tools_call_pre_call_check_enforces_mcp_server_rpm() -> None: async def test_tools_call_pre_call_hook_rejection_does_not_enforce_mcp_server_rpm() -> None: from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="catalog-call-pre-hook-rejected", @@ -854,7 +855,7 @@ async def test_tools_call_pre_call_hook_rejection_does_not_enforce_mcp_server_rp @pytest.mark.asyncio async def test_disallowed_tool_does_not_consume_mcp_server_rpm() -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="catalog-call-authorization", @@ -900,7 +901,7 @@ async def test_catalog_helpers_preserve_context_results_and_failure_policy(metho from mcp.server.context import ServerRequestContext from mcp.types import PaginatedRequestParams - from litellm.proxy._experimental.mcp_server import operations, server + from litellm.proxy.mcp_server import operations, server from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -967,7 +968,7 @@ async def test_explicit_proxy_context_rejects_catalog_operations_before_upstream from mcp.shared.exceptions import MCPError from mcp.types import METHOD_NOT_FOUND - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations operation, _, manager_method, _, _ = _catalog_case(method) upstream = AsyncMock() @@ -985,8 +986,8 @@ async def test_tool_operation_preserves_failure_messages_and_request_trace(failu from mcp.types import CallToolRequest, CallToolRequestParams from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.utils import MCPMissingUserEnvVarsError + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.utils import MCPMissingUserEnvVarsError failures = { "missing_env": ( @@ -1029,7 +1030,7 @@ async def test_tool_operation_preserves_failure_messages_and_request_trace(failu ], ) async def test_catalog_operation_preserves_empty_result_for_malformed_upstream_items(method, helper): - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations operation, _, _, _, collection = _catalog_case(method) with patch.object(operations, helper, AsyncMock(return_value=[{"unexpected": "item"}])): @@ -1042,7 +1043,7 @@ async def test_catalog_operation_preserves_empty_result_for_malformed_upstream_i async def test_tool_listing_returns_empty_result_without_dispatch_for_unavailable_catalog(catalog_unavailable): from mcp.types import ListToolsRequest - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations allowed = AsyncMock( return_value=[], side_effect=RuntimeError("catalog unavailable") if catalog_unavailable else None @@ -1062,7 +1063,7 @@ async def test_tool_listing_returns_empty_result_without_dispatch_for_unavailabl async def test_explicit_proxy_context_lists_builtin_tools_and_blocks_direct_tool_dispatch(): from mcp.types import CallToolRequest, CallToolRequestParams, ListToolsRequest - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations context = prepare_context(mcp_proxy_mode=True) allowed = AsyncMock() @@ -1104,7 +1105,7 @@ class TestChallengeMissingTokenExchangeSubject: raw_headers: dict[str, str] | None = None, requested_server: MCPServer | None = None, ) -> None: - from litellm.proxy._experimental.mcp_server.operations import _challenge_missing_token_exchange_subject + from litellm.proxy.mcp_server.operations import _challenge_missing_token_exchange_subject return _challenge_missing_token_exchange_subject( server=server, @@ -1200,7 +1201,7 @@ async def test_execute_mcp_tool_challenges_missing_subject_before_cold_listing() from fastapi import HTTPException - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations server = _server("te-exec", MCPAuth.oauth2_token_exchange) listing = AsyncMock() @@ -1230,9 +1231,9 @@ async def test_local_tool_json_array_is_converted_once_for_the_caller_revision(c text block; converting at the caller's revision keeps the upstream body exactly once.""" from unittest.mock import MagicMock - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.tool_outcome import WireCompat, parse_http_body - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.tool_outcome import WireCompat, parse_http_body + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry body = '["a","b"]' tool = MagicMock() @@ -1253,7 +1254,7 @@ async def test_discovery_preserves_caller_scope_and_proxy_restrictions(): context = prepare_context( UserAPIKeyAuth(user_id="scoped"), mcp_servers=["only-this"], mcp_proxy_mode=True, protocol_version="2025-06-18" ) - with patch("litellm.proxy._experimental.mcp_server.operations._execute_handle_list_tools", listed): + with patch("litellm.proxy.mcp_server.operations._execute_handle_list_tools", listed): result = await GatewayOperations().execute(DiscoverRequest(), context) assert result.capabilities.tools is not None assert result.capabilities.resources is None @@ -1267,8 +1268,8 @@ async def test_discovery_preserves_caller_scope_and_proxy_restrictions(): async def test_discovery_outright_tools_failure_still_advertises_other_capabilities() -> None: from mcp.types import DiscoverRequest, ListPromptsResult, ListToolsResult, Prompt - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.catalog import ToolListingFailedOutright + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.catalog import ToolListingFailedOutright tools: Final = AsyncMock(side_effect=ToolListingFailedOutright(code=-32603, message="every server failed")) prompts: Final = AsyncMock(return_value=ListPromptsResult(prompts=[Prompt(name="p")])) @@ -1289,7 +1290,7 @@ async def test_discovery_propagates_non_outright_mcp_errors_from_tools_listing() from mcp import MCPError from mcp.types import INVALID_PARAMS, DiscoverRequest - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations tools: Final = AsyncMock(side_effect=MCPError(code=INVALID_PARAMS, message="bad cursor")) context: Final = prepare_context( @@ -1304,11 +1305,11 @@ async def test_discovery_propagates_non_outright_mcp_errors_from_tools_listing() @pytest.mark.asyncio async def test_discovery_denial_cannot_advertise_tools(): - from mcp.types import DiscoverRequest from fastapi import HTTPException + from mcp.types import DiscoverRequest denied = AsyncMock(side_effect=HTTPException(status_code=403, detail="Forbidden")) - with patch("litellm.proxy._experimental.mcp_server.operations._execute_handle_list_tools", denied): + with patch("litellm.proxy.mcp_server.operations._execute_handle_list_tools", denied): with pytest.raises(HTTPException) as error: await GatewayOperations().execute(DiscoverRequest(), prepare_context(UserAPIKeyAuth(user_id="denied"))) assert error.value.status_code == 403 @@ -1319,15 +1320,16 @@ async def test_discovery_denial_cannot_advertise_tools(): async def test_discovery_lists_each_capability_with_the_same_caller(available): from mcp.types import ( DiscoverRequest, - ListToolsResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, + ListToolsResult, Prompt, Resource, ResourceTemplate, ) - from litellm.proxy._experimental.mcp_server import operations + + from litellm.proxy.mcp_server import operations context = prepare_context(UserAPIKeyAuth(user_id="scoped"), mcp_servers=["authorized"]) tools = AsyncMock(return_value=ListToolsResult(tools=[])) @@ -1408,9 +1410,9 @@ async def test_discovery_skips_disabled_capability_listings(disabled: str, monke async def test_discovery_shares_one_server_admission_across_catalog_listings() -> None: from mcp import types - from litellm.proxy._experimental.mcp_server import catalog - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk + from litellm.proxy.mcp_server import catalog + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk admitted: Final = MCPServer( server_id="discover-admitted", @@ -1506,12 +1508,13 @@ async def test_discovery_shares_one_server_admission_across_catalog_listings() - async def test_discovery_concurrent_listings_drain_on_failure_and_cancellation(outcome): from mcp.types import ( DiscoverRequest, - ListToolsResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, + ListToolsResult, ) - from litellm.proxy._experimental.mcp_server import operations + + from litellm.proxy.mcp_server import operations ready = [asyncio.Event() for _ in range(4)] closed = [asyncio.Event() for _ in range(4)] @@ -1570,7 +1573,8 @@ async def test_discovery_concurrent_listings_drain_on_failure_and_cancellation(o @pytest.mark.parametrize("log_enabled", [False, True]) async def test_tools_listing_preserves_explicit_spend_log_policy(log_enabled): from mcp.types import PaginatedRequestParams - from litellm.proxy._experimental.mcp_server import operations + + from litellm.proxy.mcp_server import operations listing = AsyncMock(return_value=operations.AggregateToolListing(tools=[], outcomes={})) with patch.object(operations, "_list_mcp_tools", listing): @@ -1614,14 +1618,15 @@ async def test_list_mcp_tools_records_the_catalog_only_when_asked( async def test_discovery_keeps_one_catalog_revision_across_concurrent_listings(monkeypatch): from mcp.types import ( DiscoverRequest, - ListToolsResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, + ListToolsResult, ) + from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import operations - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server import operations + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager = MCPServerManager() original = MCPServer(server_id="catalog-server", name="before", transport=MCPTransport.http) @@ -1667,7 +1672,7 @@ async def test_local_handler_freshness_tracks_registered_owner_with_overlapping_ from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager monkeypatch.setattr(proxy_server, "prisma_client", None) manager = MCPServerManager() @@ -1710,7 +1715,7 @@ async def test_local_call_cannot_borrow_another_servers_authority( from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() allowed: Final = MCPServer(server_id="allowed", name="allowed", transport=MCPTransport.http) @@ -1747,7 +1752,7 @@ async def test_local_call_preserves_matching_and_legacy_handlers( from datetime import datetime from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() server: Final = MCPServer(server_id="allowed", name="allowed", transport=MCPTransport.http) @@ -1777,7 +1782,7 @@ async def test_local_handler_rejects_an_owner_absent_from_the_catalog(monkeypatc from fastapi import HTTPException from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager manager: Final = MCPServerManager() handler: Final = AsyncMock(return_value="private result") @@ -1854,6 +1859,7 @@ async def test_optional_catalog_preserves_revoked_user_error(monkeypatch, reques from types import SimpleNamespace from mcp import MCPError, types + from litellm.caching.dual_cache import DualCache from litellm.proxy import proxy_server @@ -1943,7 +1949,8 @@ async def test_guardrail_context_never_recovers_a_previous_request_bearer( ) -> None: from mcp.server.auth.middleware.auth_context import auth_context_var from starlette.requests import Request - from litellm.proxy._experimental.mcp_server import server as gateway + + from litellm.proxy.mcp_server import server as gateway request: Final = ( None @@ -1988,12 +1995,19 @@ async def test_guardrail_context_never_recovers_a_previous_request_bearer( @pytest.mark.parametrize("delay", ["target", "probe", "exhausted"]) async def test_discovery_optional_probes_use_remaining_listing_budget(delay, monkeypatch): from types import SimpleNamespace + from mcp.types import ( - DiscoverRequest, ListToolsResult, ListPromptsResult, ListResourcesResult, - ListResourceTemplatesResult, ToolsCapability, Tool, + DiscoverRequest, + ListPromptsResult, + ListResourcesResult, + ListResourceTemplatesResult, + ListToolsResult, + Tool, + ToolsCapability, ) + from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import subscriptions + from litellm.proxy.mcp_server import subscriptions entered = asyncio.Event() cleaned = asyncio.Event() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.py b/tests/unit/proxy/mcp_server/test_per_user_oauth_cache.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.py rename to tests/unit/proxy/mcp_server/test_per_user_oauth_cache.py index efddd1beef3..c0e23319566 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_per_user_oauth_cache.py +++ b/tests/unit/proxy/mcp_server/test_per_user_oauth_cache.py @@ -19,7 +19,7 @@ for _mod in ("orjson",): if _mod not in sys.modules: sys.modules[_mod] = MagicMock() -from litellm.proxy._experimental.mcp_server.oauth2_token_cache import ( # noqa: E402 +from litellm.proxy.mcp_server.oauth2_token_cache import ( # noqa: E402 MCPPerUserTokenCache, compute_per_user_token_ttl, mcp_per_user_token_cache, @@ -30,7 +30,7 @@ from litellm.types.mcp_server.mcp_server_manager import MCPServer # noqa: E402 def _import_validate(): """Lazy import to avoid pulling orjson at collection time.""" - from litellm.proxy._experimental.mcp_server.discoverable_endpoints import ( + from litellm.proxy.mcp_server.discoverable_endpoints import ( _validate_token_response, ) @@ -263,7 +263,7 @@ class TestMCPPerUserTokenCache: async def test_get_returns_none_on_miss(self, cache, mock_dual_cache): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.decrypt_value_helper" + "litellm.proxy.mcp_server.oauth2_token_cache.decrypt_value_helper" ) as mock_decrypt, patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), ): @@ -278,7 +278,7 @@ class TestMCPPerUserTokenCache: fake_plaintext = "xoxb-slack-token" with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.decrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.decrypt_value_helper", return_value=fake_plaintext, ) as mock_decrypt, patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -298,7 +298,7 @@ class TestMCPPerUserTokenCache: fake_encrypted = "encrypted_blob_xyz" with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.encrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.encrypt_value_helper", return_value=fake_encrypted, ) as mock_encrypt, patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -315,7 +315,7 @@ class TestMCPPerUserTokenCache: async def test_set_uses_correct_cache_key(self, cache, mock_dual_cache): with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.encrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.encrypt_value_helper", return_value="enc", ), patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -339,7 +339,7 @@ class TestMCPPerUserTokenCache: """Cache misses and decrypt errors should both return None without raising.""" with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.decrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.decrypt_value_helper", return_value=None, # decrypt returns None on failure ), patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -355,7 +355,7 @@ class TestMCPPerUserTokenCache: mock_dual_cache.async_set_cache.side_effect = RuntimeError("Redis down") with ( patch( - "litellm.proxy._experimental.mcp_server.oauth2_token_cache.encrypt_value_helper", + "litellm.proxy.mcp_server.oauth2_token_cache.encrypt_value_helper", return_value="enc", ), patch("litellm.proxy.proxy_server.user_api_key_cache", mock_dual_cache), @@ -385,7 +385,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_returns_none_when_no_refresh_token(self, server): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token cred = {"type": "oauth2", "access_token": "OLD"} # no refresh_token result = await refresh_user_oauth_token( @@ -398,7 +398,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_returns_none_when_no_token_url(self, cred): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token server = _make_server(token_url=None) result = await refresh_user_oauth_token( @@ -411,13 +411,13 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_returns_none_on_http_error(self, server, cred): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token mock_client = AsyncMock() mock_client.post.side_effect = Exception("Connection refused") with patch( - "litellm.proxy._experimental.mcp_server.db.get_async_httpx_client", + "litellm.proxy.mcp_server.db.get_async_httpx_client", return_value=mock_client, ): result = await refresh_user_oauth_token( @@ -430,7 +430,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_stores_and_returns_new_credential(self, server, cred): - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token new_token_response = MagicMock() new_token_response.json.return_value = { @@ -453,15 +453,15 @@ class TestRefreshUserOauthToken: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_async_httpx_client", + "litellm.proxy.mcp_server.db.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new_callable=AsyncMock, ) as mock_store, patch( - "litellm.proxy._experimental.mcp_server.db.get_user_oauth_credential", + "litellm.proxy.mcp_server.db.get_user_oauth_credential", new_callable=AsyncMock, return_value=stored_cred, ), @@ -486,7 +486,7 @@ class TestRefreshUserOauthToken: @pytest.mark.asyncio async def test_falls_back_to_old_refresh_token_when_not_rotated(self, server, cred): """When provider doesn't return a new refresh_token, keep the old one.""" - from litellm.proxy._experimental.mcp_server.db import refresh_user_oauth_token + from litellm.proxy.mcp_server.db import refresh_user_oauth_token new_token_response = MagicMock() new_token_response.json.return_value = { @@ -501,15 +501,15 @@ class TestRefreshUserOauthToken: with ( patch( - "litellm.proxy._experimental.mcp_server.db.get_async_httpx_client", + "litellm.proxy.mcp_server.db.get_async_httpx_client", return_value=mock_client, ), patch( - "litellm.proxy._experimental.mcp_server.db.store_user_oauth_credential", + "litellm.proxy.mcp_server.db.store_user_oauth_credential", new_callable=AsyncMock, ) as mock_store, patch( - "litellm.proxy._experimental.mcp_server.db.get_user_oauth_credential", + "litellm.proxy.mcp_server.db.get_user_oauth_credential", new_callable=AsyncMock, return_value={"type": "oauth2", "access_token": "NEW_TOKEN"}, ), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_proxy_api_credentials.py b/tests/unit/proxy/mcp_server/test_proxy_api_credentials.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_proxy_api_credentials.py rename to tests/unit/proxy/mcp_server/test_proxy_api_credentials.py index f39aec82c3e..f3d0fed0222 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_proxy_api_credentials.py +++ b/tests/unit/proxy/mcp_server/test_proxy_api_credentials.py @@ -7,20 +7,20 @@ from fastapi import HTTPException from litellm.constants import CLI_JWT_EXPIRATION_HOURS from litellm.models.user import LiteLLM_UserTable -from litellm.proxy._experimental.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential -from litellm.proxy._experimental.mcp_server.proxy_api_credentials import ( - lookup_consent_teams, - lookup_consent_teams_from_database, - mint_proxy_credential, -) from litellm.proxy._types import LitellmUserRoles from litellm.proxy.auth.auth_checks import ExperimentalUIJWTToken from litellm.proxy.auth.route_checks import RouteChecks from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache from litellm.proxy.management_endpoints.ui_sso import CliSsoTeamDetail +from litellm.proxy.mcp_server.gateway_dcr_flow import ConsentTeam, MintedProxyCredential +from litellm.proxy.mcp_server.proxy_api_credentials import ( + lookup_consent_teams, + lookup_consent_teams_from_database, + mint_proxy_credential, +) -_LOAD_USER = "litellm.proxy._experimental.mcp_server.proxy_api_credentials.load_active_user_by_id" -_FETCH_TEAMS = "litellm.proxy._experimental.mcp_server.proxy_api_credentials.fetch_cli_sso_team_details" +_LOAD_USER = "litellm.proxy.mcp_server.proxy_api_credentials.load_active_user_by_id" +_FETCH_TEAMS = "litellm.proxy.mcp_server.proxy_api_credentials.fetch_cli_sso_team_details" _PRISMA = "litellm.proxy.proxy_server.prisma_client" TEAM_DETAILS = ( CliSsoTeamDetail(team_id="team-a", team_alias="Team A", team_models=("gpt-5.4-mini",)), diff --git a/tests/unit/proxy/_experimental/mcp_server/test_rest_endpoints.py b/tests/unit/proxy/mcp_server/test_rest_endpoints.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_rest_endpoints.py rename to tests/unit/proxy/mcp_server/test_rest_endpoints.py index 73e248ff52e..84d32934208 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_rest_endpoints.py +++ b/tests/unit/proxy/mcp_server/test_rest_endpoints.py @@ -6,7 +6,7 @@ from datetime import datetime from typing import Any, Dict, Final, Optional from unittest.mock import AsyncMock, MagicMock -from litellm.proxy._experimental.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server import operations as mcp_operations if sys.version_info < (3, 11): # BaseExceptionGroup is a builtin only from 3.11 from exceptiongroup import BaseExceptionGroup @@ -18,16 +18,16 @@ from mcp.types import CallToolResult, TextContent, Tool from starlette.requests import Request from litellm.constants import MCP_TOOL_LISTING_TIMEOUT -from litellm.proxy._experimental.mcp_server import rest_endpoints -from litellm.proxy._experimental.mcp_server.auth import ( - user_api_key_auth_mcp as auth_mcp, -) from litellm.proxy._types import ( NewMCPServerRequest, UpdateMCPServerRequest, UserAPIKeyAuth, ) from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.proxy.mcp_server import rest_endpoints +from litellm.proxy.mcp_server.auth import ( + user_api_key_auth_mcp as auth_mcp, +) from litellm.types.mcp import MCPAuth, MCPTransport, MCPUpstreamProtocol from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -114,9 +114,9 @@ class TestExecuteWithMcpClient: ) -> None: from starlette.datastructures import Headers - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.mcp_client.client import MCPClient from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager saved: Final = MCPServer( server_id="saved-preview-server", @@ -184,8 +184,8 @@ class TestExecuteWithMcpClient: ) -> None: from starlette.datastructures import Headers - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager saved: Final = MCPServer( server_id="saved-preview-server", @@ -808,10 +808,9 @@ class TestTestConnection: """The edit form resends a saved server without its masked credential; the stored one must be used, as /test/tools/list already does.""" from litellm.proxy._types import LitellmUserRoles - from litellm.types.mcp_server.mcp_server_manager import MCPServer - - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.types.mcp_server.mcp_server_manager import MCPServer manager = MCPServerManager() monkeypatch.setattr(rest_endpoints, "global_mcp_server_manager", manager) @@ -1209,8 +1208,8 @@ class TestListToolsRestAPI: async def test_single_server_rate_limit_returns_429_without_fetching_tools( self, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="rate-limited-server", @@ -1249,8 +1248,8 @@ class TestListToolsRestAPI: async def test_admin_unfiltered_tools_list_does_not_enforce_server_rpm( self, monkeypatch: pytest.MonkeyPatch ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import LitellmUserRoles + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager server: Final = MCPServer( server_id="admin-unfiltered-server", @@ -1404,7 +1403,7 @@ class TestListToolsRestAPI: return admitted_auth monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", fake_reload, ) @@ -1519,7 +1518,7 @@ class TestListToolsRestAPI: return ["toolset-tool-1"] monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", record_reload, ) monkeypatch.setattr( @@ -1573,9 +1572,9 @@ class TestListToolsRestAPI: ) from mcp.types import Tool as MCPTool - import litellm.experimental_mcp_client.client as mcp_client_module - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager - from litellm.proxy._experimental.mcp_server.server import MCPServer + import litellm.mcp_client.client as mcp_client_module + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport monkeypatch.setattr(rest_endpoints, "global_mcp_server_manager", MCPServerManager()) @@ -1766,7 +1765,7 @@ class TestListToolsRestAPI: """A single-server pass-through request whose upstream rejects the token must surface the upstream status (401 or 403) plus its WWW-Authenticate challenge, not collapse into a 200 ``unexpected_error`` body.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -1835,10 +1834,10 @@ class TestListToolsRestAPI: """A single-server listing whose upstream breaks (5xx, timeout, unreachable) must answer with the truthful gateway status instead of masking the failure as an empty-success {"tools": [], "error": null} body a caller cannot distinguish from a toolless server.""" - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPServerListError, ) - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ( + from litellm.proxy.mcp_server.faults.list_outcomes import ( ServerListFault, ) @@ -1897,7 +1896,7 @@ class TestListToolsRestAPI: caller can tell "needs upstream auth" apart from "has no tools".""" from pydantic import TypeAdapter - from litellm.proxy._experimental.mcp_server.exceptions import ( + from litellm.proxy.mcp_server.exceptions import ( MCPUpstreamAuthError, ) @@ -1971,7 +1970,7 @@ class TestListToolsRestAPI: async def test_name_resolution_finds_server_by_uuid(self, monkeypatch): """When server_id is a name string, it should be resolved to its UUID and used for the tools lookup when the UUID is in allowed_server_ids.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2053,7 +2052,7 @@ class TestListToolsRestAPI: async def test_name_not_in_allowed_returns_access_denied(self, monkeypatch): """When name resolves to a server whose UUID is NOT in allowed_server_ids, the result should be an access_denied error (not a crash or silent pass).""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2109,7 +2108,7 @@ class TestListToolsRestAPI: async def test_mcp_server_name_query_param_resolves_to_server(self, monkeypatch): """mcp_server_name is a name-based alias for server_id: it should resolve to the matching server and scope the response to it.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2189,8 +2188,8 @@ class TestListToolsRestAPI: assert result["error"] is None async def test_mcp_server_name_filter_uses_real_catalog_with_tool_search(self, monkeypatch): - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2397,7 +2396,7 @@ class TestListToolsRestAPI: async def test_oauth2_user_token_injected_for_single_server(self, monkeypatch): """For a single-server OAuth2 request, _get_user_oauth_extra_headers is called and the returned headers are forwarded to _get_tools_for_single_server.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -2578,8 +2577,8 @@ class TestCallToolRestAPI: ) async def test_executes_tool_when_allowed(self, monkeypatch, tool_name, native_tool_name): import litellm - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler, MCPServerAccess - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import MCPRequestHandler, MCPServerAccess + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager async def fake_contexts(user_api_key_auth): return [user_api_key_auth] @@ -2713,9 +2712,9 @@ class TestCallToolRestAPI: ) -> None: import litellm from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LiteLLM_TeamTable, LiteLLM_UserTable from litellm.proxy.auth import auth_checks + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager target_server: Final = MCPServer( server_id="server-b", @@ -3141,7 +3140,7 @@ class TestCallToolRestAPI: MCPUpstreamAuthError) must reach the REST caller as that status with the upstream WWW-Authenticate preserved, so an MCP client can run the upstream OAuth flow, instead of the generic 500 the catch-all would otherwise produce.""" - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError async def fake_contexts(user_api_key_auth): return [user_api_key_auth] @@ -3473,9 +3472,9 @@ class TestCallToolRestAPI: without the direct branch's relay wrapper, so an MCPUpstreamAuthError from it must be relayed by the endpoint-level handler (a real 401/403 + WWW-Authenticate) rather than falling through the catch-all into a generic 500.""" - import litellm.proxy._experimental.mcp_server.tool_search as tool_search_mod - from litellm.proxy._experimental.mcp_server.exceptions import MCPUpstreamAuthError + import litellm.proxy.mcp_server.tool_search as tool_search_mod from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.exceptions import MCPUpstreamAuthError challenge = 'Bearer resource_metadata="https://gw.example.com/.well-known/oauth-protected-resource"' @@ -3587,9 +3586,9 @@ async def test_request_selected_tool_specific_guardrail_applies_to_virtual_execu import litellm from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager, server, tool_registry from litellm.proxy._types import LiteLLM_ObjectPermissionTable from litellm.proxy.guardrails.guardrail_hooks.custom_code.custom_code_guardrail import CustomCodeGuardrail + from litellm.proxy.mcp_server import mcp_server_manager, server, tool_registry from litellm.proxy.utils import ProxyLogging guardrail: Final = CustomCodeGuardrail( @@ -3672,8 +3671,8 @@ class TestGetToolsForSingleServer: async def test_filters_tools_by_object_permission_mcp_tool_permissions(self, monkeypatch): """Test that tools are filtered by user_api_key_auth.object_permission.mcp_tool_permissions""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3728,7 +3727,7 @@ class TestGetToolsForSingleServer: async def test_no_filtering_when_object_permission_is_none(self, monkeypatch): """Test that all tools are returned when object_permission is None""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3769,8 +3768,8 @@ class TestGetToolsForSingleServer: async def test_no_filtering_when_mcp_tool_permissions_is_none(self, monkeypatch): """Test that all tools are returned when mcp_tool_permissions is None""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3816,8 +3815,8 @@ class TestGetToolsForSingleServer: async def test_no_filtering_when_server_not_in_mcp_tool_permissions(self, monkeypatch): """Test that all tools are returned when server is not in mcp_tool_permissions""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3863,8 +3862,8 @@ class TestGetToolsForSingleServer: async def test_combines_server_allowed_tools_and_object_permission_filters(self, monkeypatch): """Test that both server.allowed_tools and object_permission.mcp_tool_permissions filters are applied""" - from litellm.proxy._experimental.mcp_server.server import MCPServer from litellm.proxy._types import LiteLLM_ObjectPermissionTable + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -3920,7 +3919,7 @@ class TestGetToolsForSingleServer: async def test_apply_tool_filters_false_returns_full_catalog(self, monkeypatch): """apply_tool_filters=False returns the raw catalog without the server allowed_tools gate, so the config UI can render disabled tools as off.""" - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport mock_tools = [ @@ -4188,7 +4187,7 @@ class TestPreviewOpenAPITools: } } - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( openapi_to_mcp_generator, ) @@ -4228,7 +4227,7 @@ class TestPreviewOpenAPITools: suffixes (_2, _3, ...) get assigned to different operations and the dashboard shows names that differ from what's actually registered. """ - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( openapi_to_mcp_generator, ) @@ -4577,7 +4576,7 @@ class TestToolResponseMcpInfoEnrichment: def test_enriches_mcp_info_with_alias_and_server_id(self): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport server = MCPServer( @@ -4613,7 +4612,7 @@ class TestToolResponseMcpInfoEnrichment: def test_alias_none_is_explicit_in_mcp_info(self): from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport server = MCPServer( @@ -4678,10 +4677,10 @@ class TestRestListToolsetFiltering: from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp import ( + from litellm.proxy.mcp_server.auth.user_api_key_auth_mcp import ( MCPRequestHandler, ) - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport stub_server = MCPServer( @@ -4722,7 +4721,7 @@ class TestRestListToolsetFiltering: patch.object(MCPRequestHandler, "_get_key_object_permission", return_value=key_object_permission), patch.object(MCPRequestHandler, "_get_team_object_permission", AsyncMock(return_value=None)), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -4747,7 +4746,7 @@ class TestV1ResolvedOauth2Gate: @staticmethod def _oauth2_server(*, delegate_auth_to_upstream: bool) -> Any: - from litellm.proxy._experimental.mcp_server.server import MCPServer + from litellm.proxy.mcp_server.server import MCPServer from litellm.types.mcp import MCPTransport return MCPServer( @@ -4770,7 +4769,7 @@ class TestV1ResolvedOauth2Gate: async def test_user_oauth_headers_skip_v2_owned_servers( self, delegate_auth_to_upstream, expected_headers, expected_lookups, monkeypatch ): - from litellm.proxy._experimental.mcp_server import db as mcp_db + from litellm.proxy.mcp_server import db as mcp_db server = self._oauth2_server(delegate_auth_to_upstream=delegate_auth_to_upstream) resolve_token = AsyncMock(return_value={"access_token": "stored-token"}) @@ -4932,7 +4931,7 @@ class TestClientAllowlistOnRestRoutes: @pytest.mark.asyncio @pytest.mark.parametrize("revision", ("auto", "2024-11-05", "2025-06-18")) async def test_preview_client_honors_protocol_metadata(revision: MCPUpstreamProtocol) -> None: - from litellm.experimental_mcp_client.client import MCPClient + from litellm.mcp_client.client import MCPClient payload: Final = NewMCPServerRequest( server_name="preview", @@ -4970,9 +4969,9 @@ async def test_saved_preview_protocol_omission_and_explicit_edits( ) -> None: from starlette.datastructures import Headers - from litellm.experimental_mcp_client.client import MCPClient - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager + from litellm.mcp_client.client import MCPClient from litellm.proxy.management_endpoints import mcp_management_endpoints + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager saved: Final = MCPServer( server_id="saved-preview", @@ -5037,7 +5036,7 @@ async def test_rest_guardrail_bearer_excludes_admission_key( import litellm from litellm.caching.dual_cache import DualCache from litellm.integrations.custom_logger import CustomLogger - from litellm.proxy._experimental.mcp_server.tool_registry import global_mcp_tool_registry + from litellm.proxy.mcp_server.tool_registry import global_mcp_tool_registry observed: Final[asyncio.Queue[object]] = asyncio.Queue() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_result_conversion.py b/tests/unit/proxy/mcp_server/test_result_conversion.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_result_conversion.py rename to tests/unit/proxy/mcp_server/test_result_conversion.py index 9926fa131ab..bbc35f11f32 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_result_conversion.py +++ b/tests/unit/proxy/mcp_server/test_result_conversion.py @@ -7,7 +7,7 @@ from mcp_types.methods import serialize_server_result from mcp_types.version import KNOWN_PROTOCOL_VERSIONS, MODERN_PROTOCOL_VERSIONS from pydantic import JsonValue, ValidationError -from litellm.proxy._experimental.mcp_server.result_conversion import ( +from litellm.proxy.mcp_server.result_conversion import ( INPUT_REQUIRED_UNSUPPORTED_MESSAGE, JsonResult, TextResult, @@ -246,7 +246,8 @@ class TestToGatewayTool: @pytest.mark.parametrize("elapsed,expected", [(0, 1000), (0.0001, 999), (0.5, 500), (1, 0), (2, 0), (-1, 1000)]) def test_freshness_aging_preserves_content_and_scope(elapsed: float, expected: int) -> None: from mcp.types import ListPromptsResult, Prompt - from litellm.proxy._experimental.mcp_server.result_conversion import age_freshness + + from litellm.proxy.mcp_server.result_conversion import age_freshness result: Final = ListPromptsResult(prompts=[Prompt(name="kept")], ttl_ms=1000, cache_scope="public") aged: Final = age_freshness(result, elapsed) @@ -263,7 +264,8 @@ def test_aggregate_freshness_never_broadens_sharing( scopes: tuple[Literal["private", "public"], ...], expected: str ) -> None: from mcp.types import CacheableResult - from litellm.proxy._experimental.mcp_server.result_conversion import aggregate_freshness + + from litellm.proxy.mcp_server.result_conversion import aggregate_freshness result: Final = aggregate_freshness(tuple(CacheableResult(ttl_ms=1000, cache_scope=scope) for scope in scopes)) assert result.cache_scope == expected diff --git a/tests/unit/proxy/_experimental/mcp_server/test_semantic_tool_filter.py b/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_semantic_tool_filter.py rename to tests/unit/proxy/mcp_server/test_semantic_tool_filter.py index f0b4e94f72f..c04323d7f7c 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_semantic_tool_filter.py +++ b/tests/unit/proxy/mcp_server/test_semantic_tool_filter.py @@ -17,7 +17,6 @@ if sys.version_info < (3, 11): # BaseExceptionGroup is a builtin only from 3.11 from mcp.types import Tool as MCPTool - requires_semantic_router = pytest.mark.skipif( sys.version_info >= (3, 14), reason="The semantic-router extra excludes Python 3.14" ) @@ -33,7 +32,7 @@ async def test_semantic_filter_basic_filtering(): When: Query is "send an email" Then: Email tools should rank higher than calendar tools """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -161,7 +160,7 @@ async def test_semantic_filter_top_k_limiting(): When: top_k=5 Then: Should return at most 5 tools """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -222,7 +221,7 @@ async def test_semantic_filter_disabled(): """ Test that when filter is disabled, all tools are returned. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -261,7 +260,7 @@ async def test_semantic_filter_empty_tools(): """ Test that filter handles empty tool list gracefully. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -289,7 +288,7 @@ async def test_semantic_filter_extract_user_query(): """ Test that user query extraction works correctly from messages. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -341,10 +340,10 @@ async def test_semantic_filter_hook_triggers_on_completion(): """ Test that the hook triggers for completion requests with tools. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse # Create mock filter @@ -420,10 +419,10 @@ async def test_semantic_filter_hook_skips_no_tools(): """ Test that the hook does NOT trigger when there are no tools. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook # Create mock filter mock_router = Mock() @@ -473,10 +472,10 @@ async def test_semantic_filter_hook_preserves_native_tools(): Then: The native tools must survive unconditionally, and only MCP tools go through the semantic filter. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -605,10 +604,10 @@ async def test_semantic_filter_hook_all_native_tools(): Then: All tools pass through, and NO spurious semantic filter response headers are emitted (no litellm_semantic_filter_stats in metadata). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook mock_router = Mock() filter_instance = SemanticMCPToolFilter( @@ -706,10 +705,10 @@ async def test_semantic_filter_hook_responses_api_name_collision(): Then: The native tool must NOT be sent to the semantic filter, even though its name matches an MCP canonical. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -802,10 +801,10 @@ async def test_semantic_filter_hook_filters_expanded_litellm_proxy_tools(): were filtered out instead of silently forwarding all tools with no stats. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -924,10 +923,10 @@ async def test_semantic_filter_hook_narrows_mcp_reference_for_chat_completions() reference also removed the marker the MCP gateway matches on, which disabled tool auto-execution for require_approval="never". """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1039,10 +1038,10 @@ async def test_semantic_filter_hook_zero_matches_exposes_all_tools_on_both_paths filter_tools to fail closed must fail this test on both paths at once, instead of silently hard-limiting one surface and not the other. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1148,10 +1147,10 @@ async def test_semantic_filter_hook_filters_expanded_tools_with_string_input(): expanded-tool filtering must treat it as the user query instead of crashing (which would silently disable MCP expansion). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1218,10 +1217,10 @@ async def test_semantic_filter_hook_expansion_skips_filter_when_disabled(): stats, mirroring the generic path's enabled guard. The MCP gateway then expands the reference itself, so no tool is narrowed away. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook filter_instance = SemanticMCPToolFilter( embedding_model="text-embedding-3-small", @@ -1292,10 +1291,10 @@ async def test_semantic_filter_hook_preserves_tool_order(): Then: The output order must match the original request order, NOT native-first. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook from litellm.types.utils import Embedding, EmbeddingResponse mock_router = Mock() @@ -1402,7 +1401,7 @@ class TestGetToolsByNames: """ def _make_filter(self): - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -1572,10 +1571,10 @@ async def test_semantic_filter_headers_hook_emits_only_complete_tool_names(): contain complete tool names, in their original order, within the cap. """ from litellm.constants import MAX_MCP_SEMANTIC_FILTER_TOOLS_HEADER_LENGTH - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) - from litellm.proxy.hooks.mcp_semantic_filter import SemanticToolFilterHook filter_instance = SemanticMCPToolFilter( embedding_model="text-embedding-3-small", @@ -1654,7 +1653,7 @@ def _make_context_window_raising_router(state): def _make_context_window_filter(state, top_k: int = 3): - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -1675,7 +1674,7 @@ async def test_semantic_filter_fails_closed_on_query_time_context_window_error() user query must fail closed with a typed error instead of silently returning all tools (previously reported as N->N "success"). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) @@ -1708,7 +1707,7 @@ async def test_semantic_filter_records_build_time_context_window_error(): the build, which previously left the hook unregistered and filtering silently disabled) and must fail subsequent filtering closed. """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) @@ -1904,7 +1903,7 @@ def test_is_context_window_error_detection_variants(): generic error must not match. """ import litellm - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( _is_context_window_error, ) @@ -1941,7 +1940,7 @@ def test_is_context_window_error_sees_through_trees_the_chain_walk_missed(): ``__context__`` behind a non-matching ``__cause__``, buried inside an anyio-style ``ExceptionGroup``, and chained deeper than five links.""" import litellm - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( _is_context_window_error, ) @@ -2002,7 +2001,7 @@ def _make_keyword_embedding_router(recorded_inputs): def _make_keyword_filter(recorded_inputs, top_k: int = 3): - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticMCPToolFilter, ) @@ -2128,7 +2127,7 @@ async def test_request_time_context_window_error_is_request_scoped(): which EVERY user's MCP requests on the worker were blocked with a 400 until restart (index poisoning via a single request). """ - from litellm.proxy._experimental.mcp_server.semantic_tool_filter import ( + from litellm.proxy.mcp_server.semantic_tool_filter import ( SemanticToolFilterContextWindowError, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_server_resolution.py b/tests/unit/proxy/mcp_server/test_server_resolution.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_server_resolution.py rename to tests/unit/proxy/mcp_server/test_server_resolution.py index 4b9214916a8..4a5185a9410 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_server_resolution.py +++ b/tests/unit/proxy/mcp_server/test_server_resolution.py @@ -1,7 +1,6 @@ from __future__ import annotations import asyncio - from collections.abc import Awaitable, Callable, Mapping from dataclasses import dataclass from typing import Final, Literal @@ -10,16 +9,16 @@ from unittest.mock import Mock import pytest from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server.contracts import TargetCatalog -from litellm.proxy._experimental.mcp_server.server_resolution import ( +from litellm.proxy._types import LiteLLM_MCPServerTable, LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.mcp_server.contracts import TargetCatalog +from litellm.proxy.mcp_server.server_resolution import ( MCPServerTargetCatalog, ResolutionSource, ResolvedMCPServer, authorize_mcp_server, resolve_mcp_server, ) -from litellm.proxy._experimental.mcp_server.ui_session_utils import can_access_mcp_server -from litellm.proxy._types import LiteLLM_MCPServerTable, LitellmUserRoles, UserAPIKeyAuth +from litellm.proxy.mcp_server.ui_session_utils import can_access_mcp_server from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -342,7 +341,7 @@ async def test_authorize_uses_real_access_helper_for_canonical_id( return await can_access_mcp_server(user_api_key_auth, requested_server_id, allowed_servers) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server_resolution.can_access_mcp_server", + "litellm.proxy.mcp_server.server_resolution.can_access_mcp_server", spy_access, ) if expected_status is None: @@ -559,9 +558,9 @@ async def test_target_catalog_does_not_reuse_admin_authorization_for_another_cal async def test_catalog_without_listing_dependency_fails_explicitly(): from mcp.types import ListToolsRequest - from litellm.proxy._experimental.mcp_server.contracts import OperationContext - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager - from litellm.proxy._experimental.mcp_server.server_resolution import MCPServerTargetCatalog + from litellm.proxy.mcp_server.contracts import OperationContext + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager + from litellm.proxy.mcp_server.server_resolution import MCPServerTargetCatalog catalog = MCPServerTargetCatalog(MCPServerManager()) with pytest.raises(RuntimeError, match="listing dependency"): diff --git a/tests/unit/proxy/_experimental/mcp_server/test_short_mcp_tool_prefix.py b/tests/unit/proxy/mcp_server/test_short_mcp_tool_prefix.py similarity index 97% rename from tests/unit/proxy/_experimental/mcp_server/test_short_mcp_tool_prefix.py rename to tests/unit/proxy/mcp_server/test_short_mcp_tool_prefix.py index 7b6007c405e..89342d5a0f7 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_short_mcp_tool_prefix.py +++ b/tests/unit/proxy/mcp_server/test_short_mcp_tool_prefix.py @@ -13,8 +13,8 @@ from typing import List import pytest from mcp.types import Tool as MCPTool -from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager -from litellm.proxy._experimental.mcp_server.utils import ( +from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager +from litellm.proxy.mcp_server.utils import ( SHORT_MCP_TOOL_PREFIX_LENGTH, add_server_prefix_to_name, compute_short_server_prefix, @@ -359,7 +359,7 @@ class TestShortPrefixCollisionResolution: assert server.short_prefix is None def test_assigns_natural_hash_when_no_collision(self, monkeypatch): - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils monkeypatch.setenv("LITELLM_USE_SHORT_MCP_TOOL_PREFIX", "true") manager = MCPServerManager() @@ -375,14 +375,14 @@ class TestShortPrefixCollisionResolution: # Force every attempt=0 hash to "AAA" and attempt=1 to "AAB". # That way the second server registered must rehash to "AAB". - from litellm.proxy._experimental.mcp_server import utils as mcp_utils + from litellm.proxy.mcp_server import utils as mcp_utils def _fake_hash(server_id: str, attempt: int = 0) -> str: return "AAA" if attempt == 0 else f"AA{chr(ord('A') + attempt)}" monkeypatch.setattr(mcp_utils, "compute_short_server_prefix", _fake_hash) # Also patch the symbol that the manager imported at module load. - from litellm.proxy._experimental.mcp_server import ( + from litellm.proxy.mcp_server import ( mcp_server_manager as mgr_module, ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_state_tokens.py b/tests/unit/proxy/mcp_server/test_state_tokens.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_state_tokens.py rename to tests/unit/proxy/mcp_server/test_state_tokens.py index b3fc5a89526..fd121e79209 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_state_tokens.py +++ b/tests/unit/proxy/mcp_server/test_state_tokens.py @@ -3,8 +3,8 @@ from typing import Final import pytest -from litellm.proxy._experimental.mcp_server.outbound_credentials.result import Error, Ok -from litellm.proxy._experimental.mcp_server.state_tokens import StateTokenError, open_state, seal_state +from litellm.proxy.mcp_server.outbound_credentials.result import Error, Ok +from litellm.proxy.mcp_server.state_tokens import StateTokenError, open_state, seal_state @pytest.fixture(autouse=True) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_subscriptions.py b/tests/unit/proxy/mcp_server/test_subscriptions.py similarity index 95% rename from tests/unit/proxy/_experimental/mcp_server/test_subscriptions.py rename to tests/unit/proxy/mcp_server/test_subscriptions.py index fadb709e00f..721955a51b8 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_subscriptions.py +++ b/tests/unit/proxy/mcp_server/test_subscriptions.py @@ -12,10 +12,10 @@ from mcp.server.subscriptions import ListenHandler from mcp.shared.subscriptions import PromptsListChanged, ToolsListChanged from mcp.types import ListToolsRequest, ListToolsResult, SubscriptionFilter, SubscriptionsListenRequestParams -from litellm.experimental_mcp_client.client import MCPClient -from litellm.proxy._experimental.mcp_server import subscriptions -from litellm.proxy._experimental.mcp_server.contracts import OperationContext +from litellm.mcp_client.client import MCPClient from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server import subscriptions +from litellm.proxy.mcp_server.contracts import OperationContext from litellm.types.mcp import MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -181,7 +181,7 @@ async def test_listener_limits_release_capacity_after_cancellation(second_owner: @pytest.mark.asyncio @pytest.mark.parametrize("proxy_mode", [False, True]) async def test_subscription_requires_a_supported_http_gateway_route(proxy_mode: bool) -> None: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server token = server._mcp_proxy_mode.set(proxy_mode) try: @@ -206,7 +206,7 @@ async def test_subscription_requires_a_supported_http_gateway_route(proxy_mode: async def test_subscription_authorization_preserves_original_caller(changed: str | None) -> None: from dataclasses import replace - from litellm.proxy._experimental.mcp_server.server import _owner_fingerprint_for + from litellm.proxy.mcp_server.server import _owner_fingerprint_for initial = OperationContext(_caller=UserAPIKeyAuth(api_key="first", user_id="alice", team_id="team")) current = replace( @@ -341,7 +341,7 @@ async def test_legacy_upstream_without_capabilities_does_not_receive_subscribe() @pytest.mark.parametrize("proxy_mode", [False, True]) def test_legacy_notification_capabilities_require_a_notification_route(proxy_mode: bool) -> None: - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server token = server._mcp_proxy_mode.set(proxy_mode) try: @@ -375,7 +375,7 @@ async def test_idle_legacy_listener_detects_closed_upstream_without_restarting_w async def test_proxy_route_rejects_legacy_resource_subscription_before_setup(method: str) -> None: from mcp.types import SubscribeRequestParams, UnsubscribeRequestParams - from litellm.proxy._experimental.mcp_server import server + from litellm.proxy.mcp_server import server params = (SubscribeRequestParams if method == "subscribe_resource" else UnsubscribeRequestParams)(uri="test://value") token = server._mcp_proxy_mode.set(True) @@ -394,7 +394,7 @@ async def test_proxy_route_rejects_legacy_resource_subscription_before_setup(met async def test_only_client_initiated_listeners_consume_server_rate_limit( monkeypatch: pytest.MonkeyPatch, client_requests: tuple[str, ...], tools_list_admitted: bool ) -> None: - from litellm.proxy._experimental.mcp_server import operations + from litellm.proxy.mcp_server import operations allow_one_request(monkeypatch, "alice", "upstream") opened: Final = asyncio.Queue[None]() @@ -447,8 +447,8 @@ async def test_legacy_listener_catalog_refreshes_do_not_consume_server_rate_limi from mcp.types import ListToolsResult, ServerCapabilities, Tool, ToolsCapability from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import catalog, operations - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk + from litellm.proxy.mcp_server import catalog, operations + from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk server: Final = MCPServer(server_id="list-changed", name="list-changed", transport=MCPTransport.http) caller: Final = UserAPIKeyAuth(api_key="list-changed-key", user_id="alice") @@ -502,12 +502,12 @@ async def test_legacy_listener_catalog_refreshes_do_not_consume_server_rate_limi @pytest.mark.asyncio async def test_all_failed_tools_listing_keeps_empty_catalog_digest(monkeypatch: pytest.MonkeyPatch) -> None: - from litellm.proxy._experimental.mcp_server.catalog import ToolListingFailedOutright + from litellm.proxy.mcp_server.catalog import ToolListingFailedOutright listener_context: Final = OperationContext(_caller=UserAPIKeyAuth(user_id="listener")) empty_gateway: Final = _ListingGateway(result=ListToolsResult(tools=[])) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.operations.GatewayOperations", lambda: empty_gateway + "litellm.proxy.mcp_server.operations.GatewayOperations", lambda: empty_gateway ) empty_digest: Final = await subscriptions._listing(ToolsListChanged(), listener_context) @@ -515,7 +515,7 @@ async def test_all_failed_tools_listing_keeps_empty_catalog_digest(monkeypatch: error=ToolListingFailedOutright(code=-32603, message="Every MCP server in scope failed") ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.operations.GatewayOperations", lambda: failed_gateway + "litellm.proxy.mcp_server.operations.GatewayOperations", lambda: failed_gateway ) failed_digest: Final = await subscriptions._listing(ToolsListChanged(), listener_context) @@ -526,7 +526,7 @@ async def test_all_failed_tools_listing_keeps_empty_catalog_digest(monkeypatch: async def test_tools_listing_propagates_other_mcp_errors(monkeypatch: pytest.MonkeyPatch) -> None: failure: Final = MCPError(code=-32602, message="Bad cursor") gateway: Final = _ListingGateway(error=failure) - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.operations.GatewayOperations", lambda: gateway) + monkeypatch.setattr("litellm.proxy.mcp_server.operations.GatewayOperations", lambda: gateway) listener_context: Final = OperationContext(_caller=UserAPIKeyAuth(user_id="listener")) expected_error: Final = pytest.raises(MCPError) diff --git a/tests/unit/proxy/experimental/mcp_server/test_tool_registry.py b/tests/unit/proxy/mcp_server/test_tool_registry.py similarity index 92% rename from tests/unit/proxy/experimental/mcp_server/test_tool_registry.py rename to tests/unit/proxy/mcp_server/test_tool_registry.py index c7df359aae2..d05204b8e64 100644 --- a/tests/unit/proxy/experimental/mcp_server/test_tool_registry.py +++ b/tests/unit/proxy/mcp_server/test_tool_registry.py @@ -2,8 +2,7 @@ import json import pytest - -from litellm.proxy._experimental.mcp_server.tool_registry import MCPToolRegistry +from litellm.proxy.mcp_server.tool_registry import MCPToolRegistry # Test handler function @@ -59,7 +58,7 @@ def test_load_tools_from_config(): "name": "config_tool", "description": "A tool from config", "input_schema": {"type": "object"}, - "handler": "tests.unit.proxy.experimental.mcp_server.test_tool_registry.example_handler", + "handler": "tests.unit.proxy.mcp_server.test_tool_registry.example_handler", } ] diff --git a/tests/unit/proxy/_experimental/mcp_server/test_ui_session_utils.py b/tests/unit/proxy/mcp_server/test_ui_session_utils.py similarity index 91% rename from tests/unit/proxy/_experimental/mcp_server/test_ui_session_utils.py rename to tests/unit/proxy/mcp_server/test_ui_session_utils.py index 293d9443ced..55adbf19ffe 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_ui_session_utils.py +++ b/tests/unit/proxy/mcp_server/test_ui_session_utils.py @@ -6,14 +6,14 @@ import pytest from fastapi import HTTPException from litellm.constants import UI_SESSION_TOKEN_TEAM_ID -from litellm.proxy._experimental.mcp_server.ui_session_utils import ( +from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth +from litellm.proxy.mcp_server.ui_session_utils import ( build_effective_auth_contexts, clone_user_api_key_auth_with_team, granted_toolset_ids, - toolset_grant_contexts, resolve_ui_session_team_ids, + toolset_grant_contexts, ) -from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth def test_clone_user_api_key_auth_with_team_creates_independent_copy(): @@ -68,7 +68,7 @@ async def test_build_effective_auth_contexts_returns_cloned_contexts(monkeypatch mock_resolve = AsyncMock(return_value=["team-one", "team-two"]) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", mock_resolve, ) @@ -87,7 +87,7 @@ async def test_build_effective_auth_contexts_returns_original_when_no_resolution mock_resolve = AsyncMock(return_value=[]) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", mock_resolve, ) @@ -114,7 +114,7 @@ async def test_build_effective_auth_contexts_handles_unpicklable_parent_span( mock_resolve = AsyncMock(return_value=["team-span"]) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", mock_resolve, ) @@ -133,12 +133,12 @@ async def test_build_effective_auth_contexts_appends_admitted_user_context(monke admitted_auth = UserAPIKeyAuth(user_id="user-42") monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", AsyncMock(return_value=["team-one"]), ) reload_mock = AsyncMock(return_value=admitted_auth) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -154,7 +154,7 @@ async def test_build_effective_auth_contexts_never_widens_caller_passed_keys(mon normal_user = UserAPIKeyAuth(team_id="regular-team", user_id="user-1") reload_mock = AsyncMock() monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -169,11 +169,11 @@ async def test_build_effective_auth_contexts_survives_admitted_reload_failure(mo user_auth = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-9") monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.ui_session_utils.resolve_ui_session_team_ids", + "litellm.proxy.mcp_server.ui_session_utils.resolve_ui_session_team_ids", AsyncMock(return_value=["team-a"]), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(side_effect=HTTPException(status_code=503, detail="db down")), ) @@ -186,13 +186,13 @@ async def test_build_effective_auth_contexts_survives_admitted_reload_failure(mo async def test_acting_user_auth_returns_admitted_subject_for_non_admin_sessions(monkeypatch): """LIT-4861: acting-as-user MCP routes must resolve a non-admin dashboard session as the admitted subject so tool ceilings, reachability, and limits bind exactly as on /mcp.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth user_auth = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-42", user_role="internal_user") admitted_auth = UserAPIKeyAuth(user_id="user-42") reload_mock = AsyncMock(return_value=admitted_auth) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -204,11 +204,11 @@ async def test_acting_user_auth_returns_admitted_subject_for_non_admin_sessions( @pytest.mark.asyncio async def test_acting_user_auth_keeps_admin_sessions_and_passed_keys_unchanged(monkeypatch): - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth reload_mock = AsyncMock() monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", reload_mock, ) @@ -223,11 +223,11 @@ async def test_acting_user_auth_keeps_admin_sessions_and_passed_keys_unchanged(m @pytest.mark.asyncio async def test_acting_user_auth_falls_back_to_session_auth_on_reload_failure(monkeypatch): - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth user_auth = UserAPIKeyAuth(team_id=UI_SESSION_TOKEN_TEAM_ID, user_id="user-9", user_role="internal_user") monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(side_effect=HTTPException(status_code=503, detail="db down")), ) @@ -239,7 +239,7 @@ async def test_admitted_user_context_carries_the_request_span(monkeypatch): """Swapping the principal must not drop the request: the admitted subject is rebuilt from the user row and carries no span of its own, so every consumer would otherwise lose trace linkage for the resolution and logging it drives.""" - from litellm.proxy._experimental.mcp_server.ui_session_utils import acting_user_auth + from litellm.proxy.mcp_server.ui_session_utils import acting_user_auth class DummySpan: def __init__(self) -> None: @@ -253,7 +253,7 @@ async def test_admitted_user_context_carries_the_request_span(monkeypatch): parent_otel_span=parent_span, ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp.MCPRequestHandler.reload_admitted_user", AsyncMock(return_value=UserAPIKeyAuth(user_id="user-42")), ) diff --git a/tests/unit/proxy/_experimental/mcp_server/test_utils.py b/tests/unit/proxy/mcp_server/test_utils.py similarity index 98% rename from tests/unit/proxy/_experimental/mcp_server/test_utils.py rename to tests/unit/proxy/mcp_server/test_utils.py index 8d10219796b..00af79cd860 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_utils.py +++ b/tests/unit/proxy/mcp_server/test_utils.py @@ -3,14 +3,14 @@ from unittest.mock import patch import pytest from fastapi import HTTPException -from litellm.proxy._experimental.mcp_server.utils import ( - upstream_credential_headers, +from litellm.proxy._types import NewMCPServerRequest +from litellm.proxy.mcp_server.utils import ( build_synthetic_mcp_request, logging_safe_mcp_headers, + upstream_credential_headers, validate_and_normalize_mcp_server_payload, validate_tool_display_names, ) -from litellm.proxy._types import NewMCPServerRequest from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -26,7 +26,7 @@ def _server_forwarding(*header_names: str) -> MCPServer: def _configured_servers(*servers: MCPServer): return patch.dict( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", {server.server_id: server for server in servers}, clear=False, ) @@ -273,7 +273,7 @@ class TestBuildSyntheticMcpRequest: @pytest.mark.parametrize("field", ["structuredContent", "structured_content"]) def test_structured_content_redaction_updates_shared_dictionary(field): - from litellm.proxy._experimental.mcp_server.utils import ( + from litellm.proxy.mcp_server.utils import ( mcp_tool_result_structured_content, set_mcp_tool_result_structured_content, ) diff --git a/tests/unit/proxy/public_endpoints/test_public_endpoints.py b/tests/unit/proxy/public_endpoints/test_public_endpoints.py index cc61b6f2fcf..f60c2254b41 100644 --- a/tests/unit/proxy/public_endpoints/test_public_endpoints.py +++ b/tests/unit/proxy/public_endpoints/test_public_endpoints.py @@ -1235,8 +1235,8 @@ def test_public_mcp_hub_derives_publication_metadata_without_mutating_registry( expected_listed: bool, stored_public: bool | None, ) -> None: - from litellm.proxy._experimental.mcp_server.mcp_server_manager import MCPServerManager from litellm.proxy._types import MCPTransport + from litellm.proxy.mcp_server.mcp_server_manager import MCPServerManager from litellm.types.mcp_server.mcp_server_manager import MCPServer app: Final = FastAPI() @@ -1275,7 +1275,7 @@ def test_public_mcp_hub_derives_publication_metadata_without_mutating_registry( patch("litellm.public_mcp_servers", [server.server_id] if explicit else []), patch("litellm.public_mcp_hub_strict_whitelist", strict), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager, ), ): @@ -1307,7 +1307,7 @@ def test_public_mcp_hub_returns_empty_when_whitelist_unset(): with ( patch("litellm.public_mcp_servers", None), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): @@ -1345,7 +1345,7 @@ def test_public_mcp_hub_does_not_expose_upstream_url(): with ( patch("litellm.public_mcp_servers", ["listed"]), patch( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", mock_manager, ), ): diff --git a/tests/unit/proxy/test_dynamic_mcp_route.py b/tests/unit/proxy/test_dynamic_mcp_route.py index 4a8dddb1bf4..dc5c1ba1b79 100644 --- a/tests/unit/proxy/test_dynamic_mcp_route.py +++ b/tests/unit/proxy/test_dynamic_mcp_route.py @@ -18,21 +18,20 @@ from unittest.mock import ANY, AsyncMock, MagicMock, patch import pytest from fastapi import HTTPException - # --------------------------------------------------------------------------- # helpers # --------------------------------------------------------------------------- -_MCP_MANAGER = "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager" +_MCP_MANAGER = "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager" _HANDLE_HTTP = ( - "litellm.proxy._experimental.mcp_server.server.handle_streamable_http_mcp" + "litellm.proxy.mcp_server.server.handle_streamable_http_mcp" ) _STREAM_ASGI = "litellm.proxy.proxy_server._stream_mcp_asgi_response" _PRISMA = "litellm.proxy.proxy_server.prisma_client" _IS_ACCESS_GROUP = "litellm.proxy.proxy_server._is_mcp_access_group_cached" _USER_API_KEY_CACHE = "litellm.proxy.proxy_server.user_api_key_cache" _GET_ACCESS_GROUP_SERVERS = ( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp." + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp." "MCPRequestHandler.get_mcp_servers_from_access_groups" ) _FORWARD = "litellm.proxy.proxy_server._mcp_forward_as_path" @@ -285,7 +284,7 @@ async def test_dynamic_mcp_route_resolves_toolset(): async def fake_stream(fn, scope, receive): nonlocal captured_toolset_id - from litellm.proxy._experimental.mcp_server.server import ( + from litellm.proxy.mcp_server.server import ( mcp_active_toolset_id, ) @@ -545,7 +544,7 @@ async def test_toolset_mcp_route_unexpected_exception_returns_500_without_traceb # 7. Aggregate /mcp without a trailing slash (bare mount prefix) # --------------------------------------------------------------------------- -_IS_MCP_AVAILABLE = "litellm.proxy._experimental.mcp_server.utils.is_mcp_available" +_IS_MCP_AVAILABLE = "litellm.proxy.mcp_server.utils.is_mcp_available" def _test_client(): @@ -623,8 +622,8 @@ async def test_dynamic_route_observes_committed_peer_catalog_changes(monkeypatch from litellm.caching.caching import DualCache from litellm.proxy import proxy_server - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import LiteLLM_MCPServerTable + from litellm.proxy.mcp_server import mcp_server_manager old_row = LiteLLM_MCPServerTable( server_id="catalog-route", server_name="previous", alias="previous", transport="http", diff --git a/tests/unit/proxy/test_litellm_pre_call_utils.py b/tests/unit/proxy/test_litellm_pre_call_utils.py index e03fd9850c1..a44373b87c8 100644 --- a/tests/unit/proxy/test_litellm_pre_call_utils.py +++ b/tests/unit/proxy/test_litellm_pre_call_utils.py @@ -37,7 +37,6 @@ from litellm.litellm_core_utils.redact_messages import _get_turn_off_message_log from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM from litellm.llms.fireworks_ai.common_utils import get_fireworks_session_id from litellm.proxy._types import AddTeamCallback, ProxyException, TeamCallbackMetadata, UserAPIKeyAuth -from litellm.types.litellm_params import AGENTIC_LOOP_KWARG_NAMES from litellm.proxy.litellm_pre_call_utils import ( KeyAndTeamLoggingSettings, LiteLLMProxyRequestSetup, @@ -59,6 +58,7 @@ from litellm.proxy.litellm_pre_call_utils import ( move_guardrails_to_metadata, ) from litellm.proxy.spend_tracking.spend_tracking_utils import get_logging_payload +from litellm.types.litellm_params import AGENTIC_LOOP_KWARG_NAMES from litellm.types.utils import CredentialItem @@ -9576,7 +9576,7 @@ async def test_mcp_credentials_only_removed_from_logging_copies(path: str, custo with ( patch("litellm.proxy.proxy_server.general_settings", settings), patch.dict( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.config_mcp_servers", {"header-test": server}, clear=True, ), @@ -10371,8 +10371,8 @@ class TestResolveUserProviderCredentials: _get_hierarchical_router_settings) must be part of discovery.""" from types import SimpleNamespace - from litellm.proxy.litellm_pre_call_utils import _resolve_user_provider_credentials_for_request import litellm.proxy.auth.auth_checks as auth_checks + from litellm.proxy.litellm_pre_call_utils import _resolve_user_provider_credentials_for_request table = self._env(monkeypatch) monkeypatch.setattr( diff --git a/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py b/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py index 745488bf93f..8c62b225992 100644 --- a/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py +++ b/tests/unit/proxy/test_proxy_server_endpoints_and_startup.py @@ -29,9 +29,9 @@ import litellm import litellm.proxy.proxy_server as proxy_server_module from litellm._internal_context import current_service_target from litellm.caching.caching import RedisCache +from litellm.caching.dual_cache import DualCache from litellm.caching.redis_cluster_cache import RedisClusterCache from litellm.litellm_core_utils.get_model_cost_map import ModelCostMapReloaded -from litellm.caching.dual_cache import DualCache from litellm.proxy._types import ( AwsErrorTypeProxyException, LitellmUserRoles, @@ -9335,8 +9335,8 @@ async def test_increment_spend_counters_reseeds_from_db_on_bad_reserved_counter( from the authoritative DB and adds this request's settled cost, which the async spend flush has not written yet, so budget gating continues.""" from litellm.caching.dual_cache import DualCache - from litellm.proxy.proxy_server import increment_spend_counters from litellm.proxy.db.spend_counter_reseed import SpendCounterReseed + from litellm.proxy.proxy_server import increment_spend_counters counter_cache = DualCache() budget_reservation = { @@ -12350,8 +12350,8 @@ def _config_field_info_client(monkeypatch, user_role): from fastapi.testclient import TestClient import litellm.proxy.proxy_server as ps - from litellm.proxy.config_resolvers import SettingsStore from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.config_resolvers import SettingsStore from litellm.proxy.proxy_server import app db_record = types.SimpleNamespace( @@ -13742,11 +13742,11 @@ def test_startup_is_silent_when_mock_testing_params_disabled(caplog): def _window_spend_enqueue_env(cached_objects: dict): """Point increment_spend_counters at throwaway caches and a real WindowSpendUpdateQueue, and hand back the queue to inspect.""" + import litellm.proxy.proxy_server as ps from litellm.caching.dual_cache import DualCache from litellm.proxy.db.db_transaction_queue.window_spend_update_queue import ( WindowSpendUpdateQueue, ) - import litellm.proxy.proxy_server as ps user_api_key_cache = MagicMock() user_api_key_cache.async_get_cache = AsyncMock(side_effect=lambda key, **_: cached_objects.get(key)) @@ -13825,8 +13825,8 @@ async def test_team_window_spend_row_is_enqueued(): async def test_window_spend_row_is_enqueued_even_when_the_counter_was_reserved(): """A reservation only pre-charged the cache counter with an estimate; the row still owes the actual cost, so the enqueue must not be skipped.""" - from litellm.proxy.proxy_server import increment_spend_counters import litellm.proxy.spend_tracking.budget_reservation as br + from litellm.proxy.proxy_server import increment_spend_counters reset_at = datetime.now(timezone.utc) + timedelta(days=10) key_obj = MagicMock() @@ -15166,7 +15166,7 @@ async def test_update_general_settings_keeps_yaml_openai_websocket_passthrough() def test_settings_store_exposes_dashboard_saved_mcp_client_allowlist_to_the_mcp_gateway() -> None: - from litellm.proxy._experimental.mcp_server.client_allowlist import MCPClientAllowlist, load_mcp_client_allowlist + from litellm.proxy.mcp_server.client_allowlist import MCPClientAllowlist, load_mcp_client_allowlist from litellm.proxy.proxy_server import ProxyConfig settings: Final = ProxyConfig().settings @@ -15252,9 +15252,8 @@ async def test_token_counter_loads_a_custom_tokenizer_off_the_event_loop(monkeyp async def test_token_counter_loads_a_custom_tokenizer_once_per_identifier_revision_and_token(monkeypatch): - from litellm.rust_bridge._native import Tokenizer - from litellm import Router + from litellm.rust_bridge._native import Tokenizer from litellm.types.router import DeploymentTypedDict claude_tokenizer: Final[Tokenizer] = litellm.utils.select_tokenizer("claude-fable-5")["tokenizer"] @@ -15307,13 +15306,13 @@ async def test_auth_cache_invalidation_subscriber_evicts_byok_credentials_cached """A peer worker's BYOK revocation broadcast must reach this worker's BYOK credential cache.""" from redis.asyncio import Redis - from litellm.proxy._experimental.mcp_server.byok_credential_cache import ( + from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache + from litellm.proxy.mcp_server.byok_credential_cache import ( byok_credential_cache, byok_credential_cache_key, cache_byok_credential, get_cached_byok_credential, ) - from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache class _QueuePubSub: def __init__(self, messages: list[object]) -> None: diff --git a/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py b/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py index 3d76ad54a9c..3b0672b306e 100644 --- a/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py +++ b/tests/unit/proxy/types_utils/test_get_instance_fn_runtime_gate.py @@ -151,7 +151,7 @@ def test_mcp_tool_registry_threads_config_file_path(): # MCP tool handlers declared in ``config.yaml`` mcp_tools[].handler # may legitimately be ``s3://...``; the YAML-load path must thread # ``config_file_path`` so they resolve. - from litellm.proxy._experimental.mcp_server import tool_registry as tr + from litellm.proxy.mcp_server import tool_registry as tr fake_handler = lambda **kwargs: None # noqa: E731 — registry requires callable with patch.object(tr, "get_instance_fn", return_value=fake_handler) as mock_get: diff --git a/tests/unit/responses/mcp/conftest.py b/tests/unit/responses/mcp/conftest.py index c41ba624ac8..ac661b9a9fb 100644 --- a/tests/unit/responses/mcp/conftest.py +++ b/tests/unit/responses/mcp/conftest.py @@ -5,4 +5,4 @@ import pytest @pytest.fixture(scope="module", autouse=True) def import_mcp_server_before_manager_doubles() -> None: - importlib.import_module("litellm.proxy._experimental.mcp_server.server") + importlib.import_module("litellm.proxy.mcp_server.server") diff --git a/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py b/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py index 285d90ef8de..4cbcc6c1519 100644 --- a/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py +++ b/tests/unit/responses/mcp/test_aresponses_api_with_mcp.py @@ -17,7 +17,6 @@ import respx from mcp.types import CallToolResult, ListToolsResult, TextContent from mcp.types import Tool as MCPTool - # Import required modules import litellm from litellm.exceptions import GuardrailRaisedException, MidStreamFallbackError @@ -25,15 +24,15 @@ from litellm.integrations.custom_logger import CustomLogger from litellm.integrations.langfuse.langfuse import langfuse_trace_id, langfuse_trace_metadata from litellm.litellm_core_utils.litellm_logging import Logging from litellm.llms.xai.common_utils import xai_reported_cost_in_usd -from litellm.proxy._experimental.mcp_server import mcp_server_manager -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import ServerListOk +from litellm.proxy.mcp_server import mcp_server_manager +from litellm.proxy.mcp_server.faults.list_outcomes import ServerListOk from litellm.proxy.utils import _estimate_dispatched_failure_usage, _failure_fields_to_lift from litellm.responses.mcp.litellm_proxy_mcp_handler import LiteLLM_Proxy_MCP_Handler from litellm.responses.mcp.mcp_streaming_iterator import MCPEnhancedStreamingIterator from litellm.types.llms.openai import ( + OpenAIMcpServerTool, ResponsesAPIResponse, ResponsesAPIStreamingResponse, - OpenAIMcpServerTool, ToolParam, ) from litellm.types.utils import ModelResponse, StandardLoggingPayload, Usage @@ -1079,10 +1078,11 @@ async def test_aresponses_mcp_call_does_not_forward_admission_authorization( import types from unittest.mock import AsyncMock - from mcp.types import CallToolResult, TextContent, Tool as MCPTool + from mcp.types import CallToolResult, TextContent + from mcp.types import Tool as MCPTool - from litellm.proxy._experimental.mcp_server import mcp_server_manager from litellm.proxy._types import UserAPIKeyAuth + from litellm.proxy.mcp_server import mcp_server_manager from litellm.types.mcp import MCPAuth, MCPTransport from litellm.types.mcp_server.mcp_server_manager import MCPServer @@ -1185,6 +1185,7 @@ async def test_no_duplicate_mcp_tools_in_streaming_e2e(): sent to the LLM to ensure no duplication occurs. """ from unittest.mock import AsyncMock, patch + from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) @@ -1715,7 +1716,7 @@ async def _auto_execute_through_mcp_server( sys.modules, "litellm.proxy.proxy_server", SimpleNamespace(proxy_logging_obj=None, prisma_client=None) ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", SimpleNamespace( catalog=SimpleNamespace(operation=nullcontext), get_registry=MagicMock(return_value={}), @@ -2042,7 +2043,7 @@ def _serve_the_demo_mcp_listing(monkeypatch: pytest.MonkeyPatch) -> _ListingReco sys.modules, "litellm.proxy.proxy_server", SimpleNamespace(proxy_logging_obj=None, prisma_client=None) ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", SimpleNamespace( catalog=SimpleNamespace(operation=nullcontext), get_registry=MagicMock(return_value={}), @@ -2054,11 +2055,11 @@ def _serve_the_demo_mcp_listing(monkeypatch: pytest.MonkeyPatch) -> _ListingReco ), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.operations._get_allowed_mcp_servers", + "litellm.proxy.mcp_server.operations._get_allowed_mcp_servers", AsyncMock(return_value=[demo_server]), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.catalog.get_filtered_server_tools", + "litellm.proxy.mcp_server.catalog.get_filtered_server_tools", AsyncMock(return_value=(ListToolsResult(tools=[echo_tool]), ServerListOk(tool_count=1))), ) listing_recorder: Final = _ListingRecorder() diff --git a/tests/unit/responses/mcp/test_chat_completions_handler.py b/tests/unit/responses/mcp/test_chat_completions_handler.py index 9064eba161d..ec5968c2a1a 100644 --- a/tests/unit/responses/mcp/test_chat_completions_handler.py +++ b/tests/unit/responses/mcp/test_chat_completions_handler.py @@ -6,19 +6,17 @@ from collections.abc import Mapping, Sequence from datetime import datetime from types import MappingProxyType from typing import Final, cast +from unittest.mock import AsyncMock, patch import pytest import respx from httpx import Response from mcp.types import Tool as MCPTool -from unittest.mock import AsyncMock, patch import litellm from litellm.integrations.custom_logger import CustomLogger from litellm.litellm_core_utils.litellm_logging import Logging from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER -from litellm.types.utils import ModelResponse, StandardLoggingPayload - from litellm.responses.mcp import chat_completions_handler from litellm.responses.mcp.chat_completions_handler import ( acompletion_with_mcp, @@ -27,6 +25,7 @@ from litellm.responses.mcp.litellm_proxy_mcp_handler import ( LiteLLM_Proxy_MCP_Handler, ) from litellm.responses.utils import ResponsesAPIRequestUtils +from litellm.types.utils import ModelResponse, StandardLoggingPayload @pytest.mark.asyncio @@ -181,15 +180,16 @@ async def test_acompletion_with_mcp_passes_mcp_server_auth_headers_to_process_to @pytest.mark.asyncio async def test_acompletion_with_mcp_auto_exec_performs_follow_up(monkeypatch): - from litellm.utils import CustomStreamWrapper + from unittest.mock import MagicMock + from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) - from unittest.mock import MagicMock + from litellm.utils import CustomStreamWrapper tools = [{"type": "function", "function": {"name": "tool"}}] @@ -432,9 +432,9 @@ async def test_acompletion_with_mcp_adds_metadata_to_streaming(monkeypatch): Test that acompletion_with_mcp adds MCP metadata to CustomStreamWrapper and it appears in the final chunk's delta.provider_specific_fields. """ - from litellm.utils import CustomStreamWrapper - from litellm.types.utils import ModelResponseStream, StreamingChoices, Delta from litellm.litellm_core_utils.litellm_logging import Logging + from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices + from litellm.utils import CustomStreamWrapper tools = [{"type": "mcp", "server_url": "litellm_proxy/mcp/local"}] openai_tools = [{"type": "function", "function": {"name": "local_search"}}] @@ -588,8 +588,8 @@ async def test_acompletion_with_mcp_streaming_initial_call_is_streaming(monkeypa Test that acompletion_with_mcp makes the initial LLM call with streaming=True when stream=True is requested, instead of making a non-streaming call first. """ + from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices from litellm.utils import CustomStreamWrapper - from litellm.types.utils import ModelResponseStream, StreamingChoices, Delta tools = [{"type": "mcp", "server_url": "litellm_proxy/mcp/local"}] openai_tools = [{"type": "function", "function": {"name": "local_search"}}] @@ -762,14 +762,14 @@ async def test_acompletion_with_mcp_streaming_metadata_in_correct_chunks(monkeyp - mcp_list_tools should be in the first chunk - mcp_tool_calls and mcp_call_results should be in the final chunk of initial response """ - from litellm.utils import CustomStreamWrapper from litellm.types.utils import ( + ChatCompletionDeltaToolCall, + Delta, + Function, ModelResponseStream, StreamingChoices, - Delta, - ChatCompletionDeltaToolCall, - Function, ) + from litellm.utils import CustomStreamWrapper tools = [{"type": "mcp", "server_url": "litellm_proxy/mcp/local"}] openai_tools = [{"type": "function", "function": {"name": "local_search"}}] @@ -1083,7 +1083,7 @@ async def test_execute_tool_calls_sets_proxy_server_request_arguments(monkeypatc ) monkeypatch.setattr(mcp_handler_module, "function_setup", mock_function_setup) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager.call_tool", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager.call_tool", mock_call_tool, ) @@ -1366,7 +1366,7 @@ async def test_acompletion_with_mcp_streaming_drains_inner_stream_after_exhausti @pytest.mark.asyncio @respx.mock async def test_acompletion_with_mcp_forwards_unserved_external_mcp_tool_to_the_provider(monkeypatch): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager zapier_tool = {"type": "mcp", "server_label": "zapier", "server_url": "https://mcp.zapier.com/api/mcp/mcp"} monkeypatch.setitem(sys.modules, "litellm.proxy.proxy_server", types.SimpleNamespace(prisma_client=None)) @@ -1405,14 +1405,15 @@ async def test_acompletion_with_mcp_forwards_unserved_external_mcp_tool_to_the_p @pytest.mark.parametrize("selection_source", ["metadata", "litellm_metadata", "body"]) @pytest.mark.parametrize("logging_failure", [False, True]) async def test_request_selected_mcp_guardrail_blocks_before_upstream(monkeypatch, selected, stream, selection_source, logging_failure): - from litellm.exceptions import GuardrailRaisedException from mcp.types import Tool + from litellm.caching.caching import DualCache + from litellm.exceptions import GuardrailRaisedException from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.proxy import proxy_server - from litellm.proxy._types import UserAPIKeyAuth, LiteLLM_ObjectPermissionTable - from litellm.proxy._experimental.mcp_server import mcp_server_manager, server, tool_registry - from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing + from litellm.proxy._types import LiteLLM_ObjectPermissionTable, UserAPIKeyAuth + from litellm.proxy.mcp_server import mcp_server_manager, server, tool_registry + from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing from litellm.proxy.utils import ProxyLogging from litellm.types.guardrails import GuardrailEventHooks from litellm.types.mcp_server.mcp_server_manager import MCPServer diff --git a/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py b/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py index 26553558298..4da1bd97c3a 100644 --- a/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py +++ b/tests/unit/responses/mcp/test_litellm_proxy_mcp_handler.py @@ -18,10 +18,10 @@ import litellm from litellm.caching.caching import DualCache from litellm.integrations.custom_guardrail import CustomGuardrail from litellm.litellm_core_utils.litellm_logging import Logging -from litellm.proxy._experimental.mcp_server import operations as mcp_operations -from litellm.proxy._experimental.mcp_server.faults.list_outcomes import AggregateToolListing -from litellm.proxy._experimental.mcp_server.mcp_server_manager import ListedToolsCaller, MCPServerManager from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.mcp_server import operations as mcp_operations +from litellm.proxy.mcp_server.faults.list_outcomes import AggregateToolListing +from litellm.proxy.mcp_server.mcp_server_manager import ListedToolsCaller, MCPServerManager from litellm.proxy.utils import ProxyLogging from litellm.responses import main as responses_main from litellm.responses.mcp import litellm_proxy_mcp_handler as mcp_handler_module @@ -55,7 +55,7 @@ def _setup_mcp_call_environment(monkeypatch: pytest.MonkeyPatch) -> AsyncMock: get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) return fake_manager.call_tool @@ -187,11 +187,11 @@ def test_transform_mcp_tools_to_openai_uses_chat_format(monkeypatch): return {"responses": True} monkeypatch.setattr( - "litellm.experimental_mcp_client.tools.transform_mcp_tool_to_openai_tool", + "litellm.mcp_client.tools.transform_mcp_tool_to_openai_tool", fake_transform_chat, ) monkeypatch.setattr( - "litellm.experimental_mcp_client.tools.transform_mcp_tool_to_openai_responses_api_tool", + "litellm.mcp_client.tools.transform_mcp_tool_to_openai_responses_api_tool", fake_transform_responses, ) @@ -313,7 +313,7 @@ async def test_execute_tool_calls_strips_prefix_when_alias_differs_from_server_n mcp_info=None, tool_name_to_display_name=None, ) - from litellm.proxy._experimental.mcp_server import mcp_server_manager as _msm + from litellm.proxy.mcp_server import mcp_server_manager as _msm _msm.global_mcp_server_manager.get_mcp_server_from_tool_name = MagicMock(return_value=fake_server) @@ -355,7 +355,7 @@ async def test_execute_tool_calls_reverse_maps_display_name(monkeypatch): mcp_info=None, tool_name_to_display_name={"read_wiki_structure": "browse_repo_docs"}, ) - from litellm.proxy._experimental.mcp_server import mcp_server_manager as _msm + from litellm.proxy.mcp_server import mcp_server_manager as _msm _msm.global_mcp_server_manager.get_mcp_server_from_tool_name = MagicMock(return_value=colliding_server) _msm.global_mcp_server_manager.get_mcp_server_by_name = MagicMock(return_value=fake_server) @@ -393,7 +393,7 @@ async def test_execute_tool_calls_logs_failure_via_post_call_failure_hook(monkey call_tool=AsyncMock(side_effect=HTTPException(status_code=500, detail="boom")), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -515,7 +515,7 @@ async def test_execute_tool_calls_applies_post_call_hook_content(monkeypatch): get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -557,7 +557,7 @@ async def test_execute_tool_calls_returns_proxy_result_without_logging(monkeypat get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) handler_module = importlib.import_module("litellm.responses.mcp.litellm_proxy_mcp_handler") @@ -591,7 +591,7 @@ async def test_execute_tool_calls_passes_logging_details_to_proxy_hook(monkeypat get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) logging_obj = MagicMock() @@ -627,7 +627,7 @@ async def test_execute_tool_calls_continues_when_post_call_logging_fails(monkeyp get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -670,7 +670,7 @@ async def test_get_mcp_tools_from_manager_enables_list_tools_logging(monkeypatch ] mock_get_tools = AsyncMock(return_value=AggregateToolListing(tools=served_tools, outcomes={})) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server._get_tools_from_mcp_servers", + "litellm.proxy.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools, ) @@ -683,7 +683,7 @@ async def test_get_mcp_tools_from_manager_enables_list_tools_logging(monkeypatch get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -730,7 +730,7 @@ def test_get_parent_request_tags_from_nested_litellm_params(): async def test_get_mcp_tools_from_manager_forwards_request_tags(monkeypatch): mock_get_tools = AsyncMock(return_value=AggregateToolListing(tools=[], outcomes={})) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.server._get_tools_from_mcp_servers", + "litellm.proxy.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools, ) fake_manager = types.SimpleNamespace( @@ -741,7 +741,7 @@ async def test_get_mcp_tools_from_manager_forwards_request_tags(monkeypatch): get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) @@ -952,7 +952,7 @@ async def test_gateway_served_names_matches_alias_server_name_name_access_group_ @pytest.mark.asyncio async def test_gateway_served_names_matches_server_id_short_prefix_and_alias_case_like_the_gateway(): - from litellm.proxy._experimental.mcp_server.utils import compute_short_server_prefix + from litellm.proxy.mcp_server.utils import compute_short_server_prefix from litellm.responses.mcp.litellm_proxy_mcp_handler import _gateway_served_names server_id = "0b9ae4ca-1bd2-4faa-b183-7dd812597e3b" @@ -1040,7 +1040,7 @@ def test_should_use_gateway_still_triggers_on_http_mcp_path(): @pytest.mark.asyncio async def test_aresponses_api_with_mcp_forwards_unserved_external_mcp_tool_to_the_provider(monkeypatch): - from litellm.proxy._experimental.mcp_server.mcp_server_manager import global_mcp_server_manager + from litellm.proxy.mcp_server.mcp_server_manager import global_mcp_server_manager from litellm.responses import main as responses_main from litellm.types.llms.openai import ResponsesAPIResponse @@ -1287,7 +1287,7 @@ async def test_mcp_follow_up_call_is_stateless_when_store_is_false( @pytest.mark.asyncio async def test_responses_discovery_logs_sanitized_caller_headers(monkeypatch: pytest.MonkeyPatch): - from litellm.proxy._experimental.mcp_server import mcp_server_manager, operations + from litellm.proxy.mcp_server import mcp_server_manager, operations headers: Final = { "x-app-id": "app-a", @@ -1365,7 +1365,7 @@ async def test_bridge_listing_leaves_the_callers_catalog_unchanged( get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) with ( @@ -1453,7 +1453,7 @@ async def test_concurrent_bridge_calls_use_their_own_served_metadata(monkeypatch monkeypatch.setattr("litellm.proxy.proxy_server.proxy_logging_obj", logger) monkeypatch.setattr(mcp_operations, "global_mcp_server_manager", manager) monkeypatch.setattr(mcp_operations, "_get_allowed_mcp_servers", AsyncMock(return_value=[server])) - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", manager) + monkeypatch.setattr("litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", manager) first_listed: Final = asyncio.Event() second_listed: Final = asyncio.Event() @@ -1508,13 +1508,13 @@ def _toolset_gateway_manager(toolset_id: str, server_id: str) -> types.SimpleNam async def _tools_listing_kwargs_for_toolset_url(monkeypatch, team_toolset_id: str) -> dict[str, object]: - from litellm.proxy._experimental.mcp_server.ui_session_utils import granted_toolset_ids from litellm.proxy._types import LiteLLM_ObjectPermissionTable, LitellmUserRoles, UserAPIKeyAuth + from litellm.proxy.mcp_server.ui_session_utils import granted_toolset_ids mock_get_tools = AsyncMock(return_value=AggregateToolListing(tools=[], outcomes={})) - monkeypatch.setattr("litellm.proxy._experimental.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools) + monkeypatch.setattr("litellm.proxy.mcp_server.server._get_tools_from_mcp_servers", mock_get_tools) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", _toolset_gateway_manager("ts-granted", "srv-1"), ) monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", MagicMock()) @@ -1561,7 +1561,7 @@ async def test_apply_toolset_permissions_pins_the_auth_to_explicit_grants_only(m resolve_toolset_tool_permissions=AsyncMock(return_value={"srv-1": ["add"]}), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) diff --git a/tests/unit/responses/mcp/test_mcp_streaming_iterator.py b/tests/unit/responses/mcp/test_mcp_streaming_iterator.py index ed39da1b7a9..78b0e3d4e5b 100644 --- a/tests/unit/responses/mcp/test_mcp_streaming_iterator.py +++ b/tests/unit/responses/mcp/test_mcp_streaming_iterator.py @@ -85,7 +85,7 @@ def _mock_mcp_environment(monkeypatch: pytest.MonkeyPatch) -> AsyncMock: get_mcp_server_by_name=MagicMock(return_value=None), ) monkeypatch.setattr( - "litellm.proxy._experimental.mcp_server.mcp_server_manager.global_mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager.global_mcp_server_manager", fake_manager, ) monkeypatch.setitem( diff --git a/tests/unit/responses/mcp/test_tool_precheck.py b/tests/unit/responses/mcp/test_tool_precheck.py index a3b2c3a0efb..bd37114ccea 100644 --- a/tests/unit/responses/mcp/test_tool_precheck.py +++ b/tests/unit/responses/mcp/test_tool_precheck.py @@ -14,7 +14,7 @@ import respx import litellm from litellm.responses.mcp.tool_precheck import may_name_litellm_mcp_gateway -GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy._experimental.mcp_server.mcp_server_manager" +GATEWAY_REGISTRY_MODULE: Final = "litellm.proxy.mcp_server.mcp_server_manager" GATEWAY_HANDLER_MODULES: Final = ( "litellm.responses.mcp.litellm_proxy_mcp_handler", "litellm.responses.mcp.chat_completions_handler", diff --git a/tests/unit/test_check_mcp_operation_boundary.py b/tests/unit/test_check_mcp_operation_boundary.py index d7ac72de9f0..0969c461ad2 100644 --- a/tests/unit/test_check_mcp_operation_boundary.py +++ b/tests/unit/test_check_mcp_operation_boundary.py @@ -9,11 +9,11 @@ from scripts.check_mcp_operation_boundary import main, violations "source", ( "from mcp.server.auth.middleware.auth_context import auth_context_var as hidden", - "from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode as mode", + "from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode as mode", "caller = legacy.get_active_auth_context()", "owners = transport._stateful_session_owners", "from weakref import WeakKeyDictionary", - "from litellm.proxy._experimental.mcp_server.server import get_auth_context", + "from litellm.proxy.mcp_server.server import get_auth_context", ), ) def test_shared_operation_boundary_rejects_ambient_state(source): @@ -21,7 +21,7 @@ def test_shared_operation_boundary_rejects_ambient_state(source): def test_legacy_adapter_may_resolve_context_but_policy_must_receive_it(): - source = "from litellm.proxy._experimental.mcp_server.mcp_context import _mcp_proxy_mode" + source = "from litellm.proxy.mcp_server.mcp_context import _mcp_proxy_mode" assert violations(Path("server.py"), source) == () assert violations(Path("legacy_callbacks.py"), source) == () assert violations(Path("operations.py"), "def execute(context):\n return context.client_ip") == () @@ -32,7 +32,7 @@ def test_boundary_command_rejects_shared_state_and_accepts_explicit_context(tmp_ import subprocess import sys - package = tmp_path / "litellm/proxy/_experimental/mcp_server" + package = tmp_path / "litellm/proxy/mcp_server" package.mkdir(parents=True) module = package / "operations.py" module.write_text("from mcp.server.auth.middleware.auth_context import auth_context_var as hidden\n") diff --git a/tests/unit/test_circleci_path_filter.py b/tests/unit/test_circleci_path_filter.py index c44560b96f1..9f695960517 100644 --- a/tests/unit/test_circleci_path_filter.py +++ b/tests/unit/test_circleci_path_filter.py @@ -51,7 +51,7 @@ CI = [".github/workflows/test-unit.yml"] [ ("mcp-dependencies", ["pyproject.toml"], "run"), ("mcp-dependencies", ["uv.lock"], "run"), - ("mcp-dependencies", ["litellm/experimental_mcp_client/client.py"], "run"), + ("mcp-dependencies", ["litellm/mcp_client/client.py"], "run"), ("mcp-dependencies", ["tests/e2e/mcp/datadog_mcp.py"], "run"), ("mcp-dependencies", ["litellm-proxy-extras/pyproject.toml"], "run"), ("mcp-dependencies", ["scripts/check_mcp_sdk_install.py"], "run"), diff --git a/tests/unit/test_internal_context.py b/tests/unit/test_internal_context.py index e104cf16b04..f78c6064f76 100644 --- a/tests/unit/test_internal_context.py +++ b/tests/unit/test_internal_context.py @@ -62,13 +62,13 @@ _IN_MEMORY_ONLY_CALLERS: Final = frozenset( "litellm/llms/openai_like/model_info.py", "litellm/llms/vertex_ai/vertex_ai_non_gemini.py", "litellm/llms/watsonx/common_utils.py", - "litellm/proxy/_experimental/mcp_server/byok_credential_cache.py", - "litellm/proxy/_experimental/mcp_server/catalog.py", - "litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py", - "litellm/proxy/_experimental/mcp_server/oauth_identity_binding.py", - "litellm/proxy/_experimental/mcp_server/operations.py", - "litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py", - "litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py", + "litellm/proxy/mcp_server/byok_credential_cache.py", + "litellm/proxy/mcp_server/catalog.py", + "litellm/proxy/mcp_server/discoverable_endpoints.py", + "litellm/proxy/mcp_server/oauth_identity_binding.py", + "litellm/proxy/mcp_server/operations.py", + "litellm/proxy/mcp_server/outbound_credentials/sso_assertion_store.py", + "litellm/proxy/mcp_server/outbound_credentials/token_endpoint.py", "litellm/proxy/agent_endpoints/databricks_oauth.py", "litellm/proxy/common_utils/registry_read_through.py", "litellm/proxy/container_endpoints/ownership.py", diff --git a/tests/unit/test_private_usage_aliases.py b/tests/unit/test_private_usage_aliases.py index 88ae584f34f..1d9c2e87100 100644 --- a/tests/unit/test_private_usage_aliases.py +++ b/tests/unit/test_private_usage_aliases.py @@ -177,157 +177,157 @@ MODULE_IMPORT_ALIAS_CASES: Final = ( "PROXY_DynamicRateLimitHandlerV3", ), ( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp", "_read_request_body", "read_request_body", ), ( - "litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp", + "litellm.proxy.mcp_server.auth.user_api_key_auth_mcp", "_run_centralized_common_checks", "run_centralized_common_checks", ), ( - "litellm.proxy._experimental.mcp_server.bridge_token_flow", + "litellm.proxy.mcp_server.bridge_token_flow", "_V2_GCM_PREFIX", "V2_GCM_PREFIX", ), ( - "litellm.proxy._experimental.mcp_server.db", + "litellm.proxy.mcp_server.db", "_get_salt_key", "get_salt_key", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_bridge_mint_error_response", "bridge_mint_error_response", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_extract_user_id_from_request", "extract_user_id_from_request", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_finish_bridge_mint", "finish_bridge_mint", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_prepare_bridge_mint", "prepare_bridge_mint", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_prepare_bridge_refresh", "prepare_bridge_refresh", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_read_request_body", "read_request_body", ), ( - "litellm.proxy._experimental.mcp_server.discoverable_endpoints", + "litellm.proxy.mcp_server.discoverable_endpoints", "_reload_active_user_by_id", "reload_active_user_by_id", ), ( - "litellm.proxy._experimental.mcp_server.mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager", "_is_mcp_admitted_user_subject", "is_mcp_admitted_user_subject", ), ( - "litellm.proxy._experimental.mcp_server.mcp_server_manager", + "litellm.proxy.mcp_server.mcp_server_manager", "_redact_mcp_resource_url", "redact_mcp_resource_url", ), ( - "litellm.proxy._experimental.mcp_server.oauth2_flow_backfill", + "litellm.proxy.mcp_server.oauth2_flow_backfill", "_decode_oauth_payload", "decode_oauth_payload", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_caller_authorization_fans_out", "caller_authorization_fans_out", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_client_forwarded_authorization_headers", "client_forwarded_authorization_headers", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_redact_mcp_resource_url", "redact_mcp_resource_url", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_request_auth_header", "request_auth_header", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_request_extra_headers", "request_extra_headers", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_request_resolved_auth_headers", "request_resolved_auth_headers", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_resolve_openapi_tool_auth", "resolve_openapi_tool_auth", ), ( - "litellm.proxy._experimental.mcp_server.operations", + "litellm.proxy.mcp_server.operations", "_should_strip_caller_authorization", "should_strip_caller_authorization", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES", "UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_apply_toolset_scope", "apply_toolset_scope", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_inherit_credentials_from_existing_server", "inherit_credentials_from_existing_server", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_redact_mcp_resource_url", "redact_mcp_resource_url", ), ( - "litellm.proxy._experimental.mcp_server.rest_endpoints", + "litellm.proxy.mcp_server.rest_endpoints", "_safe_get_request_headers", "safe_get_request_headers", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_is_mcp_admitted_user_subject", "is_mcp_admitted_user_subject", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_mcp_active_toolset_id", "mcp_active_toolset_id", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_mcp_gateway_initialize_instructions", "mcp_gateway_initialize_instructions", ), ( - "litellm.proxy._experimental.mcp_server.server", + "litellm.proxy.mcp_server.server", "_mcp_gateway_server_name", "mcp_gateway_server_name", ), @@ -2310,294 +2310,294 @@ LLMS_ALIAS_CASES: Final = ( ) PROXY_ALIAS_CASES: Final = ( ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', '', '_is_mcp_admitted_user_subject', 'is_mcp_admitted_user_subject', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_mcp_auth_header_from_headers', 'get_mcp_auth_header_from_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_mcp_server_auth_headers_from_headers', 'get_mcp_server_auth_headers_from_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_mcp_servers_from_access_groups', 'get_mcp_servers_from_access_groups', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_get_oauth2_headers_from_headers', 'get_oauth2_headers_from_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.auth.user_api_key_auth_mcp', + 'litellm.proxy.mcp_server.auth.user_api_key_auth_mcp', 'MCPRequestHandler', '_safe_get_headers_from_scope', 'safe_get_headers_from_scope', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_bridge_mint_error_response', 'bridge_mint_error_response', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_extract_user_id_from_request', 'extract_user_id_from_request', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_finish_bridge_mint', 'finish_bridge_mint', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_prepare_bridge_mint', 'prepare_bridge_mint', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_prepare_bridge_refresh', 'prepare_bridge_refresh', False, ), ( - 'litellm.proxy._experimental.mcp_server.bridge_token_flow', + 'litellm.proxy.mcp_server.bridge_token_flow', '', '_reload_active_user_by_id', 'reload_active_user_by_id', False, ), ( - 'litellm.proxy._experimental.mcp_server.byok_oauth_endpoints', + 'litellm.proxy.mcp_server.byok_oauth_endpoints', '', '_user_id_from_session_cookie', 'user_id_from_session_cookie', False, ), ( - 'litellm.proxy._experimental.mcp_server.db', + 'litellm.proxy.mcp_server.db', '', '_decode_oauth_payload', 'decode_oauth_payload', False, ), ( - 'litellm.proxy._experimental.mcp_server.discoverable_endpoints', + 'litellm.proxy.mcp_server.discoverable_endpoints', '', '_raise_if_not_oauth2', 'raise_if_not_oauth2', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_context', + 'litellm.proxy.mcp_server.mcp_context', '', '_mcp_active_toolset_id', 'mcp_active_toolset_id', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_context', + 'litellm.proxy.mcp_server.mcp_context', '', '_mcp_gateway_initialize_instructions', 'mcp_gateway_initialize_instructions', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_context', + 'litellm.proxy.mcp_server.mcp_context', '', '_mcp_gateway_server_name', 'mcp_gateway_server_name', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES', 'UPSTREAM_OAUTH_DISCOVERY_AUTH_TYPES', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_caller_authorization_fans_out', 'caller_authorization_fans_out', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_client_forwarded_authorization_headers', 'client_forwarded_authorization_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_resolve_openapi_tool_auth', 'resolve_openapi_tool_auth', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', '', '_should_strip_caller_authorization', 'should_strip_caller_authorization', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_build_mcp_server_table', 'build_mcp_server_table', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_build_stdio_env', 'build_stdio_env', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_create_mcp_client', 'create_mcp_client', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_ensure_upstream_initialize_instructions_cached', 'ensure_upstream_initialize_instructions_cached', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_extract_subject_token', 'extract_subject_token', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_get_mcp_server_from_tool_name', 'get_mcp_server_from_tool_name', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_get_tools_from_server', 'get_tools_from_server', False, ), ( - 'litellm.proxy._experimental.mcp_server.mcp_server_manager', + 'litellm.proxy.mcp_server.mcp_server_manager', 'MCPServerManager', '_is_server_accessible_from_ip', 'is_server_accessible_from_ip', False, ), ( - 'litellm.proxy._experimental.mcp_server.oauth2_token_cache', + 'litellm.proxy.mcp_server.oauth2_token_cache', '', '_compute_per_user_token_ttl', 'compute_per_user_token_ttl', False, ), ( - 'litellm.proxy._experimental.mcp_server.oauth_utils', + 'litellm.proxy.mcp_server.oauth_utils', '', '_redact_mcp_resource_url', 'redact_mcp_resource_url', False, ), ( - 'litellm.proxy._experimental.mcp_server.server', + 'litellm.proxy.mcp_server.server', '', '_redact_mcp_resource_url', 'redact_mcp_resource_url', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_OPENAPI_TOOL_NAME_MAX_LEN', 'OPENAPI_TOOL_NAME_MAX_LEN', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_request_auth_header', 'request_auth_header', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_request_extra_headers', 'request_extra_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.openapi_to_mcp_generator', + 'litellm.proxy.mcp_server.openapi_to_mcp_generator', '', '_request_resolved_auth_headers', 'request_resolved_auth_headers', False, ), ( - 'litellm.proxy._experimental.mcp_server.semantic_tool_filter', + 'litellm.proxy.mcp_server.semantic_tool_filter', 'SemanticMCPToolFilter', '_extract_tool_info', 'extract_tool_info', False, ), ( - 'litellm.proxy._experimental.mcp_server.server', + 'litellm.proxy.mcp_server.server', '', '_apply_toolset_scope', 'apply_toolset_scope', False, ), ( - 'litellm.proxy._experimental.mcp_server.server_resolution', + 'litellm.proxy.mcp_server.server_resolution', 'MCPServerRegistry', '_build_mcp_server_table', 'build_mcp_server_table', False, ), ( - 'litellm.proxy._experimental.mcp_server.server_resolution', + 'litellm.proxy.mcp_server.server_resolution', 'MCPServerRegistry', '_is_server_accessible_from_ip', 'is_server_accessible_from_ip', diff --git a/ui/litellm-dashboard/src/utils/mcpHeaderUtils.ts b/ui/litellm-dashboard/src/utils/mcpHeaderUtils.ts index ebe7116c18f..f1123dd70f7 100644 --- a/ui/litellm-dashboard/src/utils/mcpHeaderUtils.ts +++ b/ui/litellm-dashboard/src/utils/mcpHeaderUtils.ts @@ -2,7 +2,7 @@ * Sanitize an MCP server alias for use in HTTP header names (x-mcp-{alias}-...). * RFC 7230 tchar allows token chars; aliases with spaces or hyphens break parsing * because the backend splits on the first dash after the x-mcp- prefix. - * Keep in sync with litellm.proxy._experimental.mcp_server.utils.sanitize_mcp_alias_for_header. + * Keep in sync with litellm.proxy.mcp_server.utils.sanitize_mcp_alias_for_header. */ export function sanitizeMcpAliasForHeader(alias: string): string { return alias