From 74c7e58ea35cfec4bfd0b7aab0dbfe1b516ce3bd Mon Sep 17 00:00:00 2001 From: Jake Kaplan Date: Thu, 6 Aug 2026 08:40:19 -0400 Subject: [PATCH] Expose configured discovery result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with OpenAI Codex --- fastmcp_slim/fastmcp/client/client.py | 5 +++++ fastmcp_slim/fastmcp/server/providers/proxy.py | 2 +- tests/client/client/test_mode_negotiation.py | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fastmcp_slim/fastmcp/client/client.py b/fastmcp_slim/fastmcp/client/client.py index 55aff6408..ae1dde726 100644 --- a/fastmcp_slim/fastmcp/client/client.py +++ b/fastmcp_slim/fastmcp/client/client.py @@ -657,6 +657,11 @@ class Client( return self._session_state.session + @property + def prior_discover(self) -> mcp_types.DiscoverResult | None: + """The configured result to adopt when `mode` pins a modern version.""" + return self._prior_discover + @property def initialize_result(self) -> mcp_types.InitializeResult | None: """Get the result of the initialization request. diff --git a/fastmcp_slim/fastmcp/server/providers/proxy.py b/fastmcp_slim/fastmcp/server/providers/proxy.py index 5ad740c7b..d2f328051 100644 --- a/fastmcp_slim/fastmcp/server/providers/proxy.py +++ b/fastmcp_slim/fastmcp/server/providers/proxy.py @@ -1079,7 +1079,7 @@ class ProxyMetadataMiddleware(Middleware): if ( not connected and client.mode in MODERN_PROTOCOL_VERSIONS - and client._prior_discover is None + and client.prior_discover is None ): client = client.new() client.mode = "auto" diff --git a/tests/client/client/test_mode_negotiation.py b/tests/client/client/test_mode_negotiation.py index 1d400a727..97c1fb3a8 100644 --- a/tests/client/client/test_mode_negotiation.py +++ b/tests/client/client/test_mode_negotiation.py @@ -22,7 +22,7 @@ from typing import Any import pytest from mcp import ClientSession from mcp.shared.exceptions import MCPError -from mcp_types import METHOD_NOT_FOUND +from mcp_types import METHOD_NOT_FOUND, DiscoverResult, ServerCapabilities from mcp_types.version import LATEST_HANDSHAKE_VERSION, LATEST_MODERN_VERSION from typing_extensions import Unpack @@ -242,6 +242,19 @@ class TestNonConformantModernPeer: class TestPinnedMode: + def test_prior_discover_is_exposed(self, fastmcp_server): + prior = DiscoverResult( + supported_versions=[LATEST_MODERN_VERSION], + capabilities=ServerCapabilities(), + ) + client = Client( + fastmcp_server, + mode=LATEST_MODERN_VERSION, + prior_discover=prior, + ) + + assert client.prior_discover is prior + async def test_pinned_modern_adopts_without_probe(self, fastmcp_server): """Pinning the modern version adopts it directly; a synthesized DiscoverResult carries no identity, so server_info is absent."""