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\Notification;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcNotification;
18: use Nexus\Mcp\Core\Schema\NotificationParams;
19: use Nexus\Mcp\Core\Schema\NotificationParams\ProgressNotificationParams;
20:
21: /**
22: * An out-of-band notification used to inform the receiver of a progress update for a long-running request.
23: *
24: * @property-read ProgressNotificationParams $params
25: *
26: * @extends JsonRpcNotification<'notifications/progress', array{
27: * jsonrpc: '2.0',
28: * method: 'notifications/progress',
29: * params: template-type<ProgressNotificationParams, NotificationParams, 'T'>,
30: * }>
31: *
32: * @see https://modelcontextprotocol.io/specification/draft/schema#progressnotification
33: */
34: final readonly class ProgressNotification extends JsonRpcNotification implements ServerNotification
35: {
36: public function __construct(ProgressNotificationParams $params)
37: {
38: parent::__construct(params: $params);
39: }
40:
41: #[\Override]
42: public static function getMethod(): string
43: {
44: return 'notifications/progress';
45: }
46:
47: #[\Override]
48: public static function fromArray(array $data): static
49: {
50: Assert::that($data)->hasOffset('params', 'missing the required "params" key.');
51: Assert::that($data['params'])
52: ->isArray('"params" must be an object, {type} given.')
53: ->isMap('"params" must be a string-keyed object.')
54: ;
55:
56: return new self(params: ProgressNotificationParams::fromArray($data['params']));
57: }
58:
59: #[\Override]
60: public function toArray(): array
61: {
62: return [
63: 'jsonrpc' => self::JSONRPC_VERSION,
64: 'method' => static::getMethod(),
65: 'params' => $this->params->toArray(),
66: ];
67: }
68: }
69: