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\Result;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18: use Nexus\Mcp\Core\Schema\Enum\ResultType;
19: use Nexus\Mcp\Core\Schema\MetaObject;
20: use Nexus\Mcp\Core\Schema\Result;
21:
22: /**
23: * Common result fields.
24: *
25: * @extends Result<array{
26: * _meta?: template-type<MetaObject, Arrayable, 'T'>,
27: * resultType: non-empty-string,
28: * }>
29: *
30: * @see https://modelcontextprotocol.io/specification/draft/schema#emptyresult
31: */
32: final readonly class EmptyResult extends Result implements ClientResult, ServerResult
33: {
34: public function __construct(MetaObject $meta = new MetaObject())
35: {
36: parent::__construct(meta: $meta);
37: }
38:
39: #[\Override]
40: public static function fromArray(array $data): static
41: {
42: $meta = new MetaObject();
43:
44: if (\array_key_exists('_meta', $data)) {
45: Assert::that($data['_meta'])
46: ->isArray('"result._meta" must be an object, {type} given.')
47: ->isMap('"result._meta" must be a string-keyed object.')
48: ;
49: $meta = MetaObject::fromArray($data['_meta']);
50: }
51:
52: return new self(meta: $meta);
53: }
54:
55: #[\Override]
56: public function toArray(): array
57: {
58: $data = [];
59: $meta = $this->meta->toArray();
60:
61: if ([] !== $meta) {
62: $data['_meta'] = $meta;
63: }
64:
65: $data['resultType'] = self::getResultType();
66:
67: return $data;
68: }
69:
70: #[\Override]
71: protected function getResultType(): string
72: {
73: return ResultType::Complete->value;
74: }
75: }
76: