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;
15:
16: /**
17: * Represents the contents of a `_meta` field, which clients and servers use to attach additional metadata to their
18: * interactions.
19: *
20: * Certain key names are reserved by MCP for protocol-level metadata; implementations MUST NOT make assumptions about
21: * values at these keys. Additionally, specific schema definitions may reserve particular names for purpose-specific
22: * metadata, as declared in those definitions.
23: *
24: * Valid keys have two segments:
25: *
26: * **Prefix:**
27: * - Optional — if specified, MUST be a series of _labels_ separated by dots (`.`), followed by a slash (`/`).
28: * - Labels MUST start with a letter and end with a letter or digit. Interior characters may be letters, digits, or
29: * hyphens (`-`).
30: * - Implementations SHOULD use reverse DNS notation (e.g., `com.example/` rather than `example.com/`).
31: * - Any prefix where the second label is `modelcontextprotocol` or `mcp` is **reserved** for MCP use. For example:
32: * `io.modelcontextprotocol/`, `dev.mcp/`, `org.modelcontextprotocol.api/`, and `com.mcp.tools/` are all reserved.
33: * However, `com.example.mcp/` is NOT reserved, as the second label is `example`.
34: *
35: * **Name:**
36: * - Unless empty, MUST start and end with an alphanumeric character (`[a-z0-9A-Z]`).
37: * - Interior characters may be alphanumeric, hyphens (`-`), underscores (`_`), or dots (`.`).
38: *
39: * @implements Arrayable<array<string, mixed>>
40: *
41: * @see https://modelcontextprotocol.io/specification/draft/schema#metaobject
42: */
43: final readonly class MetaObject implements Arrayable
44: {
45: /**
46: * @param array<string, mixed> $extras
47: */
48: public function __construct(public array $extras = [])
49: {
50: }
51:
52: #[\Override]
53: public static function fromArray(array $data): static
54: {
55: return new self(extras: $data);
56: }
57:
58: #[\Override]
59: public function toArray(): array
60: {
61: return $this->extras;
62: }
63:
64: #[\Override]
65: public function jsonSerialize(): array|\stdClass
66: {
67: return [] === $this->extras ? new \stdClass() : $this->extras;
68: }
69: }
70: