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: use Nexus\Assert\Assert;
17:
18: /**
19: * Base interface for metadata with name (identifier) and title (display name) properties.
20: *
21: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2026-07-28/schema.ts
22: */
23: abstract readonly class BaseMetadata
24: {
25: /**
26: * @param non-empty-string $name
27: * @param null|non-empty-string $title
28: */
29: public function __construct(
30: public string $name,
31: public ?string $title = null,
32: ) {
33: $label = basename(strtr(static::class, '\\', '/'));
34:
35: Assert::that($name)->isNonEmptyString(\sprintf('%s name must be a non-empty string.', $label));
36: Assert::that($title)->nullOr()->isNonEmptyString(\sprintf('%s title must be a non-empty string or null.', $label));
37: }
38:
39: /**
40: * Resolves the spec-defined display name: `title` when set, otherwise the programmatic `name`.
41: *
42: * @return non-empty-string
43: */
44: public function getDisplayName(): string
45: {
46: return $this->title ?? $this->name;
47: }
48: }
49: