[Schema][Server] feat: support sampling with tools (#409)
* feat: support sampling with tools * address sampling tools review feedback * tighten sampling tools spec compliance * drop SamplingStopReason enum in favor of open string The spec leaves stopReason open for provider-specific values, so upcasting the four known ones to enum cases makes every future enum addition a silent BC break for string comparisons. --------- Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
This commit is contained in:
parent
d8cc21a345
commit
82aac972c1
1 changed files with 682 additions and 27 deletions
|
|
@ -36,6 +36,8 @@ use Mcp\Schema\Request\ListRootsRequest;
|
|||
use Mcp\Schema\Result\CreateSamplingMessageResult;
|
||||
use Mcp\Schema\Result\ElicitResult;
|
||||
use Mcp\Schema\Result\ListRootsResult;
|
||||
use Mcp\Schema\Tool;
|
||||
use Mcp\Schema\ToolChoice;
|
||||
use Mcp\Server\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -67,6 +69,8 @@ use Mcp\Server\Session\SessionInterface;
|
|||
* includeContext?: SamplingContext,
|
||||
* stopSequences?: string[],
|
||||
* metadata?: array<string, mixed>,
|
||||
* tools?: Tool[],
|
||||
* toolChoice?: ToolChoice,
|
||||
* }
|
||||
*
|
||||
* @author Kyrian Obikwelu <koshnawaza@gmail.com>
|
||||
|
|
@ -124,6 +128,9 @@ class ClientGateway
|
|||
* @param int $maxTokens Maximum tokens to generate
|
||||
* @param int $timeout The timeout in seconds
|
||||
* @param SampleOptions $options Additional sampling options (temperature, etc.)
|
||||
* Context values other than `none` require the client's
|
||||
* sampling.context capability; tools and toolChoice require
|
||||
* the client's sampling.tools capability.
|
||||
*
|
||||
* @return CreateSamplingMessageResult The sampling response
|
||||
*
|
||||
|
|
@ -152,6 +159,8 @@ class ClientGateway
|
|||
temperature: $options['temperature'] ?? null,
|
||||
stopSequences: $options['stopSequences'] ?? null,
|
||||
metadata: $options['metadata'] ?? null,
|
||||
tools: $options['tools'] ?? null,
|
||||
toolChoice: $options['toolChoice'] ?? null,
|
||||
);
|
||||
|
||||
$response = $this->request($request, $timeout);
|
||||
|
|
|
|||
Loading…
Reference in a new issue