Annotation Interface McpSampling


@Target({METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) @Documented public @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:


 &#64;McpSampling(clients = "test-client")
 public CreateMessageResult handleSamplingRequest(CreateMessageRequest request) {
     // Process the request and return a result
     return CreateMessageResult.builder()
         .message("Generated response")
         .build();
 }

 &#64;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.CreateMessageRequest
  • McpSchema.CreateMessageResult
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Used as connection or client identifier to select the MCP client, the sampling method is associated with.
  • Element Details

    • clients

      String[] clients
      Used as connection or client identifier to select the MCP client, the sampling method is associated with.