Skip to main content

Module mcp

Module mcp 

Source
Expand description

MCP engine — operate the CMS from an AI agent.

The framework ships the whole protocol layer (rustango::mcp: JSON-RPC transport, SSE, agent auth incl. raw-key bearers, OAuth 2.1, skills + fail-closed authorization); this module contributes the CMS tools — read/search content, create + edit + publish pages, upload media, write translations, upsert snippets — plus the per-tenant skill seeding (crate::seed) and the key-management UI (account preferences / user form).

§Identity model

Every tool requires a user-owned key: the token’s uid resolves to a rustango_users row, and the tool acts as that user — page/collection permissions are enforced with the same crate::permissions checks the admin handlers use, revisions and page-log entries are attributed to the user, and the key’s tool scope re-resolves from the owner’s live RBAC on every request. Machine agents (no uid) are refused: CMS writes always have an accountable actor.

§Host wiring

ⓘ
let api = cms_admin
    .merge(rustango_cms::mcp::router(&settings.mcp))
    .merge(rustango_cms::api::router());
let csrf = CsrfConfig::default().exempt_prefix(rustango_cms::mcp::MCP_PREFIX);

The CSRF exemption is required — the global CsrfLayer otherwise rejects every JSON-RPC POST (bearer-authenticated requests carry no CSRF token, and don’t need one: the endpoint never trusts cookies).

Structs§

ToolActor
The user a tool call acts as — the key owner, loaded fresh per call.

Constants§

MCP_PREFIX
Where the MCP endpoint mounts, on every tenant host. Host apps must CSRF-exempt this prefix (see the module docs).

Functions§

require_actor
Resolve the acting user for a tool call. Refuses machine agents (CMS writes need an accountable user) and keys whose owner is gone or deactivated — fail-closed, mirroring the admin session checks.
require_any_codename
require_codename satisfied by any one of codenames — for a resource with a broad grant and a narrower one (cms_library.edit or cms_library_item__<type>.edit).
require_codename
Require a permission codename (cms_page.view, …) — the same role-union check the admin’s codename gates run, superuser bypassing.
router
The CMS MCP router: the framework’s secure tenant router (agent JWT or raw prefix.secret bearer, tenant-pinned, fail-closed skills) nested under MCP_PREFIX. Merge it into the host router OUTSIDE any session-auth layer — it carries its own authentication.