Skip to content

User should set RootsListChanged capability #871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/mcp/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = (
Expand All @@ -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
)
Expand Down
4 changes: 1 addition & 3 deletions tests/client/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading