Repository navigation
Expand file tree
/
Copy pathToolChoice.php
More file actions
57 lines (48 loc) · 1.48 KB
/
Copy pathToolChoice.php
File metadata and controls
57 lines (48 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Schema;
use Mcp\Schema\Enum\ToolChoiceMode;
use Mcp\Schema\Exception\InvalidArgumentException;
/**
* Controls how the model uses tools during sampling.
*
* @deprecated since protocol revision 2026-07-28 (SEP-2577), earliest removal 2027-07-28.
* Integrate with an LLM provider's API directly instead.
*/
final class ToolChoice implements \JsonSerializable
{
public function __construct(
public readonly ToolChoiceMode $mode = ToolChoiceMode::Auto,
) {
}
/**
* @param array{mode?: string}|array<mixed> $data
*/
public static function fromArray(array $data): self
{
if (!\array_key_exists('mode', $data)) {
return new self(ToolChoiceMode::Auto);
}
if (!\is_string($data['mode'])) {
throw new InvalidArgumentException('Invalid "mode" in ToolChoice data.');
}
if (null === $mode = ToolChoiceMode::tryFrom($data['mode'])) {
throw new InvalidArgumentException(\sprintf('Invalid tool choice mode "%s".', $data['mode']));
}
return new self($mode);
}
/**
* @return array{mode: string}
*/
public function jsonSerialize(): array
{
return ['mode' => $this->mode->value];
}
}