diff --git a/litellm-rust/crates/gateway/src/error.rs b/litellm-rust/crates/gateway/src/error.rs index 75dc04d179d..a29fce3e64f 100644 --- a/litellm-rust/crates/gateway/src/error.rs +++ b/litellm-rust/crates/gateway/src/error.rs @@ -4,8 +4,6 @@ pub enum Error { Http(#[from] litellm_http::Error), #[error("environment_variables values must be strings, numbers or booleans")] Environment, - #[error("MCP host does not yet support configured setting {0}")] - McpSetting(String), #[error(transparent)] Mcp(#[from] litellm_gateway_mcp::ConnectError), #[error("MCP requires a configured master key")] diff --git a/litellm-rust/crates/gateway/src/lib.rs b/litellm-rust/crates/gateway/src/lib.rs index 1218db083c0..a495c95238b 100644 --- a/litellm-rust/crates/gateway/src/lib.rs +++ b/litellm-rust/crates/gateway/src/lib.rs @@ -1,6 +1,5 @@ mod auth; mod error; -mod mcp_settings; mod secrets; pub use error::Error; @@ -82,21 +81,9 @@ pub async fn build_mcp( pool: &HttpClientPool, http: &litellm_http::HttpClientConfig, ) -> Result, Error> { - if !config.mcp_tools.is_empty() { - return Err(Error::McpSetting("mcp_tools".into())); - } if config.mcp_servers.is_empty() { return Ok(None); } - if let Some(setting) = mcp_settings::first_unsupported(config) { - return Err(Error::McpSetting(setting.into())); - } - if !config.guardrails.is_empty() - || !config.policies.is_empty() - || !config.policy_attachments.is_empty() - { - return Err(Error::McpSetting("guardrails or policies".into())); - } Auth::from_config(config, secrets.clone()) .validate() .await?; diff --git a/litellm-rust/crates/gateway/src/mcp_settings.rs b/litellm-rust/crates/gateway/src/mcp_settings.rs deleted file mode 100644 index 7213e0c2530..00000000000 --- a/litellm-rust/crates/gateway/src/mcp_settings.rs +++ /dev/null @@ -1,62 +0,0 @@ -use litellm_config::Config; - -pub(crate) fn first_unsupported(config: &Config) -> Option<&'static str> { - let general = &config.general_settings.mcp; - let litellm = &config.litellm_settings.mcp; - [ - ( - "mcp_advertised_versions", - general.mcp_advertised_versions.is_some(), - ), - ( - "mcp_disabled_capabilities", - general.mcp_disabled_capabilities.is_some(), - ), - ("mcp_allowed_clients", general.mcp_allowed_clients.is_some()), - ( - "mcp_require_explicit_server_scope", - general.mcp_require_explicit_server_scope.is_some(), - ), - ( - "mcp_client_id_header", - general.mcp_client_id_header.is_some(), - ), - ( - "mcp_client_side_auth_header_name", - general.mcp_client_side_auth_header_name.is_some(), - ), - ( - "mcp_allow_all_keys_respects_mcp_scope", - general.mcp_allow_all_keys_respects_mcp_scope.is_some(), - ), - ( - "mcp_prefer_client_id_metadata_document", - general.mcp_prefer_client_id_metadata_document.is_some(), - ), - ( - "mcp_internal_ip_ranges", - general.mcp_internal_ip_ranges.is_some(), - ), - ( - "mcp_trusted_proxy_ranges", - general.mcp_trusted_proxy_ranges.is_some(), - ), - ( - "mcp_xff_num_trusted_hops", - general.mcp_xff_num_trusted_hops.is_some(), - ), - ("mcp_required_fields", general.mcp_required_fields.is_some()), - ( - "mcp_session_token_signing", - general.mcp_session_token_signing.is_some(), - ), - ("mcp_aliases", litellm.mcp_aliases.is_some()), - ( - "mcp_semantic_tool_filter", - litellm.mcp_semantic_tool_filter.is_some(), - ), - ("mcp_tool_search", litellm.mcp_tool_search.is_some()), - ] - .into_iter() - .find_map(|(key, set)| set.then_some(key)) -} diff --git a/litellm-rust/crates/gateway/tests/mcp.rs b/litellm-rust/crates/gateway/tests/mcp.rs index 7494fb9bdf4..9e52a73f191 100644 --- a/litellm-rust/crates/gateway/tests/mcp.rs +++ b/litellm-rust/crates/gateway/tests/mcp.rs @@ -322,88 +322,3 @@ fn applies_configured_http_environment_before_building_clients() { if path == missing )); } - -#[rstest] -#[case::client_policy( - "general_settings: {master_key: key, mcp_allowed_clients: [approved]}", - "mcp_allowed_clients" -)] -#[case::aliases( - "general_settings: {master_key: key}\nlitellm_settings: {mcp_aliases: {d: docs}}", - "mcp_aliases" -)] -#[case::tool_search( - "general_settings: {master_key: key}\nlitellm_settings: {mcp_tool_search: {top_k: 3}}", - "mcp_tool_search" -)] -#[case::advertised_versions( - "general_settings: {mcp_advertised_versions: [2025-06-18]}", - "mcp_advertised_versions" -)] -#[case::spelled_bool( - "general_settings: {mcp_require_explicit_server_scope: 'true'}", - "mcp_require_explicit_server_scope" -)] -#[case::header( - "general_settings: {mcp_client_side_auth_header_name: x-auth}", - "mcp_client_side_auth_header_name" -)] -#[case::hops( - "general_settings: {mcp_xff_num_trusted_hops: 2}", - "mcp_xff_num_trusted_hops" -)] -#[case::signing( - "general_settings: {mcp_session_token_signing: {algorithm: RS256}}", - "mcp_session_token_signing" -)] -#[case::semantic_filter( - "litellm_settings: {mcp_semantic_tool_filter: {enabled: true}}", - "mcp_semantic_tool_filter" -)] -#[case::guardrail("guardrails: [{guardrail_name: policy}]", "guardrails or policies")] -#[case::local_tools("mcp_tools: [{name: custom}]", "mcp_tools")] -#[tokio::test] -async fn refuses_unimplemented_global_mcp_policy(#[case] settings: &str, #[case] key: &str) { - let config = Config::from_yaml(&format!( - "{settings}\nmcp_servers: {{docs: {{url: 'http://127.0.0.1:1/mcp'}}}}\n" - )) - .unwrap(); - let inference = litellm_gateway::build_inference(&config, &Environment::default()).unwrap(); - let error = litellm_gateway::build_mcp( - &config, - Arc::new(NoSecrets), - CancellationToken::new(), - &inference.resources.pool, - &inference.http, - ) - .await - .err() - .unwrap(); - assert!(matches!(error, litellm_gateway::Error::McpSetting(setting) if setting == key)); -} - -#[rstest] -#[case::general("general_settings: {mcp_whatever: 1}")] -#[case::litellm("litellm_settings: {mcp_whatever: 1}")] -#[case::null("general_settings: {mcp_trusted_proxy_ranges: null}")] -#[case::allowed_hosts("general_settings: {mcp_allowed_hosts: [localhost]}")] -#[case::allowed_origins("general_settings: {mcp_allowed_origins: ['https://app.test']}")] -#[tokio::test] -async fn unknown_null_or_supported_mcp_keys_do_not_block_mcp(#[case] settings: &str) { - let config = Config::from_yaml(&format!( - "{settings}\nmcp_servers: {{docs: {{url: 'http://127.0.0.1:1/mcp'}}}}\n" - )) - .unwrap(); - let inference = litellm_gateway::build_inference(&config, &Environment::default()).unwrap(); - let error = litellm_gateway::build_mcp( - &config, - Arc::new(NoSecrets), - CancellationToken::new(), - &inference.resources.pool, - &inference.http, - ) - .await - .err() - .unwrap(); - assert!(matches!(error, litellm_gateway::Error::Auth(_)), "{error}"); -}