[5.x]: MCP can't set `postDate` or `expiryDate` on Entries

Cerrado
#20,405 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@brandonkelly ya está trabajando en esto.

Desde el 6/11/2026.

  • #20427 de @maxdmyers — fusionado

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
73/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php
Área
backend

Línea de trabajo

Start with EntryAdapter::sharedAttributeProperties() and EntryAdapter::populate() in the MCP element adapter, then check how Entry::$postDate and Entry::$expiryDate are typed and how DateTimeHelper::toDateTime() is used elsewhere. Reproduce with elements_update and elements_create using the ISO 8601 values in the issue. Done means both date attributes can be set through MCP without the type error, with the relevant behavior covered by tests.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

repo:cms
What happened?

Setting postDate or expiryDate through elements_create, elements_update, or elements_validate fails with -32603 "Error while executing tool". elements_create fails with asUnpublishedDraft: true too. So there's no way to schedule or expire an Entry over MCP.

I temporarily patched the SDK's CallToolHandler to log the real error:

TypeError: Cannot assign string to property craft\elements\Entry::$postDate of type ?DateTime

EntryAdapter::sharedAttributeProperties() declares both attributes as strings (format: date-time), and EntryAdapter::populate() (line 194) passes them straight to Craft::configure($element, $attributes). Entry::$postDate and Entry::$expiryDate are typed ?DateTime, so PHP rejects the string. Could the adapter run them through DateTimeHelper::toDateTime() first?

Steps to reproduce
  1. Connect an MCP client as an admin.
  2. Call elements_update with {"type": "entry", "id": <id>, "attributes": {"postDate": "2026-12-01T09:00:00+00:00"}}.
  3. Do the same with expiryDate.
  4. Call elements_create with {"type": "entry", "attributes": {"sectionId": <id>, "typeId": <id>, "title": "Test", "enabled": false, "postDate": "2026-12-01T09:00:00+00:00"}}. Then try it without postDate.
Expected behavior

The Entry saves with the new date.

Actual behavior
  • Steps 2 and 3 return -32603 "Error while executing tool", even though the value is valid ISO 8601 with a UTC offset.
  • Step 4 returns the same error with postDate or expiryDate, and with asUnpublishedDraft: true. Without a date, the Entry saves.
  • "postDate": "2026-12-01" fails schema validation: "Value does not match the required format: date-time".
  • "postDate": null succeeds and sets the post date to now. I didn't expect that, and it changed the date on a live Entry.

The generic -32603 message also made this hard to track down. The agent I tested with tried 5 date formats before it gave up. With the real exception in the message, it could have told the user what was wrong.

PR #20077 loosens date input for custom Date and Time fields on 6.x, but it doesn't touch postDate or expiryDate.

Craft CMS version

5.12.0.1, and 5.x-dev (3419773)

PHP version

8.4.20

Operating system and version

DDEV 1.25.2 on macOS

Database type and version

MySQL 8.0.40

Installed plugins and versions
  • CKEditor 5.9.0
Lenguaje dominante
PHP
Estrellas
3.6k
Forks
712
Merge medio
13 h 13 min
PR fusionados (30 d)
372

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de craftcms/cms

Todos los issues de craftcms/cms

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.