From ab64f649b04a2df5699f489cc479a89633def9ce Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Tue, 24 Nov 2026 17:32:13 +0100 Subject: [PATCH] docs(36): capture phase context --- .../36-CONTEXT.md | 146 +++++++++++ .../36-DISCUSSION-LOG.md | 230 ++++++++++++++++++ 2 files changed, 376 insertions(+) create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-CONTEXT.md create mode 100644 .planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-DISCUSSION-LOG.md diff --git a/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-CONTEXT.md b/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-CONTEXT.md new file mode 100644 index 00000000..256ccb62 --- /dev/null +++ b/.planning/phases/36-granular-mcp-oauth-api-token-scope-picker/36-CONTEXT.md @@ -0,0 +1,146 @@ +# Phase 36: Granular MCP OAuth & API token scope picker - Context + +**Gathered:** 2026-11-24 +**Status:** Ready for planning + + +## Phase Boundary + +Scale the administrator MCP OAuth consent screen (`admin/src/views/ConnectView.vue`) and personal API token creation dialog (`admin/src/components/account/ApiTokenCreateDialog.vue`) to dozens of plugins and hundreds of granular feature-level scopes, fix the `admin:read` visibility footgun, expose additive plugin/group metadata on `cabana.AdminAPITokenScope`, and emit a boot-time structured warning in `pier` when any plugin registers backend write MCP tools uncovered by a non-`*` `TokenScope`. + +In addition to `summercms.go` (Go packages `pact`, `cabana`, `pier`, OpenAPI schema, admin SPA + rebuilt `modules/boardwalk/dist`, en/pl phrasebook copy, Go unit tests, Vitest coverage), this phase ships `pact.HasTokenScopes` in `sm-seo-plugin`, `sm-sitemap-plugin`, and any other core plugin discovered to have uncovered backend write MCP tools. Delivery ends at patch release tags across `summercms.go` and the updated core plugins plus a local pointer bump and verification in `sm-grzybyfunkcjonalne-app` (proving the consent screen with Journal, SEO, and Sitemap scopes locally). Production deploy of `grzybyfunkcjonalne.pl` stays separate. + + + + +## Implementation Decisions + +### Carried Forward from Explore Note (`.planning/notes/2026-11-24-mcp-consent-granular-scope-picker.md`) & Phase 32.2 +- **D-01:** **Full feature-level granularity is first-class.** Never assume a single Read/Write pair per plugin; a plugin may declare arbitrary feature-level scopes (e.g. `shop_sales:read` + `shop_orders` without `shop_customers:read`). `pact.ValidTokenScopeName` regex (`^[a-z][a-z0-9_-]*(:[a-z][a-z0-9_-]*)?$`) stays unchanged. +- **D-02:** **Option D layout (summary card + dedicated picker).** `ConnectView.vue` keeps its calm `480px` standalone card matching `LoginView.vue` with a 3-way **Access level** selector (**Full `*`** | **Read-only `admin:read`** | **Custom**), a compact summary box showing effective access, and a **Customize scopes…** button that opens a dedicated picker modal (search across plugin/group/label/code/description, `All | Selected | Read-only` filter pills, collapsible plugin/group accordions with count badges and per-group `Read` / `All` / `Clear` actions). `ApiTokenCreateDialog.vue` reuses the exact same `ScopePicker` component via an in-dialog view swap (`← Back` / `Apply scopes`, never a nested modal overlay). +- **D-03:** **Initial tier on `/connect`:** Default to **`Read-only (admin:read)`** when `admin:read` is requested and grantable. If the client requested only a narrow subset without `admin:read` or `*` (e.g. `journal:read`), open in `Custom` with the requested grantable scopes selected. If `*` is the only grantable scope, start on `Full (*)`. If no plugin scopes beyond `*` and `admin:read` are grantable, hide the `Custom` tier. Consent screen continues to hide ungrantable scopes, keep `offline_access` ticked by default, and never auto-focus Allow/Deny (Phase 32.2). +- **D-04:** **Combinable `admin:read` toggle inside Custom (fixes the PII footgun).** Inside Custom, provide an explicit opt-in toggle (unchecked by default): **"Also allow reading all other plugins (`admin:read`)"**. When enabled, every `read_only` scope row is visibly locked-checked with a `via admin:read` badge (cannot be unticked independently), and `admin:read` appears as an explicit chip on the summary card. When disabled (default in Custom), `admin:read` is omitted from the submitted scopes so unticking a sensitive `:read` scope genuinely blocks read access. +- **D-05:** **`pact.HasTokenScopes` stays explicit.** Never auto-generate `` scopes at boot (which would undermine least-privilege granular splits). + +### Picker UX & Summary Card +- **D-06:** **Capped chip list + `+N more` in the Custom summary box.** Display `admin:read` (when enabled) and write scopes first, capped at ~6 chips, followed by a `+N more` chip that opens the ScopePicker, accompanied by a summary subtitle (`"X scopes across Y plugins"`). +- **D-07:** **Smart accordion expand/collapse default.** When opening the ScopePicker: + - Small catalog (`≤ 3` groups or `≤ 12` scopes): expand all groups automatically. + - Larger catalog: expand only groups that have active selections (all collapsed if none are selected). + - While searching: always auto-expand matching groups. +- **D-08:** **`ApiTokenCreateDialog.vue` initializes on `Read-only (admin:read)`.** Matches `ConnectView.vue`'s safe 1-click default (elevating to `Full (*)` or narrowing in `Custom` is an intentional click; falls back to `Full (*)` if `admin:read` is unavailable to the admin). +- **D-09:** **Custom tier switching behavior.** Clicking **Custom** when no custom scopes are selected yet automatically opens the ScopePicker (saving an extra click). Switching away to **Read-only** or **Full** and back to **Custom** restores the previously chosen custom selection in memory. + +### Customize Modal & Mobile Styling +- **D-10:** **Responsive modal presentation on `ConnectView.vue`.** Below `640px` (mobile), render the Customize scopes modal as a `100dvh` full-screen sheet with sticky search/filter header and sticky footer; on desktop (`≥ 640px`), render a centered modal (`max-w-[640px] max-h-[85dvh]`) with sticky header and footer. +- **D-11:** **Draft until Apply semantics.** Edits inside the ScopePicker are staged as a draft until **Apply scopes** is clicked. Clicking **Cancel** / **X** / **Escape** (in `ConnectView`) or **← Back** (in `ApiTokenCreateDialog`) discards unsaved picker edits and restores the previous selection. If Custom was auto-opened empty from another tier (D-09) and the user cancels without applying, revert to the previous tier. +- **D-12:** **Surface-matched theming on shared `ScopePicker`.** `ScopePicker` uses semantic admin CSS tokens so `ApiTokenCreateDialog.vue` inherits light/dark mode automatically; `ConnectView.vue` pins light-literal tokens on its Customize modal so it remains visually seamless with the white consent card regardless of dark mode. +- **D-13:** **In-dialog swap behavior in `ApiTokenCreateDialog.vue`.** Pressing **Escape** while in the swapped ScopePicker view acts like **← Back** (discards picker draft and returns to the token form without closing the dialog or losing token name/expiry). Keep the dialog frame at a fixed `max-w-[560px]` width across both views to avoid a resize jump. + +### Backend Group Metadata & Picker Grouping +- **D-14:** **Optional `Group string` on `pact.TokenScope`.** Accepts a phrasebook key (containing `::`, validated by `validateTokenScopeMessageKeys` at boot) or literal text, mirroring `pact.Permission.Tab`. — **Reversibility:** costly — exported `pact` struct field that external plugins will populate. +- **D-15:** **`AdminAPITokenScope` additive JSON fields.** Add `PluginID string` (`json:"plugin_id"`) and `Group string` (`json:"group"`) as always-present strings (no `omitempty`, matching existing `AdminAPITokenScope` fields so OpenAPI/TS types remain plain `string`). Framework scopes (`*`, `admin:read`) and unknown stored scopes emit `plugin_id: ""` and `group: ""`. — **Reversibility:** costly — public admin OpenAPI contract shared by `/account/tokens/scopes`, `/account/tokens`, and `/mcp/consent/{request}`. +- **D-16:** **Fallback resolution order for `AdminAPITokenScope.group`.** When `TokenScope.Group` is empty, resolve in order: + 1. `::lang.plugin.name` (if present and translated in phrasebook) + 2. Matched `reg.permissions` `Tab` (if the scope's matched permissions resolve to a unanimous non-empty `Tab`, translated when containing `::`) + 3. Raw `PluginID` +- **D-17:** **Flat accordions keyed by `(plugin_id, group)`, ordered alphabetically by resolved `group` label.** Each distinct `(plugin_id, group)` pair is one collapsible accordion (no 2-level nesting, and two different plugins never collide even if they use the same label). Sort groups alphabetically (locale-aware, tie-breaking on `plugin_id`) while preserving the plugin's declared scope order within each group. When the `admin:read` toggle is ON, disable the per-group **Read** quick action and have **Clear** untick only unlocked (non-`read_only`) scopes. + +### Core Plugin Rollout & Boot Warning +- **D-18:** **Boot-time uncovered backend write MCP tool warning in `pier.Mount`.** Check every compiled backend non-read-only `MCPTool` (`guardName == "backend"`, `method` not `GET`/`HEAD`) against all registered non-`*` `TokenScope`s by both HTTP method and permission coverage (`cabana` helper called from `pier`, which already imports `cabana` — no circular dependency). Group uncovered tools by `plugin_id` and emit **one structured `Warn` log per plugin** naming `plugin`, `tools`, and guidance to implement `pact.HasTokenScopes`. Never break boot. +- **D-19:** **Core plugin `HasTokenScopes` rollout included in Phase 36.** Implement `pact.HasTokenScopes` in `sm-seo-plugin`, `sm-sitemap-plugin`, and any other core plugin found to expose uncovered backend write MCP tools. Use a clean `:read` + `` pair by default (e.g. `sitemap:read` + `sitemap`), splitting a plugin into granular feature-level scopes only where its existing permissions already separate distinct risk tiers (for example in `sm-seo-plugin` if rules/meta vs. crawls/settings have separate permissions). — **Reversibility:** costly — scope names become part of published OAuth `scopes_supported` and stored token grants. +- **D-20:** **Release & local proof boundary.** Cut patch release tags in dependency order (`summercms.go` first, then updated core plugins), and bump pointers in `sm-grzybyfunkcjonalne-app` to prove the end-to-end consent flow locally with Journal, SEO, and Sitemap scopes and zero boot warnings. Production deployment of `grzybyfunkcjonalne.pl` stays outside this phase. + +### Claude's Discretion +- Exact component file decomposition under `admin/src/components/` (e.g. `ScopePicker.vue`, `ScopeAccessControl.vue` / `ScopeSummary.vue`, composable for tier/draft state) and whether to use Reka UI `Collapsible` / `Accordion` or semantic `