The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(mcp): skip 2.0-only expectations when an older SDK is installed
liuhao1024dc9db93b20bb
diff --git a/tests/tools/conftest.py b/tests/tools/conftest.pyindex a12be220a07..7770e87b09c 100644--- a/tests/tools/conftest.py+++ b/tests/tools/conftest.py@@ -55,6 +55,29 @@ def _materialize_mcp_sdk_symbols():yield+def require_mcp_2_sdk():+ """Skip tests that pin mcp 2.0-only behaviour when an older SDK is installed.++ The runtime deliberately supports both SDK generations (the dual+ streamable-client probe in mcp_tool), so a stale ``mcp`` distribution+ imports fine and presence-only guards let these tests through — where+ they fail later with opaque SDK errors. Compare the installed+ distribution against the 2.0.0 pin carried by the ``[mcp]`` extra so the+ outcome is an explicit skip with an actionable reason.+ """+ from importlib.metadata import PackageNotFoundError, version as dist_version++ from packaging.version import Version++ try:+ found = dist_version("mcp")+ except PackageNotFoundError:+ pytest.skip("mcp SDK not installed; install the [mcp] extra")+ if Version(found) < Version("2.0.0"):+ pytest.skip(f"requires mcp>=2.0.0 (found {found}); install the [mcp] extra")++@pytest.fixture(autouse=True)def _clear_web_result_cache():"""Reset the web_search TTL memo between tests.diff --git a/tests/tools/test_mcp_capability_gating.py b/tests/tools/test_mcp_capability_gating.pyindex 794a584e858..c23ab292e7a 100644--- a/tests/tools/test_mcp_capability_gating.py+++ b/tests/tools/test_mcp_capability_gating.py@@ -257,6 +257,7 @@ def _mcp_error(code, message="boom"):class TestMethodNotFoundDetection:"""``_is_method_not_found_error`` underpins the ping→list_tools fallback."""+ @pytest.mark.usefixtures("require_mcp_2_sdk")def test_structural_code_match(self):from tools.mcp_tool_errors import _is_method_not_found_errorassert _is_method_not_found_error(_mcp_error(-32601)) is True@@ -323,6 +324,7 @@ class TestKeepaliveProbeFallback:task.session.list_tools.assert_not_called()assert task._ping_unsupported is False+ @pytest.mark.usefixtures("require_mcp_2_sdk")async def test_no_ping_no_tools_propagates_method_not_found(self):"""A server advertising neither working ping nor tools has no cheaperprobe — the -32601 must propagate rather than calling list_tools on adiff --git a/tests/tools/test_mcp_dashboard_oauth.py b/tests/tools/test_mcp_dashboard_oauth.pyindex fca56ab12fd..d7b297910dd 100644--- a/tests/tools/test_mcp_dashboard_oauth.py+++ b/tests/tools/test_mcp_dashboard_oauth.py@@ -81,6 +81,7 @@ def test_dashboard_flow_accepts_only_one_concurrent_callback():assert sorted(outcomes) == ["accepted", "rejected"][email protected]("require_mcp_2_sdk")def test_mcp_oauth_helpers_use_dashboard_flow_without_loopback_port():from tools.mcp_dashboard_oauth import DashboardOAuthFlow, dashboard_oauth_flowfrom tools.mcp_oauth import (diff --git a/tests/tools/test_mcp_elicitation.py b/tests/tools/test_mcp_elicitation.pyindex 1177c0f5fd7..4de0f2b58a9 100644--- a/tests/tools/test_mcp_elicitation.py+++ b/tests/tools/test_mcp_elicitation.py@@ -83,6 +83,7 @@ class TestElicitationHandlerFormMode:assert handler.metrics["declined"] == 0+ @pytest.mark.usefixtures("require_mcp_2_sdk")def test_schema_read_from_real_sdk_params_reaches_the_summary(self):"""The requested schema must be read off the *real* SDK model.diff --git a/tests/tools/test_mcp_oauth_missing_iss.py b/tests/tools/test_mcp_oauth_missing_iss.pyindex 68a9b69111c..f35d39eeae0 100644--- a/tests/tools/test_mcp_oauth_missing_iss.py+++ b/tests/tools/test_mcp_oauth_missing_iss.py@@ -6,7 +6,17 @@ from types import SimpleNamespaceimport pytest-pytest.importorskip("mcp.shared.auth", reason="mcp 2.x SDK not installed")+# mcp.client.auth.utils also exists in the 1.x line — only the iss validator+# below is 2.0-only, so a module presence check lets a stale SDK through and+# the unguarded imports fail at collection time instead of skipping.+_mcp_auth_utils = pytest.importorskip(+ "mcp.client.auth.utils", reason="mcp 2.x SDK not installed"+)+if not hasattr(_mcp_auth_utils, "validate_authorization_response_iss"):+ pytest.skip(+ "mcp 2.x SDK not installed (older mcp distribution present)",+ allow_module_level=True,+ )from mcp.client.auth.oauth2 import OAuthClientProvider # noqa: E402from mcp.client.auth.utils import validate_authorization_response_iss # noqa: E402