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\Schema\RequestParams;
15:
16: use Nexus\Assert\Assert;
17: use Nexus\Mcp\Core\Schema\Arrayable;
18:
19: /**
20: * The parameters for a request to elicit information from the user via a URL in the client.
21: *
22: * @implements Arrayable<array{message: non-empty-string, mode: 'url', url: non-empty-string}>
23: * @implements ElicitRequestParams<array{message: non-empty-string, mode: 'url', url: non-empty-string}>
24: *
25: * @see https://modelcontextprotocol.io/specification/draft/schema#elicitrequesturlparams
26: */
27: final readonly class ElicitRequestUrlParams implements Arrayable, ElicitRequestParams
28: {
29: public const string MODE = 'url';
30:
31: /**
32: * @var non-empty-string
33: */
34: public string $message;
35:
36: /**
37: * @var 'url'
38: */
39: public string $mode;
40:
41: /**
42: * @var non-empty-string
43: */
44: public string $url;
45:
46: public function __construct(
47: string $message,
48: string $mode,
49: string $url,
50: ) {
51: Assert::that($message)->isNonEmptyString('"params.message" must be a non-empty string.');
52: Assert::that($url)->isNonEmptyString('"params.url" must be a non-empty string.')->isUrl('"params.url" must be a valid URL.');
53: Assert::that($mode)->isIdentical(self::MODE, '"params.mode" must be {other}, {value} given.');
54:
55: $this->message = $message;
56: $this->url = $url;
57: $this->mode = $mode;
58: }
59:
60: #[\Override]
61: public static function fromArray(array $data): static
62: {
63: Assert::that($data)->hasOffset('message', '"params" is missing the required "message" key.');
64: $message = $data['message'];
65: Assert::that($message)->isString('"params.message" must be a string, {type} given.');
66:
67: Assert::that($data)->hasOffset('mode', '"params" is missing the required "mode" key.');
68: $mode = $data['mode'];
69: Assert::that($mode)->isString('"params.mode" must be a string, {type} given.');
70:
71: Assert::that($data)->hasOffset('url', '"params" is missing the required "url" key.');
72: $url = $data['url'];
73: Assert::that($url)->isString('"params.url" must be a string, {type} given.');
74:
75: return new self(message: $message, mode: $mode, url: $url);
76: }
77:
78: #[\Override]
79: public function toArray(): array
80: {
81: return [
82: 'message' => $this->message,
83: 'mode' => $this->mode,
84: 'url' => $this->url,
85: ];
86: }
87:
88: #[\Override]
89: public function jsonSerialize(): array
90: {
91: return $this->toArray();
92: }
93: }
94: