From 5ed61fe15bbbe559a26aac8e19d13226e2da75c7 Mon Sep 17 00:00:00 2001 From: Lorenzo C Date: Mon, 2 Jun 2025 22:25:47 -0300 Subject: [PATCH 1/2] Pass responsibility to user --- src/mcp/client/session.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mcp/client/session.py b/src/mcp/client/session.py index 3b7fc3fae..6a7cce82d 100644 --- a/src/mcp/client/session.py +++ b/src/mcp/client/session.py @@ -101,6 +101,7 @@ def __init__( logging_callback: LoggingFnT | None = None, message_handler: MessageHandlerFnT | None = None, client_info: types.Implementation | None = None, + support_roots_list_changed: bool = False, ) -> None: super().__init__( read_stream, @@ -114,6 +115,7 @@ def __init__( self._list_roots_callback = list_roots_callback or _default_list_roots_callback self._logging_callback = logging_callback or _default_logging_callback self._message_handler = message_handler or _default_message_handler + self._support_roots_list_changed = support_roots_list_changed async def initialize(self) -> types.InitializeResult: sampling = ( @@ -122,10 +124,7 @@ async def initialize(self) -> types.InitializeResult: else None ) roots = ( - # TODO: Should this be based on whether we - # _will_ send notifications, or only whether - # they're supported? - types.RootsCapability(listChanged=True) + types.RootsCapability(listChanged=self._support_roots_list_changed) if self._list_roots_callback is not _default_list_roots_callback else None ) From 5411b1197354e35da88f0274e84488a1115bafb2 Mon Sep 17 00:00:00 2001 From: Lorenzo C Date: Mon, 2 Jun 2025 22:35:34 -0300 Subject: [PATCH 2/2] Fix test --- tests/client/test_session.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/client/test_session.py b/tests/client/test_session.py index 72b4413d2..1112d4955 100644 --- a/tests/client/test_session.py +++ b/tests/client/test_session.py @@ -544,6 +544,4 @@ async def mock_server(): received_capabilities.roots is not None ) # Custom list_roots callback provided assert isinstance(received_capabilities.roots, types.RootsCapability) - assert ( - received_capabilities.roots.listChanged is True - ) # Should be True for custom callback + assert received_capabilities.roots.listChanged is False