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