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\RequestId;
20: use Nexus\Mcp\Core\Schema\RequestMetaObject;
21:
22: /**
23: * Context passed to a request handler. Carries metadata about the incoming
24: * request and exposes domain helpers for emitting out-of-band messages.
25: */
26: abstract readonly class AbstractContext
27: {
28: public function __construct(
29: public RequestId $requestId,
30: public Cancellation $cancellation,
31: public RequestMetaObject $meta,
32: public ?string $sessionId,
33: protected SenderInterface $sender,
34: ) {
35: }
36:
37: public function reportProgress(float $progress, ?float $total = null, ?string $message = null): void
38: {
39: $token = $this->meta->progressToken;
40:
41: if (null === $token) {
42: return;
43: }
44:
45: $this->sender->sendNotification(new ProgressNotification(
46: new ProgressNotificationParams($token, $progress, $total, $message),
47: ));
48: }
49: }
50: