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\Extension\Apps\Server;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Annotations;
18: use Nexus\Mcp\Core\Schema\Icon;
19: use Nexus\Mcp\Core\Schema\MetaObject\PayloadMetaObject;
20: use Nexus\Mcp\Core\Schema\Resource\Resource;
21: use Nexus\Mcp\Extension\Apps\Apps;
22: use Nexus\Mcp\Extension\Apps\Schema\UiResourceMeta;
23:
24: /**
25: * A `Resource` bound to the `ui://` scheme and the `text/html;profile=mcp-app` mime type.
26: */
27: final readonly class UiResource
28: {
29: public Resource $resource;
30:
31: /**
32: * @param non-empty-string $name
33: * @param non-empty-string $uri
34: * @param null|non-empty-string $title
35: * @param null|non-empty-string $description
36: * @param null|list<Icon> $icons
37: */
38: public function __construct(
39: string $name,
40: string $uri,
41: ?string $title = null,
42: ?string $description = null,
43: public ?UiResourceMeta $uiMeta = null,
44: Annotations $annotations = new Annotations(),
45: ?int $size = null,
46: ?array $icons = null,
47: ) {
48: Assert::that($uri)->startsWith(Apps::URI_PREFIX, \sprintf('UI resource "uri" must start with "%s".', Apps::URI_PREFIX));
49:
50: $extras = [];
51:
52: if (null !== $uiMeta) {
53: $uiMetaData = $uiMeta->toArray();
54:
55: if ([] !== $uiMetaData) {
56: $extras[Apps::META_KEY] = $uiMetaData;
57: }
58: }
59:
60: $this->resource = new Resource(
61: name: $name,
62: uri: $uri,
63: title: $title,
64: description: $description,
65: mimeType: Apps::MIME_TYPE,
66: annotations: $annotations,
67: size: $size,
68: icons: $icons,
69: meta: new PayloadMetaObject(extras: $extras),
70: );
71: }
72: }
73: