Skip to content

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.

View source

Public Methods ​

MethodDescription
__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() ​

View source

Arguments ​

  • $actor
  • $adapters
  • $customFieldSchema
  • $elements
  • $lifecycle
  • $elementQueryCriteria
  • $resourceLinks
  • $schemaValidator

create() ​

View source

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() ​

View source

Arguments ​

  • $type
  • $id
  • $uid
  • $siteId (integer, null) – Site ID to load the element in.
  • $hardDelete

Returns ​

array{deleted: true}

duplicate() ​

View source

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.

View source

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() ​

View source

Arguments ​

  • $type
  • $id
  • $uid
  • $siteId (integer, null) – Site ID to load the element in.
  • $fields (list<string>, null)

Returns ​

array{element: array<string,mixed>}

list() ​

View source

Arguments ​

  • $type
  • $criteria (array<string,mixed>)
  • $fields (list<string>, null)

restore() ​

View source

Arguments ​

  • $type
  • $id
  • $uid
  • $siteId (integer, null) – Site ID to load the element in. It does not limit restoration.

Returns ​

array{restored: bool}

schema() ​

View source

Arguments ​

  • $type

Returns ​

array<string,mixed>

typeResource() ​

View source

Arguments ​

  • $type

Returns ​

array<string,mixed>

typesResource() ​

View source

Returns ​

array{count: int, types: list<array{type: string, name: string, elementType: string, schema: string}>}

update() ​

View source

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() ​

View source

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 ​

ConstantDescription
AttributesSchema
ContextSchema
CriteriaSchema
FieldValuesSchema
TypeSchema