Class AsyncMcpElicitationProvider

java.lang.Object
org.springaicommunity.mcp.provider.elicitation.AsyncMcpElicitationProvider

public class AsyncMcpElicitationProvider extends Object
Provider for asynchronous elicitation callbacks.

This class scans a list of objects for methods annotated with McpElicitation and creates Function callbacks for them. These callbacks can be used to handle elicitation requests from MCP servers in a reactive way.

Example usage:


 // Create a provider with a list of objects containing @McpElicitation methods
 AsyncMcpElicitationProvider provider = new AsyncMcpElicitationProvider(List.of(elicitationHandler));

 // Get the elicitation handler
 Function<ElicitRequest, Mono<ElicitResult>> elicitationHandler = provider.getElicitationHandler();

 // Add the handler to the client features
 McpClientFeatures.Async clientFeatures = new McpClientFeatures.Async(
     clientInfo, clientCapabilities, roots,
     toolsChangeConsumers, resourcesChangeConsumers, promptsChangeConsumers,
     loggingConsumers, samplingHandler, elicitationHandler);
 
Author:
Christian Tzolov
See Also:
  • Constructor Details

    • AsyncMcpElicitationProvider

      public AsyncMcpElicitationProvider(List<Object> elicitationObjects)
      Create a new AsyncMcpElicitationProvider.
      Parameters:
      elicitationObjects - the objects containing methods annotated with McpElicitation
  • Method Details

    • getElicitationSpecifications

      public List<AsyncElicitationSpecification> getElicitationSpecifications()
      Get the elicitation specifications.
      Returns:
      the elicitation specifications
      Throws:
      IllegalStateException - if no elicitation methods are found or if multiple elicitation methods are found
    • doGetClassMethods

      protected Method[] doGetClassMethods(Object bean)
      Returns the methods of the given bean class.
      Parameters:
      bean - the bean instance
      Returns:
      the methods of the bean class