Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

tzolov
Copy link
Contributor

@tzolov 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>
@tzolov tzolov added this to the 0.11.0 milestone Jun 24, 2025
return this.listRoots(result.nextCursor());
}
return Mono.empty();
}).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootssResult, result) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootssResult, result) -> {
}).reduce(new McpSchema.ListRootsResult(new ArrayList<>(), null), (allRootsResult, result) -> {

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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 -> {
Copy link
Member

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?

Copy link
Contributor Author

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>
@tzolov
Copy link
Contributor Author

tzolov commented Jun 24, 2025

@chemicL i've addressed the comments above

- 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>
@tzolov
Copy link
Contributor Author

tzolov commented Jun 26, 2025

@chemicL I've improved the McpAsyncServerExchangeTests to validate the correct method invocation behavior

Copy link
Member

@chemicL chemicL left a 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!

tzolov added a commit that referenced this pull request Jun 27, 2025
- 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>
@tzolov
Copy link
Contributor Author

tzolov commented Jun 27, 2025

rebased, squashed and merged at 1cbace3

@tzolov tzolov closed this Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants