feat(cabana,pier): add Media Library admin API, mediafinder, Mail Images unification, and MCP tools

This commit is contained in:
Jakub Zych
2026-11-27 13:05:22 +01:00
parent 052aac4312
commit 2f0a44e504
32 changed files with 3882 additions and 69 deletions

View File

@@ -125,6 +125,20 @@ What pier does with it at boot:
- **Prompts.** A `pact.MCPPrompt` is prefixed and filtered like a tool, names its guard, declares its arguments, and renders its messages in `Render`; required arguments are checked first. A prompt never dispatches a route. An error `Render` returns is logged, and the agent gets only a fixed "the prompt could not be rendered" error. Set `Writes` on a prompt whose text directs tools that are not read-only (for example "draft a post, then create it"): it then sits under the same read/write ceiling as those tools, so a read-only grant is not offered a prompt it cannot follow.
- **Descriptions.** `Title` and `Description` are static text, at most 1024 characters, passed through unchanged. Keep them factual one-liners and never build them from data: tool text is read by the model, so data-derived text would be a prompt-injection surface.
## Built-in Media Library tools
When the admin backend is mounted, SummerCMS automatically registers the framework `summercms.media` MCP plugin (`cabana.MediaMCPPlugin`), exposing 7 tools under the `backend` guard covered by the `media:read` (`media.view_media`) and `media` (`media.view_media` + `media.manage_media`) token scopes:
- `media_prepare_upload` (`POST /media/uploads/prepare`) — mints a 5-minute single-use signed `PUT` URL for binary uploads up to `media.max_bytes` (default 25 MiB) without base64 overhead.
- `media_upload` (`POST /media/items/base64`) — uploads a file via base64 JSON up to `media.base64_max_bytes` (default 5 MiB decoded; the MCP request body cap is 8 MiB).
- `media_list` (`GET /media/items`) — lists, searches, and filters items by folder, query, type (`image` or `file`), or `sha256`.
- `media_get` (`GET /media/items/{id}`) — fetches metadata, public URL, WebP variants, and `srcset` for one item.
- `media_update` (`PUT /media/items/{id}`) — updates `alt`, `title`, `caption`, or virtual folder without changing the immutable public URL.
- `media_delete` (`DELETE /media/items/{id}`, destructive) — permanently deletes the item and removes its original and WebP variant blobs after commit.
- `media_create_folder` (`POST /media/folders`) — creates a new virtual folder.
See [Media Library](media-library.md) for details.
## Identity and sessions
Every request is authorized afresh from its bearer; a session never replaces the bearer. An OAuth access token of the application's authorization server (`oas_at_…`) is verified through the `pact.MCPTokenVerifier` the OAuth server plugin publishes: the grant's user is the frontend subject, the grant's scopes are the ceiling. With the `backend` scope and a link the published `pact.MCPLinkedBackendResolver` confirms, the linked administrator is the backend subject, resolved on every request (cached for at most five seconds on one instance and dropped at once by a link event), so unlinking takes effect on the next call with no token surgery. The verifier also reports which administrator the user consented to (`pact.MCPGrant.BackendUserID`); while the link names anyone else, or when the grant records none, the grant has no backend subject, so a link that changes after the consent never re-targets it. The backend principal keeps the administrator's real permissions, superuser included, under the grant's ceiling.