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\Resource;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18: use Nexus\Mcp\Core\Schema\MetaObject;
19: use Nexus\Mcp\Core\Validation\Rfc3986UriValidator;
20:
21: /**
22: * The contents of a specific resource or sub-resource.
23: *
24: * @template T of array<string, mixed> = array<string, mixed>
25: *
26: * @implements Arrayable<T>
27: *
28: * @see https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/draft/schema.ts
29: */
30: abstract readonly class ResourceContents implements Arrayable
31: {
32: /**
33: * @var non-empty-string
34: */
35: public string $uri;
36:
37: /**
38: * @var null|non-empty-string
39: */
40: public ?string $mimeType;
41:
42: public function __construct(
43: string $uri,
44: ?string $mimeType = null,
45: public MetaObject $meta = new MetaObject(),
46: ) {
47: Rfc3986UriValidator::validate($uri, 'resource contents "uri"');
48: Assert::that($mimeType)->nullOr()->isNonEmptyString('resource contents "mimeType" must be a non-empty string or null.');
49:
50: $this->uri = $uri;
51: $this->mimeType = $mimeType;
52: }
53:
54: #[\Override]
55: public function jsonSerialize(): array
56: {
57: return $this->toArray();
58: }
59: }
60: