1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 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\Message\Notification;
15:
16: use Nexus\Mcp\Client\Message\Notification\ClientNotification;
17: use Nexus\Mcp\Message\Notification;
18: use Nexus\Mcp\ProgressToken;
19: use Nexus\Mcp\Server\Message\Notification\ServerNotification;
20:
21: /**
22: * An out-of-band notification used to inform the receiver of a progress update for a long-running request.
23: */
24: final readonly class ProgressNotification extends Notification implements ClientNotification, ServerNotification
25: {
26: /**
27: * @param non-empty-string $jsonrpc JSON-RPC version. Must be 2.0.
28: * @param ProgressToken $progressToken The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
29: * @param float $progress The progress thus far. This should increase every time progress is made, even if the total is unknown.
30: * @param null|float $total Total number of items to process (or total progress required), if known.
31: * @param null|non-empty-string $message An optional message describing the current progress.
32: */
33: public function __construct(
34: string $jsonrpc,
35: public ProgressToken $progressToken,
36: public float $progress,
37: public ?float $total = null,
38: public ?string $message = null,
39: ) {
40: parent::__construct($jsonrpc, 'notifications/progress', array_filter([
41: 'message' => $message,
42: 'progress' => $progress,
43: 'progressToken' => $progressToken->token,
44: 'total' => $total,
45: ], static fn(mixed $value): bool => null !== $value));
46: }
47: }
48: