1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Core\Schema\Task;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18:
19: /**
20: * Metadata for augmenting a request with task execution.
21: *
22: * Include this in the `task` field of the request parameters.
23: *
24: * @implements Arrayable<array{ttl?: int}>
25: *
26: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#taskmetadata
27: */
28: final readonly class TaskMetadata implements Arrayable
29: {
30: public function __construct(public ?int $ttl = null)
31: {
32: }
33:
34: /**
35: * @param array<string, mixed> $data
36: */
37: #[\Override]
38: public static function fromArray(array $data): static
39: {
40: $ttl = $data['ttl'] ?? null;
41: Assert::that($ttl)->nullOr()->isInt('task metadata "ttl" must be an int or null, {type} given.');
42:
43: return new self($ttl);
44: }
45:
46: #[\Override]
47: public function toArray(): array
48: {
49: if (null === $this->ttl) {
50: return [];
51: }
52:
53: return ['ttl' => $this->ttl];
54: }
55:
56: #[\Override]
57: public function jsonSerialize(): array|\stdClass
58: {
59: $data = $this->toArray();
60:
61: return [] === $data ? new \stdClass() : $data;
62: }
63: }
64: