Reject listRoots early when the client has not initialized capabilities or does not advertise the roots capability, instead of sending an unsupported roots/list request.
Other server-to-client operations already fail fast when the client does not advertise the required capability. McpAsyncServerExchange.listRoots(...) did not perform the equivalent check and could send a roots/list request to a client that does not support roots.
This change adds the missing capability validation and preserves the existing "Roots not supported" error behavior.
How Has This Been Tested?
Added regression coverage for:
calling listRoots before client capabilities are initialized
calling listRoots when the client does not advertise the roots capability
verifying that no roots/list request is sent when either capability check fails
Both failures were reproduced on a clean upstream/main worktree, so they are not introduced by this change.
Breaking Changes
No.
The change only adds fail-fast validation for an operation that requires the client to advertise the roots capability. Supported clients continue through the existing request path unchanged.
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
I noticed after opening this PR that #1105 and #1137 also address #1067.
One compatibility difference is that this PR preserves the existing Roots not supported error behavior. I verified this against both HttpServletStreamableIntegrationTests.testRootsWithoutCapability and HttpServletSseIntegrationTests.testRootsWithoutCapability.
This version also directly exercises the listRoots(String cursor) overload in the missing-roots regression test and keeps the change limited to the implementation and its tests.
Happy to defer to the maintainers on which implementation to keep.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reject listRoots early when the client has not initialized capabilities or does not advertise the roots capability, instead of sending an unsupported roots/list request.
Motivation and Context
Fixes #1067.
Other server-to-client operations already fail fast when the client does not advertise the required capability. McpAsyncServerExchange.listRoots(...) did not perform the equivalent check and could send a roots/list request to a client that does not support roots.
This change adds the missing capability validation and preserves the existing "Roots not supported" error behavior.
How Has This Been Tested?
Added regression coverage for:
Targeted core tests pass locally:
The existing roots capability integration tests were also verified successfully:
A full local test run still encounters two unrelated SSE/tool timeout failures:
Both failures were reproduced on a clean upstream/main worktree, so they are not introduced by this change.
Breaking Changes
No.
The change only adds fail-fast validation for an operation that requires the client to advertise the roots capability. Supported clients continue through the existing request path unchanged.
Types of changes
Checklist
Additional context
The implementation follows the existing capability-checking pattern used by other server-to-client operations.
The production change is limited to McpAsyncServerExchange.listRoots(...), with corresponding regression tests in McpAsyncServerExchangeTests.
No documentation changes are required because this fixes SDK behavior to enforce the existing client capability contract.