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;
15:
16: /**
17: * A progress token, used to associate progress notifications with the original request.
18: */
19: final readonly class ProgressToken implements \JsonSerializable, \Stringable
20: {
21: /**
22: * @var int|non-empty-string
23: */
24: public int|string $token;
25:
26: public function __construct(int|string $token)
27: {
28: if (\is_string($token) && trim($token) === '') {
29: throw new \InvalidArgumentException('Progress token must be a non-empty string or an integer.');
30: }
31:
32: $this->token = $token;
33: }
34:
35: #[\Override]
36: public function __toString(): string
37: {
38: return (string) $this->token;
39: }
40:
41: #[\Override]
42: public function jsonSerialize(): int|string
43: {
44: return $this->token;
45: }
46: }
47: