Skip to content

feat(entries): add revision-aware behavior to EntriesRouter#30

Merged
sylvesterdamgaard merged 3 commits into
mainfrom
feat/entries-revision-support
May 6, 2026
Merged

feat(entries): add revision-aware behavior to EntriesRouter#30
sylvesterdamgaard merged 3 commits into
mainfrom
feat/entries-revision-support

Conversation

@sylvesterdamgaard
Copy link
Copy Markdown
Contributor

Summary

  • When a collection has revisions: true, the MCP server now respects Statamic's editorial workflow instead of calling $entry->save() directly on published content
  • Updates to published entries create working copies; the published version stays untouched until explicitly promoted
  • New actions (list_revisions, get_revision, restore_revision, publish_working_copy) give agents full control over the revision lifecycle
  • Graceful fallback: sites without Pro or with revisions disabled get the same behavior as before

Details

Revision-aware CRUD:

  • update on a published entry with revisions enabled creates a working copy
  • update on an unpublished entry saves directly (matches CP behavior)
  • create uses store() which saves as draft + creates an initial revision
  • publish / unpublish delegate to Statamic's built-in methods that handle the revision path automatically

New actions:

  • list_revisions - revision history for an entry (metadata only, no full snapshots)
  • get_revision - full data snapshot for a specific revision by timestamp ID
  • restore_revision - creates working copy (published) or updates directly (unpublished)
  • publish_working_copy - promotes the current working copy to published

New version param on get:

  • published (default) - live published data
  • working_copy - current working copy data (errors if none exists)
  • latest - working copy if present, else published

Security:

  • restore_revision and publish_working_copy mapped as write actions in resource policy and token scopes
  • Permission mapping: list_revisions/get_revision require view, restore_revision/publish_working_copy require publish

Test plan

  • 31 new tests in EntriesRevisionTest.php (86 assertions)
  • All 1044 existing tests still pass
  • PHPStan Level 9, zero errors
  • Pint formatting clean
  • composer quality green

When a collection has revisions enabled, the MCP server now respects
Statamic's editorial workflow instead of bypassing it with direct saves.

Changes:
- Update on published entry creates a working copy (published content unchanged)
- Create uses store() which saves as draft + initial revision
- Publish/unpublish delegate to Statamic's built-in revision-aware methods
- New actions: list_revisions, get_revision, restore_revision, publish_working_copy
- New version param on get: published, working_copy, latest
- Graceful fallback when Pro not licensed or revisions disabled

Includes HandlesRevisions trait, updated resource policy and token scope
mappings, and 31 new tests covering the full revision lifecycle.
…uality

- Fix multi-site response in publishWorkingCopyAction (re-fetch with site context)
- Fix stale revision_status/restored_as_working_copy after restoreRevisionAction
- Add confirmation gate defaults for restore_revision and publish_working_copy
- Fix normalizeTableCell unbounded recursion (unwrap one level only)
- Fix filterOutputFields to strip denied fields from list and nested responses
- Fix generateBlueprint field array shape (indexed handle/field format)
- Add revision_message type check in publishWorkingCopyAction
- Add missing PHPDoc annotations and return types for PHPStan L8
@sylvesterdamgaard sylvesterdamgaard merged commit bd4f895 into main May 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant