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 ) 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