FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Reject listRoots when roots capability is unsupported by zsewasdsdsd · Pull Request #1144 · modelcontextprotocol/java-sdk · GitHub

Repository navigation

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

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL