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\ResultResponse;
15:
16: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcResultResponse;
17: use Nexus\Mcp\Core\Schema\RequestId;
18: use Nexus\Mcp\Core\Schema\Result;
19: use Nexus\Mcp\Core\Schema\Result\SubscriptionsListenResult;
20:
21: /**
22: * A successful response from the server for a `subscriptions/listen` request,
23: * sent when the server tears the subscription down gracefully.
24: *
25: * @property-read SubscriptionsListenResult $result
26: *
27: * @extends JsonRpcResultResponse<array{
28: * jsonrpc: '2.0',
29: * id: int|non-empty-string,
30: * result: template-type<SubscriptionsListenResult, Result, 'T'>,
31: * }>
32: *
33: * @see https://modelcontextprotocol.io/specification/2026-07-28/schema#subscriptionslistenresultresponse
34: */
35: final readonly class SubscriptionsListenResultResponse extends JsonRpcResultResponse
36: {
37: public function __construct(RequestId $id, SubscriptionsListenResult $result)
38: {
39: parent::__construct(id: $id, result: $result);
40: }
41:
42: #[\Override]
43: public static function fromArray(array $data): static
44: {
45: $id = self::parseId($data);
46: $payload = self::parseResult($data);
47: self::rejectInputRequired($payload);
48:
49: return new self(id: $id, result: SubscriptionsListenResult::fromArray($payload));
50: }
51:
52: #[\Override]
53: public function toArray(): array
54: {
55: return [
56: 'jsonrpc' => self::JSONRPC_VERSION,
57: 'id' => $this->id->id,
58: 'result' => $this->result->toArray(),
59: ];
60: }
61: }
62: