Replies: 2 comments
|
its one json-rpc session request ids are unique pendingResponses is ConcurrentHashMap so parallel callTool is intended sampling rides the same session keep your sampling handler thread-safe the client itself is fine if the server keeps cwd or open files concurrent mutating tools can still collide thats the server for chapter summarize one client is enough dont new a client per chapter thats just extra initialize |
|
Use one initialized The current implementation is built to multiplex requests on one session:
For example, use Flux.fromIterable(chapters)
.flatMap(chapter -> client.callTool(requestFor(chapter)), 8)
.collectList();There are two separate thread-safety boundaries to keep in mind:
Separate clients are useful when you intentionally need separate MCP sessions, Relevant implementation points:
|
Uh oh!
There was an error while loading. Please reload this page.
Pre-submission Checklist
Question Category
Your Question
I am a bit unsure on how the MCP Client should be used in an application that runs an agent concurrently. (E.g. Summarizing a book by summarizing each chapter concurrently). Following the example: Is the idea that each Chapter summarizing call should have its own McpAsyncClient? It feels a bit weird to have multiple instances of an McpAsyncClient for the same agent. On the other Hand I was unsure if stateful MCP features like sampling would be thread safe.
Is there an official guideline? I couldn't find information about this.
All reactions