mcp - 服务端异步返回支持
2025年12月22日 下午8:49:32
v3.8.0 后,Mcp Server 支持两种异步返回方式:
| 类型 | 说明 |
|---|---|
java.util.concurrent.CompletableFuture<X> | |
org.reactivestreams.Publisher<X> | 比如:Mono<X> |
1、示例:
@McpServerEndpoint(channel = McpChannel.STREAMABLE, mcpEndpoint = "/mcp")
public class McpServerDemo {
@Inject //solon-data-rx-sqlutils
RxSqlUtils sqlUtils;
@ToolMapping(description = "查询天气预报", returnDirect = true)
public Mono<String> getWeather(@Param(description = "城市位置") String location) {
return sqlUtils.sql("select weather from weather_tb where location=?")
.params(location)
.queryValue();
}
@ResourceMapping(uri = "config://app-version", description = "获取应用版本号", mimeType = "text/config")
public CompletableFuture<String> getAppVersion() {
return CompletableFuture.completedFuture("3.2.0");
}
}