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 admin-entered oauth endpoints in management reads (#36888)

devin-ai-integration[bot]40d999b693af
diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
index a1adda2bc95..4f94f94acb5 100644
--- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
+++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
@@ -1599,6 +1599,9 @@ class MCPServerManager:
manual_token_url,
)
use_issuer_anchor = _uses_issuer_anchor(manual_issuer, is_discovery_auth_type or obo_needs_discovery)
+ configured_authorization_url = manual_authorization_url
+ configured_token_url = manual_token_url
+ configured_registration_url = manual_registration_url
manual_authorization_url, manual_token_url, manual_registration_url = _endpoints_yield_to_issuer(
manual_issuer,
is_discovery_auth_type,
@@ -1725,6 +1728,9 @@ class MCPServerManager:
authorization_url=resolved_authorization_url,
token_url=resolved_token_url,
registration_url=resolved_registration_url,
+ configured_authorization_url=configured_authorization_url,
+ configured_token_url=configured_token_url,
+ configured_registration_url=configured_registration_url,
token_endpoint_auth_method=server_config.get("token_endpoint_auth_method", None),
# TODO: utility fn the default values
transport=server_config.get("transport", MCPTransport.http),
@@ -2170,6 +2176,9 @@ class MCPServerManager:
is_discovery_auth_type
or self._obo_needs_endpoint_discovery(auth_type, token_exchange_endpoint, manual_token_url),
)
+ configured_authorization_url: Final = manual_authorization_url
+ configured_token_url: Final = manual_token_url
+ configured_registration_url: Final = manual_registration_url
manual_authorization_url, manual_token_url, manual_registration_url = _endpoints_yield_to_issuer(
manual_issuer,
is_discovery_auth_type,
@@ -2222,6 +2231,9 @@ class MCPServerManager:
authorization_url=manual_authorization_url or getattr(gated_oauth_metadata, "authorization_url", None),
token_url=manual_token_url or getattr(gated_oauth_metadata, "token_url", None),
registration_url=manual_registration_url or getattr(gated_oauth_metadata, "registration_url", None),
+ configured_authorization_url=configured_authorization_url,
+ configured_token_url=configured_token_url,
+ configured_registration_url=configured_registration_url,
token_endpoint_auth_method=(
credentials_dict.get("token_endpoint_auth_method") if credentials_dict else None
),
@@ -5858,9 +5870,9 @@ class MCPServerManager:
args=getattr(server, "args", None) or [],
env=getattr(server, "env", None) or {},
issuer=server.issuer,
- authorization_url=server.authorization_url,
- token_url=server.token_url,
- registration_url=server.registration_url,
+ authorization_url=server.configured_authorization_url or server.authorization_url,
+ token_url=server.configured_token_url or server.token_url,
+ registration_url=server.configured_registration_url or server.registration_url,
oauth2_flow=server.oauth2_flow,
dcr_bridge=server.dcr_bridge,
token_exchange_endpoint=server.token_exchange_endpoint,
@@ -5968,9 +5980,9 @@ class MCPServerManager:
args=getattr(server, "args", None) or [],
env=getattr(server, "env", None) or {},
issuer=server.issuer,
- authorization_url=server.authorization_url,
- token_url=server.token_url,
- registration_url=server.registration_url,
+ authorization_url=server.configured_authorization_url or server.authorization_url,
+ token_url=server.configured_token_url or server.token_url,
+ registration_url=server.configured_registration_url or server.registration_url,
oauth2_flow=server.oauth2_flow,
token_exchange_endpoint=server.token_exchange_endpoint,
audience=server.audience,
diff --git a/litellm/types/mcp_server/mcp_server_manager.py b/litellm/types/mcp_server/mcp_server_manager.py
index 7ec117208a0..aeeeca21d3b 100644
--- a/litellm/types/mcp_server/mcp_server_manager.py
+++ b/litellm/types/mcp_server/mcp_server_manager.py
@@ -71,6 +71,12 @@ class MCPServer(BaseModel):
authorization_url: str | None = None
token_url: str | None = None
registration_url: str | None = None
+ # Endpoints exactly as an admin stored them, unlike the resolved fields above which an anchored
+ # issuer empties (RFC 8414 section 3.3). Management reads serve these so the edit form does not
+ # load blanks and then save those blanks over the stored config.
+ configured_authorization_url: str | None = None
+ configured_token_url: str | None = None
+ configured_registration_url: str | None = None
# How the gateway authenticates to the upstream token endpoint. When
# "client_secret_basic" the credentials go in an HTTP Basic Authorization
# header (omitted from the body); None defaults to "client_secret_post".
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 54fd5242d5f..55cc8565a71 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
@@ -479,6 +479,35 @@ class TestMCPServerManager:
assert server.oauth2_flow == "authorization_code"
assert server.needs_user_oauth_token is True
+ @pytest.mark.asyncio
+ async def test_load_servers_from_config_keeps_configured_endpoints_for_management_view(self):
+ """A yaml server with a pinned issuer still reports its configured endpoints to the management
+ view, even though the runtime fields are empty because the anchored issuer is the sole endpoint
+ source. The dashboard edits that view, so emptied values there load as blank fields and the next
+ save writes the blanks over the config."""
+ manager = MCPServerManager()
+
+ config = self._oauth2_config(
+ oauth2_flow="authorization_code",
+ issuer="https://idp.example.com",
+ authorization_url="https://example.com/oauth/authorize",
+ token_url="https://example.com/oauth/token",
+ registration_url="https://example.com/oauth/register",
+ )
+ with patch.object(manager, "_fetch_issuer_anchored_oauth_metadata", new=AsyncMock(return_value=None)):
+ await manager.load_servers_from_config(config)
+
+ server = next(iter(manager.config_mcp_servers.values()))
+ assert server.authorization_url is None
+ assert server.token_url is None
+ assert server.registration_url is None
+
+ view = manager._build_mcp_server_table(server)
+
+ assert view.authorization_url == "https://example.com/oauth/authorize"
+ assert view.token_url == "https://example.com/oauth/token"
+ assert view.registration_url == "https://example.com/oauth/register"
+
@pytest.mark.asyncio
async def test_load_servers_from_config_rejects_uncorroborated_endpoints_but_keeps_resource_scopes(self):
"""A yaml server with a manual authorization_url has the same config-time mix-up exposure as a
@@ -1611,6 +1640,43 @@ class TestMCPServerManager:
assert built.token_url == "https://idp.example.com/token"
assert built.token_url != "https://attacker.example.com/steal"
+ @pytest.mark.asyncio
+ async def test_management_view_keeps_stored_endpoints_when_issuer_is_pinned(self):
+ """A pinned issuer empties the endpoints the runtime uses, but the management view must still
+ report what the admin stored. Serving the emptied values made the dashboard edit form load the
+ three endpoint fields blank, so saving with no edits sent them back as explicit nulls and wiped
+ the row, and re-entering them looked like it never saved."""
+ manager = MCPServerManager()
+ row = LiteLLM_MCPServerTable(
+ server_id="issuer-anchored-management-view",
+ alias="issuer_anchored_management_view",
+ description="issuer pinned with admin-entered endpoints",
+ url="https://up.example.com/mcp",
+ transport=MCPTransport.http,
+ auth_type=MCPAuth.oauth2,
+ oauth2_flow="authorization_code",
+ issuer="https://idp.example.com",
+ authorization_url="https://up.example.com/oauth/authorize",
+ token_url="https://up.example.com/oauth/token",
+ registration_url="https://up.example.com/oauth/register",
+ created_at=datetime.now(),
+ updated_at=datetime.now(),
+ )
+
+ with patch.object(manager, "_fetch_issuer_anchored_oauth_metadata", new=AsyncMock(return_value=None)):
+ built = await manager.build_mcp_server_from_table(row, credentials_are_encrypted=False)
+
+ assert built.authorization_url is None
+ assert built.token_url is None
+ assert built.registration_url is None
+
+ view = manager._build_mcp_server_table(built)
+
+ assert view.issuer == "https://idp.example.com"
+ assert view.authorization_url == "https://up.example.com/oauth/authorize"
+ assert view.token_url == "https://up.example.com/oauth/token"
+ assert view.registration_url == "https://up.example.com/oauth/register"
+
@pytest.mark.asyncio
@pytest.mark.parametrize(
"advertised_authorization_url",