|
| 1 | +# 682 -- MCP 5 Apps (UI Resources) |
| 2 | + |
| 3 | +## Context |
| 4 | + |
| 5 | +MCP Apps (2026-01-26 extension) lets the server advertise UI resources |
| 6 | +alongside tools: tool descriptors carry `_meta.ui.resourceUri` pointing |
| 7 | +to embedded HTML/CSS/JS assets served via `resources/list` and |
| 8 | +`resources/read`. Clients render the HTML in a sandboxed iframe; the |
| 9 | +server is purely a static asset server. This was Phase 5 of the MCP |
| 10 | +modernization umbrella (spec-mcp-0-umbrella). |
| 11 | + |
| 12 | +## Decisions |
| 13 | + |
| 14 | +- **Embedded FS only.** UI bundles ship via `//go:embed` in |
| 15 | + `internal/component/mcp/ui/embed.go`. No on-disk loading path. |
| 16 | + Single-binary deployment model; operators get new UI by deploying a |
| 17 | + new daemon. |
| 18 | + |
| 19 | +- **Capability gate on read, not on advertisement.** `_meta.ui.*` is |
| 20 | + emitted in `tools/list` unconditionally so clients discover UI-capable |
| 21 | + tools without a round-trip. `resources/list` and `resources/read` are |
| 22 | + gated on `capabilities.resources = {}` declared at initialize. |
| 23 | + |
| 24 | +- **MIME sniffing is extension-based, not content-based.** Predictable, |
| 25 | + fast, no dependency on `http.DetectContentType`. Unknown extensions |
| 26 | + default to `application/octet-stream`. |
| 27 | + |
| 28 | +- **YANG extensions for UI metadata.** `ze:ui-resource` (path), |
| 29 | + `ze:ui-permissions` (capabilities), `ze:ui-csp` (Content-Security-Policy) |
| 30 | + on command-tree grouping containers. Follows the same |
| 31 | + extension-on-container pattern as `ze:task-support`. `PathToUIResource` |
| 32 | + walks -cmd modules; hub wiring propagates to `CommandInfo.UIResource`; |
| 33 | + `buildToolDef` emits `_meta.ui` when non-nil. |
| 34 | + |
| 35 | +- **First UI bundle: bgp-peer.** Peer status panel with state, ASN, and |
| 36 | + name. Uses safe DOM methods (no innerHTML). Tagged on the `peer` |
| 37 | + container in `ze-peer-cmd.yang`. |
| 38 | + |
| 39 | +## What Worked |
| 40 | + |
| 41 | +- The `ze:task-support` extension pattern (YANG -> command.go walker -> |
| 42 | + hub map -> CommandInfo field -> buildToolDef emission) transferred |
| 43 | + directly to UI resources. Three new YANG extensions, one new walker, |
| 44 | + one new field, one enrichment block. |
| 45 | + |
| 46 | +- Path-traversal prevention is simple with `path.Clean` + prefix check |
| 47 | + before any `fs.ReadFile`. The embedded FS adds a second layer |
| 48 | + (rejects `..` outside its root). |
| 49 | + |
| 50 | +- The `groupUIResource` function inherits the UI annotation from any |
| 51 | + action in the group, so tagging the parent container (not individual |
| 52 | + commands) works correctly with the existing grouping logic. |
| 53 | + |
| 54 | +## What to Watch |
| 55 | + |
| 56 | +- `resources/updated` notifications are deferred. UI bundles are |
| 57 | + immutable at runtime so there is no notification trigger today. |
| 58 | + |
| 59 | +- `resources/list` pagination is not implemented. The embedded FS is |
| 60 | + small enough that the full list fits comfortably in one response. |
| 61 | + |
| 62 | +- The `lookupUIResource` function in hub walks parent paths to find the |
| 63 | + annotation. If a deeply nested command should NOT inherit the UI |
| 64 | + resource from its parent, an override mechanism would be needed. |
| 65 | + |
| 66 | +## Files |
| 67 | + |
| 68 | +| File | Change | |
| 69 | +|------|--------| |
| 70 | +| `internal/component/mcp/resources.go` | New: MIME sniffer, URI validator, `listResources`, `readResource`, `resourcesList`/`resourcesRead` Streamable methods | |
| 71 | +| `internal/component/mcp/resources_test.go` | New: 16 tests covering list, read, traversal, capability gate, binary blob | |
| 72 | +| `internal/component/mcp/ui/embed.go` | New: `//go:embed bgp-peer` exposing `embed.FS` | |
| 73 | +| `internal/component/mcp/ui/bgp-peer/` | New: `index.html`, `style.css`, `app.js`, `icon.png` | |
| 74 | +| `internal/component/mcp/session.go` | `clientResources` bit, `ClientSupportsResources()`, `CreateWithCapabilities` 5th arg | |
| 75 | +| `internal/component/mcp/streamable.go` | `resources/list`/`resources/read` dispatch, `parseResourcesCapability`, `resources: {}` in initialize | |
| 76 | +| `internal/component/mcp/tools.go` | `UIResourceInfo`, `uiResource` on action/toolGroup, `groupUIResource`, `_meta.ui` in `buildToolDef` | |
| 77 | +| `internal/component/mcp/tools_test.go` | 3 tests for `_meta.ui` enrichment | |
| 78 | +| `internal/component/config/yang/command.go` | `UIResourceInfo`, `PathToUIResource`, `getUIResourceExtensions` | |
| 79 | +| `internal/component/config/yang/modules/ze-extensions.yang` | `ze:ui-resource`, `ze:ui-permissions`, `ze:ui-csp` extensions | |
| 80 | +| `internal/component/bgp/plugins/cmd/peer/schema/ze-peer-cmd.yang` | Tagged `peer` container with UI extensions | |
| 81 | +| `cmd/ze/hub/main.go` | `uiResourceByPath` in `serverCommandLister`, `lookupUIResource` call | |
| 82 | +| `cmd/ze/hub/mcp.go` | `lookupUIResource` function | |
| 83 | +| `docs/architecture/mcp/overview.md` | Resources Capability section, files table, capability table, roadmap | |
| 84 | +| `docs/architecture/api/commands.md` | `resources/list`, `resources/read` method entries | |
| 85 | +| `docs/features.md` | MCP row updated with Apps | |
| 86 | +| `docs/comparison.md` | MCP Apps row added | |
0 commit comments