Skip to content

ElementAdapter ​

Type
Interface
Namespace
craft\mcp\elements
Implemented by
craft\mcp\elements\BaseElementAdapter, craft\mcp\elements\adapters\AddressAdapter, craft\mcp\elements\adapters\AssetAdapter, craft\mcp\elements\adapters\EntryAdapter, craft\mcp\elements\adapters\UserAdapter
Since
5.12.0

Exposes an element type through the elements_* MCP tools.

Register adapters with {@see \craft\mcp\elements\ElementAdapterRegistry}. Extending {@see \craft\mcp\elements\BaseElementAdapter} is recommended.

View source

Public Methods ​

MethodDescription
canDelete()
canView()
create()
createUnpublishedDraft()Creates an element as an unpublished draft, for elements_create with asUnpublishedDraft.
duplicate()
elementType()
fieldSchemaElement()Returns the element whose custom-field schema elements_field_schema describes.
find()
handle()Returns the type value MCP clients pass to select this element type, such as entries.
listQuery()Returns the base query for elements_list.
prepareValidation()Applies proposed changes in memory before elements_validate validates the element.
schema()Describes the criteria, attributes, and field-schema context the elements_* tools accept for this type.
serialize()
update()

canDelete() ​

View source

Arguments ​

  • $actor
  • $element

canView() ​

View source

Arguments ​

  • $actor
  • $element

create() ​

View source

Arguments ​

  • $attributes (array<string,mixed>) – Values matching the createAttributes schema.
  • $fields (array<string,mixed>) – Custom field values keyed by field handle.
  • $actor

Returns ​

array{element: array<string,mixed>}, array<string,mixed>

createUnpublishedDraft() ​

Creates an element as an unpublished draft, for elements_create with asUnpublishedDraft.

View source

Arguments ​

  • $attributes (array<string,mixed>) – Values matching the createAttributes schema.
  • $fields (array<string,mixed>) – Custom field values keyed by field handle.
  • $actor
  • $draftName
  • $draftNotes

Returns ​

array{element: array<string,mixed>}, array<string,mixed>

Throws ​

  • \Mcp\Exception\ToolCallException
    if the type does not support unpublished drafts.

duplicate() ​

View source

Arguments ​

  • $element
  • $mode (string, null) – One of the modes listed in duplicateModes, or null for the default.

elementType() ​

View source

Returns ​

class-string<\craft\base\ElementInterface>

fieldSchemaElement() ​

Returns the element whose custom-field schema elements_field_schema describes.

View source

Arguments ​

  • $element (craft\base\ElementInterface, null) – The existing element, or null for a new element described by the context.
  • $context (array<string,mixed>) – Values matching the fieldSchemaContext schema.
  • $actor

find() ​

View source

Arguments ​

  • $id
  • $uid
  • $siteId

handle() ​

Returns the type value MCP clients pass to select this element type, such as entries.

View source

listQuery() ​

Returns the base query for elements_list.

View source

Arguments ​

  • $actor

Throws ​

  • \Mcp\Exception\ToolCallException
    if the actor may not list elements of this type.

prepareValidation() ​

Applies proposed changes in memory before elements_validate validates the element.

View source

Arguments ​

  • $element
  • $attributes (array<string,mixed>) – Values matching the updateAttributes schema.
  • $fields (array<string,mixed>) – Custom field values keyed by field handle.
  • $actor

schema() ​

Describes the criteria, attributes, and field-schema context the elements_* tools accept for this type.

View source

Returns ​

array{type: string, name: string, elementType: class-string<\craft\base\ElementInterface>, criteria: array<string,mixed>, createAttributes?: array<string,mixed>, updateAttributes: array<string,mixed>, fieldSchemaContext?: array<string,mixed>, duplicateModes?: list<string>, notes?: list<string>}

serialize() ​

View source

Arguments ​

  • $element
  • $fields (list<string>, null) – Custom-field handles to include, or null for all non-nested custom fields.
  • $summary (boolean) – Whether the element is serialized as part of a list.

Returns ​

array<string,mixed>

update() ​

View source

Arguments ​

  • $element
  • $attributes (array<string,mixed>) – Values matching the updateAttributes schema.
  • $fields (array<string,mixed>) – Custom field values keyed by field handle.
  • $actor

Returns ​

array{element: array<string,mixed>}, array<string,mixed>