Repository navigation
Expand file tree
/
Copy pathToolExecution.php
More file actions
61 lines (53 loc) · 1.66 KB
/
Copy pathToolExecution.php
File metadata and controls
61 lines (53 loc) · 1.66 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
58
59
60
61
<?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\TaskSupport;
use Mcp\Schema\Exception\InvalidArgumentException;
/**
* Execution-related properties of a Tool.
*
* @phpstan-type ToolExecutionData array{
* taskSupport?: 'forbidden'|'optional'|'required',
* }
*/
class ToolExecution implements \JsonSerializable
{
/**
* @param ?TaskSupport $taskSupport whether the tool can be called as a task; absent means {@see TaskSupport::Forbidden}
*/
public function __construct(
public readonly ?TaskSupport $taskSupport = null,
) {
}
/**
* @param ToolExecutionData $data
*/
public static function fromArray(array $data): self
{
$taskSupport = null;
if (isset($data['taskSupport'])) {
$taskSupport = \is_string($data['taskSupport']) ? TaskSupport::tryFrom($data['taskSupport']) : null;
if (null === $taskSupport) {
throw new InvalidArgumentException('Invalid "taskSupport" in ToolExecution data; expected "forbidden", "optional" or "required".');
}
}
return new self($taskSupport);
}
/**
* @return ToolExecutionData|\stdClass an empty execution encodes as `{}`, not `[]`
*/
public function jsonSerialize(): array|\stdClass
{
if (null === $this->taskSupport) {
return new \stdClass();
}
return ['taskSupport' => $this->taskSupport->value];
}
}