Class SyncMcpElicitationProvider

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

public class SyncMcpElicitationProvider extends Object
Provider for synchronous 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.

Example usage:


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

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

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

    • SyncMcpElicitationProvider

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

    • getElicitationSpecifications

      public List<SyncElicitationSpecification> 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