Repository navigation
Fix listRoots() pagination on an empty nextCursor - #1275
Open
subhashpolisetti wants to merge 1 commit into
Open
subhashpolisetti wants to merge 1 commit into
subhashpolisetti wants to merge 1 commit into
Conversation
McpAsyncServerExchange#listRoots() kept following nextCursor when a client returned "" instead of omitting it, sending roots/list again with an empty cursor. Apply the same guard the client list methods already use.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1274
Motivation and Context
McpAsyncServerExchange#listRoots()followsnextCursoruntil it isnull. When a client answersroots/listwith"nextCursor": "", the server requests the next page with"cursor": "", and a client that keeps answering that way makeslistRoots()never complete.McpSyncServerExchange#listRoots()blocks on the sameMono, so it hangs the calling thread.#954 fixed this on the client for
listTools,listResources,listResourceTemplatesandlistPrompts. This change applies the same guard, line for line, tolistRoots(), the last aggregate list method inmcp-corewithout it:McpSyncServerExchange#listRoots()delegates to this method, so it needs no change.How Has This Been Tested?
Added
testListRootsStopsOnEmptyNextCursortoMcpAsyncServerExchangeTests: the first page returnsnextCursor: "", and the test checks that only that page is returned and thatroots/listis sent once. It fails onmain(a second request goes out with an empty cursor) and passes with this change.McpAsyncServerExchangeTests38/38,McpSyncServerExchangeTests27/27clean verify: BUILD SUCCESS (mcp-core 506, mcp-json-jackson3 45, mcp-json-jackson2 45, mcp-test 1357; 1 existingassumeTrueskip inStdioMcpAsyncClientTests)-Pjackson2: BUILD SUCCESS, same countsBreaking Changes
None. A non-empty
nextCursoris still followed; an empty one now ends pagination, as it does on the client.Types of changes
Checklist
Additional context
2.1.x,2.0.xand1.1.x. fix: stop pagination on empty cursors #954 is already on2.1.x, so this would sit next to it if you backport.listRoots(). Reject listRoots when client lacks roots capability #1070 and Reject listRoots when client lacks roots capability #1137 add capability checks tolistRoots(String cursor)in the same class; both merge cleanly with this branch.