| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace WP\McpSchema\Client\Elicitation\DTO; |
| 6 |
|
| 7 |
use WP\McpSchema\Client\Elicitation\Union\ElicitRequestParamsInterface; |
| 8 |
use WP\McpSchema\Client\Tasks\DTO\TaskMetadata; |
| 9 |
use WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta; |
| 10 |
use WP\McpSchema\Common\Tasks\DTO\TaskAugmentedRequestParams; |
| 11 |
use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 12 |
|
| 13 |
/** |
| 14 |
* The parameters for a request to elicit information from the user via a URL in the client. |
| 15 |
* |
| 16 |
* @since 2025-11-25 |
| 17 |
* |
| 18 |
* @mcp-domain Client |
| 19 |
* @mcp-subdomain Elicitation |
| 20 |
* @mcp-version 2025-11-25 |
| 21 |
*/ |
| 22 |
class ElicitRequestURLParams extends TaskAugmentedRequestParams implements ElicitRequestParamsInterface |
| 23 |
{ |
| 24 |
use ValidatesRequiredFields; |
| 25 |
|
| 26 |
public const MODE = 'url'; |
| 27 |
|
| 28 |
public const DISCRIMINATOR_FIELD = 'mode'; |
| 29 |
public const DISCRIMINATOR_VALUE = 'url'; |
| 30 |
|
| 31 |
/** |
| 32 |
* The elicitation mode. |
| 33 |
* |
| 34 |
* @since 2025-11-25 |
| 35 |
* |
| 36 |
* @var 'url' |
| 37 |
*/ |
| 38 |
protected string $mode; |
| 39 |
|
| 40 |
/** |
| 41 |
* The message to present to the user explaining why the interaction is needed. |
| 42 |
* |
| 43 |
* @since 2025-11-25 |
| 44 |
* |
| 45 |
* @var string |
| 46 |
*/ |
| 47 |
protected string $message; |
| 48 |
|
| 49 |
/** |
| 50 |
* The ID of the elicitation, which must be unique within the context of the server. |
| 51 |
* The client MUST treat this ID as an opaque value. |
| 52 |
* |
| 53 |
* @since 2025-11-25 |
| 54 |
* |
| 55 |
* @var string |
| 56 |
*/ |
| 57 |
protected string $elicitationId; |
| 58 |
|
| 59 |
/** |
| 60 |
* The URL that the user should navigate to. |
| 61 |
* |
| 62 |
* @since 2025-11-25 |
| 63 |
* |
| 64 |
* @var string |
| 65 |
*/ |
| 66 |
protected string $url; |
| 67 |
|
| 68 |
/** |
| 69 |
* @param string $message @since 2025-11-25 |
| 70 |
* @param string $elicitationId @since 2025-11-25 |
| 71 |
* @param string $url @since 2025-11-25 |
| 72 |
* @param \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task @since 2025-11-25 |
| 73 |
* @param \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta @since 2025-11-25 |
| 74 |
*/ |
| 75 |
public function __construct( |
| 76 |
string $message, |
| 77 |
string $elicitationId, |
| 78 |
string $url, |
| 79 |
?TaskMetadata $task = null, |
| 80 |
?RequestParamsMeta $_meta = null |
| 81 |
) { |
| 82 |
parent::__construct($_meta, $task); |
| 83 |
$this->mode = self::MODE; |
| 84 |
$this->message = $message; |
| 85 |
$this->elicitationId = $elicitationId; |
| 86 |
$this->url = $url; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Creates an instance from an array. |
| 91 |
* |
| 92 |
* @param array{ |
| 93 |
* task?: array<string, mixed>|\WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null, |
| 94 |
* _meta?: array<string, mixed>|\WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null, |
| 95 |
* mode: 'url', |
| 96 |
* message: string, |
| 97 |
* elicitationId: string, |
| 98 |
* url: string |
| 99 |
* } $data |
| 100 |
* @phpstan-param array<string, mixed> $data |
| 101 |
* @return self |
| 102 |
*/ |
| 103 |
public static function fromArray(array $data): self |
| 104 |
{ |
| 105 |
self::assertRequired($data, ['message', 'elicitationId', 'url']); |
| 106 |
|
| 107 |
/** @var \WP\McpSchema\Client\Tasks\DTO\TaskMetadata|null $task */ |
| 108 |
$task = isset($data['task']) |
| 109 |
? (is_array($data['task']) |
| 110 |
? TaskMetadata::fromArray(self::asArray($data['task'])) |
| 111 |
: $data['task']) |
| 112 |
: null; |
| 113 |
|
| 114 |
/** @var \WP\McpSchema\Common\JsonRpc\DTO\RequestParamsMeta|null $_meta */ |
| 115 |
$_meta = isset($data['_meta']) |
| 116 |
? (is_array($data['_meta']) |
| 117 |
? RequestParamsMeta::fromArray(self::asArray($data['_meta'])) |
| 118 |
: $data['_meta']) |
| 119 |
: null; |
| 120 |
|
| 121 |
return new self( |
| 122 |
self::asString($data['message']), |
| 123 |
self::asString($data['elicitationId']), |
| 124 |
self::asString($data['url']), |
| 125 |
$task, |
| 126 |
$_meta |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Converts the instance to an array. |
| 132 |
* |
| 133 |
* @return array<string, mixed> |
| 134 |
*/ |
| 135 |
public function toArray(): array |
| 136 |
{ |
| 137 |
$result = parent::toArray(); |
| 138 |
|
| 139 |
$result['mode'] = $this->mode; |
| 140 |
$result['message'] = $this->message; |
| 141 |
$result['elicitationId'] = $this->elicitationId; |
| 142 |
$result['url'] = $this->url; |
| 143 |
|
| 144 |
return $result; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* @return 'url' |
| 149 |
*/ |
| 150 |
public function getMode(): string |
| 151 |
{ |
| 152 |
return $this->mode; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* @return string |
| 157 |
*/ |
| 158 |
public function getMessage(): string |
| 159 |
{ |
| 160 |
return $this->message; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* @return string |
| 165 |
*/ |
| 166 |
public function getElicitationId(): string |
| 167 |
{ |
| 168 |
return $this->elicitationId; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* @return string |
| 173 |
*/ |
| 174 |
public function getUrl(): string |
| 175 |
{ |
| 176 |
return $this->url; |
| 177 |
} |
| 178 |
} |
| 179 |
|