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\Result;
15:
16: use Nexus\Mcp\Schema\Content\BlobResourceContents;
17: use Nexus\Mcp\Schema\Content\ResourceContents;
18: use Nexus\Mcp\Schema\Content\TextResourceContents;
19:
20: /**
21: * The server's response to a `resources/read` request from the client.
22: *
23: * @extends Result<array{
24: * _meta?: array<string, mixed>,
25: * contents: list<template-type<BlobResourceContents|TextResourceContents, ResourceContents, 'T'>>,
26: * }>
27: */
28: final readonly class ReadResourceResult extends Result implements ServerResult
29: {
30: /**
31: * @param list<BlobResourceContents|TextResourceContents> $contents
32: */
33: public function __construct(
34: public array $contents,
35: ?array $meta = null,
36: ) {
37: parent::__construct($meta);
38: }
39:
40: #[\Override]
41: public function toArray(): array
42: {
43: return array_filter([
44: '_meta' => $this->meta,
45: 'contents' => array_map(static fn($item) => $item->toArray(), $this->contents),
46: ], static fn(mixed $value): bool => null !== $value);
47: }
48: }
49: