| 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\ProgressToken; |
| 20: | use Nexus\Mcp\Core\Schema\RequestId; |
| 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 ?ProgressToken $progressToken, |
| 32: | protected SenderInterface $sender, |
| 33: | ) { |
| 34: | } |
| 35: | |
| 36: | public function reportProgress(float $progress, ?float $total = null, ?string $message = null): void |
| 37: | { |
| 38: | $token = $this->progressToken; |
| 39: | |
| 40: | if (null === $token) { |
| 41: | return; |
| 42: | } |
| 43: | |
| 44: | $this->sender->sendNotification(new ProgressNotification( |
| 45: | params: new ProgressNotificationParams( |
| 46: | progressToken: $token, |
| 47: | progress: $progress, |
| 48: | total: $total, |
| 49: | message: '' === $message ? null : $message, |
| 50: | ), |
| 51: | )); |
| 52: | } |
| 53: | } |
| 54: | |