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\Content;
15:
16: use Nexus\Mcp\Schema\Arrayable;
17: use Nexus\Mcp\Schema\Resource\ResourceValidator;
18:
19: /**
20: * The contents of a specific resource or sub-resource.
21: *
22: * @template T of array{
23: * _meta?: array<string, mixed>,
24: * uri: non-empty-string,
25: * mimeType?: non-empty-string,
26: * }
27: *
28: * @implements Arrayable<T>
29: */
30: abstract readonly class ResourceContents implements \JsonSerializable, Arrayable
31: {
32: /**
33: * @param non-empty-string $uri The URI of this resource.
34: * @param null|non-empty-string $mimeType The MIME type of this resource, if known.
35: * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach
36: * additional metadata to their interactions.
37: */
38: public function __construct(
39: public string $uri,
40: public ?string $mimeType = null,
41: public ?array $meta = null,
42: ) {
43: ResourceValidator::assertValidUri($this->uri);
44: }
45:
46: /**
47: * @return T
48: */
49: #[\Override]
50: public function jsonSerialize(): mixed
51: {
52: return $this->toArray();
53: }
54: }
55: