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 associating messages with a task.
21: * Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
22: *
23: * @implements Arrayable<array{taskId: non-empty-string}>
24: *
25: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#relatedtaskmetadata
26: */
27: final readonly class RelatedTaskMetadata implements Arrayable
28: {
29: /**
30: * @var non-empty-string
31: */
32: public string $taskId;
33:
34: public function __construct(string $taskId)
35: {
36: Assert::that($taskId)->isNonEmptyString('related task metadata "taskId" must be a non-empty string.');
37:
38: $this->taskId = $taskId;
39: }
40:
41: /**
42: * @param array<string, mixed> $data
43: */
44: #[\Override]
45: public static function fromArray(array $data): static
46: {
47: Assert::that($data)->hasOffset('taskId', 'related task metadata missing the required "taskId" key.');
48: $taskId = $data['taskId'];
49: Assert::that($taskId)->isString('related task metadata "taskId" must be a string, {type} given.');
50:
51: return new self($taskId);
52: }
53:
54: #[\Override]
55: public function toArray(): array
56: {
57: return ['taskId' => $this->taskId];
58: }
59:
60: #[\Override]
61: public function jsonSerialize(): array
62: {
63: return $this->toArray();
64: }
65: }
66: