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]

fix(mcp): keep origin issuer on the openid-configuration alias

mateo-berri5ddff616dcba
diff --git a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py b/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py
index da6167f1744..3139b679e5c 100644
--- a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py
+++ b/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py
@@ -2464,7 +2464,14 @@ async def oauth_authorization_server_mcp(request: Request, mcp_server_name: str
# Alias for standard OpenID discovery
@router.get("/.well-known/openid-configuration")
async def openid_configuration(request: Request):
- response = await oauth_authorization_server_mcp(request)
+ response: Final = await oauth_authorization_server_mcp(request)
+ if not isinstance(response, dict):
+ return response
+
+ request_base_url: Final = get_request_base_url(request)
+ # OIDC verifiers derive this URL from their configured issuer (the proxy origin),
+ # so keep the origin issuer here even when root resolution scoped the metadata.
+ unscoped_response: Final = {**response, "issuer": request_base_url}
# If MCPJWTSigner is active, augment the discovery doc with JWKS fields so
# MCP servers and gateways (e.g. AWS Bedrock AgentCore Gateway) can resolve
@@ -2476,17 +2483,15 @@ async def openid_configuration(request: Request):
signer: Final = get_mcp_jwt_signer()
if signer is not None:
- request_base_url: Final = get_request_base_url(request)
- if isinstance(response, dict):
- response = {
- **response,
- "jwks_uri": f"{request_base_url}/.well-known/jwks.json",
- "id_token_signing_alg_values_supported": ["RS256"],
- }
+ return {
+ **unscoped_response,
+ "jwks_uri": f"{request_base_url}/.well-known/jwks.json",
+ "id_token_signing_alg_values_supported": ["RS256"],
+ }
except ImportError:
pass
- return response
+ return unscoped_response
@router.get("/.well-known/jwks.json")
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py
index 6939fe02bdc..6bfd83b82b8 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py
@@ -8170,6 +8170,37 @@ async def test_bare_origin_discovery_resolves_single_server_not_aggregate():
global_mcp_server_manager.registry.clear()
+async def test_openid_configuration_alias_keeps_origin_issuer_on_root_resolution():
+ """OIDC verifiers derive /.well-known/openid-configuration from their configured issuer
+ (the proxy origin), so the alias must keep the origin issuer even when single-server
+ root resolution scopes the underlying authorization-server metadata."""
+ from fastapi import Request
+
+ from litellm.proxy._experimental.mcp_server.discoverable_endpoints import (
+ openid_configuration,
+ )
+ from litellm.proxy._experimental.mcp_server.mcp_server_manager import (
+ global_mcp_server_manager,
+ )
+
+ global_mcp_server_manager.registry.clear()
+ oauth2_server = _create_oauth2_server()
+ global_mcp_server_manager.registry[oauth2_server.server_id] = oauth2_server
+
+ mock_request = MagicMock(spec=Request)
+ mock_request.base_url = "https://llm.example.com/"
+ mock_request.headers = {}
+
+ try:
+ response = await openid_configuration(mock_request)
+ assert isinstance(response, dict)
+ assert response["issuer"] == "https://llm.example.com"
+ assert "/test_oauth/authorize" in response["authorization_endpoint"]
+ finally:
+ global_mcp_server_manager.registry.clear()
+
+
def test_gateway_dcr_flow_routing_engages_only_for_llm_dcrc_clients(monkeypatch):
"""The aggregate DCR arms engage for llm_dcrc_ client_ids (register always mints one,
authorize/token route into the aggregate flow); a non-gateway client_id keeps the