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 @@ -225,6 +225,13 @@ public Mono<McpSchema.ListRootsResult> listRoots() {
* @return A Mono that emits the list of roots result containing
*/
public Mono<McpSchema.ListRootsResult> listRoots(String cursor) {
if (this.clientCapabilities == null) {
return Mono
.error(new IllegalStateException("Client must be initialized. Call the initialize method first!"));
}
if (this.clientCapabilities.roots() == null) {
return Mono.error(new IllegalStateException("Roots not supported"));
}
return this.session.sendRequest(McpSchema.METHOD_ROOTS_LIST, new McpSchema.PaginatedRequest(cursor),
LIST_ROOTS_RESULT_TYPE_REF);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ void setUp() {
McpTransportContext.EMPTY);
}

@Test
void testListRootsWithNullCapabilities() {
McpAsyncServerExchange exchangeWithNullCapabilities = new McpAsyncServerExchange("testSessionId", mockSession,
null, clientInfo, McpTransportContext.EMPTY);

StepVerifier.create(exchangeWithNullCapabilities.listRoots()).verifyErrorSatisfies(error -> {
assertThat(error).isInstanceOf(IllegalStateException.class)
.hasMessage("Client must be initialized. Call the initialize method first!");
});

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

@Test
void testListRootsWithoutRootsCapability() {
McpSchema.ClientCapabilities capabilitiesWithoutRoots = McpSchema.ClientCapabilities.builder().build();
McpAsyncServerExchange exchangeWithoutRoots = new McpAsyncServerExchange("testSessionId", mockSession,
capabilitiesWithoutRoots, clientInfo, McpTransportContext.EMPTY);

StepVerifier.create(exchangeWithoutRoots.listRoots("someCursor")).verifyErrorSatisfies(error -> {
assertThat(error).isInstanceOf(IllegalStateException.class).hasMessage("Roots not supported");
});

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

@Test
void testListRootsWithSinglePage() {

Expand Down