class RubyLLM::MCP::Handlers::SamplingHandler
end
end
“Too many tokens”
return true if sample.max_tokens <= 4000
def check_token_limit
end
“Model not allowed”
return true if model_allowed?(sample.model)
def check_model
private
end
accept(response)
response = default_chat_completion(sample.model)
def execute
guard :check_token_limit
guard :check_model
allow_models “gpt-4”, “claude-3-opus”
class GuardedSamplingHandler < RubyLLM::MCP::Handlers::SamplingHandler
@example Sampling handler with guards
end
end
accept(response)
response = default_chat_completion(“gpt-4”)
def execute
class MySamplingHandler < RubyLLM::MCP::Handlers::SamplingHandler
@example Basic sampling handler
Provides access to sample object, guards, and helper methods
Base class for sampling request handlers
def initialize(sample:, coordinator:, **options)
-
options(Hash) -- handler-specific options -
coordinator(Object) -- the coordinator managing the request -
sample(RubyLLM::MCP::Sample) -- the sampling request
def initialize(sample:, coordinator:, **options) @sample = sample @coordinator = coordinator super(**options) end