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\Handler;
15:
16: use Amp\Cancellation;
17: use Nexus\Mcp\Core\Schema\Notification\ProgressNotification;
18: use Nexus\Mcp\Core\Schema\NotificationParams\ProgressNotificationParams;
19: use Nexus\Mcp\Core\Schema\ProgressToken;
20: use Nexus\Mcp\Core\Schema\RequestId;
21:
22: /**
23: * Context passed to a request handler, carrying the inbound request's metadata and out-of-band helpers.
24: */
25: abstract readonly class AbstractContext
26: {
27: public function __construct(
28: public RequestId $requestId,
29: public Cancellation $cancellation,
30: public ?ProgressToken $progressToken,
31: public SenderInterface $sender,
32: ) {
33: }
34:
35: public function reportProgress(float $progress, ?float $total = null, ?string $message = null): void
36: {
37: $token = $this->progressToken;
38:
39: if (null === $token) {
40: return;
41: }
42:
43: $this->sender->sendNotification(new ProgressNotification(
44: params: new ProgressNotificationParams(
45: progressToken: $token,
46: progress: $progress,
47: total: $total,
48: message: '' === $message ? null : $message,
49: ),
50: ));
51: }
52: }
53: