" }
}
},
"gotchas": "Leaflet requires the container …"
}
]
}
]
}
}
```
A package that ships more than one export (two hooks, or a hook plus a React `component`) adds further entries to the same `exports` array — the transport metadata is declared once and shared. The CLI threads `app.gadgets` into the in-process `AppMetadataStore` so the same singleton powers `ggui_list_gadgets`, handshake-time prompt injection, render-time validation + enrichment, and CSP derivation. ### From the console [Section titled “From the console”](#from-the-console) Editing `ggui.json` by hand isn’t the only install path for a hosted app. The [GGUI console](https://console.ggui.ai)’s per-app **Gadgets** tab (`/apps/[appId]/gadgets`) shows exactly what agents receive from `ggui_list_gadgets` — the same three-tier catalog, resolved with the same precedence the server uses at render time: stdlib floor < web-installed < `ggui.json`-declared. * **stdlib** rows are the seven always-on hooks — action-free. * **installed** rows were added through the console’s own search + install flow (not `ggui.json`). Each row carries a version menu — picking a version re-installs at that pin — and a two-step-confirm Remove that uninstalls it. * **declared** rows came from `ggui.json#app.gadgets`. The console never edits `ggui.json` for you; a declared package always wins over an installed one on an exact `package` collision, so a declared row is display-only here. Use the console tab for hosted apps where you’d rather browse + click-install a registry package than hand-edit JSON; use `ggui.json#app.gadgets` (above) when you’re checking gadget config into source control or self-hosting. ## Contract gadget refs vs `GadgetDescriptor` [Section titled “Contract gadget refs vs GadgetDescriptor”](#contract-gadget-refs-vs-gadgetdescriptor) Two distinct shapes — do not confuse them. One is the wire map a host agent authors on a contract; the other is the registry-side package descriptor an operator registers. Both are organized around a gadget **package** that ships one or more **exports**, where each export is either a hook (a `use`-prefixed camelCase name) or a component (a PascalCase name): * **Contract gadget refs** — `clientCapabilities.gadgets` on a `DataContract` is a **package-keyed two-level map** carrying IDENTITY ONLY. The outer key is the npm package name; the inner key is the export name; the inner value is a `GadgetExportUse` — `{ description?, usage? }`, usually just `{}` (optional intent-specific override prose). There is NO `hook` / `component` field on the wire — the export-name GRAMMAR is the discriminator: `useGeolocation` is a hook, `LeafletMap` is a component. There is NO `version`, NO `permission`, NO transport metadata, and NO `binding` key. The wire carries `(package, exportName)` and nothing else. * **`GadgetDescriptor`** — the full registry-side PACKAGE descriptor (what operators register on `App.gadgets`). Package-level identity (`package` + `version`) plus transport metadata (bundle URLs, `connect`, `typesUrl` / `typesSri`) declared once, plus an `exports: GadgetExport[]` array (≥1). Each `GadgetExport` is a field-presence-discriminated union — a hook export `{ hook, … }` or a component export `{ component, … }` — carrying that export’s teaching text + per-export `permission`. `version`, transport metadata, `permission`, and `requires` ALL resolve server-side from this descriptor at render time; the contract author never restates them. `createGguiGadget` authors a single-export package; multi-export packages add further `exports` entries. ## Agent reference shape [Section titled “Agent reference shape”](#agent-reference-shape) Once a package is registered on `App.gadgets`, contracts reference its exports through the package-keyed `clientCapabilities.gadgets` map — outer key = package name, inner key = export name:
```ts
const contract = {
// … propsSpec / actionSpec / contextSpec …
clientCapabilities: {
gadgets: {
"@my-org/ggui-leaflet": {
// PascalCase key ⇒ a component export. Empty value is the
// common case; an optional `{ description?, usage? }` override
// sharpens the teaching text for this specific intent.
LeafletMap: {},
},
"@ggui-ai/gadgets": {
// `use`-prefixed camelCase key ⇒ a hook export.
useGeolocation: {},
},
},
},
};
```
The wire is identity-only: render resolves each `(package, exportName)` pair against the registered `GadgetDescriptor` and enriches the persisted `ComponentGguiSession` with the canonical `version`, transport metadata, teaching text, and `permission`. To walk the map in code, call `listContractGadgets(contract)` — it flattens the package-keyed map into a `readonly GadgetUse[]`, each entry `{ package, name, description?, usage? }`. References to unregistered exports reject at render validation with `gadget_not_registered` and a did-you-mean hint when a close stdlib match exists (Levenshtein < 3 cutoff). Render also rejects with `gadget_package_mismatch` when a referenced export name belongs to a different registered package than the one keyed. ## What the renderer derives [Section titled “What the renderer derives”](#what-the-renderer-derives) When ANY gadget in `clientCapabilities.gadgets` declares `bundleUrl` / `styleUrl` / `connect[]`, the render’s spec-canonical `_meta.ui.csp` block carries the derived `{ connectDomains, resourceDomains }` (per the MCP Apps spec). The MCP-Apps host applies them to the sandboxed iframe as a Content-Security-Policy — conceptually:
```plaintext
script-src 'self' 'unsafe-inline' ;
style-src 'self' 'unsafe-inline' ;
connect-src 'self' ;
img-src 'self' data:
```
* `'unsafe-inline'` on `script-src` is needed because the render shell embeds the bootstrap as an inline `