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/2026-07-28/schema#elicitrequesturlparams
26: */
27: final readonly class ElicitRequestUrlParams implements Arrayable, ElicitRequestParams
28: {
29: public const string MODE = 'url';
30:
31: /**
32: * @param non-empty-string $message
33: * @param 'url' $mode
34: * @param non-empty-string $url
35: */
36: public function __construct(
37: public string $message,
38: public string $mode,
39: public string $url,
40: ) {
41: Assert::that($message)->isNonEmptyString('"params.message" must be a non-empty string.');
42: Assert::that($url)->isNonEmptyString('"params.url" must be a non-empty string.')->isUrl('"params.url" must be a valid URL.');
43: Assert::that($mode)->isIdentical(self::MODE, '"params.mode" must be {other}, {value} given.');
44: }
45:
46: #[\Override]
47: public static function fromArray(array $data): static
48: {
49: Assert::that($data)->hasOffset('message', '"params" is missing the required "message" key.');
50: $message = $data['message'];
51: Assert::that($message)->isNonEmptyString('"params.message" must be a non-empty string, {type} given.');
52:
53: Assert::that($data)->hasOffset('mode', '"params" is missing the required "mode" key.');
54: $mode = $data['mode'];
55: Assert::that($mode)->isIdentical(self::MODE, '"params.mode" must be {other}, {value} given.');
56:
57: Assert::that($data)->hasOffset('url', '"params" is missing the required "url" key.');
58: $url = $data['url'];
59: Assert::that($url)->isNonEmptyString('"params.url" must be a non-empty string, {type} given.');
60:
61: return new self(message: $message, mode: $mode, url: $url);
62: }
63:
64: #[\Override]
65: public function toArray(): array
66: {
67: return [
68: 'message' => $this->message,
69: 'mode' => $this->mode,
70: 'url' => $this->url,
71: ];
72: }
73:
74: #[\Override]
75: public function jsonSerialize(): array
76: {
77: return $this->toArray();
78: }
79: }
80: