Skip to content

Commit c39f515

Browse files
committed
Fix: prevent infinite recursion in listTools() when nextCursor is empty string
Signed-off-by: lance <[email protected]>
1 parent 2ee5853 commit c39f515

File tree

2 files changed

+275
-218
lines changed

2 files changed

+275
-218
lines changed

mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,10 @@ private McpSchema.CallToolResult validateToolResult(String toolName, McpSchema.C
626626
*/
627627
public Mono<McpSchema.ListToolsResult> listTools() {
628628
return this.listTools(McpSchema.FIRST_PAGE)
629-
.expand(result -> (result.nextCursor() != null) ? this.listTools(result.nextCursor()) : Mono.empty())
629+
.expand(result -> {
630+
String next = result.nextCursor();
631+
return (next != null && !next.isEmpty()) ? this.listTools(next) : Mono.empty();
632+
})
630633
.reduce(new McpSchema.ListToolsResult(new ArrayList<>(), null), (allToolsResult, result) -> {
631634
allToolsResult.tools().addAll(result.tools());
632635
return allToolsResult;

0 commit comments

Comments
 (0)