1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 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\Schema\Result;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17:
18: /**
19: * A JSON object that represents the structured result of a tool call.
20: *
21: * @implements Arrayable<array<string, mixed>>
22: */
23: #[\AllowDynamicProperties]
24: final class StructuredContent implements \JsonSerializable, Arrayable
25: {
26: /**
27: * @param array<string, mixed> $data
28: */
29: public function __construct(array $data)
30: {
31: foreach ($data as $key => $value) {
32: $this->{$key} = $value; // @phpstan-ignore property.dynamicName
33: }
34: }
35:
36: #[\Override]
37: public function toArray(): array
38: {
39: return get_object_vars($this);
40: }
41:
42: /**
43: * @return template-type<self, Arrayable, 'T'>
44: */
45: #[\Override]
46: public function jsonSerialize(): array
47: {
48: return $this->toArray();
49: }
50: }
51: