feat(cabana,pier): add Media Library admin API, mediafinder, Mail Images unification, and MCP tools
This commit is contained in:
@@ -98,6 +98,7 @@ for _, f := range form.Fields {
|
||||
| `widget` | A plugin custom element with a server action; see [Partials and widgets](partials-and-widgets.md). |
|
||||
| `partial` | A server-rendered template; see [Partials and widgets](partials-and-widgets.md). |
|
||||
| `fileupload` | Uploads for an attachOne or attachMany relation; see [File uploads](#file-uploads). |
|
||||
| `mediafinder` | Picks one or more items from the shared [Media Library](../services/media-library.md) (`mode: image\|file`, `multiple: bool`, `folder: <slug>`). |
|
||||
| `datepicker` | A date, date and time, or time of day; see [Date pickers](#date-pickers). |
|
||||
| `permissioneditor` | A list of permissions to allow, deny or leave inherited; see [Permission editor](#permission-editor). |
|
||||
| `password` | A masked input with a show and hide button. It is a form-only field: the value is sent with a save and never returned; see [Form-only fields](#form-only-fields). |
|
||||
@@ -114,11 +115,11 @@ for _, f := range form.Fields {
|
||||
| `mailimage` | A single image chosen from the mail image library (stores a file id or null). Missing library images show `backend::lang.mailimage.missing` in the admin and are a 422 on save. |
|
||||
| `mailpreview` | A valueless live preview control (`mode` required: `template`, `layout`, `partial` or `branding`); never bound or accepted in a save body. Renders the server HTML in a sandboxed iframe and can send a test to the signed-in administrator. |
|
||||
|
||||
The WinterCMS widgets that are not in this list (the media finder and the others) are not provided. A field with one of those types stops the start-up, unless a plugin registers that alias as its own field type: plugins add field types with a custom element and Go code that decides what is stored; see [Plugin field types](field-types.md).
|
||||
The WinterCMS widgets that are not in this list are not provided. A field with one of those types stops the start-up, unless a plugin registers that alias as its own field type: plugins add field types with a custom element and Go code that decides what is stored; see [Plugin field types](field-types.md).
|
||||
|
||||
### Field options
|
||||
|
||||
A field takes `label`, `comment`, `type`, `required`, `default`, `tab`, `span` (`left`, `right`, `full`, `auto`, `row`), `size` (`tiny`, `small`, `large`, `huge`, `giant`), `context`, `attributes` (scalar HTML attributes for the input), `options` and `emptyOption`, plus `nameFrom` and `relation` on relation fields, `preset` on text and mltext fields, `dependsOn` on dropdowns (see [Dependent dropdowns](#dependent-dropdowns)), `currency`, `currencyFrom`, `scale` and `max` on money fields (see [Money](#money)), `mode`, `separator` and `customTags` on taglist fields (see [Taglist](#taglist)), `language` and `mailImages` on `codeeditor` (and `mailImages` on `markdown`), `mode` on `mailpreview`, and `trigger` (see [Triggers](#triggers)). WinterCMS keys outside this set, such as `readOnly` or `disabled`, are refused.
|
||||
A field takes `label`, `comment`, `type`, `required`, `default`, `tab`, `span` (`left`, `right`, `full`, `auto`, `row`), `size` (`tiny`, `small`, `large`, `huge`, `giant`), `context`, `attributes` (scalar HTML attributes for the input), `options` and `emptyOption`, plus `nameFrom` and `relation` on relation fields, `preset` on text and mltext fields, `dependsOn` on dropdowns (see [Dependent dropdowns](#dependent-dropdowns)), `currency`, `currencyFrom`, `scale` and `max` on money fields (see [Money](#money)), `mode`, `separator` and `customTags` on taglist fields (see [Taglist](#taglist)), `mode`, `multiple` and `folder` on `mediafinder` fields, `language` and `mailImages` on `codeeditor` (and `mailImages` on `markdown`), `mode` on `mailpreview`, and `trigger` (see [Triggers](#triggers)). WinterCMS keys outside this set, such as `readOnly` or `disabled`, are refused.
|
||||
|
||||
`context: update` shows a field only on the update form, and `context: create` only on the create form; a list of contexts is also accepted, and `context: preview` shows a field only on the [preview screen](#preview-screen). The context is enforced on the server too: a field that is hidden on a form is never written by that form's save, whatever the request body holds.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user