SamplingRequestHandler implements RequestHandlerInterface
Handler for sampling requests from the server.
The MCP server may request the client to sample an LLM during tool execution. This handler wraps a user-provided callback that performs the actual LLM call.
Tags
Table of Contents
Interfaces
- RequestHandlerInterface
- Interface for handling requests from the server.
Properties
- $callback : SamplingCallbackInterface
- $logger : LoggerInterface
Methods
- __construct() : mixed
- handle() : Response<string|int, CreateSamplingMessageResult>|Error
- Handle the request and return a response or error.
- supports() : bool
- Check if this handler supports the given request.
Properties
$callback read-only
private
SamplingCallbackInterface
$callback
$logger read-only
private
LoggerInterface
$logger
= new NullLogger()
Methods
__construct()
public
__construct(SamplingCallbackInterface $callback[, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
- $callback : SamplingCallbackInterface
- $logger : LoggerInterface = new NullLogger()
handle()
Handle the request and return a response or error.
public
handle(Request $request) : Response<string|int, CreateSamplingMessageResult>|Error
Parameters
- $request : Request
Return values
Response<string|int, CreateSamplingMessageResult>|Errorsupports()
Check if this handler supports the given request.
public
supports(Request $request) : bool
Parameters
- $request : Request