diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py b/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py index b477bf3f406..22cb126c6f4 100644 --- a/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py +++ b/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py @@ -20,3 +20,15 @@ def _hermetic_server_root_path(): finally: if saved is not None: os.environ["SERVER_ROOT_PATH"] = saved + + +@pytest.fixture(autouse=True) +def _hermetic_proxy_base_url(monkeypatch): + """Isolate MCP discovery tests from a developer's ``PROXY_BASE_URL``. + + ``get_request_base_url`` resolves that env var ahead of the request's own base URL, and + ``import litellm`` loads a ``.env`` from any parent directory of the checkout, so a set value + silently overrides the origins these tests drive through the request. Clearing it here pins + the request-derived origin; a test that exercises the env override sets the value itself. + """ + monkeypatch.delenv("PROXY_BASE_URL", raising=False) diff --git a/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py index 53dda8f6648..fd2eedb9e34 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py @@ -1556,6 +1556,14 @@ class TestTeamScopedMCPServerAccess: class TestTemporaryMCPSessionEndpoints: + @pytest.fixture(autouse=True) + def unset_proxy_base_url(self, monkeypatch): + """``get_request_base_url`` resolves ``PROXY_BASE_URL`` ahead of ``request.base_url``, so a + developer with that env var set (a ``.env`` in any parent directory of the checkout is + enough, since ``import litellm`` runs dotenv) would otherwise silently bypass the mocked + ``request.base_url`` these tests assert on.""" + monkeypatch.delenv("PROXY_BASE_URL", raising=False) + def test_inherit_credentials_from_existing_server(self): payload = NewMCPServerRequest( server_id="server-123",