feat: add pagination support for listRoots operation#336
feat: add pagination support for listRoots operation#336
Conversation
tzolov
commented
Jun 24, 2025
- Add nextCursor field to ListRootsResult for cursor-based pagination
- Implement automatic pagination in McpAsyncServerExchange.listRoots()
- Update tests to verify pagination functionality
- Automatically fetches and combines all pages into single result
- Add nextCursor field to ListRootsResult for cursor-based pagination - Implement automatic pagination in McpAsyncServerExchange.listRoots() - Update tests to verify pagination functionality - Automatically fetches and combines all pages into single result Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
| return this.listRoots(result.nextCursor()); | ||
| } | ||
| return Mono.empty(); | ||
| }).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootssResult, result) -> { |
There was a problem hiding this comment.
| }).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootssResult, result) -> { | |
| }).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootsResult, result) -> { |
| return Mono.empty(); | ||
| }).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootssResult, result) -> { | ||
| allRootssResult.roots().addAll(result.roots()); | ||
| return allRootssResult; |
There was a problem hiding this comment.
The backing list needs to be made unmodifiable after being accumulated.
There was a problem hiding this comment.
I made some adjustments , but not sure if this is what you've meant.
| public Mono<McpSchema.ListRootsResult> listRoots() { | ||
| return this.listRoots(null); | ||
|
|
||
| return this.listRoots(McpSchema.FIRST_PAGE).expand(result -> { |
There was a problem hiding this comment.
There are no tests for this? Can we have a test for 0 pages, 1 page, 5 pages? Network error after 3rd page?
There was a problem hiding this comment.
I've added a new Test for the aync exchange.
…sive tests - Refactor McpAsyncServerExchange.listRoots() to return Collections.unmodifiableList - Fix typo in variable name (allRootssResult -> allRootsResult) - Improve code formatting and readability with ternary operator - Add comprehensive test suite for McpAsyncServerExchange covering: - listRoots() pagination scenarios and edge cases - Logging notification with level filtering - Elicitation creation with various capabilities - Message creation with sampling capabilities - Error handling and validation scenarios Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
|
@chemicL i've addressed the comments above |
mcp/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java
Show resolved
Hide resolved
mcp/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java
Show resolved
Hide resolved
- Verify sendNotification calls in logging notification tests - Verify sendRequest is never called when capabilities are missing - Improve test assertions to ensure correct method invocation behavior Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
|
@chemicL I've improved the McpAsyncServerExchangeTests to validate the correct method invocation behavior |
chemicL
left a comment
There was a problem hiding this comment.
LGTM! Thanks for improving the tests!
- Add nextCursor field to ListRootsResult for cursor-based pagination - Implement automatic pagination in McpAsyncServerExchange.listRoots() - Automatically fetches and combines all pages into single result - Refactor McpAsyncServerExchange.listRoots() to return Collections.unmodifiableList - Update tests to verify pagination functionality - Add test suite for McpAsyncServerExchange covering: - listRoots() pagination scenarios and edge cases - Logging notification with level filtering - Elicitation creation with various capabilities - Message creation with sampling capabilities - Error handling and validation scenarios - Verify sendNotification calls in logging notification tests - Verify sendRequest is never called when capabilities are missing Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
|
rebased, squashed and merged at 1cbace3 |