-
Notifications
You must be signed in to change notification settings - Fork 508
feat: add pagination support for listRoots operation #336
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootssResult, result) -> { | |
}).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootsResult, result) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backing list needs to be made unmodifiable after being accumulated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some adjustments , but not sure if this is what you've meant.
@@ -126,7 +128,16 @@ public Mono<McpSchema.ElicitResult> createElicitation(McpSchema.ElicitRequest el | |||
* @return A Mono that emits the list of roots result. | |||
*/ | |||
public Mono<McpSchema.ListRootsResult> listRoots() { | |||
return this.listRoots(null); | |||
|
|||
return this.listRoots(McpSchema.FIRST_PAGE).expand(result -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |