Class AsyncMcpSamplingProvider
java.lang.Object
org.springaicommunity.mcp.provider.sampling.AsyncMcpSamplingProvider
Provider for asynchronous sampling callbacks.
This class scans a list of objects for methods annotated with McpSampling and
creates Function callbacks for them. These callbacks can be used to handle
sampling requests from MCP servers in a reactive way.
Example usage:
// Create a provider with a list of objects containing @McpSampling methods
AsyncMcpSamplingProvider provider = new AsyncMcpSamplingProvider(List.of(samplingHandler));
// Get the sampling handler
Function<CreateMessageRequest, Mono<CreateMessageResult>> samplingHandler = provider.getSamplingHandler();
// Add the handler to the client features
McpClientFeatures.Async clientFeatures = new McpClientFeatures.Async(
clientInfo, clientCapabilities, roots,
toolsChangeConsumers, resourcesChangeConsumers, promptsChangeConsumers,
loggingConsumers, samplingHandler);
- Author:
- Christian Tzolov
- See Also:
-
McpSamplingAsyncMcpSamplingMethodCallbackMcpSchema.CreateMessageRequestMcpSchema.CreateMessageResult
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncMcpSamplingProvider(List<Object> samplingObjects) Create a new AsyncMcpSamplingProvider. -
Method Summary
Modifier and TypeMethodDescriptionprotected Method[]doGetClassMethods(Object bean) Returns the methods of the given bean class.Get the sampling handler.
-
Constructor Details
-
AsyncMcpSamplingProvider
Create a new AsyncMcpSamplingProvider.- Parameters:
samplingObjects- the objects containing methods annotated withMcpSampling
-
-
Method Details
-
getSamplingSpecifictions
Get the sampling handler.- Returns:
- the sampling handler
- Throws:
IllegalStateException- if no sampling methods are found or if multiple sampling methods are found
-
doGetClassMethods
Returns the methods of the given bean class.- Parameters:
bean- the bean instance- Returns:
- the methods of the bean class
-