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\Schema\Notification;
15:
16: use Nexus\Mcp\Schema\Message\JsonRpcNotification;
17: use Nexus\Mcp\Schema\ProgressToken;
18:
19: /**
20: * An out-of-band notification used to inform the receiver of a progress update for a long-running request.
21: *
22: * @extends JsonRpcNotification<array{
23: * jsonrpc: '2.0',
24: * method: 'notifications/progress',
25: * params: array{
26: * _meta?: array<string, mixed>,
27: * progressToken: int|non-empty-string,
28: * progress: float,
29: * total?: float,
30: * message?: non-empty-string
31: * },
32: * }>
33: */
34: final readonly class ProgressNotification extends JsonRpcNotification implements ClientNotification, ServerNotification
35: {
36: /**
37: * @param ProgressToken $progressToken The progress token which was given in the initial request, used
38: * to associate this notification with the request that is proceeding.
39: * @param float $progress The progress thus far. This should increase every time progress
40: * is made, even if the total is unknown.
41: * @param null|float $total Total number of items to process (or total progress required), if known.
42: * @param null|non-empty-string $message An optional message describing the current progress.
43: * @param null|array<string, mixed> $meta Reserved by MCP to allow clients and servers to attach
44: * additional metadata to their interactions.
45: */
46: public function __construct(
47: ProgressToken $progressToken,
48: float $progress,
49: ?float $total = null,
50: ?string $message = null,
51: ?array $meta = null,
52: ) {
53: parent::__construct(self::JSON_RPC_VERSION, 'notifications/progress', array_filter([
54: '_meta' => $meta,
55: 'progressToken' => $progressToken->token,
56: 'progress' => $progress,
57: 'total' => $total,
58: 'message' => $message,
59: ], static fn(mixed $value): bool => null !== $value));
60: }
61: }
62: