Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio backend tests: forget MCP discovery state between tests (#15287)

Daniel Han83c1c625672b
diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.py
index 69b821f49ac..faefeabe5e1 100644
--- a/studio/backend/tests/conftest.py
+++ b/studio/backend/tests/conftest.py
@@ -130,6 +130,21 @@ def _forget_hub_unreachable_verdict():
_forget()
[email protected](autouse = True)
+def _forget_mcp_discovery_state():
+ # Discovered tools and failed-probe cool-offs are keyed by server id, and most tests reuse "s1": a cool-off
+ # one test records made a later test on the worker skip discovery for its own "s1".
+ def _forget():
+ client = sys.modules.get("core.inference.mcp_client")
+ if client is not None:
+ client._tool_cache.clear()
+ client._probe_cooloff_until.clear()
+
+ _forget()
+ yield
+ _forget()
+
+
@pytest.fixture(autouse = True)
def _forget_load_budget_snapshots():
def _forget():
diff --git a/studio/backend/tests/test_mcp_discovery_state_reset_between_tests.py b/studio/backend/tests/test_mcp_discovery_state_reset_between_tests.py
new file mode 100644
index 00000000000..27c80a81f84
--- /dev/null
+++ b/studio/backend/tests/test_mcp_discovery_state_reset_between_tests.py
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+"""MCP discovery state one test leaves behind does not decide the next test's discovery.
+
+``mcp_client._tool_cache`` and ``_probe_cooloff_until`` are module state keyed by server id. A failed
+probe in test_mcp_apps.py left "s1" cooling off, and test_get_enabled_mcp_tools_caches_discovery, later on
+the same xdist worker, then skipped discovery for its own "s1" (``assert 0 == 1``). The two tests below
+run in order on one worker: the first leaves both behind the way a real probe does, the second fails
+unless conftest forgot them in between.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from core.inference import mcp_client
+
+pytestmark = pytest.mark.xdist_group("mcp_discovery_state_reset_between_tests")
+
+
+def test_a_probe_leaves_a_cooloff_and_a_cache_entry_behind():
+ # Recorded the way the client does it, not monkeypatched.
+ mcp_client.record_probe_failure("s1")
+ mcp_client._tool_cache[mcp_client._account_key("s2")] = [{"name": "echo"}]
+ assert mcp_client.in_failure_cooloff("s1")
+ assert mcp_client.get_cached_tools("s2") is not None
+
+
+def test_the_next_test_starts_with_neither():
+ assert not mcp_client.in_failure_cooloff("s1")
+ assert mcp_client.get_cached_tools("s2") is None