Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge pull request #39926 from BerriAI/litellm_lit6981_none_url_auth

tin-berrie3b4a82ff999
diff --git a/litellm/proxy/_experimental/mcp_server/exceptions.py b/litellm/proxy/_experimental/mcp_server/exceptions.py
index a1b3b167a4a..c818f6b05bd 100644
--- a/litellm/proxy/_experimental/mcp_server/exceptions.py
+++ b/litellm/proxy/_experimental/mcp_server/exceptions.py
@@ -5,6 +5,20 @@ from typing import Final
from fastapi import HTTPException
+class MCPServerURLCredentialsError(HTTPException):
+ """A fixed, sanitized URL-credential migration error safe for operator previews."""
+
+ def __init__(self) -> None:
+ super().__init__(
+ status_code=500,
+ detail=(
+ "misconfigured: auth_type none cannot be used with credentials embedded in the upstream URL; "
+ "remove them from the URL and configure Basic Auth with auth_type: basic and "
+ "auth_value: username:password"
+ ),
+ )
+
+
class MCPUpstreamAuthError(Exception):
"""Raised when an upstream MCP server returns an authentication failure
(typically HTTP 401) and the gateway should surface it transparently to
diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py
index 6a95a93a2a8..ea2318bd6f1 100644
--- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py
+++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/adapter.py
@@ -19,6 +19,7 @@ from pydantic import SecretStr
from typing_extensions import assert_never
from litellm.experimental_mcp_client.client import strip_auth_scheme, to_basic_credentials
+from litellm.proxy._experimental.mcp_server.exceptions import MCPServerURLCredentialsError
from litellm.proxy._experimental.mcp_server.oauth_utils import resolve_upstream_resource
from litellm.proxy._experimental.mcp_server.outbound_credentials.types import (
DEFAULT_CREDENTIAL_HEADER,
@@ -293,6 +294,8 @@ def raise_public(error: CredError) -> NoReturn:
)
case "misconfigured":
raise HTTPException(status_code=500, detail=error.summary)
+ case "url_credentials_not_allowed":
+ raise MCPServerURLCredentialsError()
case "upstream_unavailable":
raise HTTPException(status_code=503, detail=error.summary)
case "unsupported_mode":
diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py
index 3af7b51f432..404baa14350 100644
--- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py
+++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/resolver.py
@@ -134,7 +134,7 @@ class UpstreamCredentialProvider:
async def resolve_credentials(self, subject: Subject, server: ServerSpec) -> Result[httpx.Auth, CredError]:
match server.config:
case NoneConfig():
- return Ok(NoOpAuth())
+ return self._none(server)
case ApiKeyConfig() as config:
return self._api_key(config)
case PassthroughConfig():
@@ -151,6 +151,15 @@ class UpstreamCredentialProvider:
return _not_implemented(AuthSpecKind.aws_sigv4)
assert_never(server.config)
+ def _none(self, server: ServerSpec) -> Result[httpx.Auth, CredError]:
+ try:
+ resource: Final = httpx.URL(server.resource)
+ except httpx.InvalidURL:
+ return Ok(NoOpAuth())
+ if resource.userinfo:
+ return Error(CredError.of_url_credentials_not_allowed())
+ return Ok(NoOpAuth())
+
async def has_user_token(self, subject: Subject, server: ServerSpec) -> bool:
"""Whether a usable per-user token exists for this server (the preemptive 401's check).
diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py
index 67aad3e443e..632dc57dcf6 100644
--- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py
+++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py
@@ -95,6 +95,7 @@ class CredError:
tag: Literal[
"unauthorized",
"misconfigured",
+ "url_credentials_not_allowed",
"upstream_unavailable",
"unsupported_mode",
"precondition_required",
@@ -103,6 +104,7 @@ class CredError:
unauthorized: Unauthorized = case() # no usable credential for this (subject, server) -> 401 challenge
misconfigured: str = case() # the declared mode is missing required config -> 5xx (operator)
+ url_credentials_not_allowed: None = case()
upstream_unavailable: str = case() # the IdP / token endpoint could not be reached -> 503
unsupported_mode: str = case() # a raw mode string did not parse into AuthSpecKind (boundary)
precondition_required: str = case() # a required per-user value (e.g. an env var) has not been provided -> 412
@@ -129,6 +131,10 @@ class CredError:
def of_misconfigured(detail: str) -> CredError:
return CredError(misconfigured=detail)
+ @staticmethod
+ def of_url_credentials_not_allowed() -> CredError:
+ return CredError(url_credentials_not_allowed=None)
+
@staticmethod
def of_upstream_unavailable(detail: str) -> CredError:
return CredError(upstream_unavailable=detail)
@@ -154,6 +160,12 @@ class CredError:
return f"unauthorized: {self.unauthorized.detail}"
case "misconfigured":
return f"misconfigured: {self.misconfigured}"
+ case "url_credentials_not_allowed":
+ return (
+ "misconfigured: auth_type none cannot be used with credentials embedded in the upstream URL; "
+ "remove them from the URL and configure Basic Auth with auth_type: basic and "
+ "auth_value: username:password"
+ )
case "upstream_unavailable":
return f"upstream unavailable: {self.upstream_unavailable}"
case "unsupported_mode":
diff --git a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py
index b3469da9071..5fbfad54a39 100644
--- a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py
+++ b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py
@@ -18,6 +18,7 @@ from litellm.exceptions import (
)
from litellm.proxy._experimental.mcp_server.exceptions import (
MCPServerListError,
+ MCPServerURLCredentialsError,
MCPUpstreamAuthError,
)
from litellm.proxy._experimental.mcp_server.faults.list_outcomes import (
@@ -75,6 +76,8 @@ _MCP_GUARDRAIL_REJECTIONS: Final = (
def _connection_error_message(exc: BaseException, url: str | None, timeout_seconds: float) -> str:
+ if isinstance(exc, MCPServerURLCredentialsError):
+ return str(exc.detail)
if isinstance(exc, TimeoutError):
return (
f"Failed to connect to MCP server: no response from {url or 'the server'} "
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py
index c6f3b9cb1f4..d67d0df4d0e 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_adapter.py
@@ -13,6 +13,7 @@ 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 (
oauth_protected_resource_path,
raise_public,
@@ -442,6 +443,17 @@ def test_raise_public_maps_each_error_to_its_status(error, status):
assert exc_info.value.status_code == status
+def test_raise_public_marks_only_url_credentials_error_as_safe_for_preview():
+ with pytest.raises(HTTPException) as generic_exc_info:
+ raise_public(CredError.of_misconfigured("private operator detail"))
+ assert not isinstance(generic_exc_info.value, MCPServerURLCredentialsError)
+
+ error = CredError.of_url_credentials_not_allowed()
+ with pytest.raises(MCPServerURLCredentialsError) as url_exc_info:
+ raise_public(error)
+ assert url_exc_info.value.detail == error.summary
+
+
def test_raise_public_emits_unauthorized_challenge():
body = {"error": "byok_auth_required", "server_id": "s1"}
error = CredError.of_unauthorized("needs key", www_authenticate='Bearer resource_metadata="/x"', body=body)
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py
index 9d63e8c2c1c..5e2f2cf97d7 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_resolver.py
@@ -116,6 +116,35 @@ async def test_none_mode_yields_a_no_op_auth():
assert isinstance(result.ok, NoOpAuth)
+async def test_none_mode_rejects_url_userinfo():
+ spec = ServerSpec(
+ server_id="s",
+ resource="https://lit-user:[email protected]/mcp",
+ config=NoneConfig(),
+ )
+
+ result = await UpstreamCredentialProvider().resolve_credentials(_SUBJECT, spec)
+
+ assert isinstance(result, Error)
+ assert result.error.tag == "url_credentials_not_allowed"
+ assert "Basic Auth" in result.error.summary
+ assert "auth_type: basic" in result.error.summary
+ assert "auth_value: username:password" in result.error.summary
+ assert "lit-user" not in result.error.summary
+ assert "s3cr3t" not in result.error.summary
+
+
+async def test_none_mode_does_not_validate_non_credential_resource():
+ spec = ServerSpec(server_id="s", resource="https://[::1", config=NoneConfig())
+
+ result = await UpstreamCredentialProvider().resolve_credentials(_SUBJECT, spec)
+
+ assert isinstance(result, Ok)
+ assert isinstance(result.ok, NoOpAuth)
+
+
@pytest.mark.asyncio
async def test_api_key_shared_emits_the_configured_header():
config = ApiKeyConfig(
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_types.py b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_types.py
index d4b51b08e06..bacbb5c1236 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_types.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/outbound_credentials/test_types.py
@@ -75,6 +75,15 @@ def test_crederror_factory_sets_the_matching_tag(factory, expected_tag):
assert "detail text" in err.summary
+def test_url_credentials_error_has_a_fixed_actionable_summary():
+ err = CredError.of_url_credentials_not_allowed()
+
+ assert err.tag == "url_credentials_not_allowed"
+ assert "Basic Auth" in err.summary
+ assert "auth_type: basic" in err.summary
+ assert "auth_value: username:password" in err.summary
+
+
def test_apikeyconfig_requires_a_key_source():
with pytest.raises(ValidationError):
ApiKeyConfig() # type: ignore[call-arg]
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py
index 9745e508703..34dc067e7a3 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py
@@ -8966,6 +8966,24 @@ class TestCreateMcpClientV2Graft:
assert isinstance(client._resolved_auth, NoOpAuth)
assert client._mcp_auth_value is None
+ @pytest.mark.parametrize("auth_type", [None, MCPAuth.none])
+ async def test_none_mode_rejects_url_userinfo(self, auth_type):
+ with pytest.raises(HTTPException) as exc_info:
+ await MCPServerManager()._create_mcp_client(
+ self._http_server(
+ auth_type=auth_type,
+ url="https://lit-user:[email protected]/mcp",
+ )
+ )
+
+ detail = str(exc_info.value.detail)
+ assert exc_info.value.status_code == 500
+ assert "Basic Auth" in detail
+ assert "auth_type: basic" in detail
+ assert "auth_value: username:password" in detail
+ assert "lit-user" not in detail
+ assert "s3cr3t" not in detail
+
@pytest.mark.parametrize(
"auth_type, token, expected_name, expected_value",
[
@@ -11369,6 +11387,30 @@ class TestResolveOpenapiToolAuth:
assert "Authorization" not in (forwarded or {})
+ @pytest.mark.asyncio
+ async def test_none_mode_without_url_keeps_spec_path_server_unauthenticated(self):
+ server = MCPServer(
+ server_id="openapi-only",
+ name="report_api",
+ server_name="report_api",
+ url=None,
+ transport=MCPTransport.http,
+ auth_type=MCPAuth.none,
+ spec_path="https://api.example.com/openapi.json",
+ )
+
+ resolved, forwarded = await MCPServerManager().resolve_openapi_upstream_auth(
+ mcp_server=server,
+ oauth2_headers=None,
+ raw_headers=None,
+ mcp_auth_header=None,
+ user_api_key_auth=None,
+ forwarded_headers={"X-Trace": "trace-id"},
+ )
+
+ assert resolved is None
+ assert forwarded == {"X-Trace": "trace-id"}
+
class TestOpenApiHandlerRelaysUpstreamAuth:
"""`_call_openapi_tool_handler` must not flatten a re-auth signal into a generic message.
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py
index f2c8f8c80c5..c007d22117f 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py
@@ -177,6 +177,36 @@ class TestExecuteWithMcpClient:
assert "https://api.example.com/mcp/" in message
assert "30s" in message
+ def test_connection_error_message_hides_arbitrary_http_exception_detail(self):
+ message = rest_endpoints._connection_error_message(
+ HTTPException(status_code=500, detail="secret upstream detail"),
+ "https://api.example.com/mcp/",
+ 30.0,
+ )
+
+ assert "secret upstream detail" not in message
+
+ @pytest.mark.asyncio
+ async def test_none_mode_url_credentials_returns_actionable_redacted_error(self):
+ async def unreached_operation(client):
+ raise AssertionError("operation must not run for an invalid server configuration")
+
+ payload = NewMCPServerRequest(
+ server_name="example",
+ url="https://lit-user:[email protected]/mcp",
+ auth_type=MCPAuth.none,
+ )
+
+ result = await rest_endpoints._execute_with_mcp_client(payload, unreached_operation)
+
+ message = str(result["message"])
+ assert result["error"] is True
+ assert "Basic Auth" in message
+ assert "auth_type: basic" in message
+ assert "auth_value: username:password" in message
+ assert "lit-user" not in message
+ assert "s3cr3t" not in message
+
@pytest.mark.asyncio
async def test_forwards_static_headers(self, monkeypatch):
"""Ensure static_headers are forwarded to the MCP client during test calls.