I'm exploring spring-ai-starter-mcp-server-webflux
project to spin up MCP server and my expectation with this offering is the tool call processing should be asynchronous and non-blocking.
However, as per the documentation mentioned here on tool calling capabilities, the Mono
or Flux
is not supported. Which means,
Valid @Tool
implementation:
@Tool(...)
public String sampleTool(..) {
return "test-string";
}
Invalid @Tool
implementation:
@Tool(...)
public Mono<String> sampleTool(..) {
return Mono.just("test-string");
}
My question here is, if the implementation of @Tool
is synchronous - then if I've to call any remote API / make data base calls, then my code bound to I/O and my threads will be blocked. Since I've to call .block()
to return a String.
I'm trying to understand, where the concept of asynchrony / non-blocking here?
Comment From: YunKuiLu
Maybe you can try using Mcp Annotations in 1.1.0-SNAPSHOT.
@McpTool: https://docs.spring.io/spring-ai/reference/1.1-SNAPSHOT/api/mcp/mcp-annotations-server.html#_mcptool
Async Tool Server Example: https://docs.spring.io/spring-ai/reference/1.1-SNAPSHOT/api/mcp/mcp-annotations-examples.html#_async_tool_server
Comment From: deshpandeanoop
@YunKuiLu - So, is @Tool
is blocking & should consider moving to @McpTool
for async non-blocking behaviour. Just still wondering how does the current spring-ai-starter-mcp-server-webflux
has to offer, since the whole implementation of the logic that goes under tool made sync.