commercebird
/
vendor
/
wordpress
/
php-mcp-schema
/
src
/
Server
/
Prompts
/
DTO
/
PromptArgument.php
GetPromptRequest.php
3 months ago
GetPromptRequestParams.php
3 months ago
GetPromptResult.php
3 months ago
ListPromptsRequest.php
3 months ago
ListPromptsResult.php
3 months ago
Prompt.php
3 months ago
PromptArgument.php
3 months ago
PromptListChangedNotification.php
3 months ago
PromptMessage.php
3 months ago
PromptArgument.php
118 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WP\McpSchema\Server\Prompts\DTO; |
| 6 | |
| 7 | use WP\McpSchema\Common\Protocol\DTO\BaseMetadata; |
| 8 | use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 9 | |
| 10 | /** |
| 11 | * Describes an argument that a prompt can accept. |
| 12 | * |
| 13 | * @since 2024-11-05 |
| 14 | * @last-updated 2025-06-18 (added properties: title) |
| 15 | * |
| 16 | * @mcp-domain Server |
| 17 | * @mcp-subdomain Prompts |
| 18 | * @mcp-version 2025-11-25 |
| 19 | */ |
| 20 | class PromptArgument extends BaseMetadata |
| 21 | { |
| 22 | use ValidatesRequiredFields; |
| 23 | |
| 24 | /** |
| 25 | * A human-readable description of the argument. |
| 26 | * |
| 27 | * @since 2024-11-05 |
| 28 | * |
| 29 | * @var string|null |
| 30 | */ |
| 31 | protected ?string $description; |
| 32 | |
| 33 | /** |
| 34 | * Whether this argument must be provided. |
| 35 | * |
| 36 | * @since 2024-11-05 |
| 37 | * |
| 38 | * @var bool|null |
| 39 | */ |
| 40 | protected ?bool $required; |
| 41 | |
| 42 | /** |
| 43 | * @param string $name @since 2024-11-05 |
| 44 | * @param string|null $title @since 2025-06-18 |
| 45 | * @param string|null $description @since 2024-11-05 |
| 46 | * @param bool|null $required @since 2024-11-05 |
| 47 | */ |
| 48 | public function __construct( |
| 49 | string $name, |
| 50 | ?string $title = null, |
| 51 | ?string $description = null, |
| 52 | ?bool $required = null |
| 53 | ) { |
| 54 | parent::__construct($name, $title); |
| 55 | $this->description = $description; |
| 56 | $this->required = $required; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates an instance from an array. |
| 61 | * |
| 62 | * @param array{ |
| 63 | * name: string, |
| 64 | * title?: string|null, |
| 65 | * description?: string|null, |
| 66 | * required?: bool|null |
| 67 | * } $data |
| 68 | * @phpstan-param array<string, mixed> $data |
| 69 | * @return self |
| 70 | */ |
| 71 | public static function fromArray(array $data): self |
| 72 | { |
| 73 | self::assertRequired($data, ['name']); |
| 74 | |
| 75 | return new self( |
| 76 | self::asString($data['name']), |
| 77 | self::asStringOrNull($data['title'] ?? null), |
| 78 | self::asStringOrNull($data['description'] ?? null), |
| 79 | self::asBoolOrNull($data['required'] ?? null) |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Converts the instance to an array. |
| 85 | * |
| 86 | * @return array<string, mixed> |
| 87 | */ |
| 88 | public function toArray(): array |
| 89 | { |
| 90 | $result = parent::toArray(); |
| 91 | |
| 92 | if ($this->description !== null) { |
| 93 | $result['description'] = $this->description; |
| 94 | } |
| 95 | if ($this->required !== null) { |
| 96 | $result['required'] = $this->required; |
| 97 | } |
| 98 | |
| 99 | return $result; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return string|null |
| 104 | */ |
| 105 | public function getDescription(): ?string |
| 106 | { |
| 107 | return $this->description; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @return bool|null |
| 112 | */ |
| 113 | public function getRequired(): ?bool |
| 114 | { |
| 115 | return $this->required; |
| 116 | } |
| 117 | } |
| 118 |