strapi-plugin-mcp-chat 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +63 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -23,7 +23,7 @@ https://github.com/raulbalestra/strapi-plugin-mcp-chat
23
23
  - 🎙️ **Voice** — record a request (Whisper STT) and hear replies (OpenAI TTS).
24
24
  - 👁️ **Side-by-side preview panel** — the plugin's own docked iframe that shrinks the admin and shows your frontend; reloads after each edit and **stays on the same page + scroll position** (with the optional preview bridge below). This is a custom panel, *not* Strapi's official Live Preview (which is a Growth/Enterprise feature) — it works on any plan, including Community, and complements the official Preview if you have it configured.
25
25
  - 🖥️ **Optional browser control** — if a [Playwright MCP](https://github.com/microsoft/playwright-mcp) server is reachable, the agent can drive a real browser to verify changes.
26
- - 🧱 **Frontend provisioning** — upload your frontend (Next.js or TanStack Start) with a `strapi.manifest.json`; the plugin validates it, creates all content-types, seeds content and wires the preview. Never runs code from the upload — it acts only on the validated manifest.
26
+ - 🧱 **Frontend provisioning** — upload your frontend (Next.js or TanStack Start) with a `strapi.manifest.json`; the plugin validates it, creates all content-types, seeds content and wires the preview. The manifest can also be **inferred from the code** (incl. data arrays hardcoded inside components → collection types), and provisioning then **auto-connects the frontend to Strapi via live REST fetch** (generates a data layer + rewires components, with a hardcoded fallback). Never runs code from the upload — it acts only on the validated manifest.
27
27
  - 🌍 **Translate every page to any language** — create locales and translate all localized content via Strapi 5's native i18n, with **no length limits and no context blowups** (see below).
28
28
  - 🌐 **Fully bilingual (PT / EN)** — both the AI prompts/voice *and* the plugin's own admin pages, switchable with one click (the choice is shared across the chat and the menu pages).
29
29
  - 🎓 **Built-in onboarding tour** — a first-run mini-course (re-openable any time via **❓ Tour**) walks new users through chat, editing, live preview, provisioning and translation.
@@ -213,7 +213,8 @@ respects that:
213
213
  **Draft preview contract (for custom / non-provisioned frontends):** when the iframe URL
214
214
  carries `?preview=1` (or `?status=draft`), fetch Strapi with `status: 'draft'` and an API
215
215
  token that can read drafts (`STRAPI_API_TOKEN`). Provisioned frontends get this wired
216
- automatically via the generated `strapi-client` data module. Note: draft fetching keys off
216
+ automatically via the generated data layer (`src/lib/strapi.ts` + `src/hooks/useStrapi.ts`),
217
+ which reads the `?preview=1`/`?status=draft` flag from the URL. Note: draft fetching keys off
217
218
  the URL on the **client**, so with SSR the first server render may show published content
218
219
  until hydration — fine for preview, but don't rely on it for production rendering.
219
220
 
@@ -249,6 +250,37 @@ in place, not recreated) and reducing media/relations to ids.
249
250
 
250
251
  ## Frontend provisioning
251
252
 
253
+ ### Step-by-step (from the admin)
254
+
255
+ > Prerequisites: the plugin installed & enabled, `OPENAI_API_KEY` set, and Strapi
256
+ > running in **`develop`** (schema generation is dev-only). See [Install](#install).
257
+
258
+ 1. **Zip your frontend** and keep the folder at the top of the archive
259
+ (e.g. `frontend/…`). You can include a `strapi.manifest.json` at its root, or let
260
+ the plugin infer one from the code. Exclude `node_modules` (the plugin installs deps
261
+ when it runs the dev server).
262
+ 2. In the admin, open **MCP Chat** in the left menu → **Provision frontend**.
263
+ 3. **Upload the `.zip`** → click **Analyze project**. The plugin extracts it to a sibling
264
+ folder and proposes a `strapi.manifest.json` (existing one, or inferred from the code —
265
+ including data arrays inside components → collection types).
266
+ 4. **Review the manifest** (edit if you want) → click **Provision**.
267
+ 5. Strapi **restarts** and then, automatically: creates the content-types, **seeds** the
268
+ content, opens **public read**, wires the **preview** (admin CSP + `CLIENT_URL`), and
269
+ **wires the frontend to Strapi via live REST fetch**. Don't close the page — it polls
270
+ until done.
271
+ 6. Click the **🖼 Preview** button on the floating chat. The plugin boots your frontend's
272
+ dev server and shows it docked next to the admin — now reading content from Strapi.
273
+ Toggle **📝 Draft / 🌐 Live** to preview unpublished changes.
274
+ 7. Edit with the **chat** ("change the hero title to …") or in the Content Manager → the
275
+ preview reloads and reflects it. Drafts stay drafts until you publish (or turn on
276
+ Auto-publish).
277
+
278
+ > No `strapi.manifest.json` and no `OPENAI_API_KEY`? Provisioning still models the loose
279
+ > UI text as single-types and wires the preview, but it can't infer data collections or
280
+ > rewire components without the key. Add the key for the full "upload → live" flow.
281
+
282
+ ### Under the hood
283
+
252
284
  Bring a "blessed-stack" frontend (Next.js or TanStack Start) carrying a
253
285
  `strapi.manifest.json`. The plugin **never executes code from the upload** — it
254
286
  reads and validates the manifest (Zod) and, from it, provisions the backend:
@@ -256,14 +288,41 @@ reads and validates the manifest (Zod) and, from it, provisions the backend:
256
288
  ```
257
289
  upload → validate manifest → extract to ../<frontend>
258
290
  → generate src/api/**/schema.json (additive) → Strapi restarts
259
- → seed content (Document Service) → wire .env + types + preview
291
+ → seed content (Document Service) → grant public read
292
+ → wire .env + types + preview (admin.ts + CSP + CLIENT_URL)
293
+ → wire frontend to Strapi (live REST fetch)
260
294
  ```
261
295
 
262
296
  Safety rails: schema generation runs **only in `develop`** (a Content-Type
263
297
  Builder limitation); generation is **additive** (never drops/alters an existing
264
298
  type); the frontend always lands in a **sibling folder**, never inside Strapi's
265
299
  `src/`. Ready-to-use starters live in [`starters/`](./starters). The manifest can
266
- also be **inferred from the frontend code** (e.g. Figma/Lovable exports).
300
+ also be **inferred from the frontend code** (e.g. Figma/Lovable exports) — including
301
+ data arrays hardcoded inside components, which are modeled as collection types (a
302
+ deterministic guard drops any value that isn't found verbatim in the source, so the
303
+ AI can only transcribe, never invent).
304
+
305
+ ### Live-fetch wiring (the frontend becomes "live")
306
+
307
+ The last step connects the frontend to Strapi by **live REST fetch** (not a
308
+ snapshot), so editing in Strapi reflects in the page:
309
+
310
+ - Generates a tiny, dependency-free **data layer** in the frontend —
311
+ `src/lib/strapi.ts` (REST helpers, flat — no `populate`/nesting, light calls) and
312
+ `src/hooks/useStrapi.ts` (`useSection` / `useCollection`, preview/draft aware).
313
+ - **Rewires the components** to read from Strapi with a **hardcoded fallback**
314
+ (`{c.field ?? "original text"}`), leaving icons/assets/layout untouched.
315
+ - **Safe by construction:** every rewritten file is syntax-validated (esbuild, with one
316
+ retry) and backed up as `.bak`; on any doubt the file is left as-is, so the frontend
317
+ never fails to compile because of the plugin. It **only writes inside the frontend
318
+ folder — never touches Strapi.**
319
+ - Runs automatically after provisioning, and is also exposed as `POST
320
+ /mcp-chat/frontend/wire`. It's **idempotent** (components already wired are skipped).
321
+
322
+ > **Needs `OPENAI_API_KEY`** for the two AI steps (inferring collections + rewiring
323
+ > components). Without the key, provisioning still creates the text single-types and
324
+ > generates the data layer, but **does not rewire the components** (the frontend stays
325
+ > hardcoded).
267
326
 
268
327
  ## Translation (i18n)
269
328
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-mcp-chat",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "AI chat inside the Strapi 5 admin that reads and edits your content (incl. components & dynamic zones) via MCP, with voice and a side-by-side live preview.",
5
5
  "keywords": [
6
6
  "strapi",