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