| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 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: | |
| 24: | |
| 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: | |