Class ModernReactiveSupport

java.lang.Object
org.springframework.ai.mcp.annotation.common.ModernReactiveSupport

public final class ModernReactiveSupport extends Object
Return-value handling shared by the asynchronous method callbacks of a 2026-07-28 ("modern") MCP server. An MCP request has one result, so a method answers with a single value, and ReactiveAdapterRegistry tells which return types can do that:
Since:
2.1.0
Author:
Christian Tzolov
  • Method Details

    • isReactive

      public static boolean isReactive(Method method)
      Whether the declared return type is a reactive or asynchronous type: a Mono, a Publisher, a CompletionStage and the like.
    • rejectMultiValuedReturnType

      public static void rejectMultiValuedReturnType(Method method)
      Rejects a declared return type that is multi-valued by definition. Publisher and Flow.Publisher are accepted because they say nothing about the number of elements; the returned value decides.
      Parameters:
      method - the method to check
      Throws:
      IllegalArgumentException - if the method returns a Flux or another concrete multi-valued type
    • outcomeType

      public static @Nullable Type outcomeType(Method method)
      The type the method's outcome has: the type argument of a reactive return, or the generic return type otherwise. A raw reactive return has no known outcome type.
    • outcomeClass

      public static @Nullable Class<?> outcomeClass(Method method)
      The raw class of outcomeType(Method): the erased return type of a non-reactive method, and for a reactive one the class of its type argument, or null when that is not known or is not a class (a wildcard or a type variable).
    • invoke

      public static @Nullable Object invoke(Method method, Object bean, Object[] args)
      Invokes the method, surfacing the cause of an InvocationTargetException: a RuntimeException or Error as is, a checked exception wrapped in an UndeclaredThrowableException. The caller makes the method accessible once, when its callback is built.
    • invokeToMono

      public static reactor.core.publisher.Mono<Object> invokeToMono(io.modelcontextprotocol.modern.server.McpRequestContext context, Method method, Supplier<@Nullable Object> invocation)
      Runs a method invocation and normalises what it returns into a Mono. A method with a reactive return type is expected not to block, so it is invoked on subscription on the calling thread; any other goes through McpModernAsyncUtils.fromBlocking(io.modelcontextprotocol.modern.server.McpRequestContext, java.util.concurrent.Callable<T>).
      Parameters:
      context - the request context
      method - the method being invoked
      invocation - the invocation of the method
      Returns:
      the deferred result, empty when the method answers with nothing