Repository navigation
Conversation
…#1045) Add toolsFlow, promptsFlow, resourcesFlow and resourceTemplatesFlow to Client. Each returns a cold Flow that follows nextCursor page by page until the server returns none, and fails with IllegalStateException if the server repeats a cursor instead of looping forever.
There was a problem hiding this comment.
Nice work — the pagination helpers look solid, approving!
Produced by Air Automations. Name: Code review / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/409567ec-d3a7-40ac-ba95-8518ec577ac2?run=08197b1d-36d6-41b3-bddf-40fd100ef424
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.
Closes #1045
What was added
Four new
Clientfunctions that return a coldFlowand follownextCursoruntil the server returns none:toolsFlow(request, options): Flow<Tool>promptsFlow(request, options): Flow<Prompt>resourcesFlow(request, options): Flow<Resource>resourceTemplatesFlow(request, options): Flow<ResourceTemplate>Behaviour:
take(n)orfirst()stops further requests, and a pending page request is cancelled with it.McpExceptionon page 2) are thrown to the collector after the earlier items were emitted.requestis optional. If it carries a cursor, the flow starts there. Its_metais sent with every page request.optionsapply to every page request.nextCursorthat was already used in this collection (including the starting cursor), the flow throwsIllegalStateExceptioninstead of looping forever. The guard keeps a set of the cursors seen so far, so it also catches cycles longer than one page.API
client.toolsFlow().collect { tool -> println(tool.name) } val firstTen = client.toolsFlow().take(10).toList()ABI change
This is an intentional API addition.
updateKotlinAbiadded 8 lines tokotlin-sdk-client/api/kotlin-sdk-client.api(the four functions and their$defaultsynthetics) and 4 lines tokotlin-sdk-client.klib.api. No existing declaration changed.Tests
ClientListFlowTest(commonTest, in-memory transport, backtick names) covers: multiple pages collected in order, a single page, an empty result, a cold flow that restarts per collection, cancellation mid-way (no further requests),take/firststopping early, cancelling an in-flight page request, an error on page 2 propagating, a repeated cursor, a cycle back to an earlier cursor, starting cursor and_metahandling, plus one ordering test each for prompts, resources and resource templates.Run with
JAVA_HOME=<JDK 21>:I also checked the tests by mutation. With the cursor-follow broken, 10 of 14 tests fail. With the repeated-cursor guard removed, the two guard tests fail.
Only the client module JVM tests were run locally.