Class SyncMcpSamplingProvider
java.lang.Object
org.springaicommunity.mcp.provider.sampling.SyncMcpSamplingProvider
Provider for synchronous 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.
Example usage:
// Create a provider with a list of objects containing @McpSampling methods
SyncMcpSamplingProvider provider = new SyncMcpSamplingProvider(List.of(samplingHandler));
// Get the sampling handler
Function<CreateMessageRequest, CreateMessageResult> samplingHandler = provider.getSamplingHandler();
// Add the handler to the client features
McpClientFeatures.Sync clientFeatures = new McpClientFeatures.Sync(
clientInfo, clientCapabilities, roots,
toolsChangeConsumers, resourcesChangeConsumers, promptsChangeConsumers,
loggingConsumers, samplingHandler);
- Author:
- Christian Tzolov
- See Also:
-
McpSamplingSyncMcpSamplingMethodCallbackMcpSchema.CreateMessageRequestMcpSchema.CreateMessageResult
-
Constructor Summary
ConstructorsConstructorDescriptionSyncMcpSamplingProvider(List<Object> samplingObjects) Create a new SyncMcpSamplingProvider. -
Method Summary
Modifier and TypeMethodDescriptionprotected Method[]doGetClassMethods(Object bean) Returns the methods of the given bean class.Get the sampling handler.
-
Constructor Details
-
SyncMcpSamplingProvider
Create a new SyncMcpSamplingProvider.- Parameters:
samplingObjects- the objects containing methods annotated withMcpSampling
-
-
Method Details
-
getSamplingSpecifications
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
-