| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace WP\McpSchema\Common\Protocol\DTO; |
| 6 |
|
| 7 |
use WP\McpSchema\Common\AbstractDataTransferObject; |
| 8 |
use WP\McpSchema\Common\Traits\ValidatesRequiredFields; |
| 9 |
|
| 10 |
/** |
| 11 |
* Optional annotations for the client. The client can use annotations to inform how objects are used or displayed |
| 12 |
* |
| 13 |
* @since 2025-03-26 |
| 14 |
* @last-updated 2025-11-25 (modified property: audience) |
| 15 |
* |
| 16 |
* @mcp-domain Common |
| 17 |
* @mcp-subdomain Protocol |
| 18 |
* @mcp-version 2025-11-25 |
| 19 |
*/ |
| 20 |
class Annotations extends AbstractDataTransferObject |
| 21 |
{ |
| 22 |
use ValidatesRequiredFields; |
| 23 |
|
| 24 |
/** |
| 25 |
* Describes who the intended audience of this object or data is. |
| 26 |
* |
| 27 |
* It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`). |
| 28 |
* |
| 29 |
* @since 2025-03-26 |
| 30 |
* |
| 31 |
* @var array<'user'|'assistant'>|null |
| 32 |
*/ |
| 33 |
protected ?array $audience; |
| 34 |
|
| 35 |
/** |
| 36 |
* Describes how important this data is for operating the server. |
| 37 |
* |
| 38 |
* A value of 1 means "most important," and indicates that the data is |
| 39 |
* effectively required, while 0 means "least important," and indicates that |
| 40 |
* the data is entirely optional. |
| 41 |
* |
| 42 |
* @since 2025-03-26 |
| 43 |
* |
| 44 |
* @var float|null |
| 45 |
*/ |
| 46 |
protected ?float $priority; |
| 47 |
|
| 48 |
/** |
| 49 |
* The moment the resource was last modified, as an ISO 8601 formatted string. |
| 50 |
* |
| 51 |
* Should be an ISO 8601 formatted string (e.g., "2025-01-12T15:00:58Z"). |
| 52 |
* |
| 53 |
* Examples: last activity timestamp in an open file, timestamp when the resource |
| 54 |
* was attached, etc. |
| 55 |
* |
| 56 |
* @since 2025-06-18 |
| 57 |
* |
| 58 |
* @var string|null |
| 59 |
*/ |
| 60 |
protected ?string $lastModified; |
| 61 |
|
| 62 |
/** |
| 63 |
* @param array<'user'|'assistant'>|null $audience @since 2025-03-26 |
| 64 |
* @param float|null $priority @since 2025-03-26 |
| 65 |
* @param string|null $lastModified @since 2025-06-18 |
| 66 |
*/ |
| 67 |
public function __construct( |
| 68 |
?array $audience = null, |
| 69 |
?float $priority = null, |
| 70 |
?string $lastModified = null |
| 71 |
) { |
| 72 |
$this->audience = $audience; |
| 73 |
$this->priority = $priority; |
| 74 |
$this->lastModified = $lastModified; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Creates an instance from an array. |
| 79 |
* |
| 80 |
* @param array{ |
| 81 |
* audience?: array<'user'|'assistant'>|null, |
| 82 |
* priority?: float|null, |
| 83 |
* lastModified?: string|null |
| 84 |
* } $data |
| 85 |
* @phpstan-param array<string, mixed> $data |
| 86 |
* @return self |
| 87 |
*/ |
| 88 |
public static function fromArray(array $data): self |
| 89 |
{ |
| 90 |
/** @var array<'user'|'assistant'>|null $audience */ |
| 91 |
$audience = isset($data['audience']) |
| 92 |
? self::asStringArrayOrNull($data['audience']) |
| 93 |
: null; |
| 94 |
|
| 95 |
return new self( |
| 96 |
$audience, |
| 97 |
self::asFloatOrNull($data['priority'] ?? null), |
| 98 |
self::asStringOrNull($data['lastModified'] ?? null) |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Converts the instance to an array. |
| 104 |
* |
| 105 |
* @return array<string, mixed> |
| 106 |
*/ |
| 107 |
public function toArray(): array |
| 108 |
{ |
| 109 |
$result = []; |
| 110 |
|
| 111 |
if ($this->audience !== null) { |
| 112 |
$result['audience'] = $this->audience; |
| 113 |
} |
| 114 |
if ($this->priority !== null) { |
| 115 |
$result['priority'] = $this->priority; |
| 116 |
} |
| 117 |
if ($this->lastModified !== null) { |
| 118 |
$result['lastModified'] = $this->lastModified; |
| 119 |
} |
| 120 |
|
| 121 |
return $result; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* @return array<'user'|'assistant'>|null |
| 126 |
*/ |
| 127 |
public function getAudience(): ?array |
| 128 |
{ |
| 129 |
return $this->audience; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* @return float|null |
| 134 |
*/ |
| 135 |
public function getPriority(): ?float |
| 136 |
{ |
| 137 |
return $this->priority; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* @return string|null |
| 142 |
*/ |
| 143 |
public function getLastModified(): ?string |
| 144 |
{ |
| 145 |
return $this->lastModified; |
| 146 |
} |
| 147 |
} |
| 148 |
|