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/2025-11-25/schema.ts
22: */
23: abstract readonly class BaseMetadata
24: {
25: /**
26: * @var non-empty-string
27: */
28: public string $name;
29:
30: /**
31: * @var null|non-empty-string
32: */
33: public ?string $title;
34:
35: public function __construct(string $name, ?string $title = null)
36: {
37: $label = basename(strtr(static::class, '\\', '/'));
38:
39: Assert::that($name)->isNonEmptyString(\sprintf('%s name must be a non-empty string.', $label));
40: Assert::that($title)->nullOr()->isNonEmptyString(\sprintf('%s title must be a non-empty string or null.', $label));
41:
42: $this->name = $name;
43: $this->title = $title;
44: }
45:
46: /**
47: * Resolves the spec-defined display name: `title` when set, otherwise the
48: * programmatic `name`. Subclasses override to insert additional fallbacks.
49: *
50: * @return non-empty-string
51: */
52: public function getDisplayName(): string
53: {
54: return $this->title ?? $this->name;
55: }
56: }
57: