CreateMessageRequest.php
2 months ago
CreateMessageRequestParams.php
2 months ago
CreateMessageResult.php
2 months ago
ModelHint.php
2 months ago
ModelPreferences.php
2 months ago
SamplingMessage.php
2 months ago
ToolChoice.php
2 months ago
ToolResultContent.php
2 months ago
ToolUseContent.php
2 months ago
ToolChoice.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Client\Sampling\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Common\AbstractDataTransferObject; |
| 8 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 9 | |
| 10 | /** |
| 11 | * Controls tool selection behavior for sampling requests. |
| 12 | * |
| 13 | * @since 2025-11-25 |
| 14 | * |
| 15 | * @mcp-domain Client |
| 16 | * @mcp-subdomain Sampling |
| 17 | * @mcp-version 2025-11-25 |
| 18 | */ |
| 19 | class ToolChoice extends AbstractDataTransferObject |
| 20 | { |
| 21 | use ValidatesRequiredFields; |
| 22 | |
| 23 | /** |
| 24 | * Controls the tool use ability of the model: |
| 25 | * - "auto": Model decides whether to use tools (default) |
| 26 | * - "required": Model MUST use at least one tool before completing |
| 27 | * - "none": Model MUST NOT use any tools |
| 28 | * |
| 29 | * @since 2025-11-25 |
| 30 | * |
| 31 | * @var 'auto'|'required'|'none'|null |
| 32 | */ |
| 33 | protected ?string $mode; |
| 34 | |
| 35 | /** |
| 36 | * @param 'auto'|'required'|'none'|null $mode @since 2025-11-25 |
| 37 | */ |
| 38 | public function __construct( |
| 39 | ?string $mode = null |
| 40 | ) { |
| 41 | $this->mode = $mode; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates an instance from an array. |
| 46 | * |
| 47 | * @param array{ |
| 48 | * mode?: 'auto'|'required'|'none'|null |
| 49 | * } $data |
| 50 | * @phpstan-param array<string, mixed> $data |
| 51 | * @return self |
| 52 | */ |
| 53 | public static function fromArray(array $data): self |
| 54 | { |
| 55 | /** @var 'auto'|'required'|'none'|null $mode */ |
| 56 | $mode = isset($data['mode']) |
| 57 | ? self::asStringOrNull($data['mode']) |
| 58 | : null; |
| 59 | |
| 60 | return new self( |
| 61 | $mode |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Converts the instance to an array. |
| 67 | * |
| 68 | * @return array<string, mixed> |
| 69 | */ |
| 70 | public function toArray(): array |
| 71 | { |
| 72 | $result = []; |
| 73 | |
| 74 | if ($this->mode !== null) { |
| 75 | $result['mode'] = $this->mode; |
| 76 | } |
| 77 | |
| 78 | return $result; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @return 'auto'|'required'|'none'|null |
| 83 | */ |
| 84 | public function getMode(): ?string |
| 85 | { |
| 86 | return $this->mode; |
| 87 | } |
| 88 | } |
| 89 |