@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.
- package/dist/cli.js +57 -23
- package/dist/index.js +56 -22
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`,{
|
|
4
|
-
|
|
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 ${
|
|
8
|
-
You must upgrade to ${
|
|
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
|
-
---`:
|
|
14
|
+
---`:e==="major"?`
|
|
14
15
|
|
|
15
16
|
---
|
|
16
|
-
Mistflow ${
|
|
17
|
+
Mistflow ${n.latest} is available (you have ${t}).
|
|
17
18
|
This is a major update. Run \`${o}\` and restart your editor.${r}
|
|
18
|
-
---`:
|
|
19
|
+
---`:e==="minor"?`
|
|
19
20
|
|
|
20
|
-
--- Mistflow update available: ${
|
|
21
|
+
--- Mistflow update available: ${t} -> ${n.latest} ---
|
|
21
22
|
Run \`${o}\` to upgrade, then restart your editor.${r}`:`
|
|
22
23
|
|
|
23
|
-
(Mistflow ${
|
|
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
|
|
33
|
-
`,{mode:384}),
|
|
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
|
|
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!=="''"&&
|
|
38
|
-
`)}function
|
|
39
|
-
`),nextSteps:
|
|
40
|
-
`),r.projectId&&Promise.resolve().then(()=>(
|
|
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
|
-
#
|
|
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
|
-
`,
|
|
178
|
-
`),o=new RegExp(`^### \`mist ${
|
|
179
|
-
`).trim())}}});var
|
|
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(()=>(
|
|
225
|
+
`),process.exit(1));await Promise.resolve().then(()=>(Ye(),mn));
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,{mode:384})}catch{}}function
|
|
3
|
-
What's new: ${
|
|
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 ${
|
|
7
|
-
You must upgrade to ${
|
|
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
|
-
---`:
|
|
12
|
+
---`:e==="major"?`
|
|
13
13
|
|
|
14
14
|
---
|
|
15
|
-
Mistflow ${
|
|
15
|
+
Mistflow ${n.latest} is available (you have ${t}).
|
|
16
16
|
This is a major update. Run \`${o}\` and restart your editor.${r}
|
|
17
|
-
---`:
|
|
17
|
+
---`:e==="minor"?`
|
|
18
18
|
|
|
19
|
-
--- Mistflow update available: ${
|
|
19
|
+
--- Mistflow update available: ${t} -> ${n.latest} ---
|
|
20
20
|
Run \`${o}\` to upgrade, then restart your editor.${r}`:`
|
|
21
21
|
|
|
22
|
-
(Mistflow ${
|
|
23
|
-
`,{mode:384}),
|
|
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
|
|
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
|
|
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!=="''"&&
|
|
38
|
-
`),nextSteps:
|
|
39
|
-
`),r.projectId&&Promise.resolve().then(()=>(
|
|
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
|
-
#
|
|
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
|
-
`,
|
|
177
|
-
`),o=new RegExp(`^### \`mist ${
|
|
178
|
-
`).trim())}};var F=new
|
|
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
|
+
"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",
|