Repository navigation
Add async client type for modern MCP connections - #7392
Merged
Merged
Conversation
Serve the connections that speak MCP 2026-07-28 with `spring.ai.mcp.client.type=ASYNC`, on the asynchronous client of the MCP Java SDK. Until now a modern connection failed the startup with that type. - Tool callbacks: `AsyncModernMcpConnection`, `AsyncModernMcpToolCallbackProvider` and `AsyncModernMcpToolCallback` list and call the tools, and `AsyncMcpToolCallbackProvider` returns them next to the legacy ones. An `AsyncModernMcpTransportContextProvider` bean supplies the caller of a request, and `AsyncModernMcpClientScope` and `AsyncModernMcpToolCallCustomizer` mirror the synchronous types. - Handlers: reactive `@McpElicitation` and `@McpProgress` methods answer the tool calls with the `ToolContext` of the call, and reactive list-changed methods are called for a connection that sets `listen=true`. - Change notifications: `AsyncModernMcpChangeSubscriber` keeps the listen streams open and tells `AsyncModernMcpChangeListener` beans and the provider, which drops a kept tool listing. - The listing, tool call and listen stream logic of the synchronous client moves into package-private classes that both types share. Its behaviour does not change. - Resolving the tools on a non-blocking thread fails with a clear error for both types. The client docs gain the sections "Asynchronous Client Type" and "Blocking Calls". Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Fail an async tool call on a non-blocking thread before the request is sent, and not as a tool error. - Use the `AsyncModernMcpTransportContextProvider` bean as the only source of the caller. A transport context in the Reactor context of the chat call is no longer used. - Count a reactive `@McpProgress` method only if it returns `Mono<Void>`, as its provider does. - Fail the startup again for a reactive `@McpElicitation` method that does not return a `Mono`. - Move the `handlesModern...` accessors to the registry base class. Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
The check for a non-blocking thread rejected every listing, also one that a synchronous client keeps and answers without a request, which worked before. Fail up front only when a request to the server is certain, and otherwise ask the client and turn Reactor's refusal into the same message. Also correct the Javadoc of `AsyncModernMcpToolCallback.Builder.transportContext`, which still described the Reactor context fallback. Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This was referenced Nov 13, 2026
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.
Serves the connections that speak the 2026-07-28 ("modern") revision with
spring.ai.mcp.client.type=ASYNC, on the asynchronous client of the MCP Java SDK.It is the follow-up to #7385, which added the synchronous client type; until now a modern connection failed the startup with the asynchronous type.
Enable it
The connection properties are those of #7385, and the client type applies to legacy and modern connections alike:
The tools of both kinds of connections are served by the existing
AsyncMcpToolCallbackProviderbean, so aChatClientsees a single provider.Tool callbacks (
spring-ai-mcp)Each synchronous type of #7385 has an asynchronous counterpart:
SyncModernMcpConnectionAsyncModernMcpConnectionSyncModernMcpToolCallbackProviderAsyncModernMcpToolCallbackProviderSyncModernMcpToolCallbackAsyncModernMcpToolCallbackSyncModernMcpClientScopeAsyncModernMcpClientScopeSyncModernMcpToolCallCustomizerAsyncModernMcpToolCallCustomizertransportContextProviderof the clientAsyncModernMcpTransportContextProviderSyncModernMcpChangeSubscriberAsyncModernMcpChangeSubscriberSyncModernMcpChangeListenerAsyncModernMcpChangeListenerAsyncMcpToolCallbackProvidertakes the modern provider throughmodernToolCallbackProvider(...)and returns its callbacks next to the legacy ones, without caching them.AsyncModernMcpTransportContextProviderbean supplies it each time the tools are resolved, on the thread that resolves them. The listing goes out for that caller, and the callbacks of that resolution keep it, so a tool that runs later, or on another thread, is called for the same caller.McpTransportContextin the Reactor context of the chat call is not used. Spring AI's MCP server transports put the inbound request context under the same key, and it must not travel to another server.ToolCallbackProviderandToolCallbackcontracts stay blocking, as they are for the legacy asynchronous clients. A tool listing that needs a blocking call on a Reactor non-blocking thread fails with anIllegalStateExceptionthat names the connection and the thread, instead of Reactor's message, for both client types. A listing that the provider keeps needs no blocking call, and with the synchronous type neither does one that a client which outlives the request keeps. A tool call of the asynchronous type on such a thread fails before anything is sent, and not as aToolExecutionException, so the model is not invited to call the tool again.Annotated handlers (
spring-ai-mcp-annotations)@McpElicitationand@McpProgress- methods that return aMonoanswer the input requests and receive the progress of an asynchronous modern tool call. As with the synchronous type, they may take the schema types of either protocol and an optionalToolContextof the tool call.@McpToolListChanged,@McpPromptListChangedand@McpResourceListChangedmethods that returnMono<Void>are called for an asynchronous modern connection that setslisten=true.AbstractClientMcpHandlerRegistrygains hooks that decide which methods a modern client can call;ClientMcpAsyncHandlersRegistrytakes only reactive methods, and a progress method only if it returnsMono<Void>. The asynchronous registry keeps one@McpElicitationmethod for each client.Change notifications
AsyncModernMcpChangeSubscriber- keeps the listen streams open, with the reopen behaviour of the synchronous subscriber, and tellsAsyncModernMcpChangeListenerbeans and the tool callback provider.Monomust complete.Shared code
The listing, tool call and listen stream logic of the synchronous client moves into package-private classes that both types use:
ModernToolListings(kept listings, invalidation, unreachable cool-down),ModernToolCalls(request and response mapping) andModernChangeStreams(opening, reopening and telling the listeners).The behaviour of the synchronous client does not change: its existing tests pass unchanged apart from the paths of private fields, and new tests cover the non-blocking-thread cases.
Auto-configuration
McpClientModernAutoConfiguration- withtype=ASYNCit creates anAsyncModernMcpConnectionfor each modern connection, customized byMcpClientCustomizer<McpClient.AsyncBuilder>beans, and theAsyncModernMcpChangeSubscriberbean.client-scope=CUSTOMrequires anAsyncModernMcpClientScopebean. The startup guard that rejected modern connections with the asynchronous type is removed.client-scope=SHAREDtogether with anAsyncModernMcpTransportContextProviderbean is reported at startup, because a shared client keeps a private tool listing for all its callers.McpToolCallbackAutoConfiguration- builds the asynchronous modern provider, with the annotated handlers and theAsyncModernMcpToolCallCustomizerbeans applied to each tool call.AsyncModernMcpToolCallbackProviderandAsyncModernMcpToolCallbackare treated like their legacy counterparts: their tools are not listed at startup, and an MCP server does not expose them as its own tools.Changes for existing code
handlesModernFormElicitation,handlesModernUrlElicitation,handlesModernProgressandhandlesModernListChangedmove fromClientMcpSyncHandlersRegistryto the shared base class, so both registries offer them.ToolContextparameter, which isnullthere. A reactive@McpElicitationmethod that does not return aMonostill fails the startup.Not included