Annotation Interface McpSampling
Annotation for methods that handle sampling requests from MCP servers. This annotation
is applicable only for MCP clients.
Methods annotated with this annotation can be used to process sampling requests from MCP servers. The methods can have one of two signatures:
- A single parameter of type
CreateMessageRequest - Multiple parameters corresponding to the fields of
CreateMessageRequest
For synchronous handlers, the method must return CreateMessageResult. For
asynchronous handlers, the method must return Mono<CreateMessageResult>.
Example usage:
@McpSampling(clients = "test-client")
public CreateMessageResult handleSamplingRequest(CreateMessageRequest request) {
// Process the request and return a result
return CreateMessageResult.builder()
.message("Generated response")
.build();
}
@McpSampling(clients = "test-client")
public Mono<CreateMessageResult> handleAsyncSamplingRequest(CreateMessageRequest request) {
// Process the request asynchronously and return a result
return Mono.just(CreateMessageResult.builder()
.message("Generated response")
.build());
}
- Author:
- Christian Tzolov
- See Also:
-
McpSchema.CreateMessageRequestMcpSchema.CreateMessageResult
-
Required Element Summary
Required Elements
-
Element Details
-
clients
String[] clientsUsed as connection or client identifier to select the MCP client, the sampling method is associated with.
-