Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ public Mono<McpSchema.ListRootsResult> listRoots() {

// @formatter:off
return this.listRoots(McpSchema.FIRST_PAGE)
.expand(result -> (result.nextCursor() != null) ?
this.listRoots(result.nextCursor()) : Mono.empty())
.expand(result -> {
String next = result.nextCursor();
return (next != null && !next.isEmpty()) ? this.listRoots(next) : Mono.empty();
})
.reduceWith(() -> McpSchema.ListRootsResult.builder(new ArrayList<>()).build(),
(allRootsResult, result) -> {
allRootsResult.roots().addAll(result.roots());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ void testListRootsWithEmptyResult() {
}).verifyComplete();
}

@Test
void testListRootsStopsOnEmptyNextCursor() {

List<McpSchema.Root> page1Roots = Arrays
.asList(McpSchema.Root.builder("file:///home/user/project1").name("Project 1").build());
List<McpSchema.Root> page2Roots = Arrays
.asList(McpSchema.Root.builder("file:///home/user/project2").name("Project 2").build());

McpSchema.ListRootsResult page1Result = McpSchema.ListRootsResult.builder(page1Roots).nextCursor("").build();
McpSchema.ListRootsResult page2Result = McpSchema.ListRootsResult.builder(page2Roots).build();

when(mockSession.sendRequest(eq(McpSchema.METHOD_ROOTS_LIST), eq(new McpSchema.PaginatedRequest()),
any(TypeRef.class)))
.thenReturn(Mono.just(page1Result));

when(mockSession.sendRequest(eq(McpSchema.METHOD_ROOTS_LIST), eq(new McpSchema.PaginatedRequest("")),
any(TypeRef.class)))
.thenReturn(Mono.just(page2Result));

StepVerifier.create(exchange.listRoots()).assertNext(result -> {
assertThat(result.roots()).extracting(McpSchema.Root::uri).containsExactly("file:///home/user/project1");
assertThat(result.nextCursor()).isNull();
}).verifyComplete();

verify(mockSession, times(1)).sendRequest(eq(McpSchema.METHOD_ROOTS_LIST),
any(McpSchema.PaginatedRequest.class), any(TypeRef.class));
}

@Test
void testListRootsWithSpecificCursor() {

Expand Down
Loading