Elements ​
- Type
- Class
- Namespace
- craft\mcp\capabilities
- Inherits
- craft\mcp\capabilities\Elements
- Since
- 5.12.0
Lists, reads, and manages elements of every type registered with {@see ElementAdapterRegistry}.
Tool input schemas stay compact. Each element type's full criteria and attribute schemas are served by elements.schema and the craft://element-types/{type} resource, and inputs are validated against them.
Public Methods ​
| Method | Description |
|---|---|
| __construct() | |
| create() | |
| delete() | |
| duplicate() | |
| fieldSchema() | Returns the writable custom-field schema for an existing element, or for a new element described by the context. |
| get() | |
| list() | |
| restore() | |
| schema() | |
| typeResource() | |
| typesResource() | |
| update() | |
| validate() |
__construct() ​
Arguments ​
$actor$adapters$customFieldSchema$elements$lifecycle$elementQueryCriteria$resourceLinks$schemaValidator
create() ​
Arguments ​
$type$attributes(array<string,mixed>)$fields(array<string,mixed>)$asUnpublishedDraft(boolean) – Whether to save the new element as an unpublished draft instead of live content. Supported for entries.$draftName(string, null) – Name of the unpublished draft. Requires asUnpublishedDraft.$draftNotes(string, null) – Notes for the unpublished draft. Requires asUnpublishedDraft.
Returns ​
array<string,mixed>
delete() ​
Arguments ​
Returns ​
array{deleted: true}
duplicate() ​
Arguments ​
$type$id$uid$siteId(integer, null) – Site ID to load the element in.$mode(string, null) – Duplication mode. Call elements.schema for the modes the type supports.
Returns ​
array{element: array<string,mixed>}
fieldSchema() ​
Returns the writable custom-field schema for an existing element, or for a new element described by the context.
Arguments ​
$type$id(integer, null) – Existing element ID.$uid(string, null) – Existing element UID.$siteId(integer, null) – Site ID to load an existing element in.$context(array<string,mixed>)
Returns ​
array{schema: array<string,mixed>}
get() ​
Arguments ​
Returns ​
array{element: array<string,mixed>}
list() ​
Arguments ​
$type$criteria(array<string,mixed>)$fields(list<string>, null)
restore() ​
Arguments ​
$type$id$uid$siteId(integer, null) – Site ID to load the element in. It does not limit restoration.
Returns ​
array{restored: bool}
schema() ​
Arguments ​
$type
Returns ​
array<string,mixed>
typeResource() ​
Arguments ​
$type
Returns ​
array<string,mixed>
typesResource() ​
Returns ​
array{count: int, types: list<array{type: string, name: string, elementType: string, schema: string}>}
update() ​
Arguments ​
$type$id$uid$siteId(integer, null) – Site ID to load the element in.$attributes(array<string,mixed>)$fields(array<string,mixed>)
Returns ​
array<string,mixed>
validate() ​
Arguments ​
$type$id$uid$siteId(integer, null) – Site ID to load the element in.$attributes(array<string,mixed>)$fields(array<string,mixed>)
Returns ​
array{valid: bool, scenario: string, errors: array<string,list<string>>}
Constants ​
| Constant | Description |
|---|---|
AttributesSchema | |
ContextSchema | |
CriteriaSchema | |
FieldValuesSchema | |
TypeSchema |