-
Notifications
You must be signed in to change notification settings - Fork 533
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,8 @@ | |||||
|
||||||
package io.modelcontextprotocol.server; | ||||||
|
||||||
import java.util.ArrayList; | ||||||
|
||||||
import com.fasterxml.jackson.core.type.TypeReference; | ||||||
import io.modelcontextprotocol.spec.McpError; | ||||||
import io.modelcontextprotocol.spec.McpSchema; | ||||||
|
@@ -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 -> { | ||||||
if (result.nextCursor() != null) { | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
allRootssResult.roots().addAll(result.roots()); | ||||||
return allRootssResult; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||||||
}); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
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.