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: /**
17: * The contents of a specific resource or sub-resource.
18: *
19: * @extends ResourceContents<array{
20: * _meta?: array<string, mixed>,
21: * blob: non-empty-string,
22: * uri: non-empty-string,
23: * mimeType?: non-empty-string,
24: * }>
25: */
26: final readonly class BlobResourceContents extends ResourceContents
27: {
28: /**
29: * @param non-empty-string $blob A base64-encoded string representing the binary data of the item.
30: */
31: public function __construct(
32: string $uri,
33: public string $blob,
34: ?string $mimeType = null,
35: ?array $meta = null,
36: ) {
37: if (base64_encode((string) base64_decode($blob, true)) !== $blob) {
38: throw new \InvalidArgumentException('Blob resource contents must have a valid base64-encoded blob.');
39: }
40:
41: parent::__construct($uri, $mimeType, $meta);
42: }
43:
44: #[\Override]
45: public function toArray(): array
46: {
47: return array_filter([
48: '_meta' => $this->meta,
49: 'uri' => $this->uri,
50: 'mimeType' => $this->mimeType,
51: 'blob' => $this->blob,
52: ], static fn(mixed $value): bool => null !== $value);
53: }
54: }
55: