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\MetaObject;
18: use Nexus\Mcp\Core\Schema\Result;
19:
20: /**
21: * The response to a tasks/result request.
22: * The structure matches the result type of the original request.
23: * For example, a tools/call task would return the CallToolResult structure.
24: *
25: * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#gettaskpayloadresult
26: */
27: final readonly class GetTaskPayloadResult extends Result implements ClientResult, ServerResult
28: {
29: /**
30: * @param array<string, mixed> $payload
31: */
32: public function __construct(public array $payload = [], MetaObject $meta = new MetaObject())
33: {
34: parent::__construct($meta);
35: }
36:
37: /**
38: * @param array<string, mixed> $data
39: */
40: #[\Override]
41: public static function fromArray(array $data): static
42: {
43: $meta = new MetaObject();
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 = MetaObject::fromArray($data['_meta']);
51: }
52:
53: unset($data['_meta']);
54:
55: return new self($data, $meta);
56: }
57:
58: #[\Override]
59: public function toArray(): array
60: {
61: return [
62: ...parent::toArray(),
63: ...$this->payload,
64: ];
65: }
66: }
67: