@mistflow-ai/mcp 0.1.0
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/LICENSE +96 -0
- package/README.md +114 -0
- package/dist/api-client-CE7LYEXJ.js +1 -0
- package/dist/browser-manager-CZ7GKZMO.js +1 -0
- package/dist/chunk-5TUJQOFD.js +2 -0
- package/dist/chunk-C2TTUQ4F.js +1 -0
- package/dist/chunk-VQN2JJRZ.js +23 -0
- package/dist/cli.js +6 -0
- package/dist/index.js +12529 -0
- package/dist/state-manager-ZVLGPYXN.js +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mistflow.ai
|
|
4
|
+
|
|
5
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
14
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
15
|
+
available, and prepare derivative works of the software, in each case subject
|
|
16
|
+
to the limitations and conditions below.
|
|
17
|
+
|
|
18
|
+
## Limitations
|
|
19
|
+
|
|
20
|
+
You may not provide the software to third parties as a hosted or managed
|
|
21
|
+
service, where the service provides users with access to any substantial set
|
|
22
|
+
of the features or functionality of the software.
|
|
23
|
+
|
|
24
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
25
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
26
|
+
software that is protected by the license key.
|
|
27
|
+
|
|
28
|
+
You may not alter, remove, or obscure any licensing, copyright, or other
|
|
29
|
+
notices of the licensor in the software. Any use of the licensor's trademarks
|
|
30
|
+
is subject to applicable law.
|
|
31
|
+
|
|
32
|
+
## Patents
|
|
33
|
+
|
|
34
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
35
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
36
|
+
sale, import and have imported the software, in each case subject to the
|
|
37
|
+
limitations and conditions in this license. This license does not cover any
|
|
38
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
39
|
+
the software. If you or your company make any written claim that the software
|
|
40
|
+
infringes or contributes to infringement of any patent, your patent license
|
|
41
|
+
for the software granted under these terms ends immediately. If your company
|
|
42
|
+
makes such a claim, your patent license ends immediately for work on behalf
|
|
43
|
+
of your company.
|
|
44
|
+
|
|
45
|
+
## Notices
|
|
46
|
+
|
|
47
|
+
You must ensure that anyone who gets a copy of any part of the software from
|
|
48
|
+
you also gets a copy of these terms.
|
|
49
|
+
|
|
50
|
+
If you modify the software, you must include in any modified copies of the
|
|
51
|
+
software prominent notices stating that you have modified the software.
|
|
52
|
+
|
|
53
|
+
## No Other Rights
|
|
54
|
+
|
|
55
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
56
|
+
these terms.
|
|
57
|
+
|
|
58
|
+
## Termination
|
|
59
|
+
|
|
60
|
+
If you use the software in violation of these terms, such use is not
|
|
61
|
+
licensed, and your licenses will automatically terminate. If the licensor
|
|
62
|
+
provides you with a notice of your violation, and you cease all violation of
|
|
63
|
+
this license no later than 30 days after you receive that notice, your
|
|
64
|
+
licenses will be reinstated retroactively. However, if you violate these
|
|
65
|
+
terms after such reinstatement, any additional violation of these terms will
|
|
66
|
+
cause your licenses to terminate automatically and permanently.
|
|
67
|
+
|
|
68
|
+
## No Liability
|
|
69
|
+
|
|
70
|
+
*As far as the law allows, the software comes as is, without any warranty
|
|
71
|
+
or condition, and the licensor will not be liable to you for any damages
|
|
72
|
+
arising out of these terms or the use or nature of the software, under any
|
|
73
|
+
kind of legal claim.*
|
|
74
|
+
|
|
75
|
+
## Definitions
|
|
76
|
+
|
|
77
|
+
The **licensor** is the entity offering these terms, and the **software** is
|
|
78
|
+
the software the licensor makes available under these terms, including any
|
|
79
|
+
portion of it.
|
|
80
|
+
|
|
81
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
82
|
+
|
|
83
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
84
|
+
organization that you work for, plus all organizations that have control
|
|
85
|
+
over, are under the control of, or are under common control with that
|
|
86
|
+
organization. **control** means ownership of substantially all the assets of
|
|
87
|
+
an entity, or the power to direct its management and policies by vote,
|
|
88
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
89
|
+
|
|
90
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
91
|
+
these terms.
|
|
92
|
+
|
|
93
|
+
**use** means anything you do with the software requiring one of your
|
|
94
|
+
licenses.
|
|
95
|
+
|
|
96
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @mistflow-ai/mcp
|
|
2
|
+
|
|
3
|
+
The Mistflow MCP server — an app-building tool provider for AI coding editors (Claude Code, Cursor, Codex CLI, VS Code Copilot).
|
|
4
|
+
|
|
5
|
+
> Most users should not install this package directly. Use the [`mistflow-ai`](https://www.npmjs.com/package/mistflow-ai) installer instead: `npx -y mistflow-ai install`. That command auto-detects your editor and wires everything up.
|
|
6
|
+
|
|
7
|
+
## What this is
|
|
8
|
+
|
|
9
|
+
A Model Context Protocol ([MCP](https://modelcontextprotocol.io)) server that exposes Mistflow's app-building capabilities as tools to your AI coding editor. Your editor's AI does the reasoning; this server orchestrates planning, scaffolding, building, and deployment, and talks to `api.mistflow.ai` for the heavy lifting.
|
|
10
|
+
|
|
11
|
+
The server never calls an LLM itself. It's a tool orchestrator, not a brain.
|
|
12
|
+
|
|
13
|
+
## Tools exposed
|
|
14
|
+
|
|
15
|
+
| Tool | Purpose |
|
|
16
|
+
|------|---------|
|
|
17
|
+
| `mist_setup` | Device-code auth flow — log in via browser, credentials stored in `~/.mistflow/credentials.json` |
|
|
18
|
+
| `mist_plan` | Contract-first discovery → plan generation for new apps (or new features needing data models) |
|
|
19
|
+
| `mist_build` | Scaffold projects, implement plan steps, run local builds, QA the live app, generate wireframes |
|
|
20
|
+
| `mist_deploy` | Deploy to Cloudflare, preview via tunnel, redeploy/rollback, verify live site |
|
|
21
|
+
| `mist_project` | Read/update project state, browse presets, fetch runtime errors and deploy logs |
|
|
22
|
+
| `mist_config` | Manage env vars and custom domains |
|
|
23
|
+
| `mist_browser` | Browser automation for testing the live app |
|
|
24
|
+
|
|
25
|
+
## Manual install (if the installer doesn't work for you)
|
|
26
|
+
|
|
27
|
+
<details>
|
|
28
|
+
<summary>Claude Code</summary>
|
|
29
|
+
|
|
30
|
+
Run:
|
|
31
|
+
```bash
|
|
32
|
+
claude mcp add mistflow --scope user -- npx -y @mistflow-ai/mcp@latest
|
|
33
|
+
```
|
|
34
|
+
</details>
|
|
35
|
+
|
|
36
|
+
<details>
|
|
37
|
+
<summary>Cursor</summary>
|
|
38
|
+
|
|
39
|
+
Edit `~/.cursor/mcp.json`:
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"mistflow": {
|
|
44
|
+
"command": "npx",
|
|
45
|
+
"args": ["-y", "@mistflow-ai/mcp@latest"],
|
|
46
|
+
"transport": "stdio"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
</details>
|
|
52
|
+
|
|
53
|
+
<details>
|
|
54
|
+
<summary>Codex CLI</summary>
|
|
55
|
+
|
|
56
|
+
Edit `~/.codex/config.toml`:
|
|
57
|
+
```toml
|
|
58
|
+
[mcp_servers.mistflow]
|
|
59
|
+
command = "npx"
|
|
60
|
+
args = ["-y", "@mistflow-ai/mcp"]
|
|
61
|
+
```
|
|
62
|
+
</details>
|
|
63
|
+
|
|
64
|
+
<details>
|
|
65
|
+
<summary>VS Code Copilot</summary>
|
|
66
|
+
|
|
67
|
+
Edit `.vscode/mcp.json` in your workspace:
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"servers": {
|
|
71
|
+
"mistflow": {
|
|
72
|
+
"command": "npx",
|
|
73
|
+
"args": ["-y", "@mistflow-ai/mcp@latest"],
|
|
74
|
+
"type": "stdio"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
</details>
|
|
80
|
+
|
|
81
|
+
Restart your editor after editing. Then say "Log me in to Mistflow" to authenticate.
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
The server reads from environment variables and `~/.mistflow/credentials.json`.
|
|
86
|
+
|
|
87
|
+
| Variable | Purpose |
|
|
88
|
+
|----------|---------|
|
|
89
|
+
| `MISTFLOW_API_KEY` | Skip browser auth entirely — useful for CI. Prefix: `mist_`. Create a key at [app.mistflow.ai/mcp-keys](https://app.mistflow.ai/mcp-keys). |
|
|
90
|
+
| `MISTFLOW_API_URL` | Override the backend URL (default `https://api.mistflow.ai`) |
|
|
91
|
+
|
|
92
|
+
Command-line flags:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npx @mistflow-ai/mcp --api-url http://localhost:9100 # local dev
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Security notes
|
|
99
|
+
|
|
100
|
+
- Credentials are stored in `~/.mistflow/credentials.json` (readable only by the current user).
|
|
101
|
+
- API keys prefixed with `mist_` are not logged, not echoed, and redacted from any error output.
|
|
102
|
+
- The server never writes to `stdout` — all logging goes to `stderr` so it can't corrupt the MCP JSON-RPC protocol.
|
|
103
|
+
|
|
104
|
+
## Links
|
|
105
|
+
|
|
106
|
+
- Website: [mistflow.ai](https://mistflow.ai)
|
|
107
|
+
- Docs: [mistflow.ai/docs](https://mistflow.ai/docs)
|
|
108
|
+
- Installer: [`mistflow-ai`](https://www.npmjs.com/package/mistflow-ai)
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
[Elastic License 2.0](./LICENSE). Source-available, with one restriction: you may not offer `@mistflow-ai/mcp` as a hosted or managed service that competes with Mistflow. Everything else — using it inside your own apps, modifying it, embedding it in products you sell — is allowed. Paying Mistflow customers are unaffected.
|
|
113
|
+
|
|
114
|
+
Copyright (c) 2026 Mistflow.ai
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as s,B as t,C as u,D as v,E as w,F as x,G as y,H as z,I as A,J as B,K as C,L as D,M as E,N as F,O as G,P as H,Q as I,R as J,S as K,T as L,U as M,V as N,W as O,h as a,j as b,k as c,l as d,m as e,n as f,o as g,p as h,q as i,r as j,s as k,t as l,u as m,v as n,w as o,x as p,y as q,z as r}from"./chunk-VQN2JJRZ.js";export{e as MistflowApiError,s as addDomain,h as checkAuth,i as checkAuthDetailed,k as checkSubdomain,m as createDeployment,l as createProject,z as deleteEnvVar,r as discoverDecisions,G as downloadSource,M as downloadSourceWithToken,J as fetchModule,H as fetchScaffold,I as fetchStepContext,L as forkTemplate,p as generatePlan,f as getAuthHeaders,b as getBaseUrl,d as getDashboardUrl,w as getDbCredentials,A as getDeployLogs,o as getDeploymentStatus,j as getProject,B as getProjectErrors,c as getSiteUrl,K as getTemplate,a as hasCredentialsOnDisk,g as hasLocalCredentials,C as listDeployments,t as listDomains,x as listEnvVars,N as markLocalSetupDone,q as modifyPlan,E as promotePreview,D as redeployProject,v as removeDomain,F as rollbackDeployment,O as shareProject,n as uploadAndDeploy,y as upsertEnvVar,u as verifyDomain};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d}from"./chunk-C2TTUQ4F.js";export{b as closeBrowser,a as getPage,c as getSnapshot,d as takeScreenshot};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as o,b as s,j as i,n as a}from"./chunk-VQN2JJRZ.js";import{existsSync as u,readFileSync as f,writeFileSync as d,mkdirSync as m}from"fs";import{join as l}from"path";function p(t){return l(t,".mistflow","state.json")}function P(t){let e=p(t);if(!u(e))return null;try{return JSON.parse(f(e,"utf-8"))}catch{return null}}function w(t,e){let r=l(t,".mistflow");u(r)||m(r,{recursive:!0}),d(p(t),JSON.stringify(e,null,2)+`
|
|
2
|
+
`)}function C(t,e){return{projectId:t,name:e,template:"",features:[],dbSchema:[],deployCount:0,decisions:[],provenance:[]}}async function x(t){let e;try{e=a()}catch{return null}try{let r=await fetch(`${i()}/api/projects/${encodeURIComponent(t)}/state`,{headers:{...e,"Content-Type":"application/json","X-Mistflow-MCP-Version":o()}});try{s(r.headers)}catch{}return r.ok?await r.json():null}catch{return null}}async function R(t,e){let r;try{r=a()}catch{return!1}try{let n=await fetch(`${i()}/api/projects/${encodeURIComponent(t)}/state`,{method:"PUT",headers:{...r,"Content-Type":"application/json","X-Mistflow-MCP-Version":o()},body:JSON.stringify(e)});try{s(n.headers)}catch{}return n.ok}catch{return!1}}function L(t,e){let r=t.toLowerCase(),n=e.toLowerCase();return n.includes(r)||r.includes(n)?!0:r.split(/\s+/).some(c=>c.length>=3&&n.includes(c))}export{p as a,P as b,w as c,C as d,x as e,R as f,L as g};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=null,t=null,e=null,r=null;async function l(){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 s(){let n=await l();return(!a||!a.isConnected())&&(a=await n.chromium.launch({headless:!0})),t&&(await t.close().catch(()=>{}),t=null),t=await a.newContext({viewport:{width:1280,height:720},deviceScaleFactor:2}),e=await t.newPage(),e}async function c(){return e&&!e.isClosed()?e:(r||(r=s().finally(()=>{r=null})),r)}async function i(){e&&!e.isClosed()&&await e.close().catch(()=>{}),t&&await t.close().catch(()=>{}),a?.isConnected()&&await a.close().catch(()=>{}),e=null,t=null,a=null}process.once("SIGTERM",()=>{i().finally(()=>process.exit(0))});process.once("SIGINT",()=>{i().finally(()=>process.exit(0))});async function u(n){return await n.locator("body").ariaSnapshot()}async function w(n,o=!1){return await n.screenshot({fullPage:o,type:"png"})}export{c as a,i as b,u as c,w as d};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import{readFileSync as I,existsSync as S,writeFileSync as H,mkdirSync as z,renameSync as X,unlinkSync as Y}from"fs";import{join as x,dirname as Q}from"path";import{homedir as G}from"os";import{randomBytes as Z}from"crypto";function $(){return x(G(),".mistflow","credentials.json")}function d(){let e=process.env.MISTFLOW_API_KEY;if(e)return{ok:!0,creds:{apiKey:e,orgId:"",orgSlug:"env"}};let t=$();if(!S(t))return{ok:!1,reason:"missing"};try{let n=JSON.parse(I(t,"utf-8"));return typeof n.apiKey=="string"&&n.apiKey&&typeof n.orgId=="string"?{ok:!0,creds:n}:{ok:!1,reason:"invalid"}}catch{return{ok:!1,reason:"invalid"}}}function he(e){let t=$(),n=Q(t);S(n)||z(n,{recursive:!0});let r=x(n,`.credentials.tmp.${Z(8).toString("hex")}`);try{H(r,JSON.stringify(e,null,2)+`
|
|
2
|
+
`,{mode:384}),X(r,t)}catch(o){try{Y(r)}catch{}throw o}}function we(){let e=d();return e.ok?e.creds:null}function ee(){return d().ok}function _e(e){let t=x(e,"mistflow.json");if(!S(t))return null;try{return JSON.parse(I(t,"utf-8"))}catch{return null}}import{existsSync as C,readFileSync as M,writeFileSync as te,mkdirSync as ne}from"fs";import{join as b,dirname as v}from"path";import{homedir as re}from"os";import{fileURLToPath as oe}from"url";var w=null;function p(){if(w)return w;try{let e=oe(import.meta.url),t=v(e);for(let n=0;n<6;n++){let r=b(t,"package.json");if(C(r)){let s=JSON.parse(M(r,"utf-8"));if(s.name==="@mistflow-ai/mcp"&&typeof s.version=="string")return w=s.version,s.version}let o=v(t);if(o===t)break;t=o}}catch{}return w="0.0.0","0.0.0"}function _(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 T(e,t){let n=_(e),r=_(t);if(!n||!r)return 0;for(let o=0;o<3;o++){if(n[o]<r[o])return-1;if(n[o]>r[o])return 1}return 0}function E(e,t,n){if(n&&T(e,n)<0)return"unsupported";if(!t||T(e,t)>=0)return"none";let o=_(e),s=_(t);return!o||!s?"none":o[0]<s[0]?"major":o[1]<s[1]?"minor":"patch"}var l=null;function O(e){let t=e.get("x-mistflow-mcp-latest")??"",n=e.get("x-mistflow-mcp-min-supported")??"",r=e.get("x-mistflow-mcp-changelog-url")??"";!t&&!n||(l={latest:t,minSupported:n,changelogUrl:r})}function A(){let e=process.env.MISTFLOW_STATE_DIR||b(re(),".mistflow");return b(e,"upgrade-state.json")}function se(){try{let e=A();return C(e)?JSON.parse(M(e,"utf-8")):{}}catch{return{}}}function ie(e){try{let t=A(),n=v(t);C(n)||ne(n,{recursive:!0}),te(t,JSON.stringify(e,null,2)+`
|
|
3
|
+
`,{mode:384})}catch{}}var D=!1;function ae(e){return e==="patch"?7*864e5:e==="minor"?1*864e5:0}function ve(){if(process.env.MISTFLOW_NO_UPGRADE_CHECK==="1"||!l)return null;let e=p();if(e==="0.0.0")return null;let t=E(e,l.latest,l.minSupported);if(t==="none")return null;if(t==="unsupported")return j(t,e,l);if(D)return null;let n=se(),r=Date.now(),o=ae(t);return n.dismissedForVersion===l.latest&&t!=="major"||n.lastLatestSeen===l.latest&&n.lastShownMs&&r-n.lastShownMs<o?null:(D=!0,ie({...n,lastShownMs:r,lastLatestSeen:l.latest}),j(t,e,l))}function j(e,t,n){let r="npx -y mistflow-ai install",o=n.changelogUrl?`
|
|
4
|
+
What's new: ${n.changelogUrl}`:"";return e==="unsupported"?`
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
Mistflow ${t} is no longer supported.
|
|
8
|
+
You must upgrade to ${n.latest} or newer to continue:
|
|
9
|
+
|
|
10
|
+
${r}
|
|
11
|
+
|
|
12
|
+
After upgrading, restart your AI editor.${o}
|
|
13
|
+
---`:e==="major"?`
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
Mistflow ${n.latest} is available (you have ${t}).
|
|
17
|
+
This is a major update. Run \`${r}\` and restart your editor.${o}
|
|
18
|
+
---`:e==="minor"?`
|
|
19
|
+
|
|
20
|
+
--- Mistflow update available: ${t} -> ${n.latest} ---
|
|
21
|
+
Run \`${r}\` to upgrade, then restart your editor.${o}`:`
|
|
22
|
+
|
|
23
|
+
(Mistflow ${n.latest} is out, you have ${t}. Run \`${r}\` when convenient.)`}function Ce(){let e=p(),t=l??{latest:"",minSupported:"",changelogUrl:""},n=E(e,t.latest,t.minSupported);return{current:e,latest:t.latest,minSupported:t.minSupported,severity:n,upgradeCmd:"npx -y mistflow-ai install",changelogUrl:t.changelogUrl,backendSignalReceived:l!==null}}function f(){return process.env.MISTFLOW_API_URL||"https://api.mistflow.ai"}function $e(){let e=process.env.MISTFLOW_API_URL;if(e){if(e.includes("mistflow.localhost"))return e.replace("api.mistflow","mistflow");if(e.includes("localhost:9100"))return e.replace(":9100",":9102")}return"https://mistflow.ai"}function Te(){let e=process.env.MISTFLOW_API_URL;if(e){if(e.includes("mistflow.localhost"))return e.replace("api.mistflow","app.mistflow");if(e.includes("localhost:9100"))return e.replace(":9100",":9101")}return"https://app.mistflow.ai"}var a=class extends Error{constructor(n,r,o,s){super(r);this.code=n;this.statusCode=o;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"}};function ce(){let e=d();if(!e.ok)throw new a("auth_missing","No Mistflow credentials found.",401);return le(e.creds)}function le(e){return{Authorization:`ApiKey ${e.apiKey}`,"Content-Type":"application/json","X-Mistflow-MCP-Version":p()}}function y(e){try{O(e.headers)}catch{}}async function V(e,t,n){for(let r=0;r<2;r++)try{return await fetch(e,{...t,signal:AbortSignal.timeout(n)})}catch(o){let s=o instanceof Error&&o.name==="TimeoutError",c=o instanceof TypeError;if(r===0&&(s||c)){console.error(`[api] Retrying ${e} after ${s?"timeout":"network error"}`);continue}throw o}throw new Error("fetchWithRetry: exhausted retries")}async function h(e){let t=null;try{t=await e.json()}catch{t=null}let n=t&&typeof t.code=="string"?t.code:void 0,r=t&&typeof t.message=="string"?t.message:t&&typeof t.detail=="string"?t.detail:e.statusText||"Request failed";if(n)return new a(n,r,e.status,t?.details);let o=e.status;return o===401?new a("auth_invalid",r,o):o===403?new a("permission_denied",r,o):o===404?new a("not_found",r,o):o===409?new a("conflict",r,o):o===422?new a("validation_error",r,o):o===429?new a("rate_limited",r,o):o>=500?new a("server_error",e.statusText||"Internal server error",o):new a("client_error",r,o)}async function i(e,t={}){let n=ce(),{timeoutMs:r,...o}=t,s=r??3e4,c;try{c=await V(`${f()}${e}`,{...o,headers:{...n,...o.headers}},s)}catch(g){throw g instanceof Error&&g.name==="TimeoutError"?new a("network_error","Request timed out. Try again in a moment."):new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(c),!c.ok)throw await h(c);return c.json()}function ue(){return d().ok}var R=null,F=0,pe=300*1e3;async function De(){return(await de()).ok}async function de(){if(R!==null&&Date.now()<F)return R?{ok:!0}:{ok:!1,reason:"no_credentials"};if(!ue())return{ok:!1,reason:"no_credentials"};try{return await i("/api/org"),R=!0,F=Date.now()+pe,{ok:!0}}catch(e){if(R=null,!(e instanceof a))return{ok:!1,reason:"network_error"};switch(e.code){case"auth_missing":case"auth_revoked":return{ok:!1,reason:"no_credentials"};case"auth_expired":case"auth_invalid":case"auth_org_not_found":return{ok:!1,reason:"expired"};case"network_error":return{ok:!1,reason:"network_error"};case"rate_limited":case"server_error":case"upstream_error":return{ok:!1,reason:"server_error"};default:return{ok:!1,reason:"server_error"}}}}async function je(e){return i(`/api/projects/${encodeURIComponent(e)}`)}async function Me(e){return i(`/api/projects/check-subdomain?name=${encodeURIComponent(e)}`)}async function Ee(e,t,n="neon",r){return i("/api/projects",{method:"POST",body:JSON.stringify({name:e,template:t,db_provider:n,requested_subdomain:r})})}async function Oe(e,t){return i("/api/deploy",{method:"POST",body:JSON.stringify({project_id:e,build_output_url:t})})}async function Ae(e,t,n="production",r,o,s,c){let{readFileSync:g}=await import("fs"),{basename:N}=await import("path"),P=d();if(!P.ok)throw new a("auth_missing","No Mistflow credentials found.",401);let L=P.creds,q=g(t),K=new Blob([q],{type:"application/gzip"}),u=new FormData;if(u.append("project_id",e),u.append("build",K,N(t)),n!=="production"&&u.append("environment",n),r&&u.append("admin_email",r),o&&u.append("schema_pushed","true"),s){let{existsSync:B}=await import("fs");if(B(s)){let J=g(s),W=new Blob([J],{type:"application/gzip"});u.append("source",W,"source.tar.gz")}}c&&u.append("git_commit_sha",c);let m;try{m=await fetch(`${f()}/api/deploy/upload`,{method:"POST",headers:{Authorization:`ApiKey ${L.apiKey}`,"X-Mistflow-MCP-Version":p()},body:u,signal:AbortSignal.timeout(3e5)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(m),!m.ok)throw await h(m);let U=await m.json();return{...U,id:U.deployment_id}}async function Fe(e){return i(`/api/deploy/${encodeURIComponent(e)}/status`)}async function Ve(e,t){let n={description:e,conversation_id:t?.conversationId,answers:t?.answers};t?.autonomous&&(n.autonomous=!0),t?.language&&t.language.toLowerCase()!=="english"&&(n.language=t.language);let r=t?.conversationId||t?.answers?12e4:6e4;return i("/api/plan",{method:"POST",body:JSON.stringify(n),timeoutMs:r})}async function Ne(e,t){return i("/api/plan/modify",{method:"POST",body:JSON.stringify({existing_plan:e,modification:t})})}async function Le(e){return i("/api/plan/discover",{method:"POST",body:JSON.stringify({description:e})})}async function qe(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains`,{method:"POST",body:JSON.stringify({domain:t})})}async function Ke(e){return i(`/api/projects/${encodeURIComponent(e)}/domains`)}async function Be(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}/verify`)}async function Je(e,t){return i(`/api/projects/${encodeURIComponent(e)}/domains/${encodeURIComponent(t)}`,{method:"DELETE"})}async function We(e){return i(`/api/projects/${encodeURIComponent(e)}/db-credentials`)}async function He(e){return i(`/api/projects/${encodeURIComponent(e)}/env`)}async function ze(e,t,n,r){return i(`/api/projects/${encodeURIComponent(e)}/env`,{method:"PUT",body:JSON.stringify({key:t,value:n,category:r?.category??"custom",description:r?.description,setup_url:r?.setupUrl})})}async function Xe(e,t){return i(`/api/projects/${encodeURIComponent(e)}/env/${encodeURIComponent(t)}`,{method:"DELETE"})}async function Ye(e){return i(`/api/deploy/${encodeURIComponent(e)}/logs`)}async function Qe(e,t="7d"){return i(`/api/projects/${encodeURIComponent(e)}/errors?period=${encodeURIComponent(t)}`)}async function Ge(e){return i(`/api/projects/${encodeURIComponent(e)}/deployments`)}async function Ze(e){return i(`/api/deploy/${encodeURIComponent(e)}/redeploy`,{method:"POST"})}async function et(e,t){let n=new URLSearchParams({preview_deployment_id:t});return i(`/api/deploy/${encodeURIComponent(e)}/promote`,{method:"POST",body:n.toString(),headers:{"Content-Type":"application/x-www-form-urlencoded"}})}async function tt(e){return i(`/api/deploy/${encodeURIComponent(e)}/rollback`,{method:"POST"})}async function nt(e,t){let n=d();if(!n.ok)throw new a("auth_missing","Not authenticated.",401);let r=n.creds,o=await fetch(`${f()}/api/deploy/${encodeURIComponent(e)}/source`,{headers:{Authorization:`ApiKey ${r.apiKey}`,"X-Mistflow-MCP-Version":p()},signal:AbortSignal.timeout(12e4)});if(y(o),!o.ok)throw await h(o);let{writeFileSync:s}=await import("fs"),c=Buffer.from(await o.arrayBuffer());s(t,c)}async function k(e,t){let{timeoutMs:n,...r}=t??{},o=n??3e4,s;try{s=await V(`${f()}${e}`,{headers:{"Content-Type":"application/json","X-Mistflow-MCP-Version":p()},...r},o)}catch(c){throw c instanceof Error&&c.name==="TimeoutError"?new a("network_error","Request timed out. Try again in a moment."):new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(s),!s.ok)throw await h(s);return s.json()}async function rt(e="nextjs"){return k(`/api/scaffold/${encodeURIComponent(e)}`)}async function ot(e,t){return k(`/api/scaffold/${encodeURIComponent(e)}/context?step_type=${encodeURIComponent(t)}`)}async function st(e,t,n,r){return k(`/api/scaffold/${encodeURIComponent(e)}/module`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"crud",entity:t,fields:n,entity_plural:r})})}async function it(e){return k(`/api/templates/${encodeURIComponent(e)}`)}async function at(e){return i(`/api/templates/${encodeURIComponent(e)}/fork`,{method:"POST"})}async function ct(e,t,n){let r;try{r=await fetch(`${f()}/api/deploy/${encodeURIComponent(e)}/fork-source?fork_token=${encodeURIComponent(t)}`,{headers:{"X-Mistflow-MCP-Version":p()},signal:AbortSignal.timeout(12e4)})}catch{throw new a("network_error","Cannot reach Mistflow servers. Check your network.")}if(y(r),!r.ok)throw r.status===401?new a("validation_error","Fork token expired or invalid. Re-open the project in the dashboard to get a fresh token.",r.status):await h(r);let{writeFileSync:o}=await import("fs"),s=Buffer.from(await r.arrayBuffer());o(n,s)}async function lt(e){await i(`/api/projects/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({local_setup_done:!0})})}async function ut(e,t){return i(`/api/projects/${encodeURIComponent(e)}/share`,{method:"POST",body:JSON.stringify({is_template:t?.isTemplate??!1,template_description:t?.description})})}export{p as a,O as b,ve as c,Ce as d,d as e,he as f,we as g,ee as h,_e as i,f as j,$e as k,Te as l,a as m,ce as n,ue as o,De as p,de as q,je as r,Me as s,Ee as t,Oe as u,Ae as v,Fe as w,Ve as x,Ne as y,Le as z,qe as A,Ke as B,Be as C,Je as D,We as E,He as F,ze as G,Xe as H,Ye as I,Qe as J,Ge as K,Ze as L,et as M,tt as N,nt as O,rt as P,ot as Q,st as R,it as S,at as T,ct as U,lt as V,ut as W};
|
package/dist/cli.js
ADDED