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\Extension\Tasks\Schema\ResultResponse;
15:
16: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcResultResponse;
17: use Nexus\Mcp\Core\Schema\RequestId;
18: use Nexus\Mcp\Extension\Tasks\Schema\Result\GetTaskResult;
19:
20: /**
21: * Response envelope for `tasks/get`.
22: *
23: * @property-read GetTaskResult $result
24: *
25: * @extends JsonRpcResultResponse<array{
26: * jsonrpc: '2.0',
27: * id: int|non-empty-string,
28: * result: array<string, mixed>,
29: * }>
30: */
31: final readonly class GetTaskResultResponse extends JsonRpcResultResponse
32: {
33: public function __construct(RequestId $id, GetTaskResult $result)
34: {
35: parent::__construct(id: $id, result: $result);
36: }
37:
38: #[\Override]
39: public static function fromArray(array $data): static
40: {
41: $id = self::parseId($data);
42: $payload = self::parseResult($data);
43: self::rejectInputRequired($payload);
44:
45: return new self(id: $id, result: GetTaskResult::fromArray($payload));
46: }
47:
48: #[\Override]
49: public function toArray(): array
50: {
51: return [
52: 'jsonrpc' => self::JSONRPC_VERSION,
53: 'id' => $this->id->id,
54: 'result' => $this->result->toArray(),
55: ];
56: }
57: }
58: