@mistflow-ai/mcp 0.7.3 → 0.7.4

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 (3) hide show
  1. package/dist/cli.js +57 -23
  2. package/dist/index.js +56 -22
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,26 +1,27 @@
1
1
  #!/usr/bin/env node
2
- var We=Object.defineProperty;var u=(n,e)=>()=>(n&&(e=n(n=0)),e);var re=(n,e)=>{for(var t in e)We(n,t,{get:e[t],enumerable:!0})};import{existsSync as H,readFileSync as ae,writeFileSync as He,mkdirSync as ze}from"fs";import{join as K,dirname as W}from"path";import{homedir as Ge}from"os";import{fileURLToPath as Qe}from"url";function C(){if(M)return M;try{let n=Qe(import.meta.url),e=W(n);for(let t=0;t<6;t++){let o=K(e,"package.json");if(H(o)){let s=JSON.parse(ae(o,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return M=s.version,s.version}let r=W(e);if(r===e)break;e=r}}catch{}return M="0.0.0","0.0.0"}function $(n){let e=/^(\d+)\.(\d+)\.(\d+)/.exec(n.trim());return e?[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3],10)]:null}function oe(n,e){let t=$(n),o=$(e);if(!t||!o)return 0;for(let r=0;r<3;r++){if(t[r]<o[r])return-1;if(t[r]>o[r])return 1}return 0}function Xe(n,e,t){if(t&&oe(n,t)<0)return"unsupported";if(!e||oe(n,e)>=0)return"none";let r=$(n),s=$(e);return!r||!s?"none":r[0]<s[0]?"major":r[1]<s[1]?"minor":"patch"}function j(n){let e=n.get("x-mistflow-mcp-latest")??"",t=n.get("x-mistflow-mcp-min-supported")??"",o=n.get("x-mistflow-mcp-changelog-url")??"";!e&&!t||(f={latest:e,minSupported:t,changelogUrl:o})}function le(){let n=process.env.MISTFLOW_STATE_DIR||K(Ge(),".mistflow");return K(n,"upgrade-state.json")}function Ye(){try{let n=le();return H(n)?JSON.parse(ae(n,"utf-8")):{}}catch{return{}}}function Ze(n){try{let e=le(),t=W(e);H(t)||ze(t,{recursive:!0}),He(e,JSON.stringify(n,null,2)+`
3
- `,{mode:384})}catch{}}function et(n){return n==="patch"?7*864e5:n==="minor"?1*864e5:0}function ce(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!f)return null;let n=C();if(n==="0.0.0")return null;let e=Xe(n,f.latest,f.minSupported);if(e==="none")return null;if(e==="unsupported")return ie(e,n,f);if(se)return null;let t=Ye(),o=Date.now(),r=et(e);return t.dismissedForVersion===f.latest&&e!=="major"||t.lastLatestSeen===f.latest&&t.lastShownMs&&o-t.lastShownMs<r?null:(se=!0,Ze({...t,lastShownMs:o,lastLatestSeen:f.latest}),ie(e,n,f))}function ie(n,e,t){let o="npx -y mistflow-ai install",r=t.changelogUrl?`
4
- What's new: ${t.changelogUrl}`:"";return n==="unsupported"?`
2
+ var Xe=Object.defineProperty;var u=(e,t)=>()=>(e&&(t=e(e=0)),t);var oe=(e,t)=>{for(var n in t)Xe(e,n,{get:t[n],enumerable:!0})};function ce(){let e=[];return e.push("Mistflow is a full-stack app builder that creates and deploys web apps from natural language descriptions. When a user asks to build, create, or make a web app, website, landing page, dashboard, internal tool, marketplace, content site, or browser game, use Mistflow tools. Mistflow creates NEW apps from scratch. It does NOT modify existing non-Mistflow codebases."),e.push(""),e.push("Call `mist_help` at any point for the full CLI command reference. The 4 MCP tools handle short, structured, AI-native flows (auth, project state, browser automation, CLI discovery). Everything else is the `mist` CLI \u2014 invoke via your shell/bash tool."),e.push(""),e.push(Ze),e.push(""),e.push(et),e.push(""),e.push(tt),e.push(""),e.push(nt),e.push(""),e.push(ot),e.push(""),e.push(rt),e.push(""),e.push("New app workflow (entirely CLI-driven):"),e.push("1. Choose destination: if the user did not already specify a path, ask whether to scaffold in the current folder or a new subfolder here. Resolve the absolute path before `mist init`."),e.push('2. Plan: run `mist plan --describe "<user\'s description>" --json` via your shell/bash tool. Pass the user\'s description EXACTLY as written \u2014 do NOT expand, rephrase, or add features. Relay any returned questions to the user, then submit answers via `echo \'<answers-json>\' | mist plan --token <id> --answers-stdin --json`. When status becomes "design_clarify_pending", poll with `mist plan-directions --cid <id> --wait --json`. When directions are ready, the CLI writes `<cwd>/.mistflow/design-directions.html` with each direction rendered in its own fonts + palette + hero treatment \u2014 run `open "<path>"` for the user so they can see visual options, THEN ask them to pick one by name. The sentinel payload (stderr) includes the `previewPath`. Finalize with `echo \'<pick-json>\' | mist plan --cid <id> --pick-stdin --json`. If the CLI returns status "confirm_new_project" (safety gate when inside an existing codebase), ask the user whether to scaffold a new Mistflow app or edit the existing code.'),e.push("3. Mockup (optional): run `mist mockup --plan-id <id>` via your shell/bash tool \u2014 generates a visual HTML wireframe for user preview. Iterative: pass --feedback to refine, --approved to lock in the design."),e.push("4. Scaffold: run `mist init --plan-id <id> --path <absolute-path>` via your shell/bash tool. `mist init` is transactional: it registers the cloud project first, scaffolds in a temp directory, and only moves the completed app into place after both steps succeed. If it fails before that move, stop and fix the error instead of continuing to cloud commands. Returns fast; does NOT run npm install."),e.push("5. Install dependencies: run `mist install <projectPath>` via your shell/bash tool (streams output)."),e.push("6. Implement: run `mist implement <absolute-path>` via your shell/bash tool \u2014 executes plan steps one at a time. Call repeatedly until all steps are done; it auto-marks the previous step as completed on each call."),e.push("7. Deploy: run `mist deploy [path]` via your shell/bash tool \u2014 tars, uploads, polls status with live streaming. Subcommands: `mist deploy promote` (staging\u2192prod), `mist deploy preview` (local tunnel), `mist deploy rollback <id>`, `mist deploy verify <url>`, `mist deploy redeploy`."),e.push("8. QA: run `mist qa <live-url>` via your shell/bash tool, or just `mist qa` from inside the project if mistflow.json already has deploy.url. Call AFTER deploy. Do NOT show the URL to the user until QA passes."),e.push("9. Seed sample data (optional but recommended before QA when acceptance criteria depend on populated tables/lists): run `mist seed <absolute-path>` via your shell/bash tool. This defaults to local-only seeding against PGlite; use `--allow-remote` only when you intentionally want to seed a remote environment. Use `--reset` to clear the matched tables first."),e.push(""),e.push("Companion CLI (`@mistflow-ai/cli`, invoke as `mist` or via `npx -y @mistflow-ai/cli`) is the primary path for EVERYTHING except the 4 MCP tools below:"),e.push("- `mist plan` / `mist plan-directions` \u2014 plan an app."),e.push("- `mist init` \u2014 scaffold a new project from a plan (fast, ~10s)."),e.push("- `mist install` / `mist build` / `mist mockup` / `mist implement` / `mist debug` / `mist seed` / `mist qa` \u2014 local project lifecycle."),e.push("- `mist deploy` (+ promote/preview/rollback/verify/redeploy subcommands) \u2014 deploy orchestration."),e.push("- `mist status` / `mist fix` \u2014 feature manifest viewer + iteration loop."),e.push("- `mist contracts` \u2014 integration-contract layer management."),e.push("- `mist doctor` \u2014 project health diagnostics."),e.push("- `mist login` / `mist projects` / `mist logs` / `mist env` / `mist domains` / `mist rollback` \u2014 cloud-coordination commands."),e.push("- Call mist_help for the full reference."),e.push(""),e.push(it),e.push(""),e.push(st),e.push(""),e.push("Design presets (optional, between steps 2 and 3): run `mist projects designs`, `mist projects app-styles`, `mist projects integrations` via your shell/bash tool to browse catalogs. After `mist plan` generates a plan, it may recommend designs and styles \u2014 present these to the user before calling `mist init`."),e.push(""),e.push("Updating an existing Mistflow app:"),e.push("- Cosmetic or single-file changes: edit files directly, then `mist deploy` to publish."),e.push("- New page or feature (no new data model): mist_project action=get for context, build it, then `mist deploy`."),e.push('- Feature needing new data model: ask product questions, call `mist_project action=get` for context, then run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist deploy`.'),e.push('- Integration addition: ask product questions, call `mist_project action=get`, optionally browse `mist projects integrations`, run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist env` to set required keys before deploy, then `mist deploy`, then `mist qa`.'),e.push("- Bug fix: run `mist debug <absolute-path>` to analyze, fix the code, then `mist deploy`."),e.push(""),e.push("Template forking: use the Mistflow dashboard UI (app.mistflow.ai) to fork templates for now. CLI-side template-fork plumbing is in place but the API-client bridge lands in a follow-up release."),e.push(""),e.push("The 4 MCP tools:"),e.push("- mist_setup: authentication. Only call when user has never signed in or a tool returned 'auth_missing'/'auth_revoked'. Do NOT call for 500s, 404s, or network errors. Also accepts an apiKey parameter for headless auth."),e.push("- mist_project: read/write project state (actions: 'get' / 'update'). Other project queries (errors, logs, deployments, share, version, catalog browsing) moved to `mist projects <subcommand>` in the CLI."),e.push("- mist_browser: navigate, interact with, and screenshot the app during preview or after deploy. Returns screenshots inline in tool results \u2014 the one tool that genuinely needs the MCP transport."),e.push("- mist_help: returns the full CLI command reference. Call once per session to learn the available `mist` commands."),e.join(`
3
+ `)}var Ze,et,tt,nt,rt,ot,st,it,se,ie,ae,le,R=u(()=>{"use strict";Ze="When invoking `mist plan` through your shell/bash tool, give it at least a 2 minute budget before assuming it stalled. `mist plan` commonly takes 30-150s. Heavier commands like install/build/qa/deploy can need a longer budget (up to about 5 minutes).",et='Treat the CLI\'s returned JSON as authoritative. If `mist plan --describe ...` returns `status: "clarify"`, the planning call completed and is waiting on user answers. Do NOT rerun the same command or describe it as "still generating". Only poll again when status is `"design_clarify_pending"`, and then use `mist plan-directions --cid <id> --wait --json`.',tt='When submitting discovery answers back to `mist plan --token ... --answers-stdin`, prefer an array payload like `{"answers":[{"question":"...","decisionKey":"...","answer":"..."}]}`. Do NOT collapse answers into a `{decisionKey: answer}` map because multiple discovery questions can share the same decision key.',nt="Before scaffolding a NEW app, resolve the destination path explicitly. If the user asked to create/build a new app and the current directory is not already that Mistflow project, ask whether to scaffold in the current folder or a new subfolder here (unless the user already gave a path). Do NOT inspect sibling directories and silently adopt one as the base just because it looks similar. Reuse an existing Mistflow project only when the user explicitly asks to continue/edit that project.",rt="If `mist plan` fails with a message like `Request to /api/plan timed out after 60s`, the host AI should suspect a stale CLI binary before blaming the backend. Check `mist --version`. If the installed CLI is behind the backend's advertised latest version, run `mist upgrade` (for the self-installed CLI in `~/.mistflow/bin/mist`) or retry with `npx -y @mistflow-ai/cli@latest ...`.",ot="`mist init` is all-or-nothing for normal users: it registers the cloud project first, scaffolds in a temp directory, then moves the finished app into place only after both steps succeed. If auth, quota, or network registration fails, stop before any app appears locally. Do NOT suggest reusing another app unless the user explicitly asks.",st="If `mist init` fails, stop before any cloud command and explain why. Do NOT default to reusing some other existing app as recovery unless the user explicitly asked to continue that app.",it='IMPORTANT \u2014 chaining discipline: once the user approves the plan, the init \u2192 install \u2192 implement (repeat) \u2192 build \u2192 deploy \u2192 seed (when needed) \u2192 qa chain is expected. Do NOT pause between these calls to ask the user "should I continue?" or offer options like "full build vs step-by-step." The tool itself will return a status requiring user input when it actually needs one (e.g. confirm_new_project, confirm_dark_theme, awaiting promotion). Otherwise, chain calls continuously. Brief one-line status updates are fine and encouraged; permission requests are not.',se="Connect the user's Mistflow account. Call this ONLY when: (a) the user has literally never signed in, or (b) a previous tool call returned error code 'auth_missing' or 'auth_revoked'. DO NOT call this tool in response to 500 errors, 404 errors, network errors, or any generic failure \u2014 those are backend issues, not auth issues. Running mist_setup when not needed wastes the user's time and creates login fatigue. Once signed in, the MCP persists a long-lived API key and never asks again. Two-phase device code flow: (1) Call without deviceCode \u2014 opens browser, returns status 'pending' with deviceCode and userCode. Tell the user the verification code and that they need to approve in the browser. (2) Call again with deviceCode after ~15 seconds \u2014 polls for approval. Also accepts an apiKey for headless auth (skips device code entirely).",ie="Read or update Mistflow project state. 'get' loads plan progress, env vars, and deploy info \u2014 call this at the start of an incremental change so you understand the current app before editing. 'update' marks plan steps complete or adds env vars (note: `mist implement` in the CLI auto-marks the previous step, so manual updates are rarely needed).",ae="Unified browser tool for navigating, interacting with, and capturing the app. Use 'navigate' to open a URL, interaction actions (click/type/fill/etc.) to test flows, 'snapshot' to inspect the accessibility tree, and 'screenshot' for a visual capture. Use after mist_preview to verify UI, test flows, and iterate on design.",le="Returns the Mistflow CLI command reference. Call this ONCE at session start (or whenever you're unsure which tool to use) to learn every `mist` CLI command, when to prefer it over an MCP tool, and how to chain calls. Results are static \u2014 no backend round-trip, safe to call frequently."});import{existsSync as z,readFileSync as me,writeFileSync as at,mkdirSync as lt}from"fs";import{join as H,dirname as K}from"path";import{homedir as ct}from"os";import{fileURLToPath as pt}from"url";function C(){if(O)return O;try{let e=pt(import.meta.url),t=K(e);for(let n=0;n<6;n++){let o=H(t,"package.json");if(z(o)){let s=JSON.parse(me(o,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return O=s.version,s.version}let r=K(t);if(r===t)break;t=r}}catch{}return O="0.0.0","0.0.0"}function M(e){let t=/^(\d+)\.(\d+)\.(\d+)/.exec(e.trim());return t?[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3],10)]:null}function pe(e,t){let n=M(e),o=M(t);if(!n||!o)return 0;for(let r=0;r<3;r++){if(n[r]<o[r])return-1;if(n[r]>o[r])return 1}return 0}function dt(e,t,n){if(n&&pe(e,n)<0)return"unsupported";if(!t||pe(e,t)>=0)return"none";let r=M(e),s=M(t);return!r||!s?"none":r[0]<s[0]?"major":r[1]<s[1]?"minor":"patch"}function I(e){let t=e.get("x-mistflow-mcp-latest")??"",n=e.get("x-mistflow-mcp-min-supported")??"",o=e.get("x-mistflow-mcp-changelog-url")??"";!t&&!n||(g={latest:t,minSupported:n,changelogUrl:o})}function fe(){let e=process.env.MISTFLOW_STATE_DIR||H(ct(),".mistflow");return H(e,"upgrade-state.json")}function ut(){try{let e=fe();return z(e)?JSON.parse(me(e,"utf-8")):{}}catch{return{}}}function mt(e){try{let t=fe(),n=K(t);z(n)||lt(n,{recursive:!0}),at(t,JSON.stringify(e,null,2)+`
4
+ `,{mode:384})}catch{}}function ft(e){return e==="patch"?7*864e5:e==="minor"?1*864e5:0}function ge(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!g)return null;let e=C();if(e==="0.0.0")return null;let t=dt(e,g.latest,g.minSupported);if(t==="none")return null;if(t==="unsupported")return ue(t,e,g);if(de)return null;let n=ut(),o=Date.now(),r=ft(t);return n.dismissedForVersion===g.latest&&t!=="major"||n.lastLatestSeen===g.latest&&n.lastShownMs&&o-n.lastShownMs<r?null:(de=!0,mt({...n,lastShownMs:o,lastLatestSeen:g.latest}),ue(t,e,g))}function ue(e,t,n){let o="npx -y mistflow-ai install",r=n.changelogUrl?`
5
+ What's new: ${n.changelogUrl}`:"";return e==="unsupported"?`
5
6
 
6
7
  ---
7
- Mistflow ${e} is no longer supported.
8
- You must upgrade to ${t.latest} or newer to continue:
8
+ Mistflow ${t} is no longer supported.
9
+ You must upgrade to ${n.latest} or newer to continue:
9
10
 
10
11
  ${o}
11
12
 
12
13
  After upgrading, restart your AI editor.${r}
13
- ---`:n==="major"?`
14
+ ---`:e==="major"?`
14
15
 
15
16
  ---
16
- Mistflow ${t.latest} is available (you have ${e}).
17
+ Mistflow ${n.latest} is available (you have ${t}).
17
18
  This is a major update. Run \`${o}\` and restart your editor.${r}
18
- ---`:n==="minor"?`
19
+ ---`:e==="minor"?`
19
20
 
20
- --- Mistflow update available: ${e} -> ${t.latest} ---
21
+ --- Mistflow update available: ${t} -> ${n.latest} ---
21
22
  Run \`${o}\` to upgrade, then restart your editor.${r}`:`
22
23
 
23
- (Mistflow ${t.latest} is out, you have ${e}. Run \`${o}\` when convenient.)`}var M,f,se,E=u(()=>{"use strict";M=null;f=null;se=!1});function c(n,e=!1){let t=n;try{let o=ce();o&&(t=n+o)}catch{}return{content:[{type:"text",text:t}],isError:e}}function pe(n){return c(`This is not a Mistflow project (no mistflow.json found at ${n}).
24
+ (Mistflow ${n.latest} is out, you have ${t}. Run \`${o}\` when convenient.)`}var O,g,de,L=u(()=>{"use strict";O=null;g=null;de=!1});function c(e,t=!1){let n=e;try{let o=ge();o&&(n=e+o)}catch{}return{content:[{type:"text",text:n}],isError:t}}function he(e){return c(`This is not a Mistflow project (no mistflow.json found at ${e}).
24
25
 
25
26
  Mistflow creates new projects from scratch \u2014 it doesn't work inside existing codebases.
26
27
 
@@ -29,15 +30,15 @@ To get started:
29
30
  2. Run mist init --plan-id <planId> --path <absolute-path>
30
31
  3. Run mist install <absolute-path>, then mist implement <absolute-path>
31
32
 
32
- If you want to deploy an existing project, use your framework's deploy tools directly.`,!0)}var R=u(()=>{"use strict";E()});import{readFileSync as tt,existsSync as de,writeFileSync as nt,mkdirSync as rt,renameSync as ot,unlinkSync as st}from"fs";import{join as ue,dirname as it}from"path";import{homedir as at}from"os";import{randomBytes as lt}from"crypto";function me(){return ue(at(),".mistflow","credentials.json")}function A(){return(process.env.MISTFLOW_API_URL||"https://api.mistflow.ai").replace(/\/+$/,"")}function ge(){let n=me();if(!de(n))return null;try{let e=JSON.parse(tt(n,"utf-8"));return typeof e.apiKey=="string"?{[ct]:e}:e}catch{return null}}function z(){let n=process.env.MISTFLOW_API_KEY;if(n)return{ok:!0,creds:{apiKey:n,orgId:"",orgSlug:"env"}};let e=ge();if(!e)return{ok:!1,reason:"missing"};let t=A(),o=e[t];return o&&typeof o.apiKey=="string"&&o.apiKey&&typeof o.orgId=="string"?{ok:!0,creds:o}:{ok:!1,reason:"missing"}}function G(n){let e=me(),t=it(e);de(t)||rt(t,{recursive:!0});let o=ge()??{},r=A();o[r]=n;let s=ue(t,`.credentials.tmp.${lt(8).toString("hex")}`);try{nt(s,JSON.stringify(o,null,2)+`
33
- `,{mode:384}),ot(s,e)}catch(i){try{st(s)}catch{}throw i}}function Q(){return z().ok}var ct,X=u(()=>{"use strict";ct="https://api.mistflow.ai"});function g(){return A()}function P(){let n=z();if(!n.ok)throw new m("auth_missing","No Mistflow credentials found.",401);return pt(n.creds)}function pt(n){return{Authorization:`ApiKey ${n.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":C()}}function dt(n){try{j(n.headers)}catch{}}async function ut(n,e,t,o){for(let r=0;r<2;r++)try{return await fetch(n,{...e,signal:AbortSignal.timeout(t)})}catch(s){let i=s instanceof Error&&s.name==="TimeoutError",a=s instanceof TypeError;if(o&&r===0&&(i||a)){console.error(`[api] Retrying ${n} after ${i?"timeout":"network error"}`);continue}throw s}throw new Error("fetchWithRetry: exhausted retries")}async function mt(n){let e=null;try{e=await n.json()}catch{e=null}let t=e&&typeof e.code=="string"?e.code:void 0,o=e&&typeof e.message=="string"?e.message:e&&typeof e.detail=="string"?e.detail:n.statusText||"Request failed";if(t)return new m(t,o,n.status,e?.details);let r=n.status;return r===401?new m("auth_invalid",o,r):r===403?new m("permission_denied",o,r):r===404?new m("not_found",o,r):r===409?new m("conflict",o,r):r===422?new m("validation_error",o,r):r===429?new m("rate_limited",o,r):r>=500?new m("server_error",n.statusText||"Internal server error",r):new m("client_error",o,r)}async function gt(n,e={}){let t=P(),{timeoutMs:o,idempotent:r,...s}=e,i=o??3e4,a=(s.method??"GET").toUpperCase(),p=r??(a==="GET"||a==="HEAD"),l;try{l=await ut(`${g()}${n}`,{...s,headers:{...t,...s.headers}},i,p)}catch(_){throw _ instanceof Error&&_.name==="TimeoutError"?new m("network_error","Request timed out. Try again in a moment."):new m("network_error","Cannot reach Mistflow servers. Check your network.")}if(dt(l),!l.ok)throw await mt(l);return l.json()}async function fe(n,e,t="neon",o){return gt("/api/projects",{method:"POST",body:JSON.stringify({name:n,template:e,db_provider:t,requested_subdomain:o})})}var m,bn,O=u(()=>{"use strict";X();E();m=class extends Error{constructor(t,o,r,s){super(o);this.code=t;this.statusCode=r;this.details=s;this.name="MistflowApiError"}get isAuth(){return this.code.startsWith("auth_")}get isTransient(){return this.code==="server_error"||this.code==="upstream_error"||this.code==="network_error"||this.code==="rate_limited"}};bn=300*1e3});import{z as Y}from"zod";import{platform as ft}from"os";import{execFile as he}from"child_process";function yt(n){return"error"in n}function we(n){return new Promise(e=>setTimeout(e,n))}function wt(n){return new Promise(e=>{let t=ft();t==="win32"?he("cmd.exe",["/c","start","",n],o=>{o&&console.error("Could not open browser:",o.message),e(!o)}):he(t==="darwin"?"open":"xdg-open",[n],r=>{r&&console.error("Could not open browser:",r.message),e(!r)}),setTimeout(()=>e(!1),5e3)})}async function ye(n,e,t,o){let r=t,s=o.sleep??we;for(let i=0;i<e;i++){await s(r);let a;try{let l=await o.fetch(`${g()}/auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:n})});if(!l.ok)continue;a=await l.json()}catch{continue}if(yt(a))switch(a.error){case"authorization_pending":continue;case"slow_down":r+=5e3;continue;case"expired_token":return c("The sign-in link expired. Run mist_setup again to get a new code.",!0);case"access_denied":return c("Sign-in was cancelled. Run mist_setup again to try again.",!0);case"already_exchanged":return c("This sign-in link was already used. Run mist_setup again to get a new code.",!0)}let p=a.email||a.org_name||a.org_slug;return G({apiKey:a.api_key,apiKeyId:a.api_key_id,apiKeyName:a.api_key_name,orgId:a.org_id,orgSlug:a.org_slug,email:a.email}),c(`Connected to Mistflow as ${p}. You are ready to build and deploy.`)}return null}async function vt(n,e=bt){let t=n;if(t?.apiKey)try{let i=await e.fetch(`${g()}/api/org`,{headers:{Authorization:`ApiKey ${t.apiKey}`}});if(!i.ok)return c("Invalid API key. Check the key and try again.",!0);let a=await i.json();return G({apiKey:t.apiKey,orgId:a.id,orgSlug:a.slug}),c(`Connected to Mistflow as ${a.slug} via API key. You are ready to build and deploy.`)}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}if(t?.deviceCode){let i=await ye(t.deviceCode,6,5e3,e);return i||c(JSON.stringify({status:"pending",deviceCode:t.deviceCode,instruction:"The user hasn't approved yet. Wait ~15 seconds and call mist_setup again with the same deviceCode."}))}let o;try{let i=await e.fetch(`${g()}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!i.ok)return c("Cannot reach Mistflow servers. Check your internet connection.",!0);o=await i.json()}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}let r=`${o.verification_uri}?code=${o.user_code}`;console.error(`
33
+ If you want to deploy an existing project, use your framework's deploy tools directly.`,!0)}var P=u(()=>{"use strict";L()});import{readFileSync as gt,existsSync as ye,writeFileSync as ht,mkdirSync as yt,renameSync as wt,unlinkSync as bt}from"fs";import{join as we,dirname as vt}from"path";import{homedir as _t}from"os";import{randomBytes as kt}from"crypto";function be(){return we(_t(),".mistflow","credentials.json")}function A(){return(process.env.MISTFLOW_API_URL||"https://api.mistflow.ai").replace(/\/+$/,"")}function ve(){let e=be();if(!ye(e))return null;try{let t=JSON.parse(gt(e,"utf-8"));return typeof t.apiKey=="string"?{[St]:t}:t}catch{return null}}function G(){let e=process.env.MISTFLOW_API_KEY;if(e)return{ok:!0,creds:{apiKey:e,orgId:"",orgSlug:"env"}};let t=ve();if(!t)return{ok:!1,reason:"missing"};let n=A(),o=t[n];return o&&typeof o.apiKey=="string"&&o.apiKey&&typeof o.orgId=="string"?{ok:!0,creds:o}:{ok:!1,reason:"missing"}}function Q(e){let t=be(),n=vt(t);ye(n)||yt(n,{recursive:!0});let o=ve()??{},r=A();o[r]=e;let s=we(n,`.credentials.tmp.${kt(8).toString("hex")}`);try{ht(s,JSON.stringify(o,null,2)+`
34
+ `,{mode:384}),wt(s,t)}catch(i){try{bt(s)}catch{}throw i}}function Y(){return G().ok}var St,X=u(()=>{"use strict";St="https://api.mistflow.ai"});function f(){return A()}function j(){let e=G();if(!e.ok)throw new m("auth_missing","No Mistflow credentials found.",401);return xt(e.creds)}function xt(e){return{Authorization:`ApiKey ${e.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":C()}}function Rt(e){try{I(e.headers)}catch{}}async function Ct(e,t,n,o){for(let r=0;r<2;r++)try{return await fetch(e,{...t,signal:AbortSignal.timeout(n)})}catch(s){let i=s instanceof Error&&s.name==="TimeoutError",a=s instanceof TypeError;if(o&&r===0&&(i||a)){console.error(`[api] Retrying ${e} after ${i?"timeout":"network error"}`);continue}throw s}throw new Error("fetchWithRetry: exhausted retries")}async function Pt(e){let t=null;try{t=await e.json()}catch{t=null}let n=t&&typeof t.code=="string"?t.code:void 0,o=t&&typeof t.message=="string"?t.message:t&&typeof t.detail=="string"?t.detail:e.statusText||"Request failed";if(n)return new m(n,o,e.status,t?.details);let r=e.status;return r===401?new m("auth_invalid",o,r):r===403?new m("permission_denied",o,r):r===404?new m("not_found",o,r):r===409?new m("conflict",o,r):r===422?new m("validation_error",o,r):r===429?new m("rate_limited",o,r):r>=500?new m("server_error",e.statusText||"Internal server error",r):new m("client_error",o,r)}async function jt(e,t={}){let n=j(),{timeoutMs:o,idempotent:r,...s}=t,i=o??3e4,a=(s.method??"GET").toUpperCase(),p=r??(a==="GET"||a==="HEAD"),l;try{l=await Ct(`${f()}${e}`,{...s,headers:{...n,...s.headers}},i,p)}catch(_){throw _ instanceof Error&&_.name==="TimeoutError"?new m("network_error","Request timed out. Try again in a moment."):new m("network_error","Cannot reach Mistflow servers. Check your network.")}if(Rt(l),!l.ok)throw await Pt(l);return l.json()}async function _e(e,t,n="neon",o){return jt("/api/projects",{method:"POST",body:JSON.stringify({name:e,template:t,db_provider:n,requested_subdomain:o})})}var m,On,$=u(()=>{"use strict";X();L();m=class extends Error{constructor(n,o,r,s){super(o);this.code=n;this.statusCode=r;this.details=s;this.name="MistflowApiError"}get isAuth(){return this.code.startsWith("auth_")}get isTransient(){return this.code==="server_error"||this.code==="upstream_error"||this.code==="network_error"||this.code==="rate_limited"}};On=300*1e3});import{z as Z}from"zod";import{platform as It}from"os";import{execFile as ke}from"child_process";function Ut(e){return"error"in e}function xe(e){return new Promise(t=>setTimeout(t,e))}function Et(e){return new Promise(t=>{let n=It();n==="win32"?ke("cmd.exe",["/c","start","",e],o=>{o&&console.error("Could not open browser:",o.message),t(!o)}):ke(n==="darwin"?"open":"xdg-open",[e],r=>{r&&console.error("Could not open browser:",r.message),t(!r)}),setTimeout(()=>t(!1),5e3)})}async function Se(e,t,n,o){let r=n,s=o.sleep??xe;for(let i=0;i<t;i++){await s(r);let a;try{let l=await o.fetch(`${f()}/auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:e})});if(!l.ok)continue;a=await l.json()}catch{continue}if(Ut(a))switch(a.error){case"authorization_pending":continue;case"slow_down":r+=5e3;continue;case"expired_token":return c("The sign-in link expired. Run mist_setup again to get a new code.",!0);case"access_denied":return c("Sign-in was cancelled. Run mist_setup again to try again.",!0);case"already_exchanged":return c("This sign-in link was already used. Run mist_setup again to get a new code.",!0)}let p=a.email||a.org_name||a.org_slug;return Q({apiKey:a.api_key,apiKeyId:a.api_key_id,apiKeyName:a.api_key_name,orgId:a.org_id,orgSlug:a.org_slug,email:a.email}),c(`Connected to Mistflow as ${p}. You are ready to build and deploy.`)}return null}async function Ot(e,t=Dt){let n=e;if(n?.apiKey)try{let i=await t.fetch(`${f()}/api/org`,{headers:{Authorization:`ApiKey ${n.apiKey}`}});if(!i.ok)return c("Invalid API key. Check the key and try again.",!0);let a=await i.json();return Q({apiKey:n.apiKey,orgId:a.id,orgSlug:a.slug}),c(`Connected to Mistflow as ${a.slug} via API key. You are ready to build and deploy.`)}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}if(n?.deviceCode){let i=await Se(n.deviceCode,6,5e3,t);return i||c(JSON.stringify({status:"pending",deviceCode:n.deviceCode,instruction:"The user hasn't approved yet. Wait ~15 seconds and call mist_setup again with the same deviceCode."}))}let o;try{let i=await t.fetch(`${f()}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!i.ok)return c("Cannot reach Mistflow servers. Check your internet connection.",!0);o=await i.json()}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}let r=`${o.verification_uri}?code=${o.user_code}`;console.error(`
34
35
  Sign in at: ${r}
35
36
  Your code: ${o.user_code}
36
- `);try{await e.openBrowser(r)}catch{}let s=await ye(o.device_code,6,5e3,e);return s||c(JSON.stringify({status:"pending",deviceCode:o.device_code,signInUrl:r,userCode:o.user_code,instruction:"The user hasn't approved yet. Wait ~15 seconds, then call mist_setup again with deviceCode='"+o.device_code+"' to check if they approved."}))}var ht,bt,be,ve=u(()=>{"use strict";R();O();X();ht=Y.object({apiKey:Y.string().optional().describe("API key (mist_...) for headless auth. Skips the device code flow entirely. Generate one at app.mistflow.ai/mcp-keys."),deviceCode:Y.string().optional().describe("Resume polling for a pending device code. Returned by a previous mist_setup call with status 'pending'. Call mist_setup again with this value after ~15 seconds to check if the user approved.")});bt={fetch:globalThis.fetch,openBrowser:wt,sleep:we};be={name:"mist_setup",description:"Connect the user's Mistflow account. Call this ONLY when: (a) the user has literally never signed in, or (b) a previous tool call returned error code 'auth_missing' or 'auth_revoked'. DO NOT call this tool in response to 500 errors, 404 errors, network errors, or any generic failure \u2014 those are backend issues, not auth issues. Running mist_setup when not needed wastes the user's time and creates login fatigue. Once signed in, the MCP persists a long-lived API key and never asks again. Two-phase device code flow: (1) Call without deviceCode \u2014 opens browser, returns status 'pending' with deviceCode and userCode. Tell the user the verification code and that they need to approve in the browser. (2) Call again with deviceCode after ~15 seconds \u2014 polls for approval. Also accepts an apiKey for headless auth (skips device code entirely).",inputSchema:ht,handler:n=>vt(n)}});import{existsSync as _t,readFileSync as kt}from"fs";function _e(n){let e=new Set;if(!_t(n))return e;let t=kt(n,"utf-8");for(let o of t.split(`
37
- `)){let r=o.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s>0){let i=r.slice(0,s).trim(),a=r.slice(s+1).trim();a&&a!=='""'&&a!=="''"&&e.add(i)}}return e}var ke=u(()=>{"use strict"});var ne={};re(ne,{emptyState:()=>te,fetchRemoteState:()=>Pt,fuzzyMatch:()=>Tt,getLocalStatePath:()=>Z,readLocalState:()=>Rt,syncRemoteState:()=>jt,writeLocalState:()=>ee});import{existsSync as Se,readFileSync as St,writeFileSync as xt,mkdirSync as Ct}from"fs";import{join as xe}from"path";function Z(n){return xe(n,".mistflow","state.json")}function Rt(n){let e=Z(n);if(!Se(e))return null;try{return JSON.parse(St(e,"utf-8"))}catch{return null}}function ee(n,e){let t=xe(n,".mistflow");Se(t)||Ct(t,{recursive:!0}),xt(Z(n),JSON.stringify(e,null,2)+`
38
- `)}function te(n,e){return{projectId:n,name:e,template:"",features:[],dbSchema:[],deployCount:0,decisions:[],provenance:[]}}async function Pt(n){let e;try{e=P()}catch{return null}try{let t=await fetch(`${g()}/api/projects/${encodeURIComponent(n)}/state`,{headers:{...e,"Content-Type":"application/json","X-Mistflow-MCP-Version":C()}});try{j(t.headers)}catch{}return t.ok?await t.json():null}catch{return null}}async function jt(n,e){let t;try{t=P()}catch{return!1}try{let o=await fetch(`${g()}/api/projects/${encodeURIComponent(n)}/state`,{method:"PUT",headers:{...t,"Content-Type":"application/json","X-Mistflow-MCP-Version":C()},body:JSON.stringify(e)});try{j(o.headers)}catch{}return o.ok}catch{return!1}}function Tt(n,e){let t=n.toLowerCase(),o=e.toLowerCase();return o.includes(t)||t.includes(o)?!0:t.split(/\s+/).some(s=>s.length>=3&&o.includes(s))}var L=u(()=>{"use strict";O();E()});var Pe={};re(Pe,{ensureBackendRegistered:()=>At,ensureShadcnComponents:()=>Ot});import{existsSync as Re,readFileSync as It,writeFileSync as Ut}from"fs";import{join as N}from"path";import{spawn as Dt}from"child_process";function Mt(n,e,t,o,r){return new Promise(s=>{let i=Dt(n,e,{cwd:t,stdio:["pipe","pipe","pipe"],timeout:o,...r?{env:{...process.env,...r}}:{}}),a="",p="";i.stdout?.on("data",l=>{a+=l.toString()}),i.stderr?.on("data",l=>{p+=l.toString()}),i.on("close",l=>s({success:l===0,stdout:a,stderr:p})),i.on("error",l=>s({success:!1,stdout:a,stderr:p+l.message}))})}function $t(n){let e=N(n,"mistflow.json");if(!Re(e))return null;try{return JSON.parse(It(e,"utf-8"))}catch{return null}}function Et(n,e){Ut(N(n,"mistflow.json"),JSON.stringify(e,null,2))}async function Ce(n,e){try{let t=e.features,o=e.steps,r={plan:e};Array.isArray(t)&&t.length>0&&(r.features=t.map(s=>s.name)),Array.isArray(o)&&o.length>0&&(r.provenance=o.map(s=>({feature:s.name??s.title??`Step ${s.number??"?"}`,user_intent:(s.description??"").slice(0,500),decisions:"Seeded from plan",tradeoffs:"",files_affected:[]}))),await fetch(`${g()}/api/projects/${encodeURIComponent(n)}/state`,{method:"PUT",headers:{...P(),"Content-Type":"application/json"},body:JSON.stringify(r)})}catch(t){console.error("[self-heal] state sync failed:",t instanceof Error?t.message:String(t))}}async function At(n,e={}){let t=$t(n);if(t){if(!Q())return t.projectId;if(!t.projectId)try{let r=t.plan?.requestedSubdomain,s=await fe(t.name,void 0,t.dbProvider??"neon",r);return t.projectId=s.id,Et(n,t),ee(n,te(s.id,t.name)),t.plan&&await Ce(s.id,t.plan),console.error(`[self-heal] registered project ${s.id.slice(0,8)} with backend`),s.id}catch(o){console.error("[self-heal] createProject failed:",o instanceof Error?o.message:String(o));return}return e.forceSync&&t.plan&&t.projectId&&await Ce(t.projectId,t.plan),t.projectId}}async function Ot(n,e){let t=["button","card","input","label","form","dialog","table","dropdown-menu","badge","separator","skeleton","sheet","tabs","avatar","select","textarea","checkbox","switch","tooltip","popover","sonner"],o=e&&e.length>0?e:t,r=N(n,"components","ui"),s=[],i=[];for(let l of o)Re(N(r,`${l}.tsx`))?s.push(l):i.push(l);if(i.length===0)return{installed:[],alreadyPresent:s};let a={NPM_CONFIG_LEGACY_PEER_DEPS:"true"},p=await Mt("npx",["--yes","shadcn@latest","add","-y","-o",...i],n,18e4,a);return p.success?{installed:i,alreadyPresent:s}:{installed:[],alreadyPresent:s,failed:`shadcn add failed for: ${i.join(", ")}. ${p.stderr.slice(-300)}`.trim()}}var je=u(()=>{"use strict";O();L()});import{z as y}from"zod";import{resolve as Lt,join as Te}from"path";import{existsSync as Nt,readFileSync as Ie,writeFileSync as qt}from"fs";var Ft,Ue,De=u(()=>{"use strict";R();ke();Ft=y.object({action:y.enum(["get","update"]).default("get").describe("'get' reads current project state. 'update' modifies it."),projectPath:y.string().optional().describe("Path to the project directory (default: current working directory)"),completedStep:y.number().optional().describe("(update only) Mark a plan step as completed by step number"),addEnvVar:y.object({key:y.string(),description:y.string().optional(),setupUrl:y.string().optional()}).optional().describe("(update only) Add a required env var to the project manifest")}),Ue={name:"mist_state",description:"Read or update project state in mistflow.json. Use action='get' to load plan progress, env var status, and deploy info. Use action='update' to mark plan steps complete or add required env vars. Use when the user says 'mist status', 'mist state', or 'mist update state'.",inputSchema:Ft,handler:async n=>{let e=n,t=Lt(e.projectPath??process.cwd()),o=Te(t,"mistflow.json");if(!Nt(o))return pe(t);let r;try{r=JSON.parse(Ie(o,"utf-8"))}catch{return c("Failed to parse mistflow.json.",!0)}if(e.action==="get"){if(!r.projectId)try{let{ensureBackendRegistered:d}=await Promise.resolve().then(()=>(je(),Pe));await d(t)&&(r=JSON.parse(Ie(o,"utf-8")))}catch{}let a=r.plan,p=a?.steps?.filter(d=>d.status==="completed").length??0,l=a?.steps?.length??0,_=_e(Te(t,".env.local")),T=r.env?.required?Object.entries(r.env.required).map(([d,D])=>({name:d,description:D?.description,configured:_.has(d)})):[];r.projectId&&Promise.resolve().then(()=>(L(),ne)).then(({fetchRemoteState:d})=>d(r.projectId)).catch(()=>{});let x=[`Project: ${r.name}`];if(a){x.push(`Plan: ${a.summary??a.name??"unnamed"} \u2014 ${p}/${l} steps complete`);for(let d of a.steps){let D=d.status==="completed"?"\u2713":d.status==="in_progress"?"\u2192":" ";x.push(` [${D}] ${d.number}. ${d.name}`)}}let I=T.filter(d=>!d.configured);I.length>0&&x.push(`Missing env vars: ${I.map(d=>d.name).join(", ")}`),r.deploy?.url?x.push(`Deployed: ${r.deploy.url} (${r.deploy.count??0} deploys)`):x.push("Not deployed yet");let U=[],J=a?.steps?.find(d=>d.status!=="completed");return J?U.push(`NEXT: Run mist implement <absolute-path> to work on step ${J.number} (${J.name}).`):a&&p===l&&(r.deploy?.url||U.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT ask the user \u2014 just deploy.")),I.length>0&&U.push(`Missing env vars in .env.local: ${I.map(d=>d.name).join(", ")}`),c(JSON.stringify({name:r.name,projectId:r.projectId,planProgress:a?{name:a.name,summary:a.summary,totalSteps:l,completedSteps:p,steps:a.steps}:null,envStatus:T,deploy:r.deploy??null,contextMessage:x.join(`
39
- `),nextSteps:U}))}let s=[];if(e.completedStep!==void 0){let a=r.plan;if(a?.steps){let p=a.steps.findIndex(l=>l.number===e.completedStep);if(p===-1)return c(`Step ${e.completedStep} not found in the plan.`,!0);a.steps[p].status="completed",s.push(`Step ${e.completedStep} marked as completed`)}}e.addEnvVar&&(r.env||(r.env={required:{}}),r.env.required||(r.env.required={}),r.env.required[e.addEnvVar.key]={description:e.addEnvVar.description,setupUrl:e.addEnvVar.setupUrl},s.push(`Added required env var: ${e.addEnvVar.key}`)),qt(o,JSON.stringify(r,null,2)+`
40
- `),r.projectId&&Promise.resolve().then(()=>(L(),ne)).then(async({readLocalState:a,syncRemoteState:p})=>{let l=a(t);l&&await p(r.projectId,l)}).catch(()=>{});let i=[];if(e.completedStep!==void 0){let p=r.plan?.steps?.find(l=>l.status!=="completed");p?i.push(`NEXT: Run mist implement <absolute-path> to work on step ${p.number} (${p.name}). Do this now.`):i.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT suggest localhost.")}return e.addEnvVar&&(i.push(`Add ${e.addEnvVar.key} to your .env.local file`),e.addEnvVar.setupUrl&&i.push(`Get the value from: ${e.addEnvVar.setupUrl}`)),c(JSON.stringify({updated:!0,changes:s,message:s.length>0?`Project state saved. ${s.join(". ")}.`:"No changes made.",nextSteps:i.length>0?i:void 0}))}}});import{z as w}from"zod";var Vt,Me,$e=u(()=>{"use strict";De();Vt=w.object({action:w.enum(["get","update"]).default("get").describe("'get' reads current project state (context oracle \u2014 call before making decisions in an existing project). 'update' marks steps complete or adds env vars. All other project queries moved to the CLI in MCP 0.6.0: `mist projects share`, `mist projects errors`, `mist projects logs`, `mist projects deployments`, `mist projects version`, `mist projects designs`, `mist projects app-styles`, `mist projects integrations`."),projectPath:w.string().optional().describe("Path to the project directory (default: cwd)"),completedStep:w.number().optional().describe("(update) Mark a plan step as completed by step number"),addEnvVar:w.object({key:w.string(),description:w.string().optional(),setupUrl:w.string().optional()}).optional().describe("(update) Add a required env var to the project manifest")}),Me={name:"mist_project",description:"Read or update Mistflow project state. 'get' loads plan progress, env vars, and deploy info \u2014 call this at the start of an incremental change so you understand the current app before editing. 'update' marks plan steps complete or adds env vars (note: `mist implement` in the CLI auto-marks the previous step, so manual updates are rarely needed).",inputSchema:Vt,handler:async n=>{let e=n;return Ue.handler({action:e.action,projectPath:e.projectPath,completedStep:e.completedStep,addEnvVar:e.addEnvVar})}}});async function Bt(){try{return await import("playwright")}catch{throw new Error("Playwright is not installed. Run: cd packages/mcp-server && pnpm add playwright && npx playwright install chromium")}}async function Jt(){let n=await Bt();return(!k||!k.isConnected())&&(k=await n.chromium.launch({headless:!0})),b&&(await b.close().catch(()=>{}),b=null),b=await k.newContext({viewport:{width:1280,height:720},deviceScaleFactor:1}),h=await b.newPage(),h}async function Ee(){return h&&!h.isClosed()?h:(q||(q=Jt().finally(()=>{q=null})),q)}async function Ae(){h&&!h.isClosed()&&await h.close().catch(()=>{}),b&&await b.close().catch(()=>{}),k?.isConnected()&&await k.close().catch(()=>{}),h=null,b=null,k=null}async function F(n){return await n.locator("body").ariaSnapshot()}async function V(n,e=!1){return await n.screenshot({fullPage:e,type:"png"})}var k,b,h,q,Oe=u(()=>{"use strict";k=null,b=null,h=null,q=null;process.once("SIGTERM",()=>{Ae().finally(()=>process.exit(0))});process.once("SIGINT",()=>{Ae().finally(()=>process.exit(0))})});import{z as S}from"zod";var Kt,Le,Ne=u(()=>{"use strict";R();Oe();Kt=S.object({action:S.enum(["navigate","go_back","go_forward","click","type","fill","select_option","press_key","hover","screenshot","snapshot"]).describe("Action to perform. Navigation: navigate|go_back|go_forward. Interaction: click|type|fill|select_option|press_key|hover. Visual: screenshot (returns image) | snapshot (returns accessibility tree)."),url:S.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:S.string().optional().describe("CSS selector of the target element. Required for: click, type, fill, select_option, hover. Optional for screenshot (captures just that element)."),value:S.string().optional().describe("Text to type/fill, option to select, or key to press (e.g. 'Enter', 'Tab'). Required for: type, fill, select_option, press_key."),fullPage:S.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:S.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),Le={name:"mist_browser",description:"Unified browser tool for navigating, interacting with, and capturing the app. Use 'navigate' to open a URL, interaction actions (click/type/fill/etc.) to test flows, 'snapshot' to inspect the accessibility tree, and 'screenshot' for a visual capture. Use after mist_preview to verify UI, test flows, and iterate on design.",inputSchema:Kt,handler:async n=>{let e=n,t=await Ee();if(e.action==="navigate"){if(!e.url)return c("URL is required for 'navigate'.",!0);let s=[],i=l=>{l.type()==="error"&&s.push(l.text())};t.on("console",i),await t.goto(e.url,{waitUntil:"domcontentloaded",timeout:3e4}),await t.waitForLoadState("networkidle").catch(()=>{});let a=[],p=l=>a.push(l.message);if(t.on("pageerror",p),await t.waitForTimeout(500),t.removeListener("console",i),t.removeListener("pageerror",p),s.length>0||a.length>0){let l=await F(t),_=[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:l,consoleErrors:s,pageErrors:a,hasErrors:!0})}];if(e.includeScreenshot){let T=await V(t);_.push({type:"image",data:T.toString("base64"),mimeType:"image/png"})}return{content:_}}}else if(e.action==="go_back")await t.goBack({waitUntil:"domcontentloaded",timeout:1e4});else if(e.action==="go_forward")await t.goForward({waitUntil:"domcontentloaded",timeout:1e4});else if(e.action==="click"){if(!e.selector)return c("Selector is required for 'click'.",!0);await t.click(e.selector,{timeout:1e4}),await t.waitForLoadState("domcontentloaded").catch(()=>{}),await t.waitForTimeout(500)}else if(e.action==="type"){if(!e.selector)return c("Selector is required for 'type'.",!0);if(!e.value)return c("Value is required for 'type'.",!0);await t.type(e.selector,e.value,{delay:50})}else if(e.action==="fill"){if(!e.selector)return c("Selector is required for 'fill'.",!0);if(!e.value)return c("Value is required for 'fill'.",!0);await t.fill(e.selector,e.value)}else if(e.action==="select_option"){if(!e.selector)return c("Selector is required for 'select_option'.",!0);if(!e.value)return c("Value is required for 'select_option'.",!0);await t.selectOption(e.selector,e.value)}else if(e.action==="hover"){if(!e.selector)return c("Selector is required for 'hover'.",!0);await t.hover(e.selector,{timeout:1e4})}else if(e.action==="press_key"){if(!e.value)return c("Value is required for 'press_key' (e.g. 'Enter').",!0);await t.keyboard.press(e.value),await t.waitForLoadState("domcontentloaded").catch(()=>{}),await t.waitForTimeout(500)}else if(e.action==="screenshot"){e.url&&(await t.goto(e.url,{waitUntil:"domcontentloaded",timeout:3e4}),await t.waitForLoadState("networkidle").catch(()=>{}));let s;if(e.selector){let i=await t.$(e.selector);if(!i)return c(`Element not found: ${e.selector}`,!0);s=await i.screenshot({type:"png"})}else s=await V(t,e.fullPage);return{content:[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),message:`Screenshot captured (${e.fullPage?"full page":"viewport"})`})},{type:"image",data:s.toString("base64"),mimeType:"image/png"}]}}else if(e.action==="snapshot"){let s=await F(t);return{content:[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:s})}]}}let o=await F(t),r=[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:o})}];if(e.includeScreenshot){let s=await V(t);r.push({type:"image",data:s.toString("base64"),mimeType:"image/png"})}return{content:r}}}});import{z as qe}from"zod";var Fe,Ve,Be=u(()=>{"use strict";R();Fe=`# Mistflow CLI reference
37
+ `);try{await t.openBrowser(r)}catch{}let s=await Se(o.device_code,6,5e3,t);return s||c(JSON.stringify({status:"pending",deviceCode:o.device_code,signInUrl:r,userCode:o.user_code,instruction:"The user hasn't approved yet. Wait ~15 seconds, then call mist_setup again with deviceCode='"+o.device_code+"' to check if they approved."}))}var Tt,Dt,Re,Ce=u(()=>{"use strict";R();P();$();X();Tt=Z.object({apiKey:Z.string().optional().describe("API key (mist_...) for headless auth. Skips the device code flow entirely. Generate one at app.mistflow.ai/mcp-keys."),deviceCode:Z.string().optional().describe("Resume polling for a pending device code. Returned by a previous mist_setup call with status 'pending'. Call mist_setup again with this value after ~15 seconds to check if the user approved.")});Dt={fetch:globalThis.fetch,openBrowser:Et,sleep:xe};Re={name:"mist_setup",description:se,inputSchema:Tt,handler:e=>Ot(e)}});import{existsSync as Mt,readFileSync as Lt}from"fs";function Pe(e){let t=new Set;if(!Mt(e))return t;let n=Lt(e,"utf-8");for(let o of n.split(`
38
+ `)){let r=o.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s>0){let i=r.slice(0,s).trim(),a=r.slice(s+1).trim();a&&a!=='""'&&a!=="''"&&t.add(i)}}return t}var je=u(()=>{"use strict"});var re={};oe(re,{emptyState:()=>ne,fetchRemoteState:()=>Ft,fuzzyMatch:()=>Bt,getLocalStatePath:()=>ee,readLocalState:()=>qt,syncRemoteState:()=>Vt,writeLocalState:()=>te});import{existsSync as Ie,readFileSync as At,writeFileSync as $t,mkdirSync as Nt}from"fs";import{join as Te}from"path";function ee(e){return Te(e,".mistflow","state.json")}function qt(e){let t=ee(e);if(!Ie(t))return null;try{return JSON.parse(At(t,"utf-8"))}catch{return null}}function te(e,t){let n=Te(e,".mistflow");Ie(n)||Nt(n,{recursive:!0}),$t(ee(e),JSON.stringify(t,null,2)+`
39
+ `)}function ne(e,t){return{projectId:e,name:t,template:"",features:[],dbSchema:[],deployCount:0,decisions:[],provenance:[]}}async function Ft(e){let t;try{t=j()}catch{return null}try{let n=await fetch(`${f()}/api/projects/${encodeURIComponent(e)}/state`,{headers:{...t,"Content-Type":"application/json","X-Mistflow-MCP-Version":C()}});try{I(n.headers)}catch{}return n.ok?await n.json():null}catch{return null}}async function Vt(e,t){let n;try{n=j()}catch{return!1}try{let o=await fetch(`${f()}/api/projects/${encodeURIComponent(e)}/state`,{method:"PUT",headers:{...n,"Content-Type":"application/json","X-Mistflow-MCP-Version":C()},body:JSON.stringify(t)});try{I(o.headers)}catch{}return o.ok}catch{return!1}}function Bt(e,t){let n=e.toLowerCase(),o=t.toLowerCase();return o.includes(n)||n.includes(o)?!0:n.split(/\s+/).some(s=>s.length>=3&&o.includes(s))}var N=u(()=>{"use strict";$();L()});var De={};oe(De,{ensureBackendRegistered:()=>Qt,ensureShadcnComponents:()=>Yt});import{existsSync as Ee,readFileSync as Jt,writeFileSync as Wt}from"fs";import{join as q}from"path";import{spawn as Ht}from"child_process";function Kt(e,t,n,o,r){return new Promise(s=>{let i=Ht(e,t,{cwd:n,stdio:["pipe","pipe","pipe"],timeout:o,...r?{env:{...process.env,...r}}:{}}),a="",p="";i.stdout?.on("data",l=>{a+=l.toString()}),i.stderr?.on("data",l=>{p+=l.toString()}),i.on("close",l=>s({success:l===0,stdout:a,stderr:p})),i.on("error",l=>s({success:!1,stdout:a,stderr:p+l.message}))})}function zt(e){let t=q(e,"mistflow.json");if(!Ee(t))return null;try{return JSON.parse(Jt(t,"utf-8"))}catch{return null}}function Gt(e,t){Wt(q(e,"mistflow.json"),JSON.stringify(t,null,2))}async function Ue(e,t){try{let n=t.features,o=t.steps,r={plan:t};Array.isArray(n)&&n.length>0&&(r.features=n.map(s=>s.name)),Array.isArray(o)&&o.length>0&&(r.provenance=o.map(s=>({feature:s.name??s.title??`Step ${s.number??"?"}`,user_intent:(s.description??"").slice(0,500),decisions:"Seeded from plan",tradeoffs:"",files_affected:[]}))),await fetch(`${f()}/api/projects/${encodeURIComponent(e)}/state`,{method:"PUT",headers:{...j(),"Content-Type":"application/json"},body:JSON.stringify(r)})}catch(n){console.error("[self-heal] state sync failed:",n instanceof Error?n.message:String(n))}}async function Qt(e,t={}){let n=zt(e);if(n){if(!Y())return n.projectId;if(!n.projectId)try{let r=n.plan?.requestedSubdomain,s=await _e(n.name,void 0,n.dbProvider??"neon",r);return n.projectId=s.id,Gt(e,n),te(e,ne(s.id,n.name)),n.plan&&await Ue(s.id,n.plan),console.error(`[self-heal] registered project ${s.id.slice(0,8)} with backend`),s.id}catch(o){console.error("[self-heal] createProject failed:",o instanceof Error?o.message:String(o));return}return t.forceSync&&n.plan&&n.projectId&&await Ue(n.projectId,n.plan),n.projectId}}async function Yt(e,t){let n=["button","card","input","label","form","dialog","table","dropdown-menu","badge","separator","skeleton","sheet","tabs","avatar","select","textarea","checkbox","switch","tooltip","popover","sonner"],o=t&&t.length>0?t:n,r=q(e,"components","ui"),s=[],i=[];for(let l of o)Ee(q(r,`${l}.tsx`))?s.push(l):i.push(l);if(i.length===0)return{installed:[],alreadyPresent:s};let a={NPM_CONFIG_LEGACY_PEER_DEPS:"true"},p=await Kt("npx",["--yes","shadcn@latest","add","-y","-o",...i],e,18e4,a);return p.success?{installed:i,alreadyPresent:s}:{installed:[],alreadyPresent:s,failed:`shadcn add failed for: ${i.join(", ")}. ${p.stderr.slice(-300)}`.trim()}}var Oe=u(()=>{"use strict";$();N()});import{z as y}from"zod";import{resolve as Xt,join as Me}from"path";import{existsSync as Zt,readFileSync as Le,writeFileSync as en}from"fs";var tn,Ae,$e=u(()=>{"use strict";P();je();tn=y.object({action:y.enum(["get","update"]).default("get").describe("'get' reads current project state. 'update' modifies it."),projectPath:y.string().optional().describe("Path to the project directory (default: current working directory)"),completedStep:y.number().optional().describe("(update only) Mark a plan step as completed by step number"),addEnvVar:y.object({key:y.string(),description:y.string().optional(),setupUrl:y.string().optional()}).optional().describe("(update only) Add a required env var to the project manifest")}),Ae={name:"mist_state",description:"Read or update project state in mistflow.json. Use action='get' to load plan progress, env var status, and deploy info. Use action='update' to mark plan steps complete or add required env vars. Use when the user says 'mist status', 'mist state', or 'mist update state'.",inputSchema:tn,handler:async e=>{let t=e,n=Xt(t.projectPath??process.cwd()),o=Me(n,"mistflow.json");if(!Zt(o))return he(n);let r;try{r=JSON.parse(Le(o,"utf-8"))}catch{return c("Failed to parse mistflow.json.",!0)}if(t.action==="get"){if(!r.projectId)try{let{ensureBackendRegistered:d}=await Promise.resolve().then(()=>(Oe(),De));await d(n)&&(r=JSON.parse(Le(o,"utf-8")))}catch{}let a=r.plan,p=a?.steps?.filter(d=>d.status==="completed").length??0,l=a?.steps?.length??0,_=Pe(Me(n,".env.local")),T=r.env?.required?Object.entries(r.env.required).map(([d,D])=>({name:d,description:D?.description,configured:_.has(d)})):[];r.projectId&&Promise.resolve().then(()=>(N(),re)).then(({fetchRemoteState:d})=>d(r.projectId)).catch(()=>{});let x=[`Project: ${r.name}`];if(a){x.push(`Plan: ${a.summary??a.name??"unnamed"} \u2014 ${p}/${l} steps complete`);for(let d of a.steps){let D=d.status==="completed"?"\u2713":d.status==="in_progress"?"\u2192":" ";x.push(` [${D}] ${d.number}. ${d.name}`)}}let U=T.filter(d=>!d.configured);U.length>0&&x.push(`Missing env vars: ${U.map(d=>d.name).join(", ")}`),r.deploy?.url?x.push(`Deployed: ${r.deploy.url} (${r.deploy.count??0} deploys)`):x.push("Not deployed yet");let E=[],W=a?.steps?.find(d=>d.status!=="completed");return W?E.push(`NEXT: Run mist implement <absolute-path> to work on step ${W.number} (${W.name}).`):a&&p===l&&(r.deploy?.url||E.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT ask the user \u2014 just deploy.")),U.length>0&&E.push(`Missing env vars in .env.local: ${U.map(d=>d.name).join(", ")}`),c(JSON.stringify({name:r.name,projectId:r.projectId,planProgress:a?{name:a.name,summary:a.summary,totalSteps:l,completedSteps:p,steps:a.steps}:null,envStatus:T,deploy:r.deploy??null,contextMessage:x.join(`
40
+ `),nextSteps:E}))}let s=[];if(t.completedStep!==void 0){let a=r.plan;if(a?.steps){let p=a.steps.findIndex(l=>l.number===t.completedStep);if(p===-1)return c(`Step ${t.completedStep} not found in the plan.`,!0);a.steps[p].status="completed",s.push(`Step ${t.completedStep} marked as completed`)}}t.addEnvVar&&(r.env||(r.env={required:{}}),r.env.required||(r.env.required={}),r.env.required[t.addEnvVar.key]={description:t.addEnvVar.description,setupUrl:t.addEnvVar.setupUrl},s.push(`Added required env var: ${t.addEnvVar.key}`)),en(o,JSON.stringify(r,null,2)+`
41
+ `),r.projectId&&Promise.resolve().then(()=>(N(),re)).then(async({readLocalState:a,syncRemoteState:p})=>{let l=a(n);l&&await p(r.projectId,l)}).catch(()=>{});let i=[];if(t.completedStep!==void 0){let p=r.plan?.steps?.find(l=>l.status!=="completed");p?i.push(`NEXT: Run mist implement <absolute-path> to work on step ${p.number} (${p.name}). Do this now.`):i.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT suggest localhost.")}return t.addEnvVar&&(i.push(`Add ${t.addEnvVar.key} to your .env.local file`),t.addEnvVar.setupUrl&&i.push(`Get the value from: ${t.addEnvVar.setupUrl}`)),c(JSON.stringify({updated:!0,changes:s,message:s.length>0?`Project state saved. ${s.join(". ")}.`:"No changes made.",nextSteps:i.length>0?i:void 0}))}}});import{z as w}from"zod";var nn,Ne,qe=u(()=>{"use strict";R();$e();nn=w.object({action:w.enum(["get","update"]).default("get").describe("'get' reads current project state (context oracle \u2014 call before making decisions in an existing project). 'update' marks steps complete or adds env vars. All other project queries moved to the CLI in MCP 0.6.0: `mist projects share`, `mist projects errors`, `mist projects logs`, `mist projects deployments`, `mist projects version`, `mist projects designs`, `mist projects app-styles`, `mist projects integrations`."),projectPath:w.string().optional().describe("Path to the project directory (default: cwd)"),completedStep:w.number().optional().describe("(update) Mark a plan step as completed by step number"),addEnvVar:w.object({key:w.string(),description:w.string().optional(),setupUrl:w.string().optional()}).optional().describe("(update) Add a required env var to the project manifest")}),Ne={name:"mist_project",description:ie,inputSchema:nn,handler:async e=>{let t=e;return Ae.handler({action:t.action,projectPath:t.projectPath,completedStep:t.completedStep,addEnvVar:t.addEnvVar})}}});async function rn(){try{return await import("playwright")}catch{throw new Error("Playwright is not installed. Run: cd packages/mcp-server && pnpm add playwright && npx playwright install chromium")}}async function on(){let e=await rn();return(!k||!k.isConnected())&&(k=await e.chromium.launch({headless:!0})),b&&(await b.close().catch(()=>{}),b=null),b=await k.newContext({viewport:{width:1280,height:720},deviceScaleFactor:1}),h=await b.newPage(),h}async function Fe(){return h&&!h.isClosed()?h:(F||(F=on().finally(()=>{F=null})),F)}async function Ve(){h&&!h.isClosed()&&await h.close().catch(()=>{}),b&&await b.close().catch(()=>{}),k?.isConnected()&&await k.close().catch(()=>{}),h=null,b=null,k=null}async function V(e){return await e.locator("body").ariaSnapshot()}async function B(e,t=!1){return await e.screenshot({fullPage:t,type:"png"})}var k,b,h,F,Be=u(()=>{"use strict";k=null,b=null,h=null,F=null;process.once("SIGTERM",()=>{Ve().finally(()=>process.exit(0))});process.once("SIGINT",()=>{Ve().finally(()=>process.exit(0))})});import{z as S}from"zod";var sn,Je,We=u(()=>{"use strict";R();P();Be();sn=S.object({action:S.enum(["navigate","go_back","go_forward","click","type","fill","select_option","press_key","hover","screenshot","snapshot"]).describe("Action to perform. Navigation: navigate|go_back|go_forward. Interaction: click|type|fill|select_option|press_key|hover. Visual: screenshot (returns image) | snapshot (returns accessibility tree)."),url:S.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:S.string().optional().describe("CSS selector of the target element. Required for: click, type, fill, select_option, hover. Optional for screenshot (captures just that element)."),value:S.string().optional().describe("Text to type/fill, option to select, or key to press (e.g. 'Enter', 'Tab'). Required for: type, fill, select_option, press_key."),fullPage:S.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:S.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),Je={name:"mist_browser",description:ae,inputSchema:sn,handler:async e=>{let t=e,n=await Fe();if(t.action==="navigate"){if(!t.url)return c("URL is required for 'navigate'.",!0);let s=[],i=l=>{l.type()==="error"&&s.push(l.text())};n.on("console",i),await n.goto(t.url,{waitUntil:"domcontentloaded",timeout:3e4}),await n.waitForLoadState("networkidle").catch(()=>{});let a=[],p=l=>a.push(l.message);if(n.on("pageerror",p),await n.waitForTimeout(500),n.removeListener("console",i),n.removeListener("pageerror",p),s.length>0||a.length>0){let l=await V(n),_=[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),snapshot:l,consoleErrors:s,pageErrors:a,hasErrors:!0})}];if(t.includeScreenshot){let T=await B(n);_.push({type:"image",data:T.toString("base64"),mimeType:"image/png"})}return{content:_}}}else if(t.action==="go_back")await n.goBack({waitUntil:"domcontentloaded",timeout:1e4});else if(t.action==="go_forward")await n.goForward({waitUntil:"domcontentloaded",timeout:1e4});else if(t.action==="click"){if(!t.selector)return c("Selector is required for 'click'.",!0);await n.click(t.selector,{timeout:1e4}),await n.waitForLoadState("domcontentloaded").catch(()=>{}),await n.waitForTimeout(500)}else if(t.action==="type"){if(!t.selector)return c("Selector is required for 'type'.",!0);if(!t.value)return c("Value is required for 'type'.",!0);await n.type(t.selector,t.value,{delay:50})}else if(t.action==="fill"){if(!t.selector)return c("Selector is required for 'fill'.",!0);if(!t.value)return c("Value is required for 'fill'.",!0);await n.fill(t.selector,t.value)}else if(t.action==="select_option"){if(!t.selector)return c("Selector is required for 'select_option'.",!0);if(!t.value)return c("Value is required for 'select_option'.",!0);await n.selectOption(t.selector,t.value)}else if(t.action==="hover"){if(!t.selector)return c("Selector is required for 'hover'.",!0);await n.hover(t.selector,{timeout:1e4})}else if(t.action==="press_key"){if(!t.value)return c("Value is required for 'press_key' (e.g. 'Enter').",!0);await n.keyboard.press(t.value),await n.waitForLoadState("domcontentloaded").catch(()=>{}),await n.waitForTimeout(500)}else if(t.action==="screenshot"){t.url&&(await n.goto(t.url,{waitUntil:"domcontentloaded",timeout:3e4}),await n.waitForLoadState("networkidle").catch(()=>{}));let s;if(t.selector){let i=await n.$(t.selector);if(!i)return c(`Element not found: ${t.selector}`,!0);s=await i.screenshot({type:"png"})}else s=await B(n,t.fullPage);return{content:[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),message:`Screenshot captured (${t.fullPage?"full page":"viewport"})`})},{type:"image",data:s.toString("base64"),mimeType:"image/png"}]}}else if(t.action==="snapshot"){let s=await V(n);return{content:[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),snapshot:s})}]}}let o=await V(n),r=[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),snapshot:o})}];if(t.includeScreenshot){let s=await B(n);r.push({type:"image",data:s.toString("base64"),mimeType:"image/png"})}return{content:r}}}});import{z as He}from"zod";var Ke,ze,Ge=u(()=>{"use strict";R();P();Ke=`# Mistflow CLI reference
41
42
 
42
43
  The Mistflow CLI handles local execution and long-running operations that
43
44
  would hit the MCP 60s tool-call ceiling. Every command below is invokable
@@ -49,6 +50,10 @@ Or, if the user has installed the CLI globally:
49
50
 
50
51
  mist <command> [...args]
51
52
 
53
+ Never add \`@mistflow-ai/cli\` to the app's package.json. It is a standalone
54
+ companion CLI, not an app dependency. Local installs create
55
+ \`node_modules/.bin/mist\` shims and can drift from the machine-level CLI.
56
+
52
57
  Pass \`--json\` to any command to get a structured JSON response on stdout
53
58
  (progress / info goes to stderr). Errors exit non-zero with a message on
54
59
  stderr.
@@ -67,6 +72,27 @@ that planning is still running. Only poll again when the status is
67
72
  \`"design_clarify_pending"\`, and then use \`mist plan-directions\`. Let the
68
73
  user answer the questions, then submit those answers exactly once.
69
74
 
75
+ Before scaffolding a NEW app, resolve the destination path explicitly. If
76
+ the user asked to create/build a new app and the current directory is not
77
+ already that Mistflow project, ask whether to scaffold in the current
78
+ folder or a new subfolder here (unless the user already gave a path). Do
79
+ NOT inspect sibling directories and silently adopt one as the base just
80
+ because it looks similar. Reuse an existing Mistflow project only when the
81
+ user explicitly asks to continue/edit that project.
82
+
83
+ \`mist init\` is all-or-nothing for normal users: it registers the cloud
84
+ project first, scaffolds in a temp directory, then moves the app into place
85
+ only after both steps succeed. If auth, quota, or network registration
86
+ fails, stop before any app appears locally. Do NOT default to reusing some
87
+ other existing app as recovery unless the user explicitly asked to continue
88
+ that app.
89
+
90
+ If \`mist plan\` fails with a message like \`Request to /api/plan timed out
91
+ after 60s\`, suspect a stale CLI binary before blaming the backend. Check
92
+ \`mist --version\`. If the installed CLI is behind the backend's advertised
93
+ latest version, run \`mist upgrade\` (for the self-installed CLI in
94
+ \`~/.mistflow/bin/mist\`) or retry with \`npx -y @mistflow-ai/cli@latest ...\`.
95
+
70
96
  ## Commands
71
97
 
72
98
  ### \`mist plan --describe "<description>" [--json]\`
@@ -110,6 +136,8 @@ min) until ready or failed.
110
136
 
111
137
  ### \`mist init --plan-id <planId> --path <absolute-path> [--json]\`
112
138
  Scaffold a fresh Mistflow app from a cached plan. Fast and fully CLI-driven.
139
+ Registers the cloud project first, scaffolds in a temp directory, then
140
+ moves the finished app into place only after both steps succeed.
113
141
 
114
142
  ### \`mist mockup --plan-id <planId> [--json]\`
115
143
  Generate or iterate on a grayscale HTML wireframe before scaffolding. Use
@@ -157,16 +185,22 @@ exceed 30s or streams useful progress.
157
185
  The AI reads each CLI response's \`status\` field on stdout (with \`--json\`)
158
186
  and decides the next command. Example end-to-end chain:
159
187
 
188
+ # First, if the user did not specify a destination path, ask whether
189
+ # the app should be created in the current folder or a new subfolder.
160
190
  mist plan --describe "habit tracker" --json
161
191
  # \u2192 {"status":"clarify","conversation_id":"...","questions":[...]}
162
192
  # AI asks user, gets answers, then:
163
193
  echo '{...}' | mist plan --token ... --answers-stdin --json
164
194
  # \u2192 {"status":"design_clarify_pending","design_conversation_id":"..."}
165
195
  mist plan-directions --cid ... --wait --json
166
- # \u2192 {"status":"ready","directions":[...]}
167
- # AI shows picker, user picks, then:
196
+ # \u2192 {"status":"ready","directions":[...], previewPath in sentinel}
197
+ # CLI writes <cwd>/.mistflow/design-directions.html with per-direction
198
+ # fonts/colors/hero \u2014 open it for the user, then show picker.
168
199
  echo '{...}' | mist plan --cid ... --pick-stdin --json
169
200
  # \u2192 {"status":"ready","plan":{...}}
201
+ # Optional but recommended: show a wireframe before scaffolding.
202
+ mist mockup --plan-id ... --json
203
+ # \u2192 AI writes mockup HTML, opens it, asks user to approve.
170
204
  mist init --plan-id ... --path /Users/you/projects/habit-tracker --json
171
205
  mist install /Users/you/projects/habit-tracker --json
172
206
  mist implement /Users/you/projects/habit-tracker --json
@@ -174,9 +208,9 @@ and decides the next command. Example end-to-end chain:
174
208
  mist deploy /Users/you/projects/habit-tracker --json
175
209
  mist seed /Users/you/projects/habit-tracker --json
176
210
  mist qa https://your-app.mistflow.app --json
177
- `,Ve={name:"mist_help",description:"Returns the Mistflow CLI command reference. Call this ONCE at session start (or whenever you're unsure which tool to use) to learn every `mist` CLI command, when to prefer it over an MCP tool, and how to chain calls. Results are static \u2014 no backend round-trip, safe to call frequently.",inputSchema:qe.object({command:qe.string().optional().describe("Optional: name of a specific command to get focused reference for. Omit to get the full catalog.")}),handler:async n=>{let{command:e}=n;if(!e)return c(Fe);let t=Fe.split(`
178
- `),o=new RegExp(`^### \`mist ${e}`),r=-1,s=t.length;for(let i=0;i<t.length;i++)if(o.test(t[i]))r=i;else if(r>=0&&t[i].startsWith("### ")){s=i;break}else if(r>=0&&t[i].startsWith("## ")&&i>r){s=i;break}return r<0?c(`No command named '${e}' found. Call mist_help with no args to see the full catalog.`,!0):c(t.slice(r,s).join(`
179
- `).trim())}}});var Yt={};import{Server as Wt}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as Ht}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as zt,ListToolsRequestSchema as Gt}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as Qt}from"zod-to-json-schema";async function Xt(){let n=process.argv.indexOf("--api-url");n!==-1&&process.argv[n+1]&&(process.env.MISTFLOW_API_URL=process.argv[n+1]),process.argv.includes("--local")&&!process.env.MISTFLOW_API_URL&&(process.env.MISTFLOW_API_URL="http://localhost:9100");let e=new Ht;await B.connect(e),console.error(`Mistflow MCP server running on stdio (API: ${process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"})`)}var B,Je,Ke=u(()=>{"use strict";R();ve();$e();Ne();Be();B=new Wt({name:"mistflow",version:"0.3.0"},{capabilities:{tools:{}},instructions:'Mistflow is a full-stack app builder that creates and deploys web apps from natural language descriptions. When a user asks to build, create, or make a web app, website, landing page, dashboard, internal tool, marketplace, content site, or browser game, use Mistflow tools. Mistflow creates NEW apps from scratch. It does NOT modify existing non-Mistflow codebases.\n\nCall `mist_help` at any point for the full CLI command reference. The 4 MCP tools handle short, structured, AI-native flows (auth, project state, browser automation, CLI discovery). Everything else is the `mist` CLI \u2014 invoke via your shell/bash tool.\n\nWhen invoking `mist plan` through your shell/bash tool, give it at least a 2 minute budget before assuming it stalled. `mist plan` commonly takes 30-150s. Heavier commands like install/build/qa/deploy can need a longer budget (up to about 5 minutes).\n\nTreat the CLI\'s returned JSON as authoritative. If `mist plan --describe ...` returns `status: "clarify"`, the planning call completed and is waiting on user answers. Do NOT rerun the same command or describe it as "still generating". Only poll again when status is `"design_clarify_pending"`, and then use `mist plan-directions --cid <id> --wait --json`.\n\nWhen submitting discovery answers back to `mist plan --token ... --answers-stdin`, prefer an array payload like `{"answers":[{"question":"...","decisionKey":"...","answer":"..."}]}`. Do NOT collapse answers into a `{decisionKey: answer}` map because multiple discovery questions can share the same decision key.\n\nNew app workflow (entirely CLI-driven):\n1. Plan: run `mist plan --describe "<user\'s description>" --json` via your shell/bash tool. Pass the user\'s description EXACTLY as written \u2014 do NOT expand, rephrase, or add features. Relay any returned questions to the user, then submit answers via `echo \'<answers-json>\' | mist plan --token <id> --answers-stdin --json`. When status becomes "design_clarify_pending", poll with `mist plan-directions --cid <id> --wait --json`. Present the directions picker, then finalize with `echo \'<pick-json>\' | mist plan --cid <id> --pick-stdin --json`. If the CLI returns status "confirm_new_project" (safety gate when inside an existing codebase), ask the user whether to scaffold a new Mistflow app or edit the existing code.\n2. Mockup (optional): run `mist mockup --plan-id <id>` via your shell/bash tool \u2014 generates a visual HTML wireframe for user preview. Iterative: pass --feedback to refine, --approved to lock in the design.\n3. Scaffold: run `mist init --plan-id <id> --path <absolute-path>` via your shell/bash tool. Writes the Next.js scaffold, contracts/, AGENTS.md, and registers the project with Mistflow. Returns fast; does NOT run npm install.\n4. Install dependencies: run `mist install <projectPath>` via your shell/bash tool (streams output).\n5. Implement: run `mist implement <absolute-path>` via your shell/bash tool \u2014 executes plan steps one at a time. Call repeatedly until all steps are done; it auto-marks the previous step as completed on each call.\n6. Deploy: run `mist deploy [path]` via your shell/bash tool \u2014 tars, uploads, polls status with live streaming. Subcommands: `mist deploy promote` (staging\u2192prod), `mist deploy preview` (local tunnel), `mist deploy rollback <id>`, `mist deploy verify <url>`, `mist deploy redeploy`.\n7. QA: run `mist qa <live-url>` via your shell/bash tool, or just `mist qa` from inside the project if mistflow.json already has deploy.url. Call AFTER deploy. Do NOT show the URL to the user until QA passes.\n8. Seed sample data (optional but recommended before QA when acceptance criteria depend on populated tables/lists): run `mist seed <absolute-path>` via your shell/bash tool. This defaults to local-only seeding against PGlite; use `--allow-remote` only when you intentionally want to seed a remote environment. Use `--reset` to clear the matched tables first.\n\nCompanion CLI (`@mistflow-ai/cli`, invoke as `mist` or via `npx -y @mistflow-ai/cli`) is the primary path for EVERYTHING except the 4 MCP tools below:\n- `mist plan` / `mist plan-directions` \u2014 plan an app.\n- `mist init` \u2014 scaffold a new project from a plan (fast, ~10s).\n- `mist install` / `mist build` / `mist mockup` / `mist implement` / `mist debug` / `mist seed` / `mist qa` \u2014 local project lifecycle.\n- `mist deploy` (+ promote/preview/rollback/verify/redeploy subcommands) \u2014 deploy orchestration.\n- `mist status` / `mist fix` \u2014 feature manifest viewer + iteration loop.\n- `mist contracts` \u2014 integration-contract layer management.\n- `mist doctor` \u2014 project health diagnostics.\n- `mist login` / `mist projects` / `mist logs` / `mist env` / `mist domains` / `mist rollback` \u2014 cloud-coordination commands.\n- Call mist_help for the full reference.\n\nIMPORTANT \u2014 chaining discipline: once the user approves the plan, the init \u2192 install \u2192 implement (repeat) \u2192 build \u2192 deploy \u2192 seed (when needed) \u2192 qa chain is expected. Do NOT pause between these calls to ask the user "should I continue?" or offer options like "full build vs step-by-step." The tool itself will return a status requiring user input when it actually needs one (e.g. confirm_new_project, confirm_dark_theme, awaiting promotion). Otherwise, chain calls continuously. Brief one-line status updates are fine and encouraged; permission requests are not.\n\nDesign presets (optional, between steps 2 and 3): run `mist projects designs`, `mist projects app-styles`, `mist projects integrations` via your shell/bash tool to browse catalogs. After `mist plan` generates a plan, it may recommend designs and styles \u2014 present these to the user before calling `mist init`.\n\nUpdating an existing Mistflow app:\n- Cosmetic or single-file changes: edit files directly, then `mist deploy` to publish.\n- New page or feature (no new data model): mist_project action=get for context, build it, then `mist deploy`.\n- Feature needing new data model: ask product questions, call `mist_project action=get` for context, then run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist deploy`.\n- Integration addition: ask product questions, call `mist_project action=get`, optionally browse `mist projects integrations`, run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist env` to set required keys before deploy, then `mist deploy`, then `mist qa`.\n- Bug fix: run `mist debug <absolute-path>` to analyze, fix the code, then `mist deploy`.\n\nTemplate forking: use the Mistflow dashboard UI (app.mistflow.ai) to fork templates for now. CLI-side template-fork plumbing is in place but the API-client bridge lands in a follow-up release.\n\nThe 4 MCP tools:\n- mist_setup: authentication. Only call when user has never signed in or a tool returned \'auth_missing\'/\'auth_revoked\'. Do NOT call for 500s, 404s, or network errors. Also accepts an apiKey parameter for headless auth.\n- mist_project: read/write project state (actions: \'get\' / \'update\'). Other project queries (errors, logs, deployments, share, version, catalog browsing) moved to `mist projects <subcommand>` in the CLI.\n- mist_browser: navigate, interact with, and screenshot the app during preview or after deploy. Returns screenshots inline in tool results \u2014 the one tool that genuinely needs the MCP transport.\n- mist_help: returns the full CLI command reference. Call once per session to learn the available `mist` commands.'}),Je=[be,Me,Le,Ve];B.setRequestHandler(Gt,async()=>({tools:Je.map(n=>({name:n.name,description:n.description,inputSchema:Qt(n.inputSchema)}))}));B.setRequestHandler(zt,async n=>{let e=Je.find(t=>t.name===n.params.name);if(!e)return c(`Unknown tool: ${n.params.name}`,!0);try{let t=e.inputSchema.safeParse(n.params.arguments);if(!t.success){let s=t.error.issues.map(i=>`${i.path.join(".")}: ${i.message}`).join(", ");return c(`Invalid input: ${s}`,!0)}let o=n.params._meta?.progressToken,r={server:B,progressToken:o};try{return await e.handler(t.data,r)}finally{r.cleanup?.()}}catch(t){let o=t instanceof Error?t.message:"An unexpected error occurred";return console.error("Tool error:",t),c(o,!0)}});Xt().catch(n=>{console.error("Fatal error:",n),process.exit(1)})});import{readFileSync as Zt}from"fs";import{dirname as en,join as tn}from"path";import{fileURLToPath as nn}from"url";var v=process.argv[2];if(v==="--version"||v==="-v"){try{let n=en(nn(import.meta.url)),e=tn(n,"..","package.json"),t=JSON.parse(Zt(e,"utf-8"));console.log(t.version)}catch{console.log("unknown")}process.exit(0)}(v==="--help"||v==="-h")&&(console.log(`@mistflow-ai/mcp \u2014 Mistflow MCP server
211
+ `,ze={name:"mist_help",description:le,inputSchema:He.object({command:He.string().optional().describe("Optional: name of a specific command to get focused reference for. Omit to get the full catalog.")}),handler:async e=>{let{command:t}=e;if(!t)return c(Ke);let n=Ke.split(`
212
+ `),o=new RegExp(`^### \`mist ${t}`),r=-1,s=n.length;for(let i=0;i<n.length;i++)if(o.test(n[i]))r=i;else if(r>=0&&n[i].startsWith("### ")){s=i;break}else if(r>=0&&n[i].startsWith("## ")&&i>r){s=i;break}return r<0?c(`No command named '${t}' found. Call mist_help with no args to see the full catalog.`,!0):c(n.slice(r,s).join(`
213
+ `).trim())}}});var mn={};import{Server as an}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as ln}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as cn,ListToolsRequestSchema as pn}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as dn}from"zod-to-json-schema";async function un(){let e=process.argv.indexOf("--api-url");e!==-1&&process.argv[e+1]&&(process.env.MISTFLOW_API_URL=process.argv[e+1]),process.argv.includes("--local")&&!process.env.MISTFLOW_API_URL&&(process.env.MISTFLOW_API_URL="http://localhost:9100");let t=new ln;await J.connect(t),console.error(`Mistflow MCP server running on stdio (API: ${process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"})`)}var J,Qe,Ye=u(()=>{"use strict";R();P();Ce();qe();We();Ge();J=new an({name:"mistflow",version:"0.3.0"},{capabilities:{tools:{}},instructions:ce()}),Qe=[Re,Ne,Je,ze];J.setRequestHandler(pn,async()=>({tools:Qe.map(e=>({name:e.name,description:e.description,inputSchema:dn(e.inputSchema)}))}));J.setRequestHandler(cn,async e=>{let t=Qe.find(n=>n.name===e.params.name);if(!t)return c(`Unknown tool: ${e.params.name}`,!0);try{let n=t.inputSchema.safeParse(e.params.arguments);if(!n.success){let s=n.error.issues.map(i=>`${i.path.join(".")}: ${i.message}`).join(", ");return c(`Invalid input: ${s}`,!0)}let o=e.params._meta?.progressToken,r={server:J,progressToken:o};try{return await t.handler(n.data,r)}finally{r.cleanup?.()}}catch(n){let o=n instanceof Error?n.message:"An unexpected error occurred";return console.error("Tool error:",n),c(o,!0)}});un().catch(e=>{console.error("Fatal error:",e),process.exit(1)})});import{readFileSync as fn}from"fs";import{dirname as gn,join as hn}from"path";import{fileURLToPath as yn}from"url";var v=process.argv[2];if(v==="--version"||v==="-v"){try{let e=gn(yn(import.meta.url)),t=hn(e,"..","package.json"),n=JSON.parse(fn(t,"utf-8"));console.log(n.version)}catch{console.log("unknown")}process.exit(0)}(v==="--help"||v==="-h")&&(console.log(`@mistflow-ai/mcp \u2014 Mistflow MCP server
180
214
 
181
215
  Usage:
182
216
  npx @mistflow-ai/mcp Start the MCP server on stdio (default; invoked by editors)
@@ -188,4 +222,4 @@ To install the server into your editor config, use the installer:
188
222
  Use the installer package instead:
189
223
 
190
224
  npx -y mistflow-ai ${v}
191
- `),process.exit(1));await Promise.resolve().then(()=>(Ke(),Yt));
225
+ `),process.exit(1));await Promise.resolve().then(()=>(Ye(),mn));
package/dist/index.js CHANGED
@@ -1,27 +1,28 @@
1
- var Oe=Object.defineProperty;var S=(n,e)=>()=>(n&&(e=n(n=0)),e);var te=(n,e)=>{for(var t in e)Oe(n,t,{get:e[t],enumerable:!0})};import{existsSync as K,readFileSync as se,writeFileSync as Le,mkdirSync as Ne}from"fs";import{join as B,dirname as J}from"path";import{homedir as qe}from"os";import{fileURLToPath as Fe}from"url";function x(){if(U)return U;try{let n=Fe(import.meta.url),e=J(n);for(let t=0;t<6;t++){let o=B(e,"package.json");if(K(o)){let s=JSON.parse(se(o,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return U=s.version,s.version}let r=J(e);if(r===e)break;e=r}}catch{}return U="0.0.0","0.0.0"}function D(n){let e=/^(\d+)\.(\d+)\.(\d+)/.exec(n.trim());return e?[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3],10)]:null}function ne(n,e){let t=D(n),o=D(e);if(!t||!o)return 0;for(let r=0;r<3;r++){if(t[r]<o[r])return-1;if(t[r]>o[r])return 1}return 0}function Ve(n,e,t){if(t&&ne(n,t)<0)return"unsupported";if(!e||ne(n,e)>=0)return"none";let r=D(n),s=D(e);return!r||!s?"none":r[0]<s[0]?"major":r[1]<s[1]?"minor":"patch"}function R(n){let e=n.get("x-mistflow-mcp-latest")??"",t=n.get("x-mistflow-mcp-min-supported")??"",o=n.get("x-mistflow-mcp-changelog-url")??"";!e&&!t||(g={latest:e,minSupported:t,changelogUrl:o})}function ie(){let n=process.env.MISTFLOW_STATE_DIR||B(qe(),".mistflow");return B(n,"upgrade-state.json")}function Be(){try{let n=ie();return K(n)?JSON.parse(se(n,"utf-8")):{}}catch{return{}}}function Je(n){try{let e=ie(),t=J(e);K(t)||Ne(t,{recursive:!0}),Le(e,JSON.stringify(n,null,2)+`
2
- `,{mode:384})}catch{}}function Ke(n){return n==="patch"?7*864e5:n==="minor"?1*864e5:0}function ae(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!g)return null;let n=x();if(n==="0.0.0")return null;let e=Ve(n,g.latest,g.minSupported);if(e==="none")return null;if(e==="unsupported")return oe(e,n,g);if(re)return null;let t=Be(),o=Date.now(),r=Ke(e);return t.dismissedForVersion===g.latest&&e!=="major"||t.lastLatestSeen===g.latest&&t.lastShownMs&&o-t.lastShownMs<r?null:(re=!0,Je({...t,lastShownMs:o,lastLatestSeen:g.latest}),oe(e,n,g))}function oe(n,e,t){let o="npx -y mistflow-ai install",r=t.changelogUrl?`
3
- What's new: ${t.changelogUrl}`:"";return n==="unsupported"?`
1
+ var Ve=Object.defineProperty;var S=(e,t)=>()=>(e&&(t=e(e=0)),t);var te=(e,t)=>{for(var n in t)Ve(e,n,{get:t[n],enumerable:!0})};import{existsSync as W,readFileSync as pe,writeFileSync as Ye,mkdirSync as Xe}from"fs";import{join as B,dirname as J}from"path";import{homedir as Ze}from"os";import{fileURLToPath as et}from"url";function R(){if(U)return U;try{let e=et(import.meta.url),t=J(e);for(let n=0;n<6;n++){let o=B(t,"package.json");if(W(o)){let s=JSON.parse(pe(o,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return U=s.version,s.version}let r=J(t);if(r===t)break;t=r}}catch{}return U="0.0.0","0.0.0"}function E(e){let t=/^(\d+)\.(\d+)\.(\d+)/.exec(e.trim());return t?[parseInt(t[1],10),parseInt(t[2],10),parseInt(t[3],10)]:null}function ae(e,t){let n=E(e),o=E(t);if(!n||!o)return 0;for(let r=0;r<3;r++){if(n[r]<o[r])return-1;if(n[r]>o[r])return 1}return 0}function tt(e,t,n){if(n&&ae(e,n)<0)return"unsupported";if(!t||ae(e,t)>=0)return"none";let r=E(e),s=E(t);return!r||!s?"none":r[0]<s[0]?"major":r[1]<s[1]?"minor":"patch"}function C(e){let t=e.get("x-mistflow-mcp-latest")??"",n=e.get("x-mistflow-mcp-min-supported")??"",o=e.get("x-mistflow-mcp-changelog-url")??"";!t&&!n||(f={latest:t,minSupported:n,changelogUrl:o})}function de(){let e=process.env.MISTFLOW_STATE_DIR||B(Ze(),".mistflow");return B(e,"upgrade-state.json")}function nt(){try{let e=de();return W(e)?JSON.parse(pe(e,"utf-8")):{}}catch{return{}}}function rt(e){try{let t=de(),n=J(t);W(n)||Xe(n,{recursive:!0}),Ye(t,JSON.stringify(e,null,2)+`
2
+ `,{mode:384})}catch{}}function ot(e){return e==="patch"?7*864e5:e==="minor"?1*864e5:0}function ue(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!f)return null;let e=R();if(e==="0.0.0")return null;let t=tt(e,f.latest,f.minSupported);if(t==="none")return null;if(t==="unsupported")return ce(t,e,f);if(le)return null;let n=nt(),o=Date.now(),r=ot(t);return n.dismissedForVersion===f.latest&&t!=="major"||n.lastLatestSeen===f.latest&&n.lastShownMs&&o-n.lastShownMs<r?null:(le=!0,rt({...n,lastShownMs:o,lastLatestSeen:f.latest}),ce(t,e,f))}function ce(e,t,n){let o="npx -y mistflow-ai install",r=n.changelogUrl?`
3
+ What's new: ${n.changelogUrl}`:"";return e==="unsupported"?`
4
4
 
5
5
  ---
6
- Mistflow ${e} is no longer supported.
7
- You must upgrade to ${t.latest} or newer to continue:
6
+ Mistflow ${t} is no longer supported.
7
+ You must upgrade to ${n.latest} or newer to continue:
8
8
 
9
9
  ${o}
10
10
 
11
11
  After upgrading, restart your AI editor.${r}
12
- ---`:n==="major"?`
12
+ ---`:e==="major"?`
13
13
 
14
14
  ---
15
- Mistflow ${t.latest} is available (you have ${e}).
15
+ Mistflow ${n.latest} is available (you have ${t}).
16
16
  This is a major update. Run \`${o}\` and restart your editor.${r}
17
- ---`:n==="minor"?`
17
+ ---`:e==="minor"?`
18
18
 
19
- --- Mistflow update available: ${e} -> ${t.latest} ---
19
+ --- Mistflow update available: ${t} -> ${n.latest} ---
20
20
  Run \`${o}\` to upgrade, then restart your editor.${r}`:`
21
21
 
22
- (Mistflow ${t.latest} is out, you have ${e}. Run \`${o}\` when convenient.)`}var U,g,re,M=S(()=>{"use strict";U=null;g=null;re=!1});import{readFileSync as We,existsSync as ce,writeFileSync as He,mkdirSync as ze,renameSync as Ge,unlinkSync as Qe}from"fs";import{join as pe,dirname as Xe}from"path";import{homedir as Ye}from"os";import{randomBytes as Ze}from"crypto";function de(){return pe(Ye(),".mistflow","credentials.json")}function $(){return(process.env.MISTFLOW_API_URL||"https://api.mistflow.ai").replace(/\/+$/,"")}function ue(){let n=de();if(!ce(n))return null;try{let e=JSON.parse(We(n,"utf-8"));return typeof e.apiKey=="string"?{[et]:e}:e}catch{return null}}function W(){let n=process.env.MISTFLOW_API_KEY;if(n)return{ok:!0,creds:{apiKey:n,orgId:"",orgSlug:"env"}};let e=ue();if(!e)return{ok:!1,reason:"missing"};let t=$(),o=e[t];return o&&typeof o.apiKey=="string"&&o.apiKey&&typeof o.orgId=="string"?{ok:!0,creds:o}:{ok:!1,reason:"missing"}}function H(n){let e=de(),t=Xe(e);ce(t)||ze(t,{recursive:!0});let o=ue()??{},r=$();o[r]=n;let s=pe(t,`.credentials.tmp.${Ze(8).toString("hex")}`);try{He(s,JSON.stringify(o,null,2)+`
23
- `,{mode:384}),Ge(s,e)}catch(i){try{Qe(s)}catch{}throw i}}function z(){return W().ok}var et,G=S(()=>{"use strict";et="https://api.mistflow.ai"});function m(){return $()}function C(){let n=W();if(!n.ok)throw new u("auth_missing","No Mistflow credentials found.",401);return tt(n.creds)}function tt(n){return{Authorization:`ApiKey ${n.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":x()}}function nt(n){try{R(n.headers)}catch{}}async function rt(n,e,t,o){for(let r=0;r<2;r++)try{return await fetch(n,{...e,signal:AbortSignal.timeout(t)})}catch(s){let i=s instanceof Error&&s.name==="TimeoutError",a=s instanceof TypeError;if(o&&r===0&&(i||a)){console.error(`[api] Retrying ${n} after ${i?"timeout":"network error"}`);continue}throw s}throw new Error("fetchWithRetry: exhausted retries")}async function ot(n){let e=null;try{e=await n.json()}catch{e=null}let t=e&&typeof e.code=="string"?e.code:void 0,o=e&&typeof e.message=="string"?e.message:e&&typeof e.detail=="string"?e.detail:n.statusText||"Request failed";if(t)return new u(t,o,n.status,e?.details);let r=n.status;return r===401?new u("auth_invalid",o,r):r===403?new u("permission_denied",o,r):r===404?new u("not_found",o,r):r===409?new u("conflict",o,r):r===422?new u("validation_error",o,r):r===429?new u("rate_limited",o,r):r>=500?new u("server_error",n.statusText||"Internal server error",r):new u("client_error",o,r)}async function st(n,e={}){let t=C(),{timeoutMs:o,idempotent:r,...s}=e,i=o??3e4,a=(s.method??"GET").toUpperCase(),p=r??(a==="GET"||a==="HEAD"),l;try{l=await rt(`${m()}${n}`,{...s,headers:{...t,...s.headers}},i,p)}catch(b){throw b instanceof Error&&b.name==="TimeoutError"?new u("network_error","Request timed out. Try again in a moment."):new u("network_error","Cannot reach Mistflow servers. Check your network.")}if(nt(l),!l.ok)throw await ot(l);return l.json()}async function me(n,e,t="neon",o){return st("/api/projects",{method:"POST",body:JSON.stringify({name:n,template:e,db_provider:t,requested_subdomain:o})})}var u,on,E=S(()=>{"use strict";G();M();u=class extends Error{constructor(t,o,r,s){super(o);this.code=t;this.statusCode=r;this.details=s;this.name="MistflowApiError"}get isAuth(){return this.code.startsWith("auth_")}get isTransient(){return this.code==="server_error"||this.code==="upstream_error"||this.code==="network_error"||this.code==="rate_limited"}};on=300*1e3});var ee={};te(ee,{emptyState:()=>Z,fetchRemoteState:()=>wt,fuzzyMatch:()=>vt,getLocalStatePath:()=>X,readLocalState:()=>yt,syncRemoteState:()=>bt,writeLocalState:()=>Y});import{existsSync as be,readFileSync as gt,writeFileSync as ft,mkdirSync as ht}from"fs";import{join as ve}from"path";function X(n){return ve(n,".mistflow","state.json")}function yt(n){let e=X(n);if(!be(e))return null;try{return JSON.parse(gt(e,"utf-8"))}catch{return null}}function Y(n,e){let t=ve(n,".mistflow");be(t)||ht(t,{recursive:!0}),ft(X(n),JSON.stringify(e,null,2)+`
24
- `)}function Z(n,e){return{projectId:n,name:e,template:"",features:[],dbSchema:[],deployCount:0,decisions:[],provenance:[]}}async function wt(n){let e;try{e=C()}catch{return null}try{let t=await fetch(`${m()}/api/projects/${encodeURIComponent(n)}/state`,{headers:{...e,"Content-Type":"application/json","X-Mistflow-MCP-Version":x()}});try{R(t.headers)}catch{}return t.ok?await t.json():null}catch{return null}}async function bt(n,e){let t;try{t=C()}catch{return!1}try{let o=await fetch(`${m()}/api/projects/${encodeURIComponent(n)}/state`,{method:"PUT",headers:{...t,"Content-Type":"application/json","X-Mistflow-MCP-Version":x()},body:JSON.stringify(e)});try{R(o.headers)}catch{}return o.ok}catch{return!1}}function vt(n,e){let t=n.toLowerCase(),o=e.toLowerCase();return o.includes(t)||t.includes(o)?!0:t.split(/\s+/).some(s=>s.length>=3&&o.includes(s))}var A=S(()=>{"use strict";E();M()});var Se={};te(Se,{ensureBackendRegistered:()=>Pt,ensureShadcnComponents:()=>jt});import{existsSync as ke,readFileSync as _t,writeFileSync as kt}from"fs";import{join as O}from"path";import{spawn as St}from"child_process";function xt(n,e,t,o,r){return new Promise(s=>{let i=St(n,e,{cwd:t,stdio:["pipe","pipe","pipe"],timeout:o,...r?{env:{...process.env,...r}}:{}}),a="",p="";i.stdout?.on("data",l=>{a+=l.toString()}),i.stderr?.on("data",l=>{p+=l.toString()}),i.on("close",l=>s({success:l===0,stdout:a,stderr:p})),i.on("error",l=>s({success:!1,stdout:a,stderr:p+l.message}))})}function Ct(n){let e=O(n,"mistflow.json");if(!ke(e))return null;try{return JSON.parse(_t(e,"utf-8"))}catch{return null}}function Rt(n,e){kt(O(n,"mistflow.json"),JSON.stringify(e,null,2))}async function _e(n,e){try{let t=e.features,o=e.steps,r={plan:e};Array.isArray(t)&&t.length>0&&(r.features=t.map(s=>s.name)),Array.isArray(o)&&o.length>0&&(r.provenance=o.map(s=>({feature:s.name??s.title??`Step ${s.number??"?"}`,user_intent:(s.description??"").slice(0,500),decisions:"Seeded from plan",tradeoffs:"",files_affected:[]}))),await fetch(`${m()}/api/projects/${encodeURIComponent(n)}/state`,{method:"PUT",headers:{...C(),"Content-Type":"application/json"},body:JSON.stringify(r)})}catch(t){console.error("[self-heal] state sync failed:",t instanceof Error?t.message:String(t))}}async function Pt(n,e={}){let t=Ct(n);if(t){if(!z())return t.projectId;if(!t.projectId)try{let r=t.plan?.requestedSubdomain,s=await me(t.name,void 0,t.dbProvider??"neon",r);return t.projectId=s.id,Rt(n,t),Y(n,Z(s.id,t.name)),t.plan&&await _e(s.id,t.plan),console.error(`[self-heal] registered project ${s.id.slice(0,8)} with backend`),s.id}catch(o){console.error("[self-heal] createProject failed:",o instanceof Error?o.message:String(o));return}return e.forceSync&&t.plan&&t.projectId&&await _e(t.projectId,t.plan),t.projectId}}async function jt(n,e){let t=["button","card","input","label","form","dialog","table","dropdown-menu","badge","separator","skeleton","sheet","tabs","avatar","select","textarea","checkbox","switch","tooltip","popover","sonner"],o=e&&e.length>0?e:t,r=O(n,"components","ui"),s=[],i=[];for(let l of o)ke(O(r,`${l}.tsx`))?s.push(l):i.push(l);if(i.length===0)return{installed:[],alreadyPresent:s};let a={NPM_CONFIG_LEGACY_PEER_DEPS:"true"},p=await xt("npx",["--yes","shadcn@latest","add","-y","-o",...i],n,18e4,a);return p.success?{installed:i,alreadyPresent:s}:{installed:[],alreadyPresent:s,failed:`shadcn add failed for: ${i.join(", ")}. ${p.stderr.slice(-300)}`.trim()}}var xe=S(()=>{"use strict";E();A()});async function $t(){try{return await import("playwright")}catch{throw new Error("Playwright is not installed. Run: cd packages/mcp-server && pnpm add playwright && npx playwright install chromium")}}async function Et(){let n=await $t();return(!v||!v.isConnected())&&(v=await n.chromium.launch({headless:!0})),w&&(await w.close().catch(()=>{}),w=null),w=await v.newContext({viewport:{width:1280,height:720},deviceScaleFactor:1}),f=await w.newPage(),f}async function Te(){return f&&!f.isClosed()?f:(L||(L=Et().finally(()=>{L=null})),L)}async function Ie(){f&&!f.isClosed()&&await f.close().catch(()=>{}),w&&await w.close().catch(()=>{}),v?.isConnected()&&await v.close().catch(()=>{}),f=null,w=null,v=null}async function N(n){return await n.locator("body").ariaSnapshot()}async function q(n,e=!1){return await n.screenshot({fullPage:e,type:"png"})}var v,w,f,L,Ue=S(()=>{"use strict";v=null,w=null,f=null,L=null;process.once("SIGTERM",()=>{Ie().finally(()=>process.exit(0))});process.once("SIGINT",()=>{Ie().finally(()=>process.exit(0))})});import{Server as Ot}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as Lt}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as Nt,ListToolsRequestSchema as qt}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as Ft}from"zod-to-json-schema";M();function c(n,e=!1){let t=n;try{let o=ae();o&&(t=n+o)}catch{}return{content:[{type:"text",text:t}],isError:e}}function le(n){return c(`This is not a Mistflow project (no mistflow.json found at ${n}).
22
+ (Mistflow ${n.latest} is out, you have ${t}. Run \`${o}\` when convenient.)`}var U,f,le,D=S(()=>{"use strict";U=null;f=null;le=!1});import{readFileSync as st,existsSync as fe,writeFileSync as it,mkdirSync as at,renameSync as lt,unlinkSync as ct}from"fs";import{join as ge,dirname as pt}from"path";import{homedir as dt}from"os";import{randomBytes as ut}from"crypto";function he(){return ge(dt(),".mistflow","credentials.json")}function O(){return(process.env.MISTFLOW_API_URL||"https://api.mistflow.ai").replace(/\/+$/,"")}function ye(){let e=he();if(!fe(e))return null;try{let t=JSON.parse(st(e,"utf-8"));return typeof t.apiKey=="string"?{[mt]:t}:t}catch{return null}}function H(){let e=process.env.MISTFLOW_API_KEY;if(e)return{ok:!0,creds:{apiKey:e,orgId:"",orgSlug:"env"}};let t=ye();if(!t)return{ok:!1,reason:"missing"};let n=O(),o=t[n];return o&&typeof o.apiKey=="string"&&o.apiKey&&typeof o.orgId=="string"?{ok:!0,creds:o}:{ok:!1,reason:"missing"}}function K(e){let t=he(),n=pt(t);fe(n)||at(n,{recursive:!0});let o=ye()??{},r=O();o[r]=e;let s=ge(n,`.credentials.tmp.${ut(8).toString("hex")}`);try{it(s,JSON.stringify(o,null,2)+`
23
+ `,{mode:384}),lt(s,t)}catch(i){try{ct(s)}catch{}throw i}}function z(){return H().ok}var mt,G=S(()=>{"use strict";mt="https://api.mistflow.ai"});function m(){return O()}function x(){let e=H();if(!e.ok)throw new u("auth_missing","No Mistflow credentials found.",401);return ft(e.creds)}function ft(e){return{Authorization:`ApiKey ${e.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":R()}}function gt(e){try{C(e.headers)}catch{}}async function ht(e,t,n,o){for(let r=0;r<2;r++)try{return await fetch(e,{...t,signal:AbortSignal.timeout(n)})}catch(s){let i=s instanceof Error&&s.name==="TimeoutError",a=s instanceof TypeError;if(o&&r===0&&(i||a)){console.error(`[api] Retrying ${e} after ${i?"timeout":"network error"}`);continue}throw s}throw new Error("fetchWithRetry: exhausted retries")}async function yt(e){let t=null;try{t=await e.json()}catch{t=null}let n=t&&typeof t.code=="string"?t.code:void 0,o=t&&typeof t.message=="string"?t.message:t&&typeof t.detail=="string"?t.detail:e.statusText||"Request failed";if(n)return new u(n,o,e.status,t?.details);let r=e.status;return r===401?new u("auth_invalid",o,r):r===403?new u("permission_denied",o,r):r===404?new u("not_found",o,r):r===409?new u("conflict",o,r):r===422?new u("validation_error",o,r):r===429?new u("rate_limited",o,r):r>=500?new u("server_error",e.statusText||"Internal server error",r):new u("client_error",o,r)}async function wt(e,t={}){let n=x(),{timeoutMs:o,idempotent:r,...s}=t,i=o??3e4,a=(s.method??"GET").toUpperCase(),p=r??(a==="GET"||a==="HEAD"),l;try{l=await ht(`${m()}${e}`,{...s,headers:{...n,...s.headers}},i,p)}catch(b){throw b instanceof Error&&b.name==="TimeoutError"?new u("network_error","Request timed out. Try again in a moment."):new u("network_error","Cannot reach Mistflow servers. Check your network.")}if(gt(l),!l.ok)throw await yt(l);return l.json()}async function we(e,t,n="neon",o){return wt("/api/projects",{method:"POST",body:JSON.stringify({name:e,template:t,db_provider:n,requested_subdomain:o})})}var u,bn,M=S(()=>{"use strict";G();D();u=class extends Error{constructor(n,o,r,s){super(o);this.code=n;this.statusCode=r;this.details=s;this.name="MistflowApiError"}get isAuth(){return this.code.startsWith("auth_")}get isTransient(){return this.code==="server_error"||this.code==="upstream_error"||this.code==="network_error"||this.code==="rate_limited"}};bn=300*1e3});var ee={};te(ee,{emptyState:()=>Z,fetchRemoteState:()=>Ut,fuzzyMatch:()=>Dt,getLocalStatePath:()=>Y,readLocalState:()=>Tt,syncRemoteState:()=>Et,writeLocalState:()=>X});import{existsSync as Re,readFileSync as Pt,writeFileSync as jt,mkdirSync as It}from"fs";import{join as xe}from"path";function Y(e){return xe(e,".mistflow","state.json")}function Tt(e){let t=Y(e);if(!Re(t))return null;try{return JSON.parse(Pt(t,"utf-8"))}catch{return null}}function X(e,t){let n=xe(e,".mistflow");Re(n)||It(n,{recursive:!0}),jt(Y(e),JSON.stringify(t,null,2)+`
24
+ `)}function Z(e,t){return{projectId:e,name:t,template:"",features:[],dbSchema:[],deployCount:0,decisions:[],provenance:[]}}async function Ut(e){let t;try{t=x()}catch{return null}try{let n=await fetch(`${m()}/api/projects/${encodeURIComponent(e)}/state`,{headers:{...t,"Content-Type":"application/json","X-Mistflow-MCP-Version":R()}});try{C(n.headers)}catch{}return n.ok?await n.json():null}catch{return null}}async function Et(e,t){let n;try{n=x()}catch{return!1}try{let o=await fetch(`${m()}/api/projects/${encodeURIComponent(e)}/state`,{method:"PUT",headers:{...n,"Content-Type":"application/json","X-Mistflow-MCP-Version":R()},body:JSON.stringify(t)});try{C(o.headers)}catch{}return o.ok}catch{return!1}}function Dt(e,t){let n=e.toLowerCase(),o=t.toLowerCase();return o.includes(n)||n.includes(o)?!0:n.split(/\s+/).some(s=>s.length>=3&&o.includes(s))}var L=S(()=>{"use strict";M();D()});var je={};te(je,{ensureBackendRegistered:()=>qt,ensureShadcnComponents:()=>Ft});import{existsSync as Pe,readFileSync as Ot,writeFileSync as Mt}from"fs";import{join as A}from"path";import{spawn as Lt}from"child_process";function At(e,t,n,o,r){return new Promise(s=>{let i=Lt(e,t,{cwd:n,stdio:["pipe","pipe","pipe"],timeout:o,...r?{env:{...process.env,...r}}:{}}),a="",p="";i.stdout?.on("data",l=>{a+=l.toString()}),i.stderr?.on("data",l=>{p+=l.toString()}),i.on("close",l=>s({success:l===0,stdout:a,stderr:p})),i.on("error",l=>s({success:!1,stdout:a,stderr:p+l.message}))})}function $t(e){let t=A(e,"mistflow.json");if(!Pe(t))return null;try{return JSON.parse(Ot(t,"utf-8"))}catch{return null}}function Nt(e,t){Mt(A(e,"mistflow.json"),JSON.stringify(t,null,2))}async function Ce(e,t){try{let n=t.features,o=t.steps,r={plan:t};Array.isArray(n)&&n.length>0&&(r.features=n.map(s=>s.name)),Array.isArray(o)&&o.length>0&&(r.provenance=o.map(s=>({feature:s.name??s.title??`Step ${s.number??"?"}`,user_intent:(s.description??"").slice(0,500),decisions:"Seeded from plan",tradeoffs:"",files_affected:[]}))),await fetch(`${m()}/api/projects/${encodeURIComponent(e)}/state`,{method:"PUT",headers:{...x(),"Content-Type":"application/json"},body:JSON.stringify(r)})}catch(n){console.error("[self-heal] state sync failed:",n instanceof Error?n.message:String(n))}}async function qt(e,t={}){let n=$t(e);if(n){if(!z())return n.projectId;if(!n.projectId)try{let r=n.plan?.requestedSubdomain,s=await we(n.name,void 0,n.dbProvider??"neon",r);return n.projectId=s.id,Nt(e,n),X(e,Z(s.id,n.name)),n.plan&&await Ce(s.id,n.plan),console.error(`[self-heal] registered project ${s.id.slice(0,8)} with backend`),s.id}catch(o){console.error("[self-heal] createProject failed:",o instanceof Error?o.message:String(o));return}return t.forceSync&&n.plan&&n.projectId&&await Ce(n.projectId,n.plan),n.projectId}}async function Ft(e,t){let n=["button","card","input","label","form","dialog","table","dropdown-menu","badge","separator","skeleton","sheet","tabs","avatar","select","textarea","checkbox","switch","tooltip","popover","sonner"],o=t&&t.length>0?t:n,r=A(e,"components","ui"),s=[],i=[];for(let l of o)Pe(A(r,`${l}.tsx`))?s.push(l):i.push(l);if(i.length===0)return{installed:[],alreadyPresent:s};let a={NPM_CONFIG_LEGACY_PEER_DEPS:"true"},p=await At("npx",["--yes","shadcn@latest","add","-y","-o",...i],e,18e4,a);return p.success?{installed:i,alreadyPresent:s}:{installed:[],alreadyPresent:s,failed:`shadcn add failed for: ${i.join(", ")}. ${p.stderr.slice(-300)}`.trim()}}var Ie=S(()=>{"use strict";M();L()});async function Kt(){try{return await import("playwright")}catch{throw new Error("Playwright is not installed. Run: cd packages/mcp-server && pnpm add playwright && npx playwright install chromium")}}async function zt(){let e=await Kt();return(!v||!v.isConnected())&&(v=await e.chromium.launch({headless:!0})),w&&(await w.close().catch(()=>{}),w=null),w=await v.newContext({viewport:{width:1280,height:720},deviceScaleFactor:1}),g=await w.newPage(),g}async function Oe(){return g&&!g.isClosed()?g:($||($=zt().finally(()=>{$=null})),$)}async function Me(){g&&!g.isClosed()&&await g.close().catch(()=>{}),w&&await w.close().catch(()=>{}),v?.isConnected()&&await v.close().catch(()=>{}),g=null,w=null,v=null}async function N(e){return await e.locator("body").ariaSnapshot()}async function q(e,t=!1){return await e.screenshot({fullPage:t,type:"png"})}var v,w,g,$,Le=S(()=>{"use strict";v=null,w=null,g=null,$=null;process.once("SIGTERM",()=>{Me().finally(()=>process.exit(0))});process.once("SIGINT",()=>{Me().finally(()=>process.exit(0))})});import{Server as Qt}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as Yt}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as Xt,ListToolsRequestSchema as Zt}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as en}from"zod-to-json-schema";var Be="When invoking `mist plan` through your shell/bash tool, give it at least a 2 minute budget before assuming it stalled. `mist plan` commonly takes 30-150s. Heavier commands like install/build/qa/deploy can need a longer budget (up to about 5 minutes).",Je='Treat the CLI\'s returned JSON as authoritative. If `mist plan --describe ...` returns `status: "clarify"`, the planning call completed and is waiting on user answers. Do NOT rerun the same command or describe it as "still generating". Only poll again when status is `"design_clarify_pending"`, and then use `mist plan-directions --cid <id> --wait --json`.',We='When submitting discovery answers back to `mist plan --token ... --answers-stdin`, prefer an array payload like `{"answers":[{"question":"...","decisionKey":"...","answer":"..."}]}`. Do NOT collapse answers into a `{decisionKey: answer}` map because multiple discovery questions can share the same decision key.',He="Before scaffolding a NEW app, resolve the destination path explicitly. If the user asked to create/build a new app and the current directory is not already that Mistflow project, ask whether to scaffold in the current folder or a new subfolder here (unless the user already gave a path). Do NOT inspect sibling directories and silently adopt one as the base just because it looks similar. Reuse an existing Mistflow project only when the user explicitly asks to continue/edit that project.",Ke="If `mist plan` fails with a message like `Request to /api/plan timed out after 60s`, the host AI should suspect a stale CLI binary before blaming the backend. Check `mist --version`. If the installed CLI is behind the backend's advertised latest version, run `mist upgrade` (for the self-installed CLI in `~/.mistflow/bin/mist`) or retry with `npx -y @mistflow-ai/cli@latest ...`.",ze="`mist init` is all-or-nothing for normal users: it registers the cloud project first, scaffolds in a temp directory, then moves the finished app into place only after both steps succeed. If auth, quota, or network registration fails, stop before any app appears locally. Do NOT suggest reusing another app unless the user explicitly asks.",Ge="If `mist init` fails, stop before any cloud command and explain why. Do NOT default to reusing some other existing app as recovery unless the user explicitly asked to continue that app.",Qe='IMPORTANT \u2014 chaining discipline: once the user approves the plan, the init \u2192 install \u2192 implement (repeat) \u2192 build \u2192 deploy \u2192 seed (when needed) \u2192 qa chain is expected. Do NOT pause between these calls to ask the user "should I continue?" or offer options like "full build vs step-by-step." The tool itself will return a status requiring user input when it actually needs one (e.g. confirm_new_project, confirm_dark_theme, awaiting promotion). Otherwise, chain calls continuously. Brief one-line status updates are fine and encouraged; permission requests are not.',ne="Connect the user's Mistflow account. Call this ONLY when: (a) the user has literally never signed in, or (b) a previous tool call returned error code 'auth_missing' or 'auth_revoked'. DO NOT call this tool in response to 500 errors, 404 errors, network errors, or any generic failure \u2014 those are backend issues, not auth issues. Running mist_setup when not needed wastes the user's time and creates login fatigue. Once signed in, the MCP persists a long-lived API key and never asks again. Two-phase device code flow: (1) Call without deviceCode \u2014 opens browser, returns status 'pending' with deviceCode and userCode. Tell the user the verification code and that they need to approve in the browser. (2) Call again with deviceCode after ~15 seconds \u2014 polls for approval. Also accepts an apiKey for headless auth (skips device code entirely).",re="Read or update Mistflow project state. 'get' loads plan progress, env vars, and deploy info \u2014 call this at the start of an incremental change so you understand the current app before editing. 'update' marks plan steps complete or adds env vars (note: `mist implement` in the CLI auto-marks the previous step, so manual updates are rarely needed).",oe="Unified browser tool for navigating, interacting with, and capturing the app. Use 'navigate' to open a URL, interaction actions (click/type/fill/etc.) to test flows, 'snapshot' to inspect the accessibility tree, and 'screenshot' for a visual capture. Use after mist_preview to verify UI, test flows, and iterate on design.",se="Returns the Mistflow CLI command reference. Call this ONCE at session start (or whenever you're unsure which tool to use) to learn every `mist` CLI command, when to prefer it over an MCP tool, and how to chain calls. Results are static \u2014 no backend round-trip, safe to call frequently.";function ie(){let e=[];return e.push("Mistflow is a full-stack app builder that creates and deploys web apps from natural language descriptions. When a user asks to build, create, or make a web app, website, landing page, dashboard, internal tool, marketplace, content site, or browser game, use Mistflow tools. Mistflow creates NEW apps from scratch. It does NOT modify existing non-Mistflow codebases."),e.push(""),e.push("Call `mist_help` at any point for the full CLI command reference. The 4 MCP tools handle short, structured, AI-native flows (auth, project state, browser automation, CLI discovery). Everything else is the `mist` CLI \u2014 invoke via your shell/bash tool."),e.push(""),e.push(Be),e.push(""),e.push(Je),e.push(""),e.push(We),e.push(""),e.push(He),e.push(""),e.push(ze),e.push(""),e.push(Ke),e.push(""),e.push("New app workflow (entirely CLI-driven):"),e.push("1. Choose destination: if the user did not already specify a path, ask whether to scaffold in the current folder or a new subfolder here. Resolve the absolute path before `mist init`."),e.push('2. Plan: run `mist plan --describe "<user\'s description>" --json` via your shell/bash tool. Pass the user\'s description EXACTLY as written \u2014 do NOT expand, rephrase, or add features. Relay any returned questions to the user, then submit answers via `echo \'<answers-json>\' | mist plan --token <id> --answers-stdin --json`. When status becomes "design_clarify_pending", poll with `mist plan-directions --cid <id> --wait --json`. When directions are ready, the CLI writes `<cwd>/.mistflow/design-directions.html` with each direction rendered in its own fonts + palette + hero treatment \u2014 run `open "<path>"` for the user so they can see visual options, THEN ask them to pick one by name. The sentinel payload (stderr) includes the `previewPath`. Finalize with `echo \'<pick-json>\' | mist plan --cid <id> --pick-stdin --json`. If the CLI returns status "confirm_new_project" (safety gate when inside an existing codebase), ask the user whether to scaffold a new Mistflow app or edit the existing code.'),e.push("3. Mockup (optional): run `mist mockup --plan-id <id>` via your shell/bash tool \u2014 generates a visual HTML wireframe for user preview. Iterative: pass --feedback to refine, --approved to lock in the design."),e.push("4. Scaffold: run `mist init --plan-id <id> --path <absolute-path>` via your shell/bash tool. `mist init` is transactional: it registers the cloud project first, scaffolds in a temp directory, and only moves the completed app into place after both steps succeed. If it fails before that move, stop and fix the error instead of continuing to cloud commands. Returns fast; does NOT run npm install."),e.push("5. Install dependencies: run `mist install <projectPath>` via your shell/bash tool (streams output)."),e.push("6. Implement: run `mist implement <absolute-path>` via your shell/bash tool \u2014 executes plan steps one at a time. Call repeatedly until all steps are done; it auto-marks the previous step as completed on each call."),e.push("7. Deploy: run `mist deploy [path]` via your shell/bash tool \u2014 tars, uploads, polls status with live streaming. Subcommands: `mist deploy promote` (staging\u2192prod), `mist deploy preview` (local tunnel), `mist deploy rollback <id>`, `mist deploy verify <url>`, `mist deploy redeploy`."),e.push("8. QA: run `mist qa <live-url>` via your shell/bash tool, or just `mist qa` from inside the project if mistflow.json already has deploy.url. Call AFTER deploy. Do NOT show the URL to the user until QA passes."),e.push("9. Seed sample data (optional but recommended before QA when acceptance criteria depend on populated tables/lists): run `mist seed <absolute-path>` via your shell/bash tool. This defaults to local-only seeding against PGlite; use `--allow-remote` only when you intentionally want to seed a remote environment. Use `--reset` to clear the matched tables first."),e.push(""),e.push("Companion CLI (`@mistflow-ai/cli`, invoke as `mist` or via `npx -y @mistflow-ai/cli`) is the primary path for EVERYTHING except the 4 MCP tools below:"),e.push("- `mist plan` / `mist plan-directions` \u2014 plan an app."),e.push("- `mist init` \u2014 scaffold a new project from a plan (fast, ~10s)."),e.push("- `mist install` / `mist build` / `mist mockup` / `mist implement` / `mist debug` / `mist seed` / `mist qa` \u2014 local project lifecycle."),e.push("- `mist deploy` (+ promote/preview/rollback/verify/redeploy subcommands) \u2014 deploy orchestration."),e.push("- `mist status` / `mist fix` \u2014 feature manifest viewer + iteration loop."),e.push("- `mist contracts` \u2014 integration-contract layer management."),e.push("- `mist doctor` \u2014 project health diagnostics."),e.push("- `mist login` / `mist projects` / `mist logs` / `mist env` / `mist domains` / `mist rollback` \u2014 cloud-coordination commands."),e.push("- Call mist_help for the full reference."),e.push(""),e.push(Qe),e.push(""),e.push(Ge),e.push(""),e.push("Design presets (optional, between steps 2 and 3): run `mist projects designs`, `mist projects app-styles`, `mist projects integrations` via your shell/bash tool to browse catalogs. After `mist plan` generates a plan, it may recommend designs and styles \u2014 present these to the user before calling `mist init`."),e.push(""),e.push("Updating an existing Mistflow app:"),e.push("- Cosmetic or single-file changes: edit files directly, then `mist deploy` to publish."),e.push("- New page or feature (no new data model): mist_project action=get for context, build it, then `mist deploy`."),e.push('- Feature needing new data model: ask product questions, call `mist_project action=get` for context, then run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist deploy`.'),e.push('- Integration addition: ask product questions, call `mist_project action=get`, optionally browse `mist projects integrations`, run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist env` to set required keys before deploy, then `mist deploy`, then `mist qa`.'),e.push("- Bug fix: run `mist debug <absolute-path>` to analyze, fix the code, then `mist deploy`."),e.push(""),e.push("Template forking: use the Mistflow dashboard UI (app.mistflow.ai) to fork templates for now. CLI-side template-fork plumbing is in place but the API-client bridge lands in a follow-up release."),e.push(""),e.push("The 4 MCP tools:"),e.push("- mist_setup: authentication. Only call when user has never signed in or a tool returned 'auth_missing'/'auth_revoked'. Do NOT call for 500s, 404s, or network errors. Also accepts an apiKey parameter for headless auth."),e.push("- mist_project: read/write project state (actions: 'get' / 'update'). Other project queries (errors, logs, deployments, share, version, catalog browsing) moved to `mist projects <subcommand>` in the CLI."),e.push("- mist_browser: navigate, interact with, and screenshot the app during preview or after deploy. Returns screenshots inline in tool results \u2014 the one tool that genuinely needs the MCP transport."),e.push("- mist_help: returns the full CLI command reference. Call once per session to learn the available `mist` commands."),e.join(`
25
+ `)}D();function c(e,t=!1){let n=e;try{let o=ue();o&&(n=e+o)}catch{}return{content:[{type:"text",text:n}],isError:t}}function me(e){return c(`This is not a Mistflow project (no mistflow.json found at ${e}).
25
26
 
26
27
  Mistflow creates new projects from scratch \u2014 it doesn't work inside existing codebases.
27
28
 
@@ -30,13 +31,13 @@ To get started:
30
31
  2. Run mist init --plan-id <planId> --path <absolute-path>
31
32
  3. Run mist install <absolute-path>, then mist implement <absolute-path>
32
33
 
33
- If you want to deploy an existing project, use your framework's deploy tools directly.`,!0)}import{z as Q}from"zod";import{platform as it}from"os";import{execFile as ge}from"child_process";E();G();var at=Q.object({apiKey:Q.string().optional().describe("API key (mist_...) for headless auth. Skips the device code flow entirely. Generate one at app.mistflow.ai/mcp-keys."),deviceCode:Q.string().optional().describe("Resume polling for a pending device code. Returned by a previous mist_setup call with status 'pending'. Call mist_setup again with this value after ~15 seconds to check if the user approved.")});function lt(n){return"error"in n}function he(n){return new Promise(e=>setTimeout(e,n))}function ct(n){return new Promise(e=>{let t=it();t==="win32"?ge("cmd.exe",["/c","start","",n],o=>{o&&console.error("Could not open browser:",o.message),e(!o)}):ge(t==="darwin"?"open":"xdg-open",[n],r=>{r&&console.error("Could not open browser:",r.message),e(!r)}),setTimeout(()=>e(!1),5e3)})}var pt={fetch:globalThis.fetch,openBrowser:ct,sleep:he};async function fe(n,e,t,o){let r=t,s=o.sleep??he;for(let i=0;i<e;i++){await s(r);let a;try{let l=await o.fetch(`${m()}/auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:n})});if(!l.ok)continue;a=await l.json()}catch{continue}if(lt(a))switch(a.error){case"authorization_pending":continue;case"slow_down":r+=5e3;continue;case"expired_token":return c("The sign-in link expired. Run mist_setup again to get a new code.",!0);case"access_denied":return c("Sign-in was cancelled. Run mist_setup again to try again.",!0);case"already_exchanged":return c("This sign-in link was already used. Run mist_setup again to get a new code.",!0)}let p=a.email||a.org_name||a.org_slug;return H({apiKey:a.api_key,apiKeyId:a.api_key_id,apiKeyName:a.api_key_name,orgId:a.org_id,orgSlug:a.org_slug,email:a.email}),c(`Connected to Mistflow as ${p}. You are ready to build and deploy.`)}return null}async function dt(n,e=pt){let t=n;if(t?.apiKey)try{let i=await e.fetch(`${m()}/api/org`,{headers:{Authorization:`ApiKey ${t.apiKey}`}});if(!i.ok)return c("Invalid API key. Check the key and try again.",!0);let a=await i.json();return H({apiKey:t.apiKey,orgId:a.id,orgSlug:a.slug}),c(`Connected to Mistflow as ${a.slug} via API key. You are ready to build and deploy.`)}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}if(t?.deviceCode){let i=await fe(t.deviceCode,6,5e3,e);return i||c(JSON.stringify({status:"pending",deviceCode:t.deviceCode,instruction:"The user hasn't approved yet. Wait ~15 seconds and call mist_setup again with the same deviceCode."}))}let o;try{let i=await e.fetch(`${m()}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!i.ok)return c("Cannot reach Mistflow servers. Check your internet connection.",!0);o=await i.json()}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}let r=`${o.verification_uri}?code=${o.user_code}`;console.error(`
34
+ If you want to deploy an existing project, use your framework's deploy tools directly.`,!0)}import{z as Q}from"zod";import{platform as bt}from"os";import{execFile as be}from"child_process";M();G();var vt=Q.object({apiKey:Q.string().optional().describe("API key (mist_...) for headless auth. Skips the device code flow entirely. Generate one at app.mistflow.ai/mcp-keys."),deviceCode:Q.string().optional().describe("Resume polling for a pending device code. Returned by a previous mist_setup call with status 'pending'. Call mist_setup again with this value after ~15 seconds to check if the user approved.")});function _t(e){return"error"in e}function _e(e){return new Promise(t=>setTimeout(t,e))}function kt(e){return new Promise(t=>{let n=bt();n==="win32"?be("cmd.exe",["/c","start","",e],o=>{o&&console.error("Could not open browser:",o.message),t(!o)}):be(n==="darwin"?"open":"xdg-open",[e],r=>{r&&console.error("Could not open browser:",r.message),t(!r)}),setTimeout(()=>t(!1),5e3)})}var St={fetch:globalThis.fetch,openBrowser:kt,sleep:_e};async function ve(e,t,n,o){let r=n,s=o.sleep??_e;for(let i=0;i<t;i++){await s(r);let a;try{let l=await o.fetch(`${m()}/auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:e})});if(!l.ok)continue;a=await l.json()}catch{continue}if(_t(a))switch(a.error){case"authorization_pending":continue;case"slow_down":r+=5e3;continue;case"expired_token":return c("The sign-in link expired. Run mist_setup again to get a new code.",!0);case"access_denied":return c("Sign-in was cancelled. Run mist_setup again to try again.",!0);case"already_exchanged":return c("This sign-in link was already used. Run mist_setup again to get a new code.",!0)}let p=a.email||a.org_name||a.org_slug;return K({apiKey:a.api_key,apiKeyId:a.api_key_id,apiKeyName:a.api_key_name,orgId:a.org_id,orgSlug:a.org_slug,email:a.email}),c(`Connected to Mistflow as ${p}. You are ready to build and deploy.`)}return null}async function Rt(e,t=St){let n=e;if(n?.apiKey)try{let i=await t.fetch(`${m()}/api/org`,{headers:{Authorization:`ApiKey ${n.apiKey}`}});if(!i.ok)return c("Invalid API key. Check the key and try again.",!0);let a=await i.json();return K({apiKey:n.apiKey,orgId:a.id,orgSlug:a.slug}),c(`Connected to Mistflow as ${a.slug} via API key. You are ready to build and deploy.`)}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}if(n?.deviceCode){let i=await ve(n.deviceCode,6,5e3,t);return i||c(JSON.stringify({status:"pending",deviceCode:n.deviceCode,instruction:"The user hasn't approved yet. Wait ~15 seconds and call mist_setup again with the same deviceCode."}))}let o;try{let i=await t.fetch(`${m()}/auth/device`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!i.ok)return c("Cannot reach Mistflow servers. Check your internet connection.",!0);o=await i.json()}catch{return c("Cannot reach Mistflow servers. Check your internet connection.",!0)}let r=`${o.verification_uri}?code=${o.user_code}`;console.error(`
34
35
  Sign in at: ${r}
35
36
  Your code: ${o.user_code}
36
- `);try{await e.openBrowser(r)}catch{}let s=await fe(o.device_code,6,5e3,e);return s||c(JSON.stringify({status:"pending",deviceCode:o.device_code,signInUrl:r,userCode:o.user_code,instruction:"The user hasn't approved yet. Wait ~15 seconds, then call mist_setup again with deviceCode='"+o.device_code+"' to check if they approved."}))}var ye={name:"mist_setup",description:"Connect the user's Mistflow account. Call this ONLY when: (a) the user has literally never signed in, or (b) a previous tool call returned error code 'auth_missing' or 'auth_revoked'. DO NOT call this tool in response to 500 errors, 404 errors, network errors, or any generic failure \u2014 those are backend issues, not auth issues. Running mist_setup when not needed wastes the user's time and creates login fatigue. Once signed in, the MCP persists a long-lived API key and never asks again. Two-phase device code flow: (1) Call without deviceCode \u2014 opens browser, returns status 'pending' with deviceCode and userCode. Tell the user the verification code and that they need to approve in the browser. (2) Call again with deviceCode after ~15 seconds \u2014 polls for approval. Also accepts an apiKey for headless auth (skips device code entirely).",inputSchema:at,handler:n=>dt(n)};import{z as y}from"zod";import{z as h}from"zod";import{resolve as Tt,join as Ce}from"path";import{existsSync as It,readFileSync as Re,writeFileSync as Ut}from"fs";import{existsSync as ut,readFileSync as mt}from"fs";function we(n){let e=new Set;if(!ut(n))return e;let t=mt(n,"utf-8");for(let o of t.split(`
37
- `)){let r=o.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s>0){let i=r.slice(0,s).trim(),a=r.slice(s+1).trim();a&&a!=='""'&&a!=="''"&&e.add(i)}}return e}var Dt=h.object({action:h.enum(["get","update"]).default("get").describe("'get' reads current project state. 'update' modifies it."),projectPath:h.string().optional().describe("Path to the project directory (default: current working directory)"),completedStep:h.number().optional().describe("(update only) Mark a plan step as completed by step number"),addEnvVar:h.object({key:h.string(),description:h.string().optional(),setupUrl:h.string().optional()}).optional().describe("(update only) Add a required env var to the project manifest")}),Pe={name:"mist_state",description:"Read or update project state in mistflow.json. Use action='get' to load plan progress, env var status, and deploy info. Use action='update' to mark plan steps complete or add required env vars. Use when the user says 'mist status', 'mist state', or 'mist update state'.",inputSchema:Dt,handler:async n=>{let e=n,t=Tt(e.projectPath??process.cwd()),o=Ce(t,"mistflow.json");if(!It(o))return le(t);let r;try{r=JSON.parse(Re(o,"utf-8"))}catch{return c("Failed to parse mistflow.json.",!0)}if(e.action==="get"){if(!r.projectId)try{let{ensureBackendRegistered:d}=await Promise.resolve().then(()=>(xe(),Se));await d(t)&&(r=JSON.parse(Re(o,"utf-8")))}catch{}let a=r.plan,p=a?.steps?.filter(d=>d.status==="completed").length??0,l=a?.steps?.length??0,b=we(Ce(t,".env.local")),P=r.env?.required?Object.entries(r.env.required).map(([d,I])=>({name:d,description:I?.description,configured:b.has(d)})):[];r.projectId&&Promise.resolve().then(()=>(A(),ee)).then(({fetchRemoteState:d})=>d(r.projectId)).catch(()=>{});let k=[`Project: ${r.name}`];if(a){k.push(`Plan: ${a.summary??a.name??"unnamed"} \u2014 ${p}/${l} steps complete`);for(let d of a.steps){let I=d.status==="completed"?"\u2713":d.status==="in_progress"?"\u2192":" ";k.push(` [${I}] ${d.number}. ${d.name}`)}}let j=P.filter(d=>!d.configured);j.length>0&&k.push(`Missing env vars: ${j.map(d=>d.name).join(", ")}`),r.deploy?.url?k.push(`Deployed: ${r.deploy.url} (${r.deploy.count??0} deploys)`):k.push("Not deployed yet");let T=[],V=a?.steps?.find(d=>d.status!=="completed");return V?T.push(`NEXT: Run mist implement <absolute-path> to work on step ${V.number} (${V.name}).`):a&&p===l&&(r.deploy?.url||T.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT ask the user \u2014 just deploy.")),j.length>0&&T.push(`Missing env vars in .env.local: ${j.map(d=>d.name).join(", ")}`),c(JSON.stringify({name:r.name,projectId:r.projectId,planProgress:a?{name:a.name,summary:a.summary,totalSteps:l,completedSteps:p,steps:a.steps}:null,envStatus:P,deploy:r.deploy??null,contextMessage:k.join(`
38
- `),nextSteps:T}))}let s=[];if(e.completedStep!==void 0){let a=r.plan;if(a?.steps){let p=a.steps.findIndex(l=>l.number===e.completedStep);if(p===-1)return c(`Step ${e.completedStep} not found in the plan.`,!0);a.steps[p].status="completed",s.push(`Step ${e.completedStep} marked as completed`)}}e.addEnvVar&&(r.env||(r.env={required:{}}),r.env.required||(r.env.required={}),r.env.required[e.addEnvVar.key]={description:e.addEnvVar.description,setupUrl:e.addEnvVar.setupUrl},s.push(`Added required env var: ${e.addEnvVar.key}`)),Ut(o,JSON.stringify(r,null,2)+`
39
- `),r.projectId&&Promise.resolve().then(()=>(A(),ee)).then(async({readLocalState:a,syncRemoteState:p})=>{let l=a(t);l&&await p(r.projectId,l)}).catch(()=>{});let i=[];if(e.completedStep!==void 0){let p=r.plan?.steps?.find(l=>l.status!=="completed");p?i.push(`NEXT: Run mist implement <absolute-path> to work on step ${p.number} (${p.name}). Do this now.`):i.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT suggest localhost.")}return e.addEnvVar&&(i.push(`Add ${e.addEnvVar.key} to your .env.local file`),e.addEnvVar.setupUrl&&i.push(`Get the value from: ${e.addEnvVar.setupUrl}`)),c(JSON.stringify({updated:!0,changes:s,message:s.length>0?`Project state saved. ${s.join(". ")}.`:"No changes made.",nextSteps:i.length>0?i:void 0}))}};var Mt=y.object({action:y.enum(["get","update"]).default("get").describe("'get' reads current project state (context oracle \u2014 call before making decisions in an existing project). 'update' marks steps complete or adds env vars. All other project queries moved to the CLI in MCP 0.6.0: `mist projects share`, `mist projects errors`, `mist projects logs`, `mist projects deployments`, `mist projects version`, `mist projects designs`, `mist projects app-styles`, `mist projects integrations`."),projectPath:y.string().optional().describe("Path to the project directory (default: cwd)"),completedStep:y.number().optional().describe("(update) Mark a plan step as completed by step number"),addEnvVar:y.object({key:y.string(),description:y.string().optional(),setupUrl:y.string().optional()}).optional().describe("(update) Add a required env var to the project manifest")}),je={name:"mist_project",description:"Read or update Mistflow project state. 'get' loads plan progress, env vars, and deploy info \u2014 call this at the start of an incremental change so you understand the current app before editing. 'update' marks plan steps complete or adds env vars (note: `mist implement` in the CLI auto-marks the previous step, so manual updates are rarely needed).",inputSchema:Mt,handler:async n=>{let e=n;return Pe.handler({action:e.action,projectPath:e.projectPath,completedStep:e.completedStep,addEnvVar:e.addEnvVar})}};import{z as _}from"zod";Ue();var At=_.object({action:_.enum(["navigate","go_back","go_forward","click","type","fill","select_option","press_key","hover","screenshot","snapshot"]).describe("Action to perform. Navigation: navigate|go_back|go_forward. Interaction: click|type|fill|select_option|press_key|hover. Visual: screenshot (returns image) | snapshot (returns accessibility tree)."),url:_.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:_.string().optional().describe("CSS selector of the target element. Required for: click, type, fill, select_option, hover. Optional for screenshot (captures just that element)."),value:_.string().optional().describe("Text to type/fill, option to select, or key to press (e.g. 'Enter', 'Tab'). Required for: type, fill, select_option, press_key."),fullPage:_.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:_.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),De={name:"mist_browser",description:"Unified browser tool for navigating, interacting with, and capturing the app. Use 'navigate' to open a URL, interaction actions (click/type/fill/etc.) to test flows, 'snapshot' to inspect the accessibility tree, and 'screenshot' for a visual capture. Use after mist_preview to verify UI, test flows, and iterate on design.",inputSchema:At,handler:async n=>{let e=n,t=await Te();if(e.action==="navigate"){if(!e.url)return c("URL is required for 'navigate'.",!0);let s=[],i=l=>{l.type()==="error"&&s.push(l.text())};t.on("console",i),await t.goto(e.url,{waitUntil:"domcontentloaded",timeout:3e4}),await t.waitForLoadState("networkidle").catch(()=>{});let a=[],p=l=>a.push(l.message);if(t.on("pageerror",p),await t.waitForTimeout(500),t.removeListener("console",i),t.removeListener("pageerror",p),s.length>0||a.length>0){let l=await N(t),b=[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:l,consoleErrors:s,pageErrors:a,hasErrors:!0})}];if(e.includeScreenshot){let P=await q(t);b.push({type:"image",data:P.toString("base64"),mimeType:"image/png"})}return{content:b}}}else if(e.action==="go_back")await t.goBack({waitUntil:"domcontentloaded",timeout:1e4});else if(e.action==="go_forward")await t.goForward({waitUntil:"domcontentloaded",timeout:1e4});else if(e.action==="click"){if(!e.selector)return c("Selector is required for 'click'.",!0);await t.click(e.selector,{timeout:1e4}),await t.waitForLoadState("domcontentloaded").catch(()=>{}),await t.waitForTimeout(500)}else if(e.action==="type"){if(!e.selector)return c("Selector is required for 'type'.",!0);if(!e.value)return c("Value is required for 'type'.",!0);await t.type(e.selector,e.value,{delay:50})}else if(e.action==="fill"){if(!e.selector)return c("Selector is required for 'fill'.",!0);if(!e.value)return c("Value is required for 'fill'.",!0);await t.fill(e.selector,e.value)}else if(e.action==="select_option"){if(!e.selector)return c("Selector is required for 'select_option'.",!0);if(!e.value)return c("Value is required for 'select_option'.",!0);await t.selectOption(e.selector,e.value)}else if(e.action==="hover"){if(!e.selector)return c("Selector is required for 'hover'.",!0);await t.hover(e.selector,{timeout:1e4})}else if(e.action==="press_key"){if(!e.value)return c("Value is required for 'press_key' (e.g. 'Enter').",!0);await t.keyboard.press(e.value),await t.waitForLoadState("domcontentloaded").catch(()=>{}),await t.waitForTimeout(500)}else if(e.action==="screenshot"){e.url&&(await t.goto(e.url,{waitUntil:"domcontentloaded",timeout:3e4}),await t.waitForLoadState("networkidle").catch(()=>{}));let s;if(e.selector){let i=await t.$(e.selector);if(!i)return c(`Element not found: ${e.selector}`,!0);s=await i.screenshot({type:"png"})}else s=await q(t,e.fullPage);return{content:[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),message:`Screenshot captured (${e.fullPage?"full page":"viewport"})`})},{type:"image",data:s.toString("base64"),mimeType:"image/png"}]}}else if(e.action==="snapshot"){let s=await N(t);return{content:[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:s})}]}}let o=await N(t),r=[{type:"text",text:JSON.stringify({url:t.url(),title:await t.title(),snapshot:o})}];if(e.includeScreenshot){let s=await q(t);r.push({type:"image",data:s.toString("base64"),mimeType:"image/png"})}return{content:r}}};import{z as Me}from"zod";var $e=`# Mistflow CLI reference
37
+ `);try{await t.openBrowser(r)}catch{}let s=await ve(o.device_code,6,5e3,t);return s||c(JSON.stringify({status:"pending",deviceCode:o.device_code,signInUrl:r,userCode:o.user_code,instruction:"The user hasn't approved yet. Wait ~15 seconds, then call mist_setup again with deviceCode='"+o.device_code+"' to check if they approved."}))}var ke={name:"mist_setup",description:ne,inputSchema:vt,handler:e=>Rt(e)};import{z as y}from"zod";import{z as h}from"zod";import{resolve as Vt,join as Te}from"path";import{existsSync as Bt,readFileSync as Ue,writeFileSync as Jt}from"fs";import{existsSync as xt,readFileSync as Ct}from"fs";function Se(e){let t=new Set;if(!xt(e))return t;let n=Ct(e,"utf-8");for(let o of n.split(`
38
+ `)){let r=o.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s>0){let i=r.slice(0,s).trim(),a=r.slice(s+1).trim();a&&a!=='""'&&a!=="''"&&t.add(i)}}return t}var Wt=h.object({action:h.enum(["get","update"]).default("get").describe("'get' reads current project state. 'update' modifies it."),projectPath:h.string().optional().describe("Path to the project directory (default: current working directory)"),completedStep:h.number().optional().describe("(update only) Mark a plan step as completed by step number"),addEnvVar:h.object({key:h.string(),description:h.string().optional(),setupUrl:h.string().optional()}).optional().describe("(update only) Add a required env var to the project manifest")}),Ee={name:"mist_state",description:"Read or update project state in mistflow.json. Use action='get' to load plan progress, env var status, and deploy info. Use action='update' to mark plan steps complete or add required env vars. Use when the user says 'mist status', 'mist state', or 'mist update state'.",inputSchema:Wt,handler:async e=>{let t=e,n=Vt(t.projectPath??process.cwd()),o=Te(n,"mistflow.json");if(!Bt(o))return me(n);let r;try{r=JSON.parse(Ue(o,"utf-8"))}catch{return c("Failed to parse mistflow.json.",!0)}if(t.action==="get"){if(!r.projectId)try{let{ensureBackendRegistered:d}=await Promise.resolve().then(()=>(Ie(),je));await d(n)&&(r=JSON.parse(Ue(o,"utf-8")))}catch{}let a=r.plan,p=a?.steps?.filter(d=>d.status==="completed").length??0,l=a?.steps?.length??0,b=Se(Te(n,".env.local")),P=r.env?.required?Object.entries(r.env.required).map(([d,T])=>({name:d,description:T?.description,configured:b.has(d)})):[];r.projectId&&Promise.resolve().then(()=>(L(),ee)).then(({fetchRemoteState:d})=>d(r.projectId)).catch(()=>{});let k=[`Project: ${r.name}`];if(a){k.push(`Plan: ${a.summary??a.name??"unnamed"} \u2014 ${p}/${l} steps complete`);for(let d of a.steps){let T=d.status==="completed"?"\u2713":d.status==="in_progress"?"\u2192":" ";k.push(` [${T}] ${d.number}. ${d.name}`)}}let j=P.filter(d=>!d.configured);j.length>0&&k.push(`Missing env vars: ${j.map(d=>d.name).join(", ")}`),r.deploy?.url?k.push(`Deployed: ${r.deploy.url} (${r.deploy.count??0} deploys)`):k.push("Not deployed yet");let I=[],V=a?.steps?.find(d=>d.status!=="completed");return V?I.push(`NEXT: Run mist implement <absolute-path> to work on step ${V.number} (${V.name}).`):a&&p===l&&(r.deploy?.url||I.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT ask the user \u2014 just deploy.")),j.length>0&&I.push(`Missing env vars in .env.local: ${j.map(d=>d.name).join(", ")}`),c(JSON.stringify({name:r.name,projectId:r.projectId,planProgress:a?{name:a.name,summary:a.summary,totalSteps:l,completedSteps:p,steps:a.steps}:null,envStatus:P,deploy:r.deploy??null,contextMessage:k.join(`
39
+ `),nextSteps:I}))}let s=[];if(t.completedStep!==void 0){let a=r.plan;if(a?.steps){let p=a.steps.findIndex(l=>l.number===t.completedStep);if(p===-1)return c(`Step ${t.completedStep} not found in the plan.`,!0);a.steps[p].status="completed",s.push(`Step ${t.completedStep} marked as completed`)}}t.addEnvVar&&(r.env||(r.env={required:{}}),r.env.required||(r.env.required={}),r.env.required[t.addEnvVar.key]={description:t.addEnvVar.description,setupUrl:t.addEnvVar.setupUrl},s.push(`Added required env var: ${t.addEnvVar.key}`)),Jt(o,JSON.stringify(r,null,2)+`
40
+ `),r.projectId&&Promise.resolve().then(()=>(L(),ee)).then(async({readLocalState:a,syncRemoteState:p})=>{let l=a(n);l&&await p(r.projectId,l)}).catch(()=>{});let i=[];if(t.completedStep!==void 0){let p=r.plan?.steps?.find(l=>l.status!=="completed");p?i.push(`NEXT: Run mist implement <absolute-path> to work on step ${p.number} (${p.name}). Do this now.`):i.push("NEXT: All steps complete! Run mist deploy <absolute-path> to deploy the app now. Do NOT suggest localhost.")}return t.addEnvVar&&(i.push(`Add ${t.addEnvVar.key} to your .env.local file`),t.addEnvVar.setupUrl&&i.push(`Get the value from: ${t.addEnvVar.setupUrl}`)),c(JSON.stringify({updated:!0,changes:s,message:s.length>0?`Project state saved. ${s.join(". ")}.`:"No changes made.",nextSteps:i.length>0?i:void 0}))}};var Ht=y.object({action:y.enum(["get","update"]).default("get").describe("'get' reads current project state (context oracle \u2014 call before making decisions in an existing project). 'update' marks steps complete or adds env vars. All other project queries moved to the CLI in MCP 0.6.0: `mist projects share`, `mist projects errors`, `mist projects logs`, `mist projects deployments`, `mist projects version`, `mist projects designs`, `mist projects app-styles`, `mist projects integrations`."),projectPath:y.string().optional().describe("Path to the project directory (default: cwd)"),completedStep:y.number().optional().describe("(update) Mark a plan step as completed by step number"),addEnvVar:y.object({key:y.string(),description:y.string().optional(),setupUrl:y.string().optional()}).optional().describe("(update) Add a required env var to the project manifest")}),De={name:"mist_project",description:re,inputSchema:Ht,handler:async e=>{let t=e;return Ee.handler({action:t.action,projectPath:t.projectPath,completedStep:t.completedStep,addEnvVar:t.addEnvVar})}};import{z as _}from"zod";Le();var Gt=_.object({action:_.enum(["navigate","go_back","go_forward","click","type","fill","select_option","press_key","hover","screenshot","snapshot"]).describe("Action to perform. Navigation: navigate|go_back|go_forward. Interaction: click|type|fill|select_option|press_key|hover. Visual: screenshot (returns image) | snapshot (returns accessibility tree)."),url:_.string().optional().describe("URL to navigate to. Required for 'navigate'; optional for 'screenshot' (navigates before capturing)."),selector:_.string().optional().describe("CSS selector of the target element. Required for: click, type, fill, select_option, hover. Optional for screenshot (captures just that element)."),value:_.string().optional().describe("Text to type/fill, option to select, or key to press (e.g. 'Enter', 'Tab'). Required for: type, fill, select_option, press_key."),fullPage:_.boolean().default(!1).describe("For 'screenshot': capture the full scrollable page instead of just the viewport."),includeScreenshot:_.boolean().default(!1).describe("For navigate/interact actions: also return a screenshot alongside the accessibility snapshot.")}),Ae={name:"mist_browser",description:oe,inputSchema:Gt,handler:async e=>{let t=e,n=await Oe();if(t.action==="navigate"){if(!t.url)return c("URL is required for 'navigate'.",!0);let s=[],i=l=>{l.type()==="error"&&s.push(l.text())};n.on("console",i),await n.goto(t.url,{waitUntil:"domcontentloaded",timeout:3e4}),await n.waitForLoadState("networkidle").catch(()=>{});let a=[],p=l=>a.push(l.message);if(n.on("pageerror",p),await n.waitForTimeout(500),n.removeListener("console",i),n.removeListener("pageerror",p),s.length>0||a.length>0){let l=await N(n),b=[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),snapshot:l,consoleErrors:s,pageErrors:a,hasErrors:!0})}];if(t.includeScreenshot){let P=await q(n);b.push({type:"image",data:P.toString("base64"),mimeType:"image/png"})}return{content:b}}}else if(t.action==="go_back")await n.goBack({waitUntil:"domcontentloaded",timeout:1e4});else if(t.action==="go_forward")await n.goForward({waitUntil:"domcontentloaded",timeout:1e4});else if(t.action==="click"){if(!t.selector)return c("Selector is required for 'click'.",!0);await n.click(t.selector,{timeout:1e4}),await n.waitForLoadState("domcontentloaded").catch(()=>{}),await n.waitForTimeout(500)}else if(t.action==="type"){if(!t.selector)return c("Selector is required for 'type'.",!0);if(!t.value)return c("Value is required for 'type'.",!0);await n.type(t.selector,t.value,{delay:50})}else if(t.action==="fill"){if(!t.selector)return c("Selector is required for 'fill'.",!0);if(!t.value)return c("Value is required for 'fill'.",!0);await n.fill(t.selector,t.value)}else if(t.action==="select_option"){if(!t.selector)return c("Selector is required for 'select_option'.",!0);if(!t.value)return c("Value is required for 'select_option'.",!0);await n.selectOption(t.selector,t.value)}else if(t.action==="hover"){if(!t.selector)return c("Selector is required for 'hover'.",!0);await n.hover(t.selector,{timeout:1e4})}else if(t.action==="press_key"){if(!t.value)return c("Value is required for 'press_key' (e.g. 'Enter').",!0);await n.keyboard.press(t.value),await n.waitForLoadState("domcontentloaded").catch(()=>{}),await n.waitForTimeout(500)}else if(t.action==="screenshot"){t.url&&(await n.goto(t.url,{waitUntil:"domcontentloaded",timeout:3e4}),await n.waitForLoadState("networkidle").catch(()=>{}));let s;if(t.selector){let i=await n.$(t.selector);if(!i)return c(`Element not found: ${t.selector}`,!0);s=await i.screenshot({type:"png"})}else s=await q(n,t.fullPage);return{content:[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),message:`Screenshot captured (${t.fullPage?"full page":"viewport"})`})},{type:"image",data:s.toString("base64"),mimeType:"image/png"}]}}else if(t.action==="snapshot"){let s=await N(n);return{content:[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),snapshot:s})}]}}let o=await N(n),r=[{type:"text",text:JSON.stringify({url:n.url(),title:await n.title(),snapshot:o})}];if(t.includeScreenshot){let s=await q(n);r.push({type:"image",data:s.toString("base64"),mimeType:"image/png"})}return{content:r}}};import{z as $e}from"zod";var Ne=`# Mistflow CLI reference
40
41
 
41
42
  The Mistflow CLI handles local execution and long-running operations that
42
43
  would hit the MCP 60s tool-call ceiling. Every command below is invokable
@@ -48,6 +49,10 @@ Or, if the user has installed the CLI globally:
48
49
 
49
50
  mist <command> [...args]
50
51
 
52
+ Never add \`@mistflow-ai/cli\` to the app's package.json. It is a standalone
53
+ companion CLI, not an app dependency. Local installs create
54
+ \`node_modules/.bin/mist\` shims and can drift from the machine-level CLI.
55
+
51
56
  Pass \`--json\` to any command to get a structured JSON response on stdout
52
57
  (progress / info goes to stderr). Errors exit non-zero with a message on
53
58
  stderr.
@@ -66,6 +71,27 @@ that planning is still running. Only poll again when the status is
66
71
  \`"design_clarify_pending"\`, and then use \`mist plan-directions\`. Let the
67
72
  user answer the questions, then submit those answers exactly once.
68
73
 
74
+ Before scaffolding a NEW app, resolve the destination path explicitly. If
75
+ the user asked to create/build a new app and the current directory is not
76
+ already that Mistflow project, ask whether to scaffold in the current
77
+ folder or a new subfolder here (unless the user already gave a path). Do
78
+ NOT inspect sibling directories and silently adopt one as the base just
79
+ because it looks similar. Reuse an existing Mistflow project only when the
80
+ user explicitly asks to continue/edit that project.
81
+
82
+ \`mist init\` is all-or-nothing for normal users: it registers the cloud
83
+ project first, scaffolds in a temp directory, then moves the app into place
84
+ only after both steps succeed. If auth, quota, or network registration
85
+ fails, stop before any app appears locally. Do NOT default to reusing some
86
+ other existing app as recovery unless the user explicitly asked to continue
87
+ that app.
88
+
89
+ If \`mist plan\` fails with a message like \`Request to /api/plan timed out
90
+ after 60s\`, suspect a stale CLI binary before blaming the backend. Check
91
+ \`mist --version\`. If the installed CLI is behind the backend's advertised
92
+ latest version, run \`mist upgrade\` (for the self-installed CLI in
93
+ \`~/.mistflow/bin/mist\`) or retry with \`npx -y @mistflow-ai/cli@latest ...\`.
94
+
69
95
  ## Commands
70
96
 
71
97
  ### \`mist plan --describe "<description>" [--json]\`
@@ -109,6 +135,8 @@ min) until ready or failed.
109
135
 
110
136
  ### \`mist init --plan-id <planId> --path <absolute-path> [--json]\`
111
137
  Scaffold a fresh Mistflow app from a cached plan. Fast and fully CLI-driven.
138
+ Registers the cloud project first, scaffolds in a temp directory, then
139
+ moves the finished app into place only after both steps succeed.
112
140
 
113
141
  ### \`mist mockup --plan-id <planId> [--json]\`
114
142
  Generate or iterate on a grayscale HTML wireframe before scaffolding. Use
@@ -156,16 +184,22 @@ exceed 30s or streams useful progress.
156
184
  The AI reads each CLI response's \`status\` field on stdout (with \`--json\`)
157
185
  and decides the next command. Example end-to-end chain:
158
186
 
187
+ # First, if the user did not specify a destination path, ask whether
188
+ # the app should be created in the current folder or a new subfolder.
159
189
  mist plan --describe "habit tracker" --json
160
190
  # \u2192 {"status":"clarify","conversation_id":"...","questions":[...]}
161
191
  # AI asks user, gets answers, then:
162
192
  echo '{...}' | mist plan --token ... --answers-stdin --json
163
193
  # \u2192 {"status":"design_clarify_pending","design_conversation_id":"..."}
164
194
  mist plan-directions --cid ... --wait --json
165
- # \u2192 {"status":"ready","directions":[...]}
166
- # AI shows picker, user picks, then:
195
+ # \u2192 {"status":"ready","directions":[...], previewPath in sentinel}
196
+ # CLI writes <cwd>/.mistflow/design-directions.html with per-direction
197
+ # fonts/colors/hero \u2014 open it for the user, then show picker.
167
198
  echo '{...}' | mist plan --cid ... --pick-stdin --json
168
199
  # \u2192 {"status":"ready","plan":{...}}
200
+ # Optional but recommended: show a wireframe before scaffolding.
201
+ mist mockup --plan-id ... --json
202
+ # \u2192 AI writes mockup HTML, opens it, asks user to approve.
169
203
  mist init --plan-id ... --path /Users/you/projects/habit-tracker --json
170
204
  mist install /Users/you/projects/habit-tracker --json
171
205
  mist implement /Users/you/projects/habit-tracker --json
@@ -173,6 +207,6 @@ and decides the next command. Example end-to-end chain:
173
207
  mist deploy /Users/you/projects/habit-tracker --json
174
208
  mist seed /Users/you/projects/habit-tracker --json
175
209
  mist qa https://your-app.mistflow.app --json
176
- `,Ee={name:"mist_help",description:"Returns the Mistflow CLI command reference. Call this ONCE at session start (or whenever you're unsure which tool to use) to learn every `mist` CLI command, when to prefer it over an MCP tool, and how to chain calls. Results are static \u2014 no backend round-trip, safe to call frequently.",inputSchema:Me.object({command:Me.string().optional().describe("Optional: name of a specific command to get focused reference for. Omit to get the full catalog.")}),handler:async n=>{let{command:e}=n;if(!e)return c($e);let t=$e.split(`
177
- `),o=new RegExp(`^### \`mist ${e}`),r=-1,s=t.length;for(let i=0;i<t.length;i++)if(o.test(t[i]))r=i;else if(r>=0&&t[i].startsWith("### ")){s=i;break}else if(r>=0&&t[i].startsWith("## ")&&i>r){s=i;break}return r<0?c(`No command named '${e}' found. Call mist_help with no args to see the full catalog.`,!0):c(t.slice(r,s).join(`
178
- `).trim())}};var F=new Ot({name:"mistflow",version:"0.3.0"},{capabilities:{tools:{}},instructions:'Mistflow is a full-stack app builder that creates and deploys web apps from natural language descriptions. When a user asks to build, create, or make a web app, website, landing page, dashboard, internal tool, marketplace, content site, or browser game, use Mistflow tools. Mistflow creates NEW apps from scratch. It does NOT modify existing non-Mistflow codebases.\n\nCall `mist_help` at any point for the full CLI command reference. The 4 MCP tools handle short, structured, AI-native flows (auth, project state, browser automation, CLI discovery). Everything else is the `mist` CLI \u2014 invoke via your shell/bash tool.\n\nWhen invoking `mist plan` through your shell/bash tool, give it at least a 2 minute budget before assuming it stalled. `mist plan` commonly takes 30-150s. Heavier commands like install/build/qa/deploy can need a longer budget (up to about 5 minutes).\n\nTreat the CLI\'s returned JSON as authoritative. If `mist plan --describe ...` returns `status: "clarify"`, the planning call completed and is waiting on user answers. Do NOT rerun the same command or describe it as "still generating". Only poll again when status is `"design_clarify_pending"`, and then use `mist plan-directions --cid <id> --wait --json`.\n\nWhen submitting discovery answers back to `mist plan --token ... --answers-stdin`, prefer an array payload like `{"answers":[{"question":"...","decisionKey":"...","answer":"..."}]}`. Do NOT collapse answers into a `{decisionKey: answer}` map because multiple discovery questions can share the same decision key.\n\nNew app workflow (entirely CLI-driven):\n1. Plan: run `mist plan --describe "<user\'s description>" --json` via your shell/bash tool. Pass the user\'s description EXACTLY as written \u2014 do NOT expand, rephrase, or add features. Relay any returned questions to the user, then submit answers via `echo \'<answers-json>\' | mist plan --token <id> --answers-stdin --json`. When status becomes "design_clarify_pending", poll with `mist plan-directions --cid <id> --wait --json`. Present the directions picker, then finalize with `echo \'<pick-json>\' | mist plan --cid <id> --pick-stdin --json`. If the CLI returns status "confirm_new_project" (safety gate when inside an existing codebase), ask the user whether to scaffold a new Mistflow app or edit the existing code.\n2. Mockup (optional): run `mist mockup --plan-id <id>` via your shell/bash tool \u2014 generates a visual HTML wireframe for user preview. Iterative: pass --feedback to refine, --approved to lock in the design.\n3. Scaffold: run `mist init --plan-id <id> --path <absolute-path>` via your shell/bash tool. Writes the Next.js scaffold, contracts/, AGENTS.md, and registers the project with Mistflow. Returns fast; does NOT run npm install.\n4. Install dependencies: run `mist install <projectPath>` via your shell/bash tool (streams output).\n5. Implement: run `mist implement <absolute-path>` via your shell/bash tool \u2014 executes plan steps one at a time. Call repeatedly until all steps are done; it auto-marks the previous step as completed on each call.\n6. Deploy: run `mist deploy [path]` via your shell/bash tool \u2014 tars, uploads, polls status with live streaming. Subcommands: `mist deploy promote` (staging\u2192prod), `mist deploy preview` (local tunnel), `mist deploy rollback <id>`, `mist deploy verify <url>`, `mist deploy redeploy`.\n7. QA: run `mist qa <live-url>` via your shell/bash tool, or just `mist qa` from inside the project if mistflow.json already has deploy.url. Call AFTER deploy. Do NOT show the URL to the user until QA passes.\n8. Seed sample data (optional but recommended before QA when acceptance criteria depend on populated tables/lists): run `mist seed <absolute-path>` via your shell/bash tool. This defaults to local-only seeding against PGlite; use `--allow-remote` only when you intentionally want to seed a remote environment. Use `--reset` to clear the matched tables first.\n\nCompanion CLI (`@mistflow-ai/cli`, invoke as `mist` or via `npx -y @mistflow-ai/cli`) is the primary path for EVERYTHING except the 4 MCP tools below:\n- `mist plan` / `mist plan-directions` \u2014 plan an app.\n- `mist init` \u2014 scaffold a new project from a plan (fast, ~10s).\n- `mist install` / `mist build` / `mist mockup` / `mist implement` / `mist debug` / `mist seed` / `mist qa` \u2014 local project lifecycle.\n- `mist deploy` (+ promote/preview/rollback/verify/redeploy subcommands) \u2014 deploy orchestration.\n- `mist status` / `mist fix` \u2014 feature manifest viewer + iteration loop.\n- `mist contracts` \u2014 integration-contract layer management.\n- `mist doctor` \u2014 project health diagnostics.\n- `mist login` / `mist projects` / `mist logs` / `mist env` / `mist domains` / `mist rollback` \u2014 cloud-coordination commands.\n- Call mist_help for the full reference.\n\nIMPORTANT \u2014 chaining discipline: once the user approves the plan, the init \u2192 install \u2192 implement (repeat) \u2192 build \u2192 deploy \u2192 seed (when needed) \u2192 qa chain is expected. Do NOT pause between these calls to ask the user "should I continue?" or offer options like "full build vs step-by-step." The tool itself will return a status requiring user input when it actually needs one (e.g. confirm_new_project, confirm_dark_theme, awaiting promotion). Otherwise, chain calls continuously. Brief one-line status updates are fine and encouraged; permission requests are not.\n\nDesign presets (optional, between steps 2 and 3): run `mist projects designs`, `mist projects app-styles`, `mist projects integrations` via your shell/bash tool to browse catalogs. After `mist plan` generates a plan, it may recommend designs and styles \u2014 present these to the user before calling `mist init`.\n\nUpdating an existing Mistflow app:\n- Cosmetic or single-file changes: edit files directly, then `mist deploy` to publish.\n- New page or feature (no new data model): mist_project action=get for context, build it, then `mist deploy`.\n- Feature needing new data model: ask product questions, call `mist_project action=get` for context, then run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist deploy`.\n- Integration addition: ask product questions, call `mist_project action=get`, optionally browse `mist projects integrations`, run `mist plan --describe "<change request>" --existing-plan-id <id>`, then `mist implement`, then `mist env` to set required keys before deploy, then `mist deploy`, then `mist qa`.\n- Bug fix: run `mist debug <absolute-path>` to analyze, fix the code, then `mist deploy`.\n\nTemplate forking: use the Mistflow dashboard UI (app.mistflow.ai) to fork templates for now. CLI-side template-fork plumbing is in place but the API-client bridge lands in a follow-up release.\n\nThe 4 MCP tools:\n- mist_setup: authentication. Only call when user has never signed in or a tool returned \'auth_missing\'/\'auth_revoked\'. Do NOT call for 500s, 404s, or network errors. Also accepts an apiKey parameter for headless auth.\n- mist_project: read/write project state (actions: \'get\' / \'update\'). Other project queries (errors, logs, deployments, share, version, catalog browsing) moved to `mist projects <subcommand>` in the CLI.\n- mist_browser: navigate, interact with, and screenshot the app during preview or after deploy. Returns screenshots inline in tool results \u2014 the one tool that genuinely needs the MCP transport.\n- mist_help: returns the full CLI command reference. Call once per session to learn the available `mist` commands.'}),Ae=[ye,je,De,Ee];F.setRequestHandler(qt,async()=>({tools:Ae.map(n=>({name:n.name,description:n.description,inputSchema:Ft(n.inputSchema)}))}));F.setRequestHandler(Nt,async n=>{let e=Ae.find(t=>t.name===n.params.name);if(!e)return c(`Unknown tool: ${n.params.name}`,!0);try{let t=e.inputSchema.safeParse(n.params.arguments);if(!t.success){let s=t.error.issues.map(i=>`${i.path.join(".")}: ${i.message}`).join(", ");return c(`Invalid input: ${s}`,!0)}let o=n.params._meta?.progressToken,r={server:F,progressToken:o};try{return await e.handler(t.data,r)}finally{r.cleanup?.()}}catch(t){let o=t instanceof Error?t.message:"An unexpected error occurred";return console.error("Tool error:",t),c(o,!0)}});async function Vt(){let n=process.argv.indexOf("--api-url");n!==-1&&process.argv[n+1]&&(process.env.MISTFLOW_API_URL=process.argv[n+1]),process.argv.includes("--local")&&!process.env.MISTFLOW_API_URL&&(process.env.MISTFLOW_API_URL="http://localhost:9100");let e=new Lt;await F.connect(e),console.error(`Mistflow MCP server running on stdio (API: ${process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"})`)}Vt().catch(n=>{console.error("Fatal error:",n),process.exit(1)});
210
+ `,qe={name:"mist_help",description:se,inputSchema:$e.object({command:$e.string().optional().describe("Optional: name of a specific command to get focused reference for. Omit to get the full catalog.")}),handler:async e=>{let{command:t}=e;if(!t)return c(Ne);let n=Ne.split(`
211
+ `),o=new RegExp(`^### \`mist ${t}`),r=-1,s=n.length;for(let i=0;i<n.length;i++)if(o.test(n[i]))r=i;else if(r>=0&&n[i].startsWith("### ")){s=i;break}else if(r>=0&&n[i].startsWith("## ")&&i>r){s=i;break}return r<0?c(`No command named '${t}' found. Call mist_help with no args to see the full catalog.`,!0):c(n.slice(r,s).join(`
212
+ `).trim())}};var F=new Qt({name:"mistflow",version:"0.3.0"},{capabilities:{tools:{}},instructions:ie()}),Fe=[ke,De,Ae,qe];F.setRequestHandler(Zt,async()=>({tools:Fe.map(e=>({name:e.name,description:e.description,inputSchema:en(e.inputSchema)}))}));F.setRequestHandler(Xt,async e=>{let t=Fe.find(n=>n.name===e.params.name);if(!t)return c(`Unknown tool: ${e.params.name}`,!0);try{let n=t.inputSchema.safeParse(e.params.arguments);if(!n.success){let s=n.error.issues.map(i=>`${i.path.join(".")}: ${i.message}`).join(", ");return c(`Invalid input: ${s}`,!0)}let o=e.params._meta?.progressToken,r={server:F,progressToken:o};try{return await t.handler(n.data,r)}finally{r.cleanup?.()}}catch(n){let o=n instanceof Error?n.message:"An unexpected error occurred";return console.error("Tool error:",n),c(o,!0)}});async function tn(){let e=process.argv.indexOf("--api-url");e!==-1&&process.argv[e+1]&&(process.env.MISTFLOW_API_URL=process.argv[e+1]),process.argv.includes("--local")&&!process.env.MISTFLOW_API_URL&&(process.env.MISTFLOW_API_URL="http://localhost:9100");let t=new Yt;await F.connect(t),console.error(`Mistflow MCP server running on stdio (API: ${process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"})`)}tn().catch(e=>{console.error("Fatal error:",e),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistflow-ai/mcp",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Mistflow MCP server for AI coding editors. Installed into Claude Code, Cursor, Codex CLI, and VS Code Copilot by the mistflow-ai installer.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",