From 0a59a67a5dbc4fe919523c1c4f6fa466f5d07a10 Mon Sep 17 00:00:00 2001 From: Vineeth Sai Date: Fri, 21 Aug 2026 10:35:19 -0700 Subject: [PATCH 1/4] fix(mcp): bound OAuth discovery when the resource GET opens an event stream A Streamable HTTP MCP server may answer GET on the resource URL with the optional server-to-client SSE stream and hold it open. OAuth discovery ran that GET buffered, so it waited for a body that never ends. `MCP_METADATA_TIMEOUT` does not save it. That value is httpx's per-read timeout, not a deadline for the whole request, so any keepalive arriving inside the window resets the clock and discovery never reaches the well-known protected-resource and authorization-server lookups. Confirmed with a transport that emits a keepalive every `MCP_METADATA_TIMEOUT / 4`: the buffered GET is still blocked after three times the timeout, while the streamed one returns immediately. Only the status line and any `WWW-Authenticate` header matter at this step, and both arrive before the body, so request the response unbuffered and close it unread. `AsyncHTTPHandler.get` gains the `stream` flag that `post`, `put`, `patch` and `delete` already carry, built the same way. Fixes #37499 --- litellm/llms/custom_httpx/http_handler.py | 13 ++ .../mcp_server/mcp_server_manager.py | 9 +- .../mcp_server/test_mcp_server_manager.py | 122 ++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index e1f0fc9e7d3..e6b4676700c 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -654,6 +654,7 @@ class AsyncHTTPHandler: headers: dict | None = None, follow_redirects: bool | None = None, timeout: float | httpx.Timeout | None = None, + stream: bool = False, ): # Set follow_redirects to UseClientDefault if None _follow_redirects: Final = follow_redirects if follow_redirects is not None else USE_CLIENT_DEFAULT @@ -661,6 +662,18 @@ class AsyncHTTPHandler: params = params or {} params.update(HTTPHandler.extract_query_params(url)) + if stream: + # Same shape as post/put/patch/delete: return once the status and + # headers are in, leaving the body for the caller to read or close. + req: Final = self.client.build_request( + "GET", + url, + params=params, + headers=headers, + timeout=timeout, + ) + return await self.client.send(req, stream=True, follow_redirects=_follow_redirects) + response: Final = await self.client.get( url, params=params, diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index d7f238f142c..8c5f542c64e 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -4557,7 +4557,14 @@ class MCPServerManager: llm_provider=httpxSpecialProvider.MCP, params={"timeout": MCP_METADATA_TIMEOUT}, # mutable-ok: HTTP client factory requires a dict ) - response: Final = await client.get(server_url) + # The MCP resource URL is allowed to answer GET with an open + # server-to-client SSE stream, which a buffered read would wait on + # forever: MCP_METADATA_TIMEOUT is httpx's per-read timeout, and a + # keepalive arriving inside it resets the clock indefinitely. Only + # the status line and any WWW-Authenticate header matter here, and + # both are in before the body, so close it unread. + response: Final = await client.get(server_url, stream=True) + await response.aclose() response.raise_for_status() ( authorization_servers, 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 46fef83092d..434507922e5 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 @@ -3957,6 +3957,8 @@ class TestMCPServerManager: mock_response = MagicMock() mock_response.raise_for_status = MagicMock() + # The resource GET is streamed now, so discovery closes the body it did not read. + mock_response.aclose = AsyncMock() mock_client = MagicMock() mock_client.get = AsyncMock(return_value=mock_response) @@ -4014,6 +4016,8 @@ class TestMCPServerManager: mock_response = MagicMock() mock_response.raise_for_status = MagicMock() + # The resource GET is streamed now, so discovery closes the body it did not read. + mock_response.aclose = AsyncMock() mock_client = MagicMock() mock_client.get = AsyncMock(return_value=mock_response) @@ -12567,3 +12571,121 @@ async def test_pre_call_tool_check_honors_guardrail_attached_to_key(monkeypatch, with pytest.raises(HTTPException) as exc_info: await call assert exc_info.value.status_code == 400 + +class _EndlessEventStream(httpx.AsyncByteStream): + """A server-to-client SSE body that keeps sending keepalives and never ends.""" + + def __init__(self, gap: float): + self._gap = gap + + async def __aiter__(self): + while True: + await asyncio.sleep(self._gap) + yield b": keepalive\n\n" + + +class _StreamableHttpMCPTransport(httpx.AsyncBaseTransport): + """GET on the MCP resource opens an event stream; well-known lookups 404. + + Both are ordinary Streamable HTTP behaviour: a server may answer GET with the + optional server-to-client stream, and one without RFC 9728 metadata 404s. + """ + + def __init__(self, gap: float): + self.gap = gap + self.resource_gets = 0 + + async def handle_async_request(self, request: httpx.Request) -> httpx.Response: + if ".well-known" in request.url.path: + return httpx.Response(404, content=b"", request=request) + self.resource_gets += 1 + return httpx.Response( + 200, + headers={"content-type": "text/event-stream"}, + stream=_EndlessEventStream(self.gap), + request=request, + ) + + +class TestOAuthDiscoveryAgainstAnOpenEventStream: + """Discovery must not wait on an MCP resource GET that never ends (issue #37499). + + MCP_METADATA_TIMEOUT is httpx's per-read timeout, not a deadline for the whole + request, so a keepalive arriving inside it resets the clock forever. Only the + status line and any WWW-Authenticate header matter here, and both land before + the body does. + """ + + @staticmethod + def _handler(gap: float, timeout: float): + from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler + + transport = _StreamableHttpMCPTransport(gap) + handler = AsyncHTTPHandler(timeout=timeout) + handler.client = httpx.AsyncClient(transport=transport, timeout=timeout) + return handler, transport + + @pytest.mark.asyncio + async def test_discovery_completes_without_consuming_the_stream(self): + manager = MCPServerManager() + timeout = 0.2 + handler, transport = self._handler(gap=timeout / 4, timeout=timeout) + + with ( + patch( + "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + return_value=handler, + ), + patch( + "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", + timeout, + ), + ): + metadata, attempts = await asyncio.wait_for( + manager._discover_metadata_recording_attempts( + "https://stream.example.com/mcp", + allow_origin_fallback=False, + ), + # Ten keepalives' worth. A buffered read never gets here. + timeout=timeout * 10, + ) + + assert transport.resource_gets == 1 + # 200 with no RFC 9728 challenge, so discovery falls through to the + # well-known lookup and reports that it found nothing. + assert metadata is None + assert any("HTTP 200 (no RFC 9728 challenge)" in attempt for attempt in attempts) + + @pytest.mark.asyncio + async def test_streamed_get_returns_status_and_headers_without_reading_the_body(self): + """The AsyncHTTPHandler half, on its own.""" + timeout = 0.2 + handler, _ = self._handler(gap=timeout / 4, timeout=timeout) + + response = await asyncio.wait_for( + handler.get("https://stream.example.com/mcp", stream=True), + timeout=timeout * 10, + ) + + assert response.status_code == 200 + assert response.headers["content-type"] == "text/event-stream" + assert response.is_stream_consumed is False + await response.aclose() + + @pytest.mark.asyncio + async def test_buffered_get_is_still_the_default(self): + """Control: without stream=True the body is read as before.""" + handler = None + from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler + + class _Json(httpx.AsyncBaseTransport): + async def handle_async_request(self, request): + return httpx.Response(200, json={"ok": True}, request=request) + + handler = AsyncHTTPHandler(timeout=1.0) + handler.client = httpx.AsyncClient(transport=_Json(), timeout=1.0) + + response = await handler.get("https://plain.example.com/thing") + + assert response.json() == {"ok": True} + assert response.is_stream_consumed is True From ee90d30f7e2e27fdc2aa396260669e90c9612233 Mon Sep 17 00:00:00 2001 From: Vineeth Sai Date: Tue, 25 Aug 2026 12:58:07 -0700 Subject: [PATCH 2/4] chore(mcp): give the two discovery patches test-quality reasons The test-quality gate flags TQ008 on both `patch(...)` calls in the new test. Neither is pinning the test to the wiring: the first substitutes a real `httpx.AsyncClient` over a `MockTransport`, which is the HTTP boundary the rule asks for, and `_discover_metadata_recording_attempts` builds its own client with no injection seam, so a patch is the only way the fake gets in; the other discovery tests in this file do the same. The second is a module constant, shortened so the read-timeout assertion does not take the production timeout. --- .../proxy/_experimental/mcp_server/test_mcp_server_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 434507922e5..7f52b08c8ff 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 @@ -12632,11 +12632,11 @@ class TestOAuthDiscoveryAgainstAnOpenEventStream: handler, transport = self._handler(gap=timeout / 4, timeout=timeout) with ( - patch( + patch( # test-quality-ok: the fake IS the HTTP boundary, a real httpx.AsyncClient over MockTransport; _discover_metadata_recording_attempts builds its own client with no injection seam, and the other discovery tests in this file substitute it the same way "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", return_value=handler, ), - patch( + patch( # test-quality-ok: a module constant, not wiring; shortened so the read-timeout assertion does not take the production timeout to run "litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", timeout, ), From 488f90e7bf145e85d9774038bdf42c27376a35ad Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 11:58:32 -0700 Subject: [PATCH 3/4] fix(mcp): give startup OAuth discovery the same metadata deadline as deferred discovery With LITELLM_MCP_OAUTH_DISCOVERY_ON_STARTUP on, config and DB server loads awaited OAuth discovery with no overall deadline, so a protected-resource or authorization-server metadata URL that keeps sending bytes held server loading and proxy boot forever. Both startup paths now share one helper that bounds discovery by MCP_METADATA_TIMEOUT, which the deferred path already uses, and leave the endpoints unresolved on a timeout --- .../mcp_server/mcp_server_manager.py | 49 +++++++++++---- .../mcp_server/test_mcp_server_manager.py | 61 +++++++++++++++++++ 2 files changed, 99 insertions(+), 11 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index 48fed2e203e..2ed441959fd 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -2080,6 +2080,34 @@ class MCPServerManager: def _registered_server(self, server: MCPServer) -> MCPServer: return self.registry.get(server.server_id) or self.config_mcp_servers.get(server.server_id) or server + async def _discover_oauth_metadata_within_deadline( + self, + server_url: str | None, + issuer_anchor: str | None, + *, + allow_origin_fallback: bool, + warn_when_no_metadata: bool, + ) -> MCPOAuthMetadata | None: + discovery: Final = ( + self._fetch_issuer_anchored_oauth_metadata(issuer_anchor, server_url) + if issuer_anchor is not None + else self._descovery_metadata( + server_url=server_url or "", + allow_origin_fallback=allow_origin_fallback, + warn_when_no_metadata=warn_when_no_metadata, + ) + ) + try: + return await asyncio.wait_for(discovery, timeout=MCP_METADATA_TIMEOUT) + except asyncio.TimeoutError: + verbose_logger.warning( + "MCP OAuth discovery for %s timed out after %ss; " + "OAuth endpoints stay unresolved until a rebuild succeeds", + server_url, + MCP_METADATA_TIMEOUT, + ) + return None + async def _discover_oauth_metadata_for_server(self, server: MCPServer) -> MCPOAuthMetadata | None: manual_issuer: Final = _blank_to_none(server.issuer) manual_authorization_url: Final = _blank_to_none(server.authorization_url) @@ -2627,11 +2655,10 @@ class MCPServerManager: discovery_deferred = should_discover and not self._oauth_discovery_on_startup if not should_discover or discovery_deferred: mcp_oauth_metadata = None - elif use_issuer_anchor and manual_issuer is not None: - mcp_oauth_metadata = await self._fetch_issuer_anchored_oauth_metadata(manual_issuer, server_url) else: - mcp_oauth_metadata = await self._descovery_metadata( - server_url=server_url, + mcp_oauth_metadata = await self._discover_oauth_metadata_within_deadline( + server_url, + manual_issuer if use_issuer_anchor else None, allow_origin_fallback=is_discovery_auth_type, warn_when_no_metadata=warn_on_empty_discovery, ) @@ -3120,16 +3147,16 @@ class MCPServerManager: (is_discovery_auth_type and not has_all_upstream_oauth_fields) or obo_needs_discovery ) discovery_deferred: Final = needs_discovery and not self._oauth_discovery_on_startup - if not needs_discovery or discovery_deferred: - mcp_oauth_metadata: MCPOAuthMetadata | None = None - elif use_issuer_anchor and manual_issuer is not None: - mcp_oauth_metadata = await self._fetch_issuer_anchored_oauth_metadata(manual_issuer, server_url) - else: - mcp_oauth_metadata = await self._descovery_metadata( - server_url=server_url, + mcp_oauth_metadata: Final = ( + None + if not needs_discovery or discovery_deferred + else await self._discover_oauth_metadata_within_deadline( + server_url, + manual_issuer if use_issuer_anchor else None, allow_origin_fallback=is_discovery_auth_type, warn_when_no_metadata=warn_on_empty_discovery, ) + ) if use_issuer_anchor: return mcp_oauth_metadata, discovery_deferred gated_metadata: Final = ( diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py index 20397c4005c..88363171ed3 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py +++ b/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py @@ -4640,6 +4640,67 @@ class TestMCPServerManager: assert metadata is None assert "HTTP 200 (no RFC 9728 challenge)" in attempts[0] + @pytest.mark.asyncio + @pytest.mark.parametrize("source", ["config", "database"]) + async def test_startup_discovery_gives_up_on_metadata_that_never_finishes( + self, source: str, monkeypatch: pytest.MonkeyPatch + ): + body: Final = _OpenEventStream() + + def respond(request: httpx.Request) -> httpx.Response: + if request.url.path == "/mcp": + return httpx.Response(200) + if request.url.path == "/.well-known/oauth-protected-resource/mcp": + return httpx.Response(200, headers={"Content-Type": "application/json"}, stream=body) + return httpx.Response(404) + + monkeypatch.setenv("LITELLM_MCP_OAUTH_DISCOVERY_ON_STARTUP", "1") + manager: Final = MCPServerManager() + with ( + patch( + "litellm.proxy._experimental.mcp_server.mcp_server_manager.get_async_httpx_client", + return_value=_handler_answering(respond), + ), + patch("litellm.proxy._experimental.mcp_server.mcp_server_manager.MCP_METADATA_TIMEOUT", 0.05), + ): + if source == "config": + await asyncio.wait_for( + manager.load_servers_from_config( + { + "stuck": { + "url": "https://stuck.example.com/mcp", + "transport": "http", + "auth_type": "oauth2", + "oauth2_flow": "authorization_code", + "client_id": "qa-client", + } + } + ), + timeout=5, + ) + server = next(iter(manager.config_mcp_servers.values())) + else: + server = await asyncio.wait_for( + manager.build_mcp_server_from_table( + LiteLLM_MCPServerTable( + server_id="stuck", + alias="stuck", + url="https://stuck.example.com/mcp", + transport=MCPTransport.http, + auth_type=MCPAuth.oauth2, + oauth2_flow="authorization_code", + created_at=datetime.now(), + updated_at=datetime.now(), + ), + credentials_are_encrypted=False, + ), + timeout=5, + ) + + assert body.read_started.is_set() + assert server.authorization_url is None + assert server.token_url is None + @pytest.mark.asyncio async def test_fetch_single_authorization_server_metadata_supports_azure_issuer_path( self, From 3370486fafe3a494089abb5c122753bf5676395d Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 20 Oct 2026 13:28:48 -0700 Subject: [PATCH 4/4] fix(mcp): bound each OAuth metadata fetch instead of the whole startup discovery chain The previous commit wrapped startup discovery in one MCP_METADATA_TIMEOUT deadline. A slow but healthy chain (a few seconds per step) then gave up before it finished, where it used to resolve. Each metadata GET now gets its own MCP_METADATA_TIMEOUT bound instead, so a URL that keeps sending bytes no longer hangs startup and a slow chain still resolves. --- .../mcp_server/mcp_server_manager.py | 53 +++++-------------- .../mcp_server/test_mcp_server_manager.py | 21 ++++++-- 2 files changed, 29 insertions(+), 45 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index 2ed441959fd..4faa543f68f 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -2080,34 +2080,6 @@ class MCPServerManager: def _registered_server(self, server: MCPServer) -> MCPServer: return self.registry.get(server.server_id) or self.config_mcp_servers.get(server.server_id) or server - async def _discover_oauth_metadata_within_deadline( - self, - server_url: str | None, - issuer_anchor: str | None, - *, - allow_origin_fallback: bool, - warn_when_no_metadata: bool, - ) -> MCPOAuthMetadata | None: - discovery: Final = ( - self._fetch_issuer_anchored_oauth_metadata(issuer_anchor, server_url) - if issuer_anchor is not None - else self._descovery_metadata( - server_url=server_url or "", - allow_origin_fallback=allow_origin_fallback, - warn_when_no_metadata=warn_when_no_metadata, - ) - ) - try: - return await asyncio.wait_for(discovery, timeout=MCP_METADATA_TIMEOUT) - except asyncio.TimeoutError: - verbose_logger.warning( - "MCP OAuth discovery for %s timed out after %ss; " - "OAuth endpoints stay unresolved until a rebuild succeeds", - server_url, - MCP_METADATA_TIMEOUT, - ) - return None - async def _discover_oauth_metadata_for_server(self, server: MCPServer) -> MCPOAuthMetadata | None: manual_issuer: Final = _blank_to_none(server.issuer) manual_authorization_url: Final = _blank_to_none(server.authorization_url) @@ -2655,10 +2627,11 @@ class MCPServerManager: discovery_deferred = should_discover and not self._oauth_discovery_on_startup if not should_discover or discovery_deferred: mcp_oauth_metadata = None + elif use_issuer_anchor and manual_issuer is not None: + mcp_oauth_metadata = await self._fetch_issuer_anchored_oauth_metadata(manual_issuer, server_url) else: - mcp_oauth_metadata = await self._discover_oauth_metadata_within_deadline( - server_url, - manual_issuer if use_issuer_anchor else None, + mcp_oauth_metadata = await self._descovery_metadata( + server_url=server_url, allow_origin_fallback=is_discovery_auth_type, warn_when_no_metadata=warn_on_empty_discovery, ) @@ -3147,16 +3120,16 @@ class MCPServerManager: (is_discovery_auth_type and not has_all_upstream_oauth_fields) or obo_needs_discovery ) discovery_deferred: Final = needs_discovery and not self._oauth_discovery_on_startup - mcp_oauth_metadata: Final = ( - None - if not needs_discovery or discovery_deferred - else await self._discover_oauth_metadata_within_deadline( - server_url, - manual_issuer if use_issuer_anchor else None, + if not needs_discovery or discovery_deferred: + mcp_oauth_metadata: MCPOAuthMetadata | None = None + elif use_issuer_anchor and manual_issuer is not None: + mcp_oauth_metadata = await self._fetch_issuer_anchored_oauth_metadata(manual_issuer, server_url) + else: + mcp_oauth_metadata = await self._descovery_metadata( + server_url=server_url, allow_origin_fallback=is_discovery_auth_type, warn_when_no_metadata=warn_on_empty_discovery, ) - ) if use_issuer_anchor: return mcp_oauth_metadata, discovery_deferred gated_metadata: Final = ( @@ -5138,8 +5111,8 @@ class MCPServerManager: # internal MCP servers. Do not run them through user URL # validation, but also do not follow redirects because the # redirect target would not inherit the same-authority guarantee. - return await client.get(url, follow_redirects=False) - return await async_safe_get(client, url) + return await asyncio.wait_for(client.get(url, follow_redirects=False), timeout=MCP_METADATA_TIMEOUT) + return await asyncio.wait_for(async_safe_get(client, url), timeout=MCP_METADATA_TIMEOUT) async def _descovery_metadata( self, diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py index 88363171ed3..98287dbd67f 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py +++ b/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py @@ -11,7 +11,7 @@ import anyio from collections.abc import AsyncIterator, Awaitable, Callable, Iterator from datetime import datetime from pathlib import Path -from types import SimpleNamespace +from types import MappingProxyType, SimpleNamespace from typing import Any, Dict, Final, Literal, Optional, TypeVar, cast from unittest.mock import AsyncMock, MagicMock, patch @@ -4642,17 +4642,28 @@ class TestMCPServerManager: @pytest.mark.asyncio @pytest.mark.parametrize("source", ["config", "database"]) - async def test_startup_discovery_gives_up_on_metadata_that_never_finishes( + async def test_startup_discovery_moves_past_metadata_that_never_finishes( self, source: str, monkeypatch: pytest.MonkeyPatch ): body: Final = _OpenEventStream() + documents: Final = MappingProxyType( + { + "/.well-known/oauth-protected-resource": {"authorization_servers": ["https://stuck.example.com"]}, + "/.well-known/oauth-authorization-server": { + "issuer": "https://stuck.example.com", + "authorization_endpoint": "https://stuck.example.com/authorize", + "token_endpoint": "https://stuck.example.com/token", + }, + } + ) def respond(request: httpx.Request) -> httpx.Response: if request.url.path == "/mcp": return httpx.Response(200) if request.url.path == "/.well-known/oauth-protected-resource/mcp": return httpx.Response(200, headers={"Content-Type": "application/json"}, stream=body) - return httpx.Response(404) + document: Final = documents.get(request.url.path) + return httpx.Response(404) if document is None else httpx.Response(200, json=document) monkeypatch.setenv("LITELLM_MCP_OAUTH_DISCOVERY_ON_STARTUP", "1") manager: Final = MCPServerManager() @@ -4698,8 +4709,8 @@ class TestMCPServerManager: ) assert body.read_started.is_set() - assert server.authorization_url is None - assert server.token_url is None + assert server.authorization_url == "https://stuck.example.com/authorize" + assert server.token_url == "https://stuck.example.com/token" @pytest.mark.asyncio async def test_fetch_single_authorization_server_metadata_supports_azure_issuer_path(