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.
Public Methods ​
| Method | Description |
|---|---|
| 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() ​
Arguments ​
$actor$element
canView() ​
Arguments ​
$actor$element
create() ​
Arguments ​
$attributes(array<string,mixed>) – Values matching thecreateAttributesschema.$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.
Arguments ​
$attributes(array<string,mixed>) – Values matching thecreateAttributesschema.$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() ​
Arguments ​
$element$mode(string, null) – One of the modes listed induplicateModes, ornullfor the default.
elementType() ​
Returns ​
class-string<\craft\base\ElementInterface>
fieldSchemaElement() ​
Returns the element whose custom-field schema elements.field-schema describes.
Arguments ​
$element(craft\base\ElementInterface, null) – The existing element, ornullfor a new element described by the context.$context(array<string,mixed>) – Values matching thefieldSchemaContextschema.$actor
find() ​
Arguments ​
$id$uid$siteId
handle() ​
Returns the type value MCP clients pass to select this element type, such as entries.
listQuery() ​
Returns the base query for elements.list.
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.
Arguments ​
$element$attributes(array<string,mixed>) – Values matching theupdateAttributesschema.$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.
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() ​
Arguments ​
$element$fields(list<string>, null) – Custom-field handles to include, ornullfor all non-nested custom fields.$summary(boolean) – Whether the element is serialized as part of a list.
Returns ​
array<string,mixed>
update() ​
Arguments ​
$element$attributes(array<string,mixed>) – Values matching theupdateAttributesschema.$fields(array<string,mixed>) – Custom field values keyed by field handle.$actor
Returns ​
array{element: array<string,mixed>}, array<string,mixed>