@mcp-use/cli 4.0.0-beta.9 → 4.0.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/dist/bin.js +1 -1
- package/dist/chunk-3XW44DRS.js +1 -0
- package/dist/chunk-F5XPOFT7.js +1 -0
- package/dist/{chunk-DB3E6LBX.js → chunk-FLGSKQGU.js} +2 -2
- package/dist/chunk-HQYBGY3V.js +90 -0
- package/dist/chunk-ICHICRCP.js +4 -0
- package/dist/chunk-ISAAAHEM.js +14 -0
- package/dist/chunk-LNASFQWW.js +1 -0
- package/dist/chunk-VUVLJMYY.js +11 -0
- package/dist/commands/build.js +5 -5
- package/dist/commands/client.js +1 -1
- package/dist/commands/deploy.js +73 -1
- package/dist/commands/deployments.js +59 -6
- package/dist/commands/dev.js +2 -2
- package/dist/commands/identity.js +38 -2
- package/dist/commands/organizations.js +43 -2
- package/dist/commands/screenshot.js +48 -3
- package/dist/commands/servers.js +90 -2
- package/dist/commands/start.js +1 -1
- package/dist/commands/typecheck.js +1 -1
- package/dist/index.js +1 -1
- package/dist/node-bridge-WOT2W5YZ.js +1 -0
- package/dist/{start-CGEGBZOH.js → start-PCNMGPDW.js} +1 -1
- package/dist/tunnel-FOJUZGIJ.js +1 -0
- package/package.json +7 -4
- package/types/vite-client.d.ts +3 -0
- package/dist/chunk-ALPMVGHI.js +0 -3
- package/dist/chunk-FEEM7DWN.js +0 -37
- package/dist/chunk-LHNHT6HO.js +0 -8
- package/dist/chunk-N6R74JIF.js +0 -33
- package/dist/chunk-OVFUQAEG.js +0 -1
- package/dist/chunk-ZELLSKD2.js +0 -1
- package/dist/node-bridge-JJIA6K5P.js +0 -1
- package/dist/tunnel-AQ2WE7EL.js +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as n}from"./chunk-
|
|
2
|
+
import{a as n}from"./chunk-HQYBGY3V.js";import"./chunk-USIKTT3N.js";n(process.argv.slice(2),{frameworkVersion:"4.0.0"}).then(e=>{process.exitCode=e},e=>{console.error(e instanceof Error?e.message:String(e)),process.exitCode=1});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as a,j as w,k as h,l as _,m as C}from"./chunk-VUVLJMYY.js";import{join as O}from"path";var y=O(C,"config.json");function g(){return(process.env.MCP_USE_CLOUD_API_URL??process.env.MCP_API_URL??"https://cloud.manufact.com/api/v1").replace(/\/+$/,"").replace(/\/api\/v1$/,"")+"/api/v1"}function j(){return(process.env.MCP_USE_CLOUD_WEB_URL??"https://manufact.com").replace(/\/+$/,"")}function R(){return g().replace(/\/api\/v1$/,"")}async function I(){return w(y,{})}async function T(t){await h(y,t)}async function E(){await _(y)}function k(t,n){let e=t.filter(i=>i.id===n||i.slug===n);if(e.length!==1)throw new a(e.length===0?"organization_not_found":"organization_ambiguous",`Organization not found: ${n}`);return e[0]}var c=class t{#n;#e;constructor(n,e){this.#n=n,this.#e=e}static async create(n){let e=await I(),i=process.env.MCP_USE_API_KEY??e.apiKey;if(i===void 0||i==="")throw new a("not_authenticated","Not logged in. Run `mcp-use login`.");return new t(i,n??e.orgId)}static withApiKey(n){return new t(n)}async request(n,e={}){let i=b(this.#n,e),r=e.organizationId??this.#e,o=await fetch(`${g()}${n}`,{...e,headers:{Accept:"application/json","x-api-key":this.#n,...r!==void 0?{"x-profile-id":r}:{},...e.body!==void 0?{"Content-Type":"application/json"}:{},...e.headers}}),d=await o.text(),s;try{s=d===""?void 0:JSON.parse(d)}catch{s=d}if(!o.ok)throw A(n,o.status,f(s,i));return s}async multipartRequest(n,e,i={}){let r=v(this.#n,e),o=new AbortController,d=setTimeout(()=>o.abort(),i.timeoutMs??12e4);try{let s=await fetch(`${g()}${n}`,{method:i.method??"POST",headers:{Accept:"application/json","x-api-key":this.#n,...this.#e!==void 0?{"x-profile-id":this.#e}:{}},body:e,signal:o.signal}),l=await s.text(),u;try{u=l===""?void 0:JSON.parse(l)}catch{u=l}if(!s.ok)throw A(n,s.status,f(u,r));return u}catch(s){throw s instanceof Error&&s.name==="AbortError"?new a("cloud_api_timeout",`Cloud upload timed out after ${(i.timeoutMs??12e4)/1e3} seconds.`):s}finally{clearTimeout(d)}}async identity(){let n=await this.request("/test-auth");return{userId:n.user_id,email:n.email,organizations:n.profiles.map(e=>({id:e.id,name:e.profile_name,slug:e.slug,role:e.role})),defaultOrganizationId:n.default_profile_id}}async setDefaultOrganization(n){await this.request(`/organizations/${n}/set-default`,{method:"POST"})}};async function U(t){let n=await I(),e=await(await c.create()).identity(),i=t!==void 0?k(e.organizations,t):e.organizations.find(r=>r.id===(n.orgId??e.defaultOrganizationId));if(i===void 0)throw new a("organization_required","No active organization. Run `mcp-use org use <id-or-slug>`.");return{api:await c.create(i.id),organizationId:i.id}}function P(t){if(typeof t=="string"&&t!=="")return t;if(!(t===null||typeof t!="object"))for(let n of["message","error","detail"]){let e=t[n];if(typeof e=="string"&&e!=="")return e}}function A(t,n,e){let i=P(e)??`Cloud API request failed (${n}).`,r={status:n,...z(e)!==void 0?{validation:z(e)}:{}};if(n===401)return new a("not_authenticated",i,r);if(n===403)return new a("forbidden",i,r);if(n===404&&/^\/servers(?:\/|$)/.test(t))return new a("server_not_found",i,r);if(n===404&&/^\/deployments(?:\/|$)/.test(t))return new a("deployment_not_found",i,r);let o=t.match(/^\/deployments\/([^/]+)\/stop$/);if(o!==null){let d=decodeURIComponent(o[1]??"");return new a("deployment_stop_failed",i,{...r,nextSteps:[{description:"Inspect the deployment state",command:`mcp-use deployments get ${d} --json`},{description:"Delete the deployment instead",command:`mcp-use deployments delete ${d} --yes --json`}]})}return n===400||n===422?new a("validation_error",i,r):new a("cloud_api_error",i,r)}function z(t){if(t===null||typeof t!="object")return;let n=t.details;if(!(n===null||typeof n!="object"&&!Array.isArray(n)))return n}function b(t,n){let e=new Set([t]),i=new Headers(n.headers);for(let r of["authorization","x-api-key"]){let o=i.get(r);o!==null&&e.add(o)}if(typeof n.body=="string")try{p(JSON.parse(n.body),e)}catch{}return e}function v(t,n){let e=new Set([t]);for(let[i,r]of n.entries())if(typeof r=="string")if(/^(?:env|environment|environmentVariables)$/i.test(i))try{m(JSON.parse(r),e)}catch{e.add(r)}else S(i)&&e.add(r);return e}function p(t,n,e=!1){if(typeof t=="string"){e&&n.add(t);return}if(Array.isArray(t)){for(let i of t)p(i,n,e);return}if(!(t===null||typeof t!="object"))for(let[i,r]of Object.entries(t)){let o=e||S(i)||/^(?:env|environment|environmentVariables)$/i.test(i);p(r,n,o)}}function m(t,n){if(typeof t=="string")n.add(t);else if(Array.isArray(t))for(let e of t)m(e,n);else if(t!==null&&typeof t=="object")for(let e of Object.values(t))m(e,n)}function S(t){return/(?:authorization|api[-_]?key|password|secret|token|value)/i.test(t)}function f(t,n){if(typeof t=="string"){let e=t;for(let i of n)i!==""&&(e=e.replaceAll(i,"[REDACTED]"));return e}return Array.isArray(t)?t.map(e=>f(e,n)):t===null||typeof t!="object"?t:Object.fromEntries(Object.entries(t).map(([e,i])=>[e,f(i,n)]))}export{j as a,R as b,I as c,T as d,E as e,k as f,c as g,U as h};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import Y from"http";import{mkdir as D,readFile as H,writeFile as X}from"fs/promises";import{dirname as z}from"path";var J="https://api.tunnel.mcp-use.run",Q=3e4,$=64*1024,w=256*1024,x=1024*1024,O=100,j=25e3,W=5,G=1,V=2,L=3,Z=4,ee=5,te=6,T=36;function K(){return process.env.MCP_USE_TUNNEL_API??J}var v=1e3,F=3e4,ne=new Set(["connection","keep-alive","proxy-authenticate","proxy-authorization","proxy-connection","te","trailer","transfer-encoding","upgrade"]);function M(s){return new Promise(i=>{setTimeout(i,s)})}function C(s){process.env.MCP_USE_TUNNEL_DEBUG==="1"&&console.log(`[mcp-use] ${s}`)}function B(s){return typeof s=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(s)}function U(s,i=!1){let u={};for(let[o,d]of Object.entries(s)){let l=o.toLowerCase();d===void 0||ne.has(l)||i&&(l==="host"||l==="content-length")||(u[l]=typeof d=="number"?String(d):d)}return u}function P(s,i,u){let o=new TextEncoder().encode(i);if(o.byteLength!==T)throw new Error("Invalid tunnel request identifier");let d=new Uint8Array(1+T+u.byteLength);return d[0]=s,d.set(o,1),d.set(u,1+T),d}function re(s){let i=Buffer.from(s);if(i.byteLength<1+T||i.byteLength>1+T+w)return;let u=i.subarray(1,1+T).toString("ascii");if(B(u))return{kind:i[0]??0,requestId:u,body:i.subarray(1+T)}}function N(s){let i=new Uint8Array(s.byteLength);return i.set(s),i}async function oe(s){for(;s.readyState===WebSocket.OPEN&&s.bufferedAmount>x;)await M(5);if(s.readyState!==WebSocket.OPEN)throw new Error("Tunnel socket closed while applying backpressure")}function b(s,i){let u=JSON.stringify(i);if(Buffer.byteLength(u)>$)throw new Error("Tunnel control message exceeds 64 KiB");s.send(u)}async function se(s){let i=await s.text(),u={};try{u=JSON.parse(i)}catch{}if(!s.ok)throw new Error(u.error??`Tunnel relay returned HTTP ${s.status}`);return u}async function ie(s){let i=await fetch(new URL("/api/tunnels/request",K()),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s===void 0?{}:{subdomain:s}),signal:AbortSignal.timeout(1e4)}),u=await se(i);if(typeof u.tunnel_id!="string"||typeof u.token!="string"||typeof u.connect_url!="string"||typeof u.public_url!="string")throw new Error("Tunnel relay returned an invalid reservation");return u}async function A(s){if(s.token!==void 0)try{await fetch(new URL(`/api/tunnels/${encodeURIComponent(s.subdomain)}`,K()),{method:"DELETE",headers:{authorization:`Bearer ${s.token}`},signal:AbortSignal.timeout(2e3)})}catch{}}async function ae(s,i,u){let o=new WebSocket(i.connect_url);o.binaryType="arraybuffer";let d=new Map,l=new Map,f=!1,g=!1,y=!1,_,q=(n,e)=>{let t=d.get(n);if(t!==void 0&&(d.delete(n),t.request.destroy(),t.response?.destroy(),o.readyState===WebSocket.OPEN))try{b(o,{type:"response-error",requestId:n,message:e instanceof Error?e.message:String(e)})}catch{}},I=n=>{if(!B(n.requestId)||d.has(n.requestId)||d.size>=O||typeof n.method!="string"||typeof n.path!="string"||!n.path.startsWith("/")){o.close(1008,"Invalid request");return}let e=U(n.headers,!0),t=n.headers["x-forwarded-host"];typeof t=="string"&&(e.host=t);let r=Y.request({hostname:"127.0.0.1",port:s,method:n.method,path:n.path,headers:e}),c={request:r};d.set(n.requestId,c),r.on("response",a=>{c.response=a,(async()=>{b(o,{type:"response-start",requestId:n.requestId,status:a.statusCode??502,headers:U(a.headers)});for await(let S of a){let p=Buffer.from(S);for(let R=0;R<p.byteLength;R+=w)await oe(o),o.send(P(V,n.requestId,p.subarray(R,R+w)))}d.has(n.requestId)&&(d.delete(n.requestId),b(o,{type:"response-end",requestId:n.requestId}))})().catch(S=>{q(n.requestId,S)})}),r.on("error",a=>{q(n.requestId,a)})},E=(n,e=1e3,t="")=>{let r=l.get(n);if(r!==void 0){l.delete(n);try{r.socket.close(e,t.slice(0,123))}catch{r.socket.close()}}},m=(n,e,t)=>{let r=l.get(n);if(r!==void 0){if(!r.open){if(r.queuedBytes+t.byteLength>x){E(n,1009,"WebSocket buffer limit reached"),b(o,{type:"websocket-error",requestId:n,message:"WebSocket buffer limit reached"});return}r.queue.push({kind:e,body:t}),r.queuedBytes+=t.byteLength;return}r.socket.send(e===L?t.toString("utf8"):N(t))}},h=n=>{if(!B(n.requestId)||l.has(n.requestId)||d.size+l.size>=O||typeof n.path!="string"||!n.path.startsWith("/")||n.protocols!==void 0&&(!Array.isArray(n.protocols)||n.protocols.some(c=>typeof c!="string"||!/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(c)))){o.close(1008,"Invalid WebSocket request");return}let e=new URL(n.path,`ws://127.0.0.1:${s}`);if(e.origin!==`ws://127.0.0.1:${s}`){o.close(1008,"Invalid WebSocket path");return}let t=new WebSocket(e,n.protocols??[]);t.binaryType="arraybuffer";let r={socket:t,open:!1,queue:[],queuedBytes:0};l.set(n.requestId,r),t.addEventListener("open",()=>{if(l.get(n.requestId)===r){r.open=!0;for(let c of r.queue)t.send(c.kind===L?c.body.toString("utf8"):N(c.body));r.queue=[],r.queuedBytes=0,b(o,{type:"websocket-ready",requestId:n.requestId,...t.protocol!==""&&{protocol:t.protocol}})}}),t.addEventListener("message",c=>{if(o.readyState===WebSocket.OPEN){if(typeof c.data=="string"){let a=Buffer.from(c.data);if(a.byteLength>w){E(n.requestId,1009,"WebSocket message too large");return}o.send(P(ee,n.requestId,a))}else if(c.data instanceof ArrayBuffer){let a=Buffer.from(c.data);if(a.byteLength>w){E(n.requestId,1009,"WebSocket message too large");return}o.send(P(te,n.requestId,a))}}}),t.addEventListener("close",c=>{l.get(n.requestId)===r&&(l.delete(n.requestId),o.readyState===WebSocket.OPEN&&b(o,{type:"websocket-close",requestId:n.requestId,code:c.code,reason:c.reason}))}),t.addEventListener("error",()=>{l.get(n.requestId)===r&&o.readyState===WebSocket.OPEN&&b(o,{type:"websocket-error",requestId:n.requestId,message:"Local WebSocket connection failed"})})},k=new Promise((n,e)=>{let t=setTimeout(()=>{o.close(),e(new Error("Tunnel setup timed out"))},Q);o.addEventListener("open",()=>{b(o,{type:"authenticate",token:i.token})}),o.addEventListener("message",r=>{if(r.data instanceof ArrayBuffer){let p=re(r.data);if(p===void 0){o.close(1003,"Invalid body frame");return}p.kind===G?d.get(p.requestId)?.request.write(p.body):p.kind===L||p.kind===Z?m(p.requestId,p.kind,p.body):o.close(1003,"Invalid body frame");return}if(typeof r.data!="string"){o.close(1003,"Invalid message");return}let c=r.data;if(Buffer.byteLength(c)>$){o.close(1009,"Control message too large");return}let a;try{a=JSON.parse(c)}catch{o.close(1003,"Invalid JSON");return}if(a.type==="auth-required")return;if(a.type==="ready"){f||(f=!0,clearTimeout(t),a.keepalive===!0&&(_=setInterval(()=>{if(o.readyState===WebSocket.OPEN){if(y){o.close(1011,"Tunnel keepalive timed out");return}y=!0,b(o,{type:"ping"})}},j),_.unref()),n());return}if(a.type==="pong"){y=!1;return}if(a.type==="request-start"){I(a);return}if(a.type==="websocket-open"){h(a);return}if(!B(a.requestId)){o.close(1008,"Invalid request identifier");return}let S=d.get(a.requestId);if(a.type==="request-end")S?.request.end();else if(a.type==="cancel"&&S!==void 0)d.delete(a.requestId),S.request.destroy(),S.response?.destroy();else if(a.type==="websocket-close"){let p=Number.isInteger(a.code)&&(a.code??0)>=1e3&&(a.code??0)<=4999?a.code:1e3;E(a.requestId,p,a.reason??"")}else o.close(1003,"Unsupported message")}),o.addEventListener("error",()=>{f||(clearTimeout(t),e(new Error("Tunnel WebSocket connection failed")))},{once:!0})});return o.addEventListener("close",n=>{_!==void 0&&clearInterval(_);for(let[e,t]of d)d.delete(e),t.request.destroy(),t.response?.destroy();for(let e of l.keys())E(e,1011,"Tunnel disconnected");!g&&f&&u(n)}),await k,Object.defineProperty(o,"__mcpUseIntentionalClose",{value:()=>{g=!0}}),{url:i.public_url,subdomain:i.tunnel_id,token:i.token,socket:o,reservation:i}}function ue(s){let i=s.__mcpUseIntentionalClose;i?.()}function fe(s){let i,u=null,o,d=!1,l,f=v,g,y=0,_=async()=>{try{let e=await H(s,"utf8"),t=JSON.parse(e);return typeof t.subdomain=="string"?{subdomain:t.subdomain,...typeof t.token=="string"&&{token:t.token},...typeof t.connect_url=="string"&&{connect_url:t.connect_url},...typeof t.public_url=="string"&&{public_url:t.public_url}}:void 0}catch{return}},q=async e=>{try{await D(z(s),{recursive:!0}),await X(s,JSON.stringify(e,null,2),{encoding:"utf8",mode:384})}catch(t){console.warn(`[mcp-use] failed to save tunnel state: ${t instanceof Error?t.message:String(t)}`)}},I=()=>{},E=e=>e?.token!==void 0&&e.connect_url!==void 0&&e.public_url!==void 0?{tunnel_id:e.subdomain,token:e.token,connect_url:e.connect_url,public_url:e.public_url}:void 0,m=e=>({subdomain:e.tunnel_id,token:e.token,connect_url:e.connect_url,public_url:e.public_url}),h=async e=>{await q(m(e.reservation))},k=async(e,t)=>ae(e,t,r=>{i=void 0,u=null;let c=r.code===1008||r.reason==="Tunnel expired"||r.reason==="Tunnel deleted";g=c?void 0:t,C(`tunnel connection closed (${r.code}${r.reason===""?"":`: ${r.reason}`}); ${c?"allocating a replacement":"reattaching"}`),I()}),n=async(e,t)=>{console.log(`[mcp-use] starting tunnel for port ${e}\u2026`);let r=await ie(t);return k(e,r)};return I=()=>{d||o===void 0||u!==null||l!==void 0||(l=(async()=>{for(;!d&&o!==void 0&&u===null;)try{if(g!==void 0&&y<W)try{let r=await k(o,g);i=r,u=r.url,y=0,f=v,await h(r),C("tunnel reattached");return}catch(r){if(y+=1,C(`tunnel reattach attempt ${y} failed: ${r instanceof Error?r.message:String(r)}`),y<W){await M(f),f=Math.min(f*2,F);continue}}let e=await _();e!==void 0&&await A(e),g=void 0,y=0;let t;try{t=await n(o,e?.subdomain)}catch(r){if(e?.subdomain===void 0)throw r;console.log(`[mcp-use] tunnel "${e.subdomain}" unavailable, requesting a new one\u2026`),t=await n(o)}i=t,u=t.url,await h(t),f=v;return}catch(e){console.warn(`[mcp-use] tunnel restart failed: ${e instanceof Error?e.message:String(e)}`),await M(f),f=Math.min(f*2,F)}})().finally(()=>{l=void 0}))},{status(){return{url:u}},async start(e){if(d=!1,o=e,i!==void 0&&u!==null)return{url:u,subdomain:i.subdomain};let t=await _(),r,c=E(t);if(c!==void 0)try{r=await k(e,c)}catch{await A(m(c)),r=await n(e,c.tunnel_id).catch(async()=>(console.log(`[mcp-use] tunnel "${c.tunnel_id}" unavailable, requesting a new one\u2026`),n(e)))}else{t!==void 0&&await A(t);try{r=await n(e,t?.subdomain)}catch(a){if(t?.subdomain===void 0)throw a;console.log(`[mcp-use] tunnel "${t.subdomain}" unavailable, requesting a new one\u2026`),r=await n(e)}}return i=r,u=r.url,g=r.reservation,y=0,await h(r),{url:r.url,subdomain:r.subdomain}},async stop(){d=!0,l!==void 0&&await l;let e=i,t=e?.reservation??g;i=void 0,u=null,o=void 0,f=v,g=void 0,y=0,t!==void 0&&await A(m(t)),e!==void 0&&(ue(e.socket),e.socket.close(1e3,"Client shutdown"))}}}export{K as a,fe as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{existsSync as s}from"fs";import{isAbsolute as p,join as f,resolve as d}from"path";var i=["src/index.ts","src/index.tsx","src/server.ts","src/server.tsx","index.ts","index.tsx","server.ts","server.tsx"];function j(t,e){if(e!==void 0){let n=p(e)?e:d(t,e);if(!s(n))throw new Error(`Entry not found: ${n} (from --entry "${e}")`);return n}for(let n of i){let r=f(t,n);if(s(r))return r}throw new Error(`No server entry found in ${t}. Looked for: ${i.join(", ")}. Create one of these (default-exporting your MCPServer instance) or pass --entry <path>.`)}import{readFile as l,writeFile as
|
|
2
|
-
`)}async function
|
|
1
|
+
import{existsSync as s}from"fs";import{isAbsolute as p,join as f,resolve as d}from"path";var i=["src/index.ts","src/index.tsx","src/server.ts","src/server.tsx","index.ts","index.tsx","server.ts","server.tsx"];function j(t,e){if(e!==void 0){let n=p(e)?e:d(t,e);if(!s(n))throw new Error(`Entry not found: ${n} (from --entry "${e}")`);return n}for(let n of i){let r=f(t,n);if(s(r))return r}throw new Error(`No server entry found in ${t}. Looked for: ${i.join(", ")}. Create one of these (default-exporting your MCPServer instance) or pass --entry <path>.`)}import{readFile as l,writeFile as c}from"fs/promises";import{extname as m,join as E,relative as g,sep as x}from"path";var h="mcp-env.d.ts",u="// Generated by mcp-use. Do not edit.",y=["// mcp-use generated env declaration","// mcp-use auto-generated typing"];function A(t,e){let n=g(t,e).split(x).join("/"),r=m(n),o=r===".mts"?".mjs":r===".cts"?".cjs":r===".ts"||r===".tsx"?".js":r;return r!==o&&(n=`${n.slice(0,-r.length)}${o}`),n.startsWith(".")?n:`./${n}`}function D(t,e){let n=A(t,e);return[u,'import "mcp-use/vite-client";',"",'declare module "mcp-use/react" {'," interface Register {",` tools: typeof import(${JSON.stringify(n)});`," }","}","","export {};",""].join(`
|
|
2
|
+
`)}async function v(t,e){let n=E(t,h),r=D(t,e);try{let o=await l(n,"utf8");return o===r?"unchanged":N(o)?(await c(n,r,"utf8"),"updated"):"user-owned"}catch(o){if(!a(o,"ENOENT"))throw o}try{return await c(n,r,{encoding:"utf8",flag:"wx"}),"created"}catch(o){if(!a(o,"EEXIST"))throw o;return v(t,e)}}function N(t){return[u,...y].some(e=>t.startsWith(e))}function a(t,e){return t!==null&&typeof t=="object"&&"code"in t&&t.code===e}export{j as a,v as b};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import{a as l}from"./chunk-USIKTT3N.js";import{resolve as c}from"path";var s=Object.getOwnPropertyDescriptor(globalThis,"localStorage");s?.get!==void 0&&s.configurable&&Object.defineProperty(globalThis,"localStorage",{configurable:!0,enumerable:s.enumerable??!1,value:void 0,writable:!0});var i=`mcp-use \u2014 run MCP servers built with mcp-use
|
|
2
|
+
|
|
3
|
+
Usage: mcp-use <command> [options]
|
|
4
|
+
|
|
5
|
+
Commands:
|
|
6
|
+
dev Start the dev server
|
|
7
|
+
build Build the server into .mcp-use/build
|
|
8
|
+
typecheck Refresh MCP types and run the project's TypeScript compiler
|
|
9
|
+
start Serve the production build from .mcp-use/build
|
|
10
|
+
login Authenticate the cloud CLI
|
|
11
|
+
logout Log out of the cloud CLI
|
|
12
|
+
whoami Show the authenticated cloud identity
|
|
13
|
+
org Manage the active organization
|
|
14
|
+
servers Manage cloud servers and environment variables
|
|
15
|
+
deployments Manage cloud deployments and logs
|
|
16
|
+
deploy Deploy from GitHub or upload local source
|
|
17
|
+
client Connect to and invoke MCP servers
|
|
18
|
+
screenshot Capture an MCP Apps view
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
-p, --port <n> Port to serve on (dev/start; default: $PORT or 3000)
|
|
22
|
+
--host <host> Host to bind (dev/start; default: $HOST or 127.0.0.1)
|
|
23
|
+
--entry <path> Server entry module (dev/build/typecheck only)
|
|
24
|
+
--path <directory> Project root (default: current directory)
|
|
25
|
+
--mcp-dir <dir> Directory containing the MCP entry and views/
|
|
26
|
+
--views-dir <dir> Views directory (default: views/ or <mcp-dir>/views/)
|
|
27
|
+
--source-maps Emit source maps in build output (build only)
|
|
28
|
+
--inline Embed view JS and CSS in MCP resources (build only)
|
|
29
|
+
-- <tsc options> Forward remaining options to TypeScript (typecheck only)
|
|
30
|
+
--with-inspector Mount Inspector on the production listener (start only)
|
|
31
|
+
--tunnel Expose the server through a public tunnel (dev/start only)
|
|
32
|
+
--no-open Do not auto-open the inspector in a browser (dev only)
|
|
33
|
+
--no-inspector Start dev without loading the optional Inspector
|
|
34
|
+
-h, --help Show this help
|
|
35
|
+
-v, --version Print the version`,p={dev:`Usage: mcp-use dev [options]
|
|
36
|
+
|
|
37
|
+
Start the development MCP server with view hot reload.
|
|
38
|
+
|
|
39
|
+
Options:
|
|
40
|
+
-p, --port <n> Listener port (default: $PORT or 3000)
|
|
41
|
+
--host <host> Bind host (default: $HOST or 127.0.0.1)
|
|
42
|
+
--path <directory> Project root (default: current directory)
|
|
43
|
+
--entry <path> Server entry module
|
|
44
|
+
--mcp-dir <dir> Directory containing the entry and views/
|
|
45
|
+
--views-dir <dir> Views directory
|
|
46
|
+
--tunnel Start a public tunnel
|
|
47
|
+
--no-open Do not open Inspector
|
|
48
|
+
--no-inspector Do not load Inspector
|
|
49
|
+
-h, --help Show this help
|
|
50
|
+
|
|
51
|
+
Exit codes: 0 started/help, 2 invalid arguments, 1 startup failure`,build:`Usage: mcp-use build [options]
|
|
52
|
+
|
|
53
|
+
Build the MCP server into .mcp-use/build.
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
--path <directory> Project root (default: current directory)
|
|
57
|
+
--entry <path> Server entry module
|
|
58
|
+
--mcp-dir <dir> Directory containing the entry and views/
|
|
59
|
+
--views-dir <dir> Views directory
|
|
60
|
+
--source-maps Emit source maps
|
|
61
|
+
--inline Embed view JavaScript and CSS in MCP resources
|
|
62
|
+
-h, --help Show this help
|
|
63
|
+
|
|
64
|
+
Exit codes: 0 built/help, 2 invalid arguments, 1 build failure`,typecheck:`Usage: mcp-use typecheck [options] [-- <tsc options>]
|
|
65
|
+
|
|
66
|
+
Refresh MCP types and run the selected project's TypeScript compiler.
|
|
67
|
+
|
|
68
|
+
Options:
|
|
69
|
+
--path <directory> Project root (default: current directory)
|
|
70
|
+
--entry <path> Server entry module
|
|
71
|
+
--mcp-dir <dir> Directory containing the MCP entry
|
|
72
|
+
-- <tsc options> Forward remaining options to TypeScript
|
|
73
|
+
-h, --help Show this help
|
|
74
|
+
|
|
75
|
+
Exit codes: 0 passed/help, 2 invalid arguments, otherwise the compiler or operational exit code`,start:`Usage: mcp-use start [options]
|
|
76
|
+
|
|
77
|
+
Serve the production build from .mcp-use/build.
|
|
78
|
+
|
|
79
|
+
Options:
|
|
80
|
+
-p, --port <n> Listener port (default: $PORT or 3000)
|
|
81
|
+
--host <host> Bind host (default: $HOST or 127.0.0.1)
|
|
82
|
+
--path <directory> Project root (default: current directory)
|
|
83
|
+
--with-inspector Mount Inspector on the production listener
|
|
84
|
+
--tunnel Start a public tunnel
|
|
85
|
+
-h, --help Show this help
|
|
86
|
+
|
|
87
|
+
Exit codes: 0 started/help, 2 invalid arguments, 1 startup failure`};async function d(t,r={frameworkVersion:"unknown"}){if(t.length===1&&["--version","-v"].includes(t[0]??""))return console.log(r.frameworkVersion),0;if(t.some(e=>e==="--help"||e==="-h")){let e=t[0];if(e===void 0||e==="--help"||e==="-h")return console.log(i),0;let u=p[e];if(u!==void 0)return console.log(u),0}let o=t[0];if(o==="login"||o==="logout"||o==="whoami"){let{runIdentity:e}=await import("./commands/identity.js");return e(o,t.slice(1))}if(o==="org"){let{runOrganizations:e}=await import("./commands/organizations.js");return e(t.slice(1))}if(o==="servers"){let{runServers:e}=await import("./commands/servers.js");return e(t.slice(1))}if(o==="deployments"){let{runDeployments:e}=await import("./commands/deployments.js");return e(t.slice(1))}if(o==="deploy"){let{runDeploy:e}=await import("./commands/deploy.js");return e(t.slice(1))}if(o==="client"){let{runClient:e}=await import("./commands/client.js");return e(t.slice(1))}if(o==="screenshot"){let{runScreenshot:e}=await import("./commands/screenshot.js");return e(t.slice(1))}let n;try{n=l(t)}catch(e){return console.error(e instanceof Error?e.message:String(e)),2}if(n.version)return console.log(r.frameworkVersion),0;if(n.help)return console.log(i),0;switch(n.command){case"start":return h(n);case"dev":case"build":return f(n.command,n);case"typecheck":return m(n);case void 0:return console.error(i),2;default:return console.error(`Unknown command: ${n.command}
|
|
88
|
+
|
|
89
|
+
${i}`),2}}async function m(t){try{let{runTypecheck:r}=await import("./commands/typecheck.js");return await r({cwd:c(process.cwd(),t.path??"."),...t.entry!==void 0&&{entry:t.entry},...t.mcpDir!==void 0&&{mcpDir:t.mcpDir},...t.passthrough.length>0&&{tscArgs:t.passthrough}})}catch(r){return console.error(a(r)),1}}async function h(t){let r;try{let{runStart:e}=await import("./commands/start.js");r=await e({cwd:c(process.cwd(),t.path??"."),port:t.port,host:t.host,...t.inspector===!0&&{withInspector:!0},tunnel:t.tunnel})}catch(e){return console.error(e instanceof Error?e.message:String(e)),1}console.log(`mcp-use server running at ${r.url}`),r.tunnelUrl!==void 0&&console.log(`mcp-use public MCP URL: ${r.tunnelUrl}`);let o=!1,n=()=>{o||(o=!0,r.close().then(()=>process.exit(0),e=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)}))};return process.once("SIGINT",n),process.once("SIGTERM",n),0}async function f(t,r){let o={cwd:c(process.cwd(),r.path??"."),...r.entry!==void 0&&{entry:r.entry},...r.mcpDir!==void 0&&{mcpDir:r.mcpDir},...r.viewsDir!==void 0&&{viewsDir:r.viewsDir},...r.port!==void 0&&{port:r.port},...r.host!==void 0&&{host:r.host},...r.tunnel&&{tunnel:!0},...!r.open&&{open:!1},...r.inspector===!1&&{inspector:!1},...r.sourceMaps&&{sourceMaps:!0},...r.inline&&{inline:!0}};try{if(t==="dev"){let{runDev:n}=await import("./commands/dev.js");await n(o)}else{let{runBuild:n}=await import("./commands/build.js");await n(o)}return 0}catch(n){return console.error(a(n)),1}}function a(t){let r=t instanceof Error?t.message:String(t);return/tunnel|bore connection/i.test(r)?["[tunnel_connection_timeout] Public tunnel could not establish a connection.",`Cause: ${r}`,"","Retry:"," mcp-use dev --tunnel","","Verify outbound network access and tunnel service status:"," https://local.mcp-use.run"].join(`
|
|
90
|
+
`):r}export{d as a};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{a as f,b as l,d as m}from"./chunk-7G4TXPP4.js";import{existsSync as V}from"fs";import{join as _}from"path";import{fileURLToPath as I}from"url";var h=["vite.config.ts","vite.config.js","vite.config.mts","vite.config.cjs"];function C(t){for(let e of h){let r=_(t,e);if(V(r))return r}return!1}function O(){return I(import.meta.resolve("tailwindcss/index.css"))}import{join as s}from"path";var x=".mcp-use",E="manifest.json";function k(t){let e=s(t,x),r=s(e,"build");return{projectRoot:t,workspace:e,build:r,generated:s(e,"generated"),cache:s(e,"cache"),state:s(e,"state"),cloud:s(e,"cloud"),buildManifest:s(r,E),tunnel:s(e,"state","tunnel.json")}}import{existsSync as g,readdirSync as D}from"fs";import{isAbsolute as R,join as P,resolve as y}from"path";import S from"@vitejs/plugin-react";var T="views",a="virtual:mcp-use/views/",c=`\0${a}`;function d(t,e){let r=e??T;return R(r)?r:y(t,r)}function G(t,e){let r=d(t,e);if(!g(r))return[];let n=[];for(let i of D(r,{withFileTypes:!0})){if(!i.isDirectory())continue;let o=P(r,i.name,"view.tsx");g(o)&&n.push({name:i.name,entryPath:o})}return n.sort((i,o)=>i.name.localeCompare(o.name)),n}function A(t){return`${a}${t}`}function M(t){return`/@id/__x00__${a}${t}`}function K(t,e,r){let n=d(e,r);return t===n||t.startsWith(`${n}/`)}function Z(t){let e={};for(let r of t)e[r.name]={kind:"external",entry:M(r.name),css:[],scripts:["/@vite/client"]};return e}async function q(t,e,r){let{createServer:n}=await import("vite");return n({root:t,configFile:r,envDir:!1,logLevel:"warn",cacheDir:e,resolve:{tsconfigPaths:!0,alias:f(t)},oxc:{jsx:{runtime:"automatic"}},plugins:[m(t),S()],server:{middlewareMode:!0,hmr:!1,ws:!1},ssr:{...l(t)}})}var u="virtual:mcp-use/tailwind.css",v=`\0${u}`,p="virtual:mcp-use/csp-runtime",w=`\0${p}`,b=["react","react-dom"],U={exclude:["mcp-use/react"],include:["react","react-dom","react-dom/client"]};function Y(t){return{name:"mcp-use-views",config(){return{resolve:{dedupe:b},optimizeDeps:U}},applyToEnvironment(e){return e.name==="client"},resolveId(e){if(e===p)return w;if(e===u)return v;if(e.startsWith(a))return`\0${e}`},load(e){if(e===w)return["globalThis.__zod_globalConfig ??= {};","globalThis.__zod_globalConfig.jitless = true;",""].join(`
|
|
2
|
+
`);if(e===v)return['@import "tailwindcss";',"@custom-variant dark (&:where(.dark, .dark *, [data-theme=dark], [data-theme=dark] *));"].join(`
|
|
3
|
+
`);if(!e.startsWith(c))return;let r=e.slice(c.length),n=t.getViews().find(o=>o.name===r);if(n===void 0)return;let i=[];return i.push(`import ${JSON.stringify(p)};`),t.dev?.reactRefresh===!0&&i.push('import "@vitejs/plugin-react/preamble";'),i.push(`import ${JSON.stringify(u)};`),i.push('import { bootstrapView } from "mcp-use/react";',`import * as viewModule from ${JSON.stringify(n.entryPath)};`,"bootstrapView(viewModule);"),t.dev!==void 0&&i.push("if (import.meta.hot) {"," import.meta.hot.accept();","}"),i.push(""),i.join(`
|
|
4
|
+
`)}}}export{C as a,O as b,k as c,d,G as e,A as f,K as g,Z as h,q as i,b as j,U as k,Y as l};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{a,b as g,d as z,e as f,f as F,g as G,h as K,i as b,j as T,k as P,m as _}from"./chunk-VUVLJMYY.js";import{createHash as ke}from"crypto";import{rm as ee}from"fs/promises";import{join as A}from"path";import{createInterface as Oe}from"readline/promises";import{parseArgs as E}from"util";var d=["-h, --help","Show this help"],h=["--json","Emit machine-readable JSON (accepted anywhere after client)"],S=new Map;function m(e,t){S.set(e,t)}m("",{usage:"mcp-use client <command>",summary:"Connect to and invoke saved HTTP(S) MCP servers.",commands:[["connect <name> <url>","Connect and save a server"],["list","List saved servers"],["remove <name>","Remove a saved server"],["<name>","Invoke a saved server"]],options:[d]});m("connect",{usage:"mcp-use client connect <name> <url> [options]",summary:"Connect to and save an HTTP(S) MCP server.",options:[['-H, --header <"Key: Value">',"Static header (repeatable)"],["--no-oauth","Skip OAuth on authorization challenges"],["--auth-timeout <ms>","OAuth wait timeout (default: 300000)"],["--protocol <auto|legacy|modern>","Protocol mode (default: auto; modern is stateless/sessionless)"],["--no-open","Print the OAuth URL without opening a browser"],h,d],notes:["JSON mode never opens a browser or prints an OAuth URL/state. If new consent is required, it returns oauth_interaction_required with an interactive retry command."]});m("list",{usage:"mcp-use client list [options]",summary:"List saved MCP servers.",options:[h,d]});m("remove",{usage:"mcp-use client remove <name> [options]",summary:"Immediately remove a saved server and its credentials.",options:[h,d]});m("<name>",{usage:"mcp-use client <name> <command>",summary:"Invoke a saved MCP server.",commands:[["tools","List, describe, or call tools"],["resources","List or read resources"],["prompts","List or get prompts"],["auth","Inspect or clear saved OAuth state"]],options:[d]});m("<name> tools",{usage:"mcp-use client <name> tools <command>",summary:"Use tools on a saved MCP server.",commands:[["list","List tools"],["describe <tool>","Show a tool definition"],["call <tool> [args...]","Call a tool"]],options:[d]});m("<name> tools list",{usage:"mcp-use client <name> tools list [options]",summary:"List tools on a saved MCP server.",options:[h,d]});m("<name> tools describe",{usage:"mcp-use client <name> tools describe <tool> [options]",summary:"Show one tool definition.",options:[h,d]});m("<name> tools call",{usage:"mcp-use client <name> tools call <tool> [args...] [options]",summary:"Call a tool on a saved MCP server.",options:[["--timeout <ms>","Call timeout (default: 30000)"],h,d],notes:["Arguments are one JSON object or key=value/key:=<json> pairs; do not mix forms."]});m("<name> resources",{usage:"mcp-use client <name> resources <command>",summary:"Use resources on a saved MCP server.",commands:[["list","List resources"],["read <uri>","Read a resource"]],options:[d]});m("<name> resources list",{usage:"mcp-use client <name> resources list [options]",summary:"List resources on a saved MCP server.",options:[h,d]});m("<name> resources read",{usage:"mcp-use client <name> resources read <uri> [options]",summary:"Read one resource.",options:[h,d]});m("<name> prompts",{usage:"mcp-use client <name> prompts <command>",summary:"Use prompts on a saved MCP server.",commands:[["list","List prompts"],["get <prompt> [args...]","Get a prompt"]],options:[d]});m("<name> prompts list",{usage:"mcp-use client <name> prompts list [options]",summary:"List prompts on a saved MCP server.",options:[h,d]});m("<name> prompts get",{usage:"mcp-use client <name> prompts get <prompt> [args...] [options]",summary:"Get a prompt from a saved MCP server.",options:[h,d],notes:["Arguments are one JSON object or key=value/key:=<json> pairs; do not mix forms."]});m("<name> auth",{usage:"mcp-use client <name> auth <command>",summary:"Manage saved OAuth state.",commands:[["status","Show OAuth status"],["logout","Delete saved OAuth credentials"]],options:[d]});m("<name> auth status",{usage:"mcp-use client <name> auth status [options]",summary:"Show saved OAuth status.",options:[h,d]});m("<name> auth logout",{usage:"mcp-use client <name> auth logout [options]",summary:"Delete saved OAuth credentials but keep the server.",options:[["--yes","Skip the confirmation prompt"],h,d]});function V(e){let t=e.filter(u=>u!=="--help"&&u!=="-h"&&u!=="--json"),n=t[0];if(n===void 0)return{text:k(S.get(""))};if(n==="connect"||n==="list"||n==="remove")return{text:k(S.get(n))};let o=t[1];if(o===void 0)return{text:k(S.get("<name>"))};if(!["tools","resources","prompts","auth"].includes(o))return{error:`Unknown client command family: ${o}`};let r=t[2],s=`<name> ${o}`;if(r===void 0)return{text:k(S.get(s))};let i=`${s} ${r}`,l=S.get(i);return l===void 0?{error:`Unknown client ${o} command: ${r}`}:{text:k(l)}}function k(e){let t=[`Usage: ${e.usage}`,e.summary];return e.commands!==void 0&&t.push(W("Commands",e.commands)),e.options!==void 0&&t.push(W("Options",e.options)),e.notes!==void 0&&t.push(e.notes.join(`
|
|
2
|
+
`)),t.join(`
|
|
3
|
+
|
|
4
|
+
`)}function W(e,t){let n=Math.max(...t.map(([o])=>o.length));return`${e}:
|
|
5
|
+
${t.map(([o,r])=>` ${o.padEnd(n)} ${r}`).join(`
|
|
6
|
+
`)}`}import{spawn as ue}from"child_process";import{readFileSync as le}from"fs";import{chmod as de,mkdir as me}from"fs/promises";import{dirname as pe,join as $,resolve as fe}from"path";import{pathToFileURL as Q}from"url";var O=$(_,"client-sdk"),w="@mcp-use/client",ge="^2.0.0-alpha.0",he=[`[mcp-use] ${w} is not installed.`,"The `mcp-use client` and `mcp-use screenshot` commands require it.","Install it in your project:",""," npm install @mcp-use/client",""," pnpm add @mcp-use/client",""," bun add @mcp-use/client"].join(`
|
|
7
|
+
`);async function we(e){let t=fe(e);for(;;){if(await b($(t,"package.json")))return t;let n=pe(t);if(n===t)return;t=n}}async function X(e={}){try{return await Se()}catch(t){if(!Y(t))throw t;if(e.allowInstall===!1)throw new g("client_install_required",`${w} is required for this command.`,{nextSteps:[{description:"Install the optional client SDK",command:`npm install ${w}`}]});let n=await ve();try{return n.location==="sandbox"?await be():await Ce(n.projectRoot)}catch(o){throw Y(o)?new a(he):o}}}async function ve(){let e=Pe(),t=`${w}@${e}`,n=await we(process.cwd());if(process.stderr.write(`[mcp-use] installing ${w}\u2026
|
|
8
|
+
`),n!==void 0){let[s,i]=ye(t);if(await Z(s,i,n)!==0)throw new g("client_install_failed",`Failed to install ${w}.`);return{location:"project",projectRoot:n}}await me(O,{recursive:!0,mode:448}),await de(O,448);let o=$(O,"package.json");if(await b(o)||await P(o,{private:!0,dependencies:{[w]:e}}),await Z("npm",["install",t],O)!==0)throw new g("client_install_failed",`Failed to install ${w}.`);return{location:"sandbox"}}function ye(e){let t=process.env.npm_config_user_agent??"";return t.startsWith("pnpm/")?["pnpm",["add",e]]:t.startsWith("bun/")?["bun",["add",e]]:["npm",["install",e]]}function Pe(){for(let e of["../package.json","../../package.json"])try{let t=le(new URL(e,import.meta.url),"utf8"),n=JSON.parse(t);if(n.name!=="mcp-use")continue;let o=n.peerDependencies?.[w];if(typeof o=="string"&&o.length>0)return o}catch{}return ge}async function Se(){return I(),import("@mcp-use/client")}async function Ce(e){I();let t=Q($(e,"package.json")).href;return import(await import.meta.resolve(w,t))}async function be(){I();let e=$(O,"node_modules",w,"dist","index.js");return await import(Q(e).href)}function I(){let e=Object.getOwnPropertyDescriptor(globalThis,"localStorage");e?.get===void 0||e.configurable!==!0||Object.defineProperty(globalThis,"localStorage",{configurable:!0,enumerable:e.enumerable??!1,value:void 0,writable:!0})}function Y(e){if(!(e instanceof Error))return!1;let t=e.code;return t==="ERR_MODULE_NOT_FOUND"||t==="MODULE_NOT_FOUND"?e.message.includes(w)||e.message.includes("Cannot find package"):!1}function Z(e,t,n){return new Promise((o,r)=>{let s=ue(e,t,{cwd:n,stdio:"inherit",shell:process.platform==="win32"});s.once("error",r),s.once("exit",(i,l)=>{o(l==="SIGINT"?130:i??1)})})}var te=A(_,"client"),L=A(te,"servers.json");async function nt(e){if(e.includes("--help")||e.includes("-h")){let r=V(e);return r.text!==void 0?(process.stdout.write(`${r.text}
|
|
9
|
+
`),0):(process.stderr.write(`${r.error}
|
|
10
|
+
`),2)}let t=z(e),n=e.filter(r=>r!=="--json"),o=n[0];try{if(o==="connect")return await $e(n.slice(1),t);if(o==="list")return await Re(n.slice(1),t);if(o==="remove")return await Ae(n.slice(1),t);if(o===void 0)throw new a("Usage: mcp-use client <connect|list|remove|name>");return await Ee(o,n.slice(1),t)}catch(r){return F(r instanceof TypeError?new a(r.message):r,t)}}async function $e(e,t){let{values:n,positionals:o}=E({args:[...e],allowPositionals:!0,strict:!0,options:{header:{type:"string",short:"H",multiple:!0},"no-oauth":{type:"boolean"},"auth-timeout":{type:"string"},protocol:{type:"string",default:"auto"},"no-open":{type:"boolean"}}});if(o.length!==2)throw new a("Usage: mcp-use client connect <name> <url>");let[r,s]=o;je(r);let i=new URL(s);if(!["http:","https:"].includes(i.protocol))throw new a("Client URLs must use http or https.");let l=Ue(n.protocol),u=re(n["auth-timeout"]??"300000","--auth-timeout"),c=await x();if(c.servers[r]!==void 0)throw new a(`Saved server already exists: ${r}`);let p={headers:Le(n.header??[])},y={url:i.href,oauth:n["no-oauth"]!==!0,protocol:l};return await(await U(r,y,p,u,oe({noOpen:n["no-open"]===!0,json:t}),t,`mcp-use client connect ${r} <url> --no-open`)).disconnect(),c.servers[r]=y,await P(L,c),await P(J(r),p),f({name:r,url:se(y.url),protocol:l},t,`Connected and saved ${r}.`),0}async function Re(e,t){C(e);let n=await x(),o=Object.entries(n.servers).map(([r,s])=>({name:r,...s,url:se(s.url)}));return f(o,t,o.map(r=>`${r.name} ${r.url}`).join(`
|
|
11
|
+
`)||"No saved servers."),0}async function Ae(e,t){let{positionals:n}=E({args:[...e],allowPositionals:!0,strict:!0,options:{}}),o=R(n,"mcp-use client remove <name>"),r=await x();return delete r.servers[o],await P(L,r),await ee(H(o),{recursive:!0,force:!0}),f({removed:o},t,`Removed ${o}.`),0}async function Ee(e,t,n){let r=(await x()).servers[e];if(r===void 0)throw new a(`Unknown saved server: ${e}. Run \`mcp-use client connect ${e} <url>\`.`);let s=t[0],i=t[1];if(s==="auth"){if(i==="status"){C(t.slice(2));let c=await b(D(e));return f({name:e,oauth:r.oauth,authenticated:c},n,c?"Authenticated.":"No saved OAuth session."),0}if(i==="logout"){let{values:c,positionals:p}=E({args:[...t.slice(2)],allowPositionals:!0,strict:!0,options:{yes:{type:"boolean"}}});if(p.length!==0)throw new a(`Usage: mcp-use client ${e} auth logout`);return await G(`Delete OAuth credentials for ${e}?`,{yes:c.yes===!0,json:n})&&(await ee(D(e),{recursive:!0,force:!0}),f({loggedOut:e},n,`Logged out ${e}.`)),0}}xe(e,s,i,t.slice(2));let l=await T(J(e),{}),u=await U(e,r,l,3e5,oe({noOpen:!1,json:n}),n);try{if(s==="tools"){if(i==="list"){C(t.slice(2));let c=await u.listTools();return f(c,n,c.map(p=>p.description?`${p.name} - ${p.description}`:p.name).join(`
|
|
12
|
+
`)),0}if(i==="describe"){let c=R(t.slice(2),`mcp-use client ${e} tools describe <tool>`),p=(await u.listTools()).find(y=>y.name===c);if(p===void 0)throw new a(`Tool not found: ${c}`);return f(p,n),0}if(i==="call")return await Te(u,e,t.slice(2),n)}if(s==="resources"){if(i==="list"){C(t.slice(2));let c=await u.listResources();return f(c,n),0}if(i==="read"){let c=R(t.slice(2),`mcp-use client ${e} resources read <uri>`);return f(await u.readResource(c),n),0}}if(s==="prompts"){if(i==="list")return C(t.slice(2)),f(await u.listPrompts(),n),0;if(i==="get"){let c=t[2];if(c===void 0)throw new a(`Usage: mcp-use client ${e} prompts get <prompt> [args]`);return f(await u.getPrompt(c,j(t.slice(3))),n),0}}throw new a(`Usage: mcp-use client ${e} <tools|resources|prompts|auth> ...`)}finally{await u.disconnect()}}function xe(e,t,n,o){if(t==="tools"&&n==="list"||t==="resources"&&n==="list"||t==="prompts"&&n==="list"){C(o);return}if(t==="tools"&&n==="describe"){R(o,`mcp-use client ${e} tools describe <tool>`);return}if(t==="tools"&&n==="call"){ne(e,o);return}if(t==="resources"&&n==="read"){R(o,`mcp-use client ${e} resources read <uri>`);return}if(t==="prompts"&&n==="get"){if(o[0]===void 0)throw new a(`Usage: mcp-use client ${e} prompts get <prompt> [args]`);j(o.slice(1));return}throw new a(`Usage: mcp-use client ${e} <tools|resources|prompts|auth> ...`)}async function Te(e,t,n,o){let{tool:r,timeout:s,positionals:i}=ne(t,n),l=await e.callTool(r,j(i),{timeout:s});if(l.isError===!0)throw new g("tool_error",`Tool ${r} returned an error.`,l);return f(l,o),0}function ne(e,t){let n=t[0];if(n===void 0)throw new a(`Usage: mcp-use client ${e} tools call <tool> [args]`);let{values:o,positionals:r}=E({args:[...t.slice(1)],allowPositionals:!0,strict:!0,options:{timeout:{type:"string",default:"30000"}}}),s=re(o.timeout,"--timeout");return j(r),{tool:n,timeout:s,positionals:r}}async function U(e,t,n,o,r=process.stdin.isTTY?"ask":"never",s=!1,i=`mcp-use client ${e} tools list`){let{createOAuthProvider:l,MCPClient:u,logger:c}=await X({allowInstall:!s});s&&(c.level="silent");let p,y=s&&t.oauth?new Promise((v,ce)=>{p=ce}):void 0,B=D(e),M=t.oauth?await l(t.url,{baseDir:B,authTimeoutMs:o,storageKeyPrefix:`mcp-use-cli:${e}`,openBrowser:async v=>{if(s){setImmediate(()=>{p?.(new g("oauth_interaction_required","OAuth interaction is required; retry this command without --json in a terminal.",{server:e,nextSteps:[{description:"Authenticate interactively in a terminal",command:i}]}))});return}if(r==="never"){process.stderr.write(`Open this URL to authenticate:
|
|
13
|
+
${v}
|
|
14
|
+
`);return}await _e(),K(v)}}):void 0,ae=t.protocol==="auto"?{protocolNegotiation:"auto"}:t.protocol==="modern"?{protocolNegotiation:{pin:"2026-07-28"}}:{protocolNegotiation:"legacy",clientOptions:{supportedProtocolVersions:["2025-11-25"]}},q=new u({mcpServers:{[e]:{url:t.url,...n.headers!==void 0?{headers:n.headers}:{},...M!==void 0?{authProvider:M}:{oauth:!1},...ae}}});try{let v=q.connect(e);return await(y===void 0?v:Promise.race([v,y]))}catch(v){throw v instanceof g&&v.code==="oauth_interaction_required"?(M?.dispose?.(),await q.closeSession?.(e),v):Ne(Ie(v,t.protocol),t,n)}}async function ot(e,t=3e5,n=!1){let r=(await x()).servers[e];if(r===void 0)throw new a(`Unknown saved server: ${e}`);let s=await T(J(e),{});return U(e,r,s,t,process.stdin.isTTY?"ask":"never",n)}async function rt(e,t,n=!1){return U("screenshot",{url:e,oauth:!1,protocol:"auto"},{headers:t},3e5,"never",n)}function j(e){if(e.length===0)return{};if(e.length===1&&e[0]?.trimStart().startsWith("{")){let n=JSON.parse(e[0]);if(n===null||Array.isArray(n)||typeof n!="object")throw new a("The JSON argument must be an object.");return n}let t={};for(let n of e){let o=n.indexOf(":="),r=n.indexOf("="),s=o>=0?o:r,i=o>=0?2:1;if(s<=0)throw new a(`Expected key=value or key:=<json>, received: ${n}`);let l=n.slice(0,s).replace(/^--/,""),u=n.slice(s+i);t[l]=o>=0?JSON.parse(u):u}return t}function oe(e){return e.json||e.noOpen||!process.stdin.isTTY?"never":"ask"}async function _e(){let e=Oe({input:process.stdin,output:process.stderr});try{await e.question("This server requires OAuth. Press Enter to open your browser.")}finally{e.close()}}function Le(e){let t={};for(let n of e){let o=n.indexOf(":");if(o<=0)throw new a(`Invalid header: ${n}`);t[n.slice(0,o).trim()]=n.slice(o+1).trim()}return t}function Ue(e){if(e!=="auto"&&e!=="legacy"&&e!=="modern")throw new a("Invalid protocol. Expected auto, legacy, or modern.");return e}function re(e,t){let n=Number(e);if(!Number.isInteger(n)||n<=0)throw new a(`${t} must be a positive integer.`);return n}function je(e){if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(e))throw new a("Server names must be 1-64 filesystem-safe letters, numbers, dots, dashes, or underscores.")}function se(e){let t=new URL(e);(t.username!==""||t.password!=="")&&(t.username="[REDACTED]",t.password="");for(let n of[...t.searchParams.keys()])t.searchParams.set(n,"[REDACTED]");return t.hash!==""&&(t.hash="[REDACTED]"),t.href}async function x(){let e=await T(L,{servers:{}}),t={servers:{}},n=!1;for(let[o,r]of Object.entries(e.servers)){let s=Me(r.protocol);t.servers[o]={...r,protocol:s},n||=s!==r.protocol}return n&&await P(L,t),t}function Me(e){if(e==="auto"||e==="legacy"||e==="modern")return e;if(e===void 0)return"auto";if(e==="2025-11-25")return"legacy";if(e==="2026-07-28")return"modern";throw new a("Saved server has an invalid protocol setting. Remove and reconnect it.")}function Ie(e,t){return t==="auto"||!(e instanceof Error)||!e.message.includes("Unsupported protocol version")&&!e.message.includes("pinned protocol version")?e:t==="legacy"?new g("protocol_mismatch","Server does not support the requested legacy protocol."):new g("protocol_mismatch","Server does not support the requested modern protocol (stateless/sessionless, no fallback).")}function Ne(e,t,n){let o=De(t.url,n.headers);if(!(e instanceof Error)||o.size===0)return e;let r=ie(e.message,o);if(e instanceof g)return new g(e.code,r,N(e.details,o));let s=new Error(r);return s.name=e.name,s}function De(e,t){let n=new Set,o=new URL(e);for(let r of[o.username,o.password,...o.searchParams.values(),o.hash.slice(1)])r!==""&&n.add(r);for(let r of Object.values(t??{}))if(r!==""){n.add(r);let s=r.match(/^Bearer\s+(.+)$/i)?.[1];s!==void 0&&n.add(s)}return n}function N(e,t){return typeof e=="string"?ie(e,t):Array.isArray(e)?e.map(n=>N(n,t)):e===null||typeof e!="object"?e:Object.fromEntries(Object.entries(e).map(([n,o])=>[n,N(o,t)]))}function ie(e,t){let n=e;for(let o of t)n=n.replaceAll(o,"[REDACTED]");return n}function H(e){return A(te,"credentials",ke("sha256").update(e).digest("hex"))}function J(e){return A(H(e),"credentials.json")}function D(e){return A(H(e),"oauth")}function C(e){E({args:[...e],allowPositionals:!1,strict:!0,options:{}})}function R(e,t){if(e.length!==1)throw new a(`Usage: ${t}`);return e[0]}export{nt as a,ot as b,rt as c,j as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{execFile as t}from"child_process";function d(n,e=process.platform){let r;try{r=new URL(n)}catch{return}if(r.protocol!=="http:"&&r.protocol!=="https:"||r.username||r.password)return;let o=r.toString();return e==="darwin"?{command:"open",args:[o]}:e==="win32"?{command:"rundll32.exe",args:["url.dll,FileProtocolHandler",o]}:{command:"xdg-open",args:[o]}}function i(n){let e=d(n);if(e)try{t(e.command,e.args,{timeout:15e3,windowsHide:!0},()=>{}).unref()}catch{}}export{i as a};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{a as c}from"./chunk-LNASFQWW.js";import{constants as l}from"fs";import{access as m,chmod as d,mkdir as w,readFile as y,rename as x,rm as g,writeFile as $}from"fs/promises";import{homedir as S}from"os";import{dirname as b,join as p}from"path";import{createInterface as k}from"readline/promises";var r=class extends Error{exitCode=2},s=class extends Error{code;details;constructor(e,t,o){super(t),this.code=e,this.details=o}},u=class extends s{exitCode=2};function _(n){return n.includes("--json")}function h(n,e,t){e?process.stdout.write(`${JSON.stringify(n)}
|
|
2
|
+
`):t!==void 0?process.stdout.write(`${t}
|
|
3
|
+
`):typeof n=="string"?process.stdout.write(`${n}
|
|
4
|
+
`):process.stdout.write(`${JSON.stringify(n,null,2)}
|
|
5
|
+
`)}function v(n,e){let t=n instanceof r||n instanceof s&&"exitCode"in n&&n.exitCode===2,o=n instanceof s,f=o?n.code:t?"usage_error":"command_failed",i=n instanceof Error?n.message:String(n);if(e)process.stderr.write(`${JSON.stringify({error:{code:f,message:i,...o&&n.details!==void 0?{details:n.details}:{}}})}
|
|
6
|
+
`);else if(process.stderr.write(`${i}
|
|
7
|
+
`),o&&N(n.details))for(let a of n.details.nextSteps)process.stderr.write(`
|
|
8
|
+
${a.description}:
|
|
9
|
+
${a.command}
|
|
10
|
+
`);return t?2:1}function N(n){if(n===null||typeof n!="object")return!1;let e=n.nextSteps;return Array.isArray(e)&&e.every(t=>t!==null&&typeof t=="object"&&typeof t.description=="string"&&typeof t.command=="string")}async function A(n,e){if(e.yes)return!0;if(e.json||!process.stdin.isTTY)throw new r(`${n} Pass --yes to confirm.`);let t=k({input:process.stdin,output:process.stdout});try{return(await t.question(`${n} [y/N] `)).trim().toLowerCase()==="y"}finally{t.close()}}function B(n){c(n)}async function C(n){try{return await m(n,l.F_OK),!0}catch{return!1}}async function F(n,e){try{return JSON.parse(await y(n,"utf8"))}catch(t){if(t.code==="ENOENT")return e;throw new s("invalid_state",`Could not read ${n}.`,{cause:t instanceof Error?t.message:String(t)})}}async function I(n,e){let t=b(n);await w(t,{recursive:!0,mode:448}),await d(t,448);let o=p(t,`.${n.slice(n.lastIndexOf("/")+1)}.${process.pid}.${Date.now()}.tmp`);await $(o,`${JSON.stringify(e,null,2)}
|
|
11
|
+
`,{mode:384}),await x(o,n),await d(n,384)}async function L(n){await g(n,{force:!0})}var D=p(S(),".mcp-use");export{r as a,s as b,u as c,_ as d,h as e,v as f,A as g,B as h,C as i,F as j,I as k,L as l,D as m};
|
package/dist/commands/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
`)),
|
|
3
|
-
`)}}return{kind:"external",entry:
|
|
4
|
-
`);let
|
|
5
|
-
`);let
|
|
1
|
+
import{a as C,b as L,c as j,d as O,e as N,f as T,i as A,l as F}from"../chunk-ICHICRCP.js";import{a as M,b as R,c as B,d as S}from"../chunk-7G4TXPP4.js";import{a as $,b as V}from"../chunk-FLGSKQGU.js";import{randomBytes as J}from"crypto";import{existsSync as G}from"fs";import{cp as ie,mkdir as x,rm as se,writeFile as P}from"fs/promises";import{join as p,relative as y,resolve as oe}from"path";import ae from"@tailwindcss/vite";import ce from"@vitejs/plugin-react";import{build as U}from"vite";import{createServerModuleRunner as k}from"vite";var te="/mcp",I="http://localhost:3000";async function re(e,t){let i=k(e,{hmr:!1,sourcemapInterceptor:"node"}),r=process.env.MCP_URL;try{r===void 0&&(process.env.MCP_URL=I);let n=(await i.import(t)).default;if(n===null||typeof n!="object")throw new Error("The server entry must default-export the MCPServer instance.");return n.basePath??te}finally{r===void 0?delete process.env.MCP_URL:process.env.MCP_URL=r,await i.close()}}async function q(e,t){return re(e,t)}async function E(e,t,i){let r=k(e,{hmr:!1,sourcemapInterceptor:"node"}),s=process.env.MCP_URL;try{s===void 0&&(process.env.MCP_URL=I);let c=(await r.import(t)).default;if(c===null||typeof c!="object")throw new Error("The server entry must default-export the MCPServer instance.");if(typeof c.__primeViews!="function")throw new Error("The entry's default export does not support __primeViews.");c.__primeViews(i),c.__mount()}finally{s===void 0?delete process.env.MCP_URL:process.env.MCP_URL=s,await r.close()}}function ne(e){return e.replace(/\/+$/,"")}function W(e){return ne(e)}import{hostHeaderValidationResponse as ve,originValidationResponse as be}from"@modelcontextprotocol/server";function H(e,t){let i=t.replace(/^\/+/,"");return e==="/"?`/${i}`:`${e}/${i}`}function D(e,t){return`${H(e,`_mcp-use/views/${t}`)}/`}var m="index.js",ue="entry-wrapper.ts",le=100*1024*1024;async function z(e,t){let i=p(e,"public");G(i)&&await ie(i,t,{recursive:!0})}async function Y(e,t,i){let r=p(e,ue);await x(e,{recursive:!0});let s=JSON.stringify(i);return await P(r,[`import server from ${JSON.stringify(t)};`,'import { registerViews } from "mcp-use";',`server[registerViews](${s});`,"export default server;",""].join(`
|
|
2
|
+
`)),r}function de(){let e=process.env.MCP_ASSETS_URL;if(!(e===void 0||e.trim()===""))try{return W(new URL(e).href.replace(/\/$/,""))}catch{return}}function _(e,t,i,r){let s=e.replace(/^\/+/,"");return`${i}${D(r,t)}${s}`}function fe(e,t,i,r){return e.kind!=="external"?e:{...e,entry:_(e.entry,t,i,r),css:e.css.map(s=>_(s,t,i,r)),...e.scripts!==void 0&&{scripts:e.scripts.map(s=>_(s,t,i,r))}}}async function pe(e,t){let i=p(t.viewsOutDir,e.name),r=await U({root:t.cwd,configFile:t.userViteConfig,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:t.cacheDir,resolve:{tsconfigPaths:!0,alias:{tailwindcss:L()}},oxc:{jsx:{runtime:"automatic"}},plugins:[ae(),ce(),F({getViews:()=>[e]})],build:{outDir:i,emptyOutDir:!0,write:!t.inline,target:"es2022",sourcemap:t.inline?!1:t.sourceMaps,minify:!0,cssCodeSplit:!1,chunkSizeWarningLimit:1e3,assetsInlineLimit:le,rollupOptions:{input:{[e.name]:T(e.name)},output:{format:"es",codeSplitting:!t.inline,entryFileNames:"assets/[name]-[hash].js",chunkFileNames:"assets/[name]-[hash].js",assetFileNames:"assets/[name]-[hash][extname]"}}},base:"./"}),s=Array.isArray(r)?r[0]:r;if(s===void 0||!("output"in s))throw new Error(`Client build for view "${e.name}" produced no output.`);let n=s.output,c=Array.isArray(n)?n:Object.values(n),l,g,d,f=[];for(let a of c){if(typeof a!="object"||a===null||!("fileName"in a)||typeof a.fileName!="string")continue;let o=a;o.type==="chunk"&&o.isEntry===!0?(l=o.fileName,d=o.code):o.type==="asset"&&o.fileName.endsWith(".css")&&(g=o.fileName,typeof o.source=="string"?f.push(o.source):o.source instanceof Uint8Array&&f.push(new TextDecoder().decode(o.source)))}if(l===void 0)throw new Error(`Client build produced no entry chunk for view "${e.name}".`);if(t.inline){if(d===void 0)throw new Error(`Client build produced no entry source for view "${e.name}".`);return{kind:"inline",js:d,css:f.join(`
|
|
3
|
+
`)}}return{kind:"external",entry:l.replace(/^\/+/,""),css:g!==void 0?[g.replace(/^\/+/,"")]:[]}}async function me(e){let t=performance.now();B(e.cwd,"production");let i=e.mcpDir===void 0?e.cwd:oe(e.cwd,e.mcpDir),r=e.entry===void 0?$(i):$(e.cwd,e.entry),s=await V(e.cwd,r);(s==="created"||s==="updated")&&console.log(`[mcp-use] ${s} mcp-env.d.ts`);let n=j(e.cwd),c=e.viewsDir??(e.mcpDir===void 0?void 0:p(e.mcpDir,"views"));G(O(e.cwd,c))||console.log("[mcp-use] views directory not configured.");let l=N(e.cwd,c),g=C(e.cwd),d=e.sourceMaps===!0,f=e.inline===!0,a;if(l.length===0){a??=await A(e.cwd,n.cache,!1);try{await E(a.environments.ssr,r,{});let ee=await Y(n.cache,r,{});await U({root:e.cwd,configFile:!1,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:n.cache,resolve:{tsconfigPaths:!0,alias:M(e.cwd)},plugins:[S(e.cwd)],build:{ssr:ee,outDir:n.build,emptyOutDir:!0,target:"node22",sourcemap:d,minify:!1,rollupOptions:{output:{format:"es",entryFileNames:m}}},ssr:{...R(e.cwd),target:"node"}})}finally{await a?.close()}await z(e.cwd,p(n.build,"views/public"));let u={buildId:J(8).toString("hex"),entryPoint:m,createdAt:new Date().toISOString(),views:{}};await x(n.build,{recursive:!0}),await P(n.buildManifest,`${JSON.stringify(u,null,2)}
|
|
4
|
+
`);let h=Math.round(performance.now()-t);console.log(`[mcp-use] built ${y(e.cwd,r)} \u2192 ${y(e.cwd,n.build)}/${m} (${h}ms)`);return}await se(n.build,{recursive:!0,force:!0});let w=p(n.build,"views");await x(w,{recursive:!0}),a??=await A(e.cwd,n.cache,!1);let o,v={},b=de();try{o=await q(a.environments.ssr,r);for(let u of l){let h=await pe(u,{cwd:e.cwd,cacheDir:n.cache,viewsOutDir:w,userViteConfig:g,sourceMaps:d,inline:f});b!==void 0&&!f&&(h=fe(h,u.name,b,o)),v[u.name]=h}if(b!==void 0&&!f){let u=`${b}${D(o,"<view-name>")}`;console.log(`[mcp-use] MCP_ASSETS_URL set \u2014 publish ${y(e.cwd,w)}/ at ${u}`),o!=="/mcp"&&console.log(`[mcp-use] CDN manifest uses basePath ${o} from server entry`)}await z(e.cwd,p(w,"public")),await E(a.environments.ssr,r,v)}finally{await a.close()}let K=await Y(n.cache,r,v);await U({root:e.cwd,configFile:!1,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:n.cache,resolve:{tsconfigPaths:!0,alias:M(e.cwd)},oxc:{jsx:{runtime:"automatic"}},plugins:[S(e.cwd)],build:{ssr:K,outDir:n.build,emptyOutDir:!1,target:"node22",sourcemap:d,minify:!1,rollupOptions:{output:{format:"es",entryFileNames:m}}},ssr:{...R(e.cwd),target:"node"}});let Q={buildId:J(8).toString("hex"),entryPoint:m,createdAt:new Date().toISOString(),views:v};await x(n.build,{recursive:!0}),await P(n.buildManifest,`${JSON.stringify(Q,null,2)}
|
|
5
|
+
`);let X=Math.round(performance.now()-t),Z=l.map(u=>u.name).join(", ");console.log(`[mcp-use] built ${y(e.cwd,r)} + views (${Z}) \u2192 ${y(e.cwd,n.build)}/${m} (${X}ms)`)}export{me as runBuild};
|
package/dist/commands/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d}from"../chunk-
|
|
1
|
+
import{a,b,c,d}from"../chunk-ISAAAHEM.js";import"../chunk-VUVLJMYY.js";import"../chunk-LNASFQWW.js";export{c as openDirectConnection,b as openSavedConnection,d as parseMcpArguments,a as runClient};
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1 +1,73 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as N,h as K}from"../chunk-3XW44DRS.js";import{a as h,b as p,c as v,d as M,e as J,f as F,g as V,h as Y,i as E,j as W,k as U}from"../chunk-VUVLJMYY.js";import"../chunk-LNASFQWW.js";import{execFile as Se}from"child_process";import{createReadStream as Ce}from"fs";import{appendFile as re,lstat as Ie,opendir as je,readFile as T,writeFile as $e}from"fs/promises";import{basename as se,isAbsolute as Z,join as k,relative as _e,resolve as ae}from"path";import{createInterface as ce}from"readline/promises";import{parseArgs as Re,promisify as Ge}from"util";import{createGzip as Ee}from"zlib";var de=Ge(Se),X=80*1024*1024,Ae=new Set([".git","node_modules","dist","build",".next",".turbo",".vercel",".cache",".parcel-cache",".pytest_cache",".ruff_cache",".mypy_cache","__pycache__",".venv","venv","coverage",".nyc_output",".output","out","target",".mcp-use"]),De=`Deploy an MCP server to Manufact Cloud.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
mcp-use deploy [path] [options]
|
|
5
|
+
|
|
6
|
+
Source modes:
|
|
7
|
+
GitHub (default) Deploy the current origin. If none exists, an interactive
|
|
8
|
+
run can create a private repository; --yes authorizes the
|
|
9
|
+
same flow without prompts.
|
|
10
|
+
Managed upload Pass --no-github on the first deploy to upload local
|
|
11
|
+
source. Linked managed projects auto-detect this on retry.
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
--org <id-or-slug> Target organization (default: active organization)
|
|
15
|
+
--name <name> Cloud server/repository name (default: project name)
|
|
16
|
+
--branch <name> Branch (default: current Git branch, or main)
|
|
17
|
+
--root-dir <path> Project root inside the repository/upload directory
|
|
18
|
+
--region <region> Cloud region identifier
|
|
19
|
+
--env <KEY=VALUE> Environment variable; repeatable
|
|
20
|
+
--env-file <path> Load environment variables from a file
|
|
21
|
+
--build-command <cmd> Override the build command
|
|
22
|
+
--start-command <cmd> Override the start command
|
|
23
|
+
--dockerfile <path> Dockerfile path relative to the selected source root
|
|
24
|
+
--watch-paths <glob> GitHub auto-deploy path filter; repeatable
|
|
25
|
+
--wait-for-ci Wait for other GitHub checks before auto-deploy
|
|
26
|
+
--no-github Upload local source to a managed private repository
|
|
27
|
+
--new Create a new server instead of using the local link
|
|
28
|
+
--open Open the server page after a successful deployment
|
|
29
|
+
-y, --yes Authorize confirmations and Git/repository mutations
|
|
30
|
+
--json Emit exactly one JSON result or error; never prompt
|
|
31
|
+
-h, --help Show this help without Git, auth, or network access
|
|
32
|
+
|
|
33
|
+
Automation:
|
|
34
|
+
--json does not authorize mutations. Use --json --yes for headless GitHub
|
|
35
|
+
repository creation, or --json --no-github for a managed source upload.
|
|
36
|
+
--new requires --yes in JSON or non-interactive environments.
|
|
37
|
+
|
|
38
|
+
Incompatible combinations:
|
|
39
|
+
--open cannot be combined with --json because JSON mode never opens a browser.
|
|
40
|
+
--no-github cannot replace a linked GitHub server in place; add --new --yes
|
|
41
|
+
to create a separate managed-source server.
|
|
42
|
+
--watch-paths and --wait-for-ci are GitHub-only.
|
|
43
|
+
|
|
44
|
+
Managed archive:
|
|
45
|
+
Uploads the selected project without .git, dependencies, build output,
|
|
46
|
+
.mcp-use, .env*, caches, coverage, OS metadata, or symbolic links.
|
|
47
|
+
The compressed archive limit is 80 MB.
|
|
48
|
+
|
|
49
|
+
Examples:
|
|
50
|
+
mcp-use deploy
|
|
51
|
+
mcp-use deploy --yes
|
|
52
|
+
mcp-use deploy --no-github
|
|
53
|
+
mcp-use deploy --no-github --json
|
|
54
|
+
mcp-use deploy --json --yes
|
|
55
|
+
mcp-use deploy --env-file .env.production --open
|
|
56
|
+
|
|
57
|
+
Exit codes:
|
|
58
|
+
0 Success or help
|
|
59
|
+
1 Git, API, upload, or deployment failure
|
|
60
|
+
2 Invalid arguments or an explicit headless choice is required`;async function ut(t){let e=M(t);try{let{values:n,positionals:o}=Te(t);if(n.help===!0)return process.stdout.write(`${De}
|
|
61
|
+
`),0;if(n.json===!0&&n.open===!0)throw new v("invalid_argument_combination","--open cannot be combined with --json; JSON mode never opens a browser.",{nextSteps:[{description:"Deploy as JSON without opening a browser",command:"mcp-use deploy --json"},{description:"Deploy and open the server page interactively",command:"mcp-use deploy --open"}]});let r=ae(o[0]??process.cwd()),s=k(r,".mcp-use","cloud","link.json");if(n.new===!0&&!await V("Create a new cloud server for this project?",{yes:n.yes===!0,json:e}))return 0;let{api:i,organizationId:c}=await K(n.org),a=await W(s,null),u=n.new===!0||a===null;if(!u&&a!==null&&a.organizationId!==c)throw new p("organization_mismatch","The linked server belongs to another organization. Pass --new --yes to create one.",{nextSteps:[{description:"Create a server in the selected organization",command:"mcp-use deploy --new --yes"}]});let l=!u&&a!==null&&await ze(i,a);if(n["no-github"]===!0&&!u&&a!==null&&!l)throw new v("source_mode_conflict","This project is linked to a GitHub-backed server; managed upload cannot replace its source in place.",{serverId:a.serverId,nextSteps:[{description:"Redeploy the linked GitHub server",command:"mcp-use deploy"},{description:"Create a separate managed-source server",command:"mcp-use deploy --no-github --new --yes"}]});if(n["no-github"]===!0||l){if(n["watch-paths"]!==void 0||n["wait-for-ci"]===!0)throw new v("source_mode_conflict","--watch-paths and --wait-for-ci are available only for GitHub deployments.",{nextSteps:[{description:"Upload managed source without GitHub trigger options",command:"mcp-use deploy --no-github"},{description:"Deploy through GitHub with trigger options",command:"mcp-use deploy --yes --watch-paths <glob>"}]});return await Oe({api:i,organizationId:c,cwd:r,linkPath:s,existing:u?null:a,values:n,json:e})}return await Ue({api:i,organizationId:c,cwd:r,linkPath:s,existing:u?null:a,values:n,json:e})}catch(n){return F(n instanceof TypeError?new h(n.message):n,e)}}function Te(t){let{values:e,positionals:n}=Re({args:[...t],allowPositionals:!0,strict:!0,options:{org:{type:"string"},name:{type:"string"},branch:{type:"string"},"root-dir":{type:"string"},region:{type:"string"},env:{type:"string",multiple:!0},"env-file":{type:"string"},"build-command":{type:"string"},"start-command":{type:"string"},dockerfile:{type:"string"},"watch-paths":{type:"string",multiple:!0},"wait-for-ci":{type:"boolean"},"no-github":{type:"boolean"},new:{type:"boolean"},open:{type:"boolean"},yes:{type:"boolean",short:"y"},json:{type:"boolean"},help:{type:"boolean",short:"h"}}});if(n.length>1)throw new h("Usage: mcp-use deploy [path] [options]");return e["watch-paths"]!==void 0&&(e["watch-paths"]=Ne(e["watch-paths"])),{values:e,positionals:n}}function Ne(t){if(t.length===1&&t[0]==="")return[];if(t.length>32)throw new h("--watch-paths accepts at most 32 patterns.");if(t.some(e=>e===""))throw new h("--watch-paths accepts an empty value only by itself to clear all patterns.");if(t.some(e=>e.length>512))throw new h("--watch-paths patterns may not exceed 512 characters.");return t}async function Oe(t){let{api:e,organizationId:n,cwd:o,linkPath:r,existing:s,values:i,json:c}=t,a=o,u=q(o,i["root-dir"]??".","--root-dir");if(!await E(u))throw new h(`Project directory not found: ${u}`);L(u,i.dockerfile,"--dockerfile"),await et(a);let l=await he(a,i["env-file"],i.env??[]),y=await Ze(a);He(y.byteLength);let w=i.branch??"main",I=i.name??await ye(u),m,g,P;if(s!==null){m=s.serverId,g=s.serverSlug,await le(e,m,i),await ue(e,m,l,i.branch);let d=new FormData;oe(d,y),d.set("branch",w),d.set("commitMessage","Redeploy from mcp-use CLI"),await e.multipartRequest(`/servers/${encodeURIComponent(m)}/source`,d),P=(await e.request("/deployments",{method:"POST",body:JSON.stringify({serverId:m,branch:w,trigger:"redeploy"})})).id}else{let d=new FormData;oe(d,y),d.set("organizationId",n),d.set("managed","true"),d.set("name",I),d.set("repoName",we(I)),d.set("private","true"),d.set("branch",w),d.set("commitMessage","Deploy from mcp-use CLI"),i.region!==void 0&&d.set("region",i.region),i["root-dir"]!==void 0&&d.set("rootDir",i["root-dir"]),i["build-command"]!==void 0&&d.set("buildCommand",i["build-command"]),i["start-command"]!==void 0&&d.set("startCommand",i["start-command"]),i.dockerfile!==void 0&&d.set("dockerfilePath",i.dockerfile),Object.keys(l).length>0&&d.set("env",JSON.stringify(l));let f=await e.multipartRequest("/servers",d);if(f.deploymentId===null)throw ve(f.server.id);m=f.server.id,g=f.server.slug,P=f.deploymentId}return await U(r,{organizationId:n,serverId:m,...g!==void 0?{serverSlug:g}:{},sourceType:"managed"}),await pe(a),ke({sourceType:"managed",serverId:m,...g!==void 0?{serverSlug:g}:{},deploymentId:P,label:"managed source",values:i,json:c})}function He(t){if(!(t<=X))throw new p("archive_too_large",`Project archive is ${(t/1024/1024).toFixed(2)} MB; the maximum is 80 MB.`,{sizeBytes:t,maxBytes:X,nextSteps:[{description:"Exclude large generated files and retry",command:"mcp-use deploy --no-github"}]})}async function Ue(t){let{api:e,organizationId:n,cwd:o,linkPath:r,existing:s,values:i,json:c}=t,a=await ee(o),u,l;if(!a.isRepository||a.remote===void 0){if(a.unavailable===!0)throw new p("git_unavailable","Git is not installed or could not be executed.",{nextSteps:[{description:"Deploy without GitHub",command:"mcp-use deploy --no-github"}]});await Le(i,c);let d=await Q(e,n);l=await Be(d,i,c);let f=i.name??await ye(o),R=we(f),G;try{G=await e.request(`/github/installations/${encodeURIComponent(l.installationId)}/repos`,{method:"POST",body:JSON.stringify({name:R,private:!0,org:l.account?.login??void 0})})}catch(x){throw new p("github_repository_creation_failed",`Could not create the private GitHub repository ${R}.`,{account:l.account?.login??null,cause:x instanceof Error?x.message:String(x),nextSteps:[{description:"Retry with a unique repository name",command:"mcp-use deploy --name <unique-name> --yes"},{description:"Deploy without GitHub",command:"mcp-use deploy --no-github"}]})}try{await qe(o,a,G.cloneUrl)}catch(x){let S=x instanceof p?x:B(x,o),Pe=S.details!==null&&typeof S.details=="object"&&!Array.isArray(S.details)?S.details:{},H=Me(S.details);throw H.some(xe=>xe.command==="mcp-use deploy --yes")||H.push({description:"Retry using the repository already created",command:"mcp-use deploy --yes"}),new p(S.code,S.message,{...Pe,repository:G.fullName,url:G.htmlUrl,nextSteps:H})}a=await ee(o),u=G.fullName}else u=We(a.remote);let y=a.root??o,w=i.branch??a.branch;if(w===void 0||w===""||w==="HEAD")throw new p("detached_head","Cannot infer a branch from detached HEAD; pass --branch.",{nextSteps:[{description:"Deploy an explicit branch",command:"mcp-use deploy --branch <branch>"}]});L(y,i["root-dir"],"--root-dir"),L(y,i.dockerfile,"--dockerfile");let I=await he(o,i["env-file"],i.env??[]);a.dirty===!0&&await Fe(y,w,i,c);let m,g,P;if(s!==null)m=s.serverId,g=s.serverSlug,await le(e,m,i),await ue(e,m,I,i.branch),P=(await e.request("/deployments",{method:"POST",body:JSON.stringify({serverId:m,branch:w,trigger:"manual"})})).id;else{let d=l===void 0?await Q(e,n):[l];if(l??=await Ke(e,d,u),l===void 0){let R=`${N()}/settings`;throw new p(d.length===0?"github_installation_required":"github_access_required",d.length===0?"No GitHub App installation is connected to this organization.":`The mcp-use GitHub App cannot access ${u}.`,{repository:u,url:R,nextSteps:[{description:"Configure GitHub access",command:R},{description:"Retry deployment",command:"mcp-use deploy"}]})}let f=await e.request("/servers",{method:"POST",body:JSON.stringify({type:"github",organizationId:n,installationId:l.id??l.installationId,name:i.name??se(u),repoFullName:u,branch:w,...i["root-dir"]!==void 0?{rootDir:i["root-dir"]}:{},...i.region!==void 0?{region:i.region}:{},...i["build-command"]!==void 0?{buildCommand:i["build-command"]}:{},...i["start-command"]!==void 0?{startCommand:i["start-command"]}:{},...i.dockerfile!==void 0?{dockerfilePath:i.dockerfile}:{},...i["watch-paths"]!==void 0?{watchPaths:i["watch-paths"]}:{},...i["wait-for-ci"]!==void 0?{waitForCi:i["wait-for-ci"]}:{},...Object.keys(I).length>0?{env:I}:{}})});if(f.deploymentId===null)throw ve(f.server.id);m=f.server.id,g=f.server.slug,P=f.deploymentId}return await U(r,{organizationId:n,serverId:m,...g!==void 0?{serverSlug:g}:{},repository:u,sourceType:"github"}),await pe(y),ke({sourceType:"github",serverId:m,...g!==void 0?{serverSlug:g}:{},deploymentId:P,label:u,values:i,json:c})}async function ue(t,e,n,o){if(Object.keys(n).length===0)return;let r=o===void 0?"":`?branch=${encodeURIComponent(o)}`,s=await t.request(`/servers/${encodeURIComponent(e)}/env-variables${r}`),i=new Map(s.map(c=>[c.key,c]));await Promise.all(Object.entries(n).map(async([c,a])=>{let u=i.get(c),l=JSON.stringify({key:c,value:a,branch:o??null,environments:o===void 0?["production"]:["preview"]});u===void 0?await t.request(`/servers/${encodeURIComponent(e)}/env-variables`,{method:"POST",body:l}):await t.request(`/servers/${encodeURIComponent(e)}/env-variables/${encodeURIComponent(u.id)}`,{method:"PATCH",body:l})}))}async function le(t,e,n){let o={...n["root-dir"]!==void 0?{rootDir:n["root-dir"]}:{},...n["build-command"]!==void 0?{buildCommand:n["build-command"]}:{},...n["start-command"]!==void 0?{startCommand:n["start-command"]}:{},...n.dockerfile!==void 0?{dockerfilePath:n.dockerfile}:{}},r={...n.name!==void 0?{name:n.name}:{},...n.branch!==void 0?{productionBranch:n.branch}:{},...n.region!==void 0?{region:n.region}:{},...n["watch-paths"]!==void 0?{watchPaths:n["watch-paths"]}:{},...n["wait-for-ci"]!==void 0?{waitForCi:n["wait-for-ci"]}:{},...Object.keys(o).length>0?{config:o}:{}};Object.keys(r).length!==0&&await t.request(`/servers/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify(r)})}async function ze(t,e){if(e.sourceType!==void 0)return e.sourceType==="managed";if(e.repository===void 0)return!0;try{return(await t.request(`/servers/${encodeURIComponent(e.serverId)}`)).connectedRepository?.isManaged===!0}catch{return!1}}async function Le(t,e){if(t.yes===!0)return;if(e||!process.stdin.isTTY)throw new v("deployment_mode_required","No GitHub origin was found. Choose a deployment mode explicitly.",{nextSteps:[{description:"Upload local source without GitHub",command:"mcp-use deploy --no-github"},{description:"Create a private GitHub repository and push",command:"mcp-use deploy --yes"}]});if(!await be("No GitHub origin was found. Create a private repository and push this project?",!0))throw new v("deployment_mode_required","Deployment cancelled. Choose a deployment mode.",{nextSteps:[{description:"Upload local source without GitHub",command:"mcp-use deploy --no-github"},{description:"Retry GitHub setup",command:"mcp-use deploy"}]})}async function Q(t,e){let n=await t.request(`/github/installations?organizationId=${encodeURIComponent(e)}`);if(n.installations.length===0){let o=`${N()}/settings`;throw new p("github_installation_required","No GitHub App installation is connected to this organization.",{url:o,nextSteps:[{description:"Connect GitHub in the cloud dashboard",command:o},{description:"Retry deployment after connecting GitHub",command:"mcp-use deploy"},{description:"Deploy without GitHub",command:"mcp-use deploy --no-github"}]})}return n.installations}async function Be(t,e,n){let o=[...t].sort((s,i)=>{let c=s.account?.type?.toLowerCase()==="organization",a=i.account?.type?.toLowerCase()==="organization";return Number(a)-Number(c)});if(o.length===1||e.yes===!0)return o[0];if(n||!process.stdin.isTTY)throw new v("github_installation_required","Multiple GitHub installations are available; pass --yes to select deterministically.",{nextSteps:[{description:"Use the default organization installation",command:"mcp-use deploy --yes"}]});process.stdout.write(`Choose the GitHub account for the new repository:
|
|
62
|
+
`);for(let[s,i]of o.entries())process.stdout.write(` ${s+1}. ${i.account?.login??i.installationId}
|
|
63
|
+
`);let r=ce({input:process.stdin,output:process.stdout});try{let s=await r.question("Account [1]: "),i=s.trim()===""?0:Number(s)-1;if(!Number.isInteger(i)||i<0||i>=o.length)throw new h("Invalid GitHub account selection.");return o[i]}finally{r.close()}}async function qe(t,e,n){try{await Je(t),e.isRepository||await b(t,["init"]),await b(t,["remote","add","origin",n]),await b(t,["add","."]),(await j(t,["diff","--cached","--quiet"])).ok||await b(t,["commit","-m","Initial commit"]),await b(t,["branch","-M","main"]),await b(t,["push","-u","origin","main"])}catch(o){throw B(o,t)}}function Me(t){if(t===null||typeof t!="object")return[];let e=t.nextSteps;return Array.isArray(e)?e.filter(o=>o!==null&&typeof o=="object"&&"description"in o&&typeof o.description=="string"&&"command"in o&&typeof o.command=="string"):[]}async function Je(t){let e=k(t,".gitignore"),n="";try{n=await T(e,"utf8")}catch(o){if(o.code!=="ENOENT")throw o}n.split(/\r?\n/).map(o=>o.trim()).includes(".mcp-use/")||(n===""?await $e(e,`.mcp-use/
|
|
64
|
+
`,"utf8"):await re(e,`${n.endsWith(`
|
|
65
|
+
`)?"":`
|
|
66
|
+
`}.mcp-use/
|
|
67
|
+
`))}async function pe(t){let e=k(t,".git","info","exclude");if(await E(e))try{let n=await T(e,"utf8");if(n.split(/\r?\n/).map(o=>o.trim()).includes(".mcp-use/"))return;await re(e,`${n.endsWith(`
|
|
68
|
+
`)||n===""?"":`
|
|
69
|
+
`}.mcp-use/
|
|
70
|
+
`)}catch{}}async function Fe(t,e,n,o){if(n.yes!==!0){if(o||!process.stdin.isTTY)throw new v("git_changes_require_confirmation","The repository has uncommitted changes.",{nextSteps:[{description:"Authorize committing and pushing the changes",command:"mcp-use deploy --yes"},{description:"Commit the changes yourself",command:"git add . && git commit && git push"}]});if(!await be("Commit and push the current changes before deploying?",!0))return}try{await b(t,["add","."]),await b(t,["commit","-m","Deploy changes"]),await b(t,["push","origin",e])}catch(r){throw B(r,t)}}async function ee(t){let e=await j(t,["rev-parse","--is-inside-work-tree"]);if(!e.ok){if(e.unavailable!==!0&&!Ve(e))throw A("git rev-parse --is-inside-work-tree",e);return{isRepository:!1,...e.unavailable!==void 0?{unavailable:e.unavailable}:{}}}let[n,o,r,s]=await Promise.all([j(t,["rev-parse","--show-toplevel"]),j(t,["remote","get-url","origin"]),j(t,["branch","--show-current"]),j(t,["status","--porcelain"])]);if(!n.ok||n.stdout==="")throw A("git rev-parse --show-toplevel",n);if(!o.ok&&!Ye(o))throw A("git remote get-url origin",o);if(!r.ok)throw A("git branch --show-current",r);if(!s.ok)throw A("git status --porcelain",s);return{isRepository:!0,root:n.stdout,...o.ok&&o.stdout!==""?{remote:o.stdout}:{},...r.ok?{branch:r.stdout}:{},dirty:s.ok&&s.stdout!==""}}async function j(t,e){try{let n=await de("git",e,{cwd:t});return{ok:!0,stdout:n.stdout.trim(),stderr:n.stderr.trim()}}catch(n){let o=n;return{ok:!1,stdout:String(o.stdout??"").trim(),stderr:String(o.stderr??o.message??"").trim(),...o.code==="ENOENT"?{unavailable:!0}:{},...o.code!==void 0?{code:o.code}:{}}}}function Ve(t){return/not a git repository|not inside a work tree/i.test(`${t.stderr}
|
|
71
|
+
${t.stdout}`)}function Ye(t){return/no such remote(?:\s+['"]?origin)?/i.test(`${t.stderr}
|
|
72
|
+
${t.stdout}`)}function A(t,e){let n=$(e.stderr||e.stdout||"Git returned no diagnostics.");return new p("git_command_failed",`${t} failed: ${n}`,{command:t,...e.code!==void 0?{exitCode:e.code}:{},nextSteps:[{description:"Verify the repository with Git",command:"git status"},{description:"Deploy without GitHub",command:"mcp-use deploy --no-github"}]})}async function b(t,e){try{await de("git",e,{cwd:t})}catch(n){let o=n;throw new O(`git ${e.join(" ")}`,String(o.stderr??o.stdout??""),o.code)}}var O=class extends Error{constructor(n,o,r){super(o.trim()||`${n} failed`);this.command=n;this.output=o;this.exitCode=r}};function B(t,e){if(!(t instanceof O))return new p("git_command_failed",t instanceof Error?t.message:String(t));if(/tell me who you are|author identity unknown|unable to auto-detect email address|empty ident (?:name|email)|user\.email|user\.name/i.test(t.output)){let r=$(t.command);return new p("git_identity_required","Git needs a user name and email before it can create a commit.",{command:r,nextSteps:[{description:"Set the email for this project",command:`git -C ${JSON.stringify(e)} config user.email "you@example.com"`},{description:"Set the name for this project",command:`git -C ${JSON.stringify(e)} config user.name "Your Name"`},{description:"Retry deployment",command:"mcp-use deploy --yes"}]})}if(/non-fast-forward|rejected|unrelated histories/i.test(t.output)){let r=$(t.command);return new p("git_push_rejected","GitHub rejected the push because the remote branch contains other commits.",{command:r,nextSteps:[{description:"Reconcile the remote branch",command:"git pull --rebase origin main --allow-unrelated-histories && git push -u origin main"}]})}let n=$(t.command),o=$(t.output.trim());return new p("git_command_failed",`${n} failed${o===""?".":`: ${o}`}`,{command:n,exitCode:t.exitCode})}function We(t){let e=t.match(/github\.com[/:]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/);if(e?.[1]===void 0||e[2]===void 0){let n=$(t);throw new p("unsupported_remote",`The origin remote is not a supported GitHub repository: ${n}`,{remote:n,nextSteps:[{description:"Set a GitHub origin",command:"git remote set-url origin https://github.com/<owner>/<repo>.git"},{description:"Deploy without GitHub",command:"mcp-use deploy --no-github"}]})}return`${e[1]}/${e[2]}`}function $(t){return t.replace(/\b(https?:\/\/)[^/@\s]+(?::[^@\s]*)?@/gi,"$1[REDACTED]@")}async function Ke(t,e,n){let[o,r]=n.split("/"),s=[...e].sort((i,c)=>{let a=i.account?.login?.toLowerCase()===o.toLowerCase(),u=c.account?.login?.toLowerCase()===o.toLowerCase();return Number(u)-Number(a)});for(let i of s)try{if((await t.request(`/github/installations/${encodeURIComponent(i.installationId)}/repos/${encodeURIComponent(o)}/${encodeURIComponent(r)}/access`)).hasAccess)return i}catch{}}async function Ze(t){let e=Ee(),n=[],o=(async()=>{for await(let r of e)n.push(Buffer.from(r))})();try{await me(e,t,""),await _(e,Buffer.alloc(1024)),e.end()}catch(r){throw e.destroy(r instanceof Error?r:new Error(String(r))),r}return await o,Buffer.concat(n)}async function me(t,e,n){let o=await je(n===""?e:k(e,n)),r=[];for await(let s of o)r.push(s);r.sort((s,i)=>s.name.localeCompare(i.name));for(let s of r){let i=n===""?s.name:k(n,s.name);if(!Xe(i))continue;let c=k(e,i),a=await Ie(c),l={path:`app/${i.replaceAll("\\","/")}`,mode:a.mode&511,mtime:Math.floor(a.mtimeMs/1e3)};if(a.isDirectory())await te(t,{...l,type:"directory",size:0}),await me(t,e,i);else if(a.isFile()){await te(t,{...l,type:"file",size:a.size});for await(let y of Ce(c))await _(t,y);await ge(t,a.size)}else if(a.isSymbolicLink())continue}}function Xe(t){let e=t.split(/[/\\]/).filter(Boolean);if(e.some(o=>Ae.has(o)))return!1;let n=e.at(-1)??"";return n===".DS_Store"||n==="Thumbs.db"||n==="desktop.ini"?!1:!n.startsWith(".env")}async function te(t,e){let n={},o=fe(e.path);if((o===void 0||!z(e.path))&&(n.path=e.path),e.linkPath!==void 0&&(Buffer.byteLength(e.linkPath)>100||!z(e.linkPath))&&(n.linkpath=e.linkPath),Object.keys(n).length>0){let r=Buffer.from(Object.entries(n).map(([s,i])=>Qe(s,i)).join(""));await _(t,ne({path:"PaxHeader/entry",mode:420,mtime:e.mtime,size:r.length,type:"pax"})),await _(t,r),await ge(t,r.length)}await _(t,ne({...e,path:o===void 0?"app/PaxEntry":e.path,...e.linkPath!==void 0&&(Buffer.byteLength(e.linkPath)>100||!z(e.linkPath))?{linkPath:"PaxLink"}:{}}))}function ne(t){let e=Buffer.alloc(512),n=fe(t.path)??{name:t.path.slice(-100),prefix:""};C(e,n.name,0,100),D(e,t.mode,100,8),D(e,0,108,8),D(e,0,116,8),D(e,t.size,124,12),D(e,t.mtime,136,12),e.fill(32,148,156),e[156]=t.type==="directory"?53:t.type==="symlink"?50:t.type==="pax"?120:48,t.linkPath!==void 0&&C(e,t.linkPath,157,100),C(e,"ustar",257,6),C(e,"00",263,2),C(e,"mcp-use",265,32),C(e,"mcp-use",297,32),C(e,n.prefix,345,155);let r=e.reduce((s,i)=>s+i,0).toString(8).padStart(6,"0");return e.write(r,148,6,"ascii"),e[154]=0,e[155]=32,e}function fe(t){if(Buffer.byteLength(t)<=100)return{name:t,prefix:""};for(let e=t.lastIndexOf("/");e>0;){let n=t.slice(0,e),o=t.slice(e+1);if(Buffer.byteLength(n)<=155&&Buffer.byteLength(o)<=100)return{name:o,prefix:n};e=t.lastIndexOf("/",e-1)}}function Qe(t,e){let n=`${t}=${e}
|
|
73
|
+
`,o=Buffer.byteLength(n)+3;for(;;){let r=`${o} ${n}`,s=Buffer.byteLength(r);if(s===o)return r;o=s}}function z(t){return Buffer.byteLength(t)===t.length}function C(t,e,n,o){t.write(e,n,o,"utf8")}function D(t,e,n,o){let r=Math.max(0,e).toString(8).padStart(o-1,"0").slice(-(o-1));t.write(r,n,o-1,"ascii"),t[n+o-1]=0}async function ge(t,e){let n=(512-e%512)%512;n>0&&await _(t,Buffer.alloc(n))}async function _(t,e){t.write(e)||await new Promise((n,o)=>{let r=()=>{t.off("drain",s),t.off("error",i)},s=()=>{r(),n()},i=c=>{r(),o(c)};t.once("drain",s),t.once("error",i)})}function oe(t,e){t.set("sourceFile",new Blob([new Uint8Array(e)],{type:"application/gzip"}),"source.tar.gz")}function q(t,e,n){if(Z(e))throw new h(`${n} must be relative.`);let o=ae(t,e),r=_e(t,o);if(r.startsWith("..")||Z(r))throw new h(`${n} must not escape the project directory.`);return o}function L(t,e,n){e!==void 0&&q(t,e,n)}async function he(t,e,n){let o={};if(e!==void 0){let r=q(t,e,"--env-file");if(!await E(r))throw new h(`Environment file not found: ${e}`);for(let s of(await T(r,"utf8")).split(/\r?\n/)){let i=s.trim();i===""||i.startsWith("#")||ie(o,i)}}for(let r of n)ie(o,r);return o}function ie(t,e){let n=e.indexOf("="),o=e.slice(0,n);if(n<=0||!/^[A-Za-z_][A-Za-z0-9_]*$/.test(o))throw new h("Invalid environment assignment; expected KEY=VALUE.");t[o]=e.slice(n+1)}async function ye(t){try{let e=JSON.parse(await T(k(t,"package.json"),"utf8"));if(typeof e.name=="string"&&e.name.trim()!=="")return e.name}catch{}return se(t)}async function et(t){let e=k(t,"package.json");if(!await E(e))return;let n;try{n=JSON.parse(await T(e,"utf8"))}catch{return}if(n.workspaces!==void 0)return;let o=["dependencies","devDependencies","optionalDependencies","peerDependencies"],r=[];for(let s of o){let i=n[s];if(!(i===null||typeof i!="object"||Array.isArray(i)))for(let[c,a]of Object.entries(i))typeof a=="string"&&a.startsWith("workspace:")&&r.push(c)}if(r.length!==0)throw new p("workspace_dependencies_unresolved",`This upload root uses workspace dependencies but is not a workspace root: ${r.join(", ")}.`,{dependencies:r,nextSteps:[{description:"Deploy the monorepo root and select this package",command:"mcp-use deploy <monorepo-root> --no-github --root-dir <package-path>"},{description:"Use published dependency versions for a standalone upload",command:"Replace workspace:* versions in package.json, then run mcp-use deploy --no-github"}]})}function we(t){return t.trim().replace(/[^a-zA-Z0-9._-]+/g,"-").replace(/^[-.]+|[-.]+$/g,"").slice(0,80)||"mcp-server"}async function be(t,e){let n=ce({input:process.stdin,output:process.stdout});try{let r=(await n.question(`${t} ${e?"[Y/n]":"[y/N]"} `)).trim().toLowerCase();return r===""?e:r==="y"||r==="yes"}finally{n.close()}}function ve(t){return new p("deployment_not_created","Server was created but no deployment was started.",{serverId:t,nextSteps:[{description:"Inspect the server",command:`mcp-use servers get ${t}`}]})}function ke(t){let e=`${N()}/${encodeURIComponent(t.serverSlug??t.serverId)}`,n={sourceType:t.sourceType,serverId:t.serverId,deploymentId:t.deploymentId,status:"pending",webUrl:e};return t.values.open===!0&&Y(e),J(n,t.json,`Deployment ${t.deploymentId} started for ${t.label}.`),0}export{He as assertManagedArchiveSize,ut as runDeploy};
|
|
@@ -1,6 +1,59 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import{h as m}from"../chunk-3XW44DRS.js";import{a as u,d as h,e as a,f as w,g as b}from"../chunk-VUVLJMYY.js";import"../chunk-LNASFQWW.js";import{parseArgs as E}from"util";var A=`Usage: mcp-use deployments <command> [options]
|
|
2
|
+
|
|
3
|
+
Manage cloud deployments and logs.
|
|
4
|
+
|
|
5
|
+
Commands:
|
|
6
|
+
list List deployments
|
|
7
|
+
get <deployment-id> Show one deployment
|
|
8
|
+
logs <deployment-id> Read runtime or build logs
|
|
9
|
+
restart <deployment-id> Create a replacement deployment
|
|
10
|
+
stop <deployment-id> Stop a deployment
|
|
11
|
+
delete <deployment-id> Delete a deployment
|
|
12
|
+
|
|
13
|
+
Run mcp-use deployments <command> --help for all options.
|
|
14
|
+
|
|
15
|
+
Exit codes:
|
|
16
|
+
0 Success or help
|
|
17
|
+
2 Invalid arguments or confirmation required
|
|
18
|
+
1 API or operational failure`,U={list:`Usage: mcp-use deployments list [options]
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
--org <id-or-slug> Override the active organization
|
|
22
|
+
--server <id> Filter by server
|
|
23
|
+
--limit <n> Results per page (default: 30; range: 1-100)
|
|
24
|
+
--skip <n> Results to skip (default: 0)
|
|
25
|
+
--json Emit the complete API page
|
|
26
|
+
-h, --help Show this help`,get:`Usage: mcp-use deployments get <deployment-id> [--json]
|
|
27
|
+
|
|
28
|
+
Options:
|
|
29
|
+
--json Emit the complete deployment object
|
|
30
|
+
-h, --help Show this help`,logs:`Usage: mcp-use deployments logs <deployment-id> [options]
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--build Read build logs instead of runtime logs
|
|
34
|
+
--follow Poll build logs until a terminal status
|
|
35
|
+
--json Emit exactly one object; with --follow, emit only at completion
|
|
36
|
+
-h, --help Show this help`,restart:`Usage: mcp-use deployments restart <deployment-id> [options]
|
|
37
|
+
|
|
38
|
+
Options:
|
|
39
|
+
--branch <name> Override the source branch
|
|
40
|
+
--follow Follow build logs after restart
|
|
41
|
+
--json Emit exactly one object; with --follow, emit only at completion
|
|
42
|
+
-h, --help Show this help`,stop:`Usage: mcp-use deployments stop <deployment-id> [options]
|
|
43
|
+
|
|
44
|
+
Options:
|
|
45
|
+
--yes Confirm without prompting
|
|
46
|
+
--json Emit the result; never prompt
|
|
47
|
+
-h, --help Show this help`,delete:`Usage: mcp-use deployments delete <deployment-id> [options]
|
|
48
|
+
|
|
49
|
+
Options:
|
|
50
|
+
--yes Confirm without prompting
|
|
51
|
+
--json Emit the result; never prompt
|
|
52
|
+
-h, --help Show this help`};async function x(e){if(e.some(t=>t==="--help"||t==="-h"))return process.stdout.write(`${U[e[0]??""]??A}
|
|
53
|
+
`),0;let n=h(e);try{let t=e[0];if(t==="list")return await j(e.slice(1),n);if(t==="get")return await T(e.slice(1),n);if(t==="logs")return await C(e.slice(1),n);if(t==="restart")return await D(e.slice(1),n);if(t==="stop")return await O(e.slice(1),n);if(t==="delete")return await k(e.slice(1),n);throw new u("Usage: mcp-use deployments <list|get|logs|restart|stop|delete>")}catch(t){return w(t instanceof TypeError?new u(t.message):t,n)}}async function j(e,n){let{values:t}=E({args:[...e],allowPositionals:!1,strict:!0,options:{org:{type:"string"},server:{type:"string"},limit:{type:"string",default:"30"},skip:{type:"string",default:"0"},json:{type:"boolean"}}}),o=$(t.limit,"--limit",1,100),s=$(t.skip,"--skip",0),r=new URLSearchParams({limit:String(o),skip:String(s),...t.server!==void 0?{serverId:t.server}:{}}),{api:i}=await m(t.org),d=await i.request(`/deployments?${r}`);return a(d,n,L(d)),0}async function T(e,n){let{positionals:t}=g(e,{json:{type:"boolean"}}),o=y(t,"mcp-use deployments get <deployment-id>"),{api:s}=await m(),r=await s.request(`/deployments/${encodeURIComponent(o)}`);return a(r,n,B(r)),0}async function C(e,n){let{values:t,positionals:o}=g(e,{build:{type:"boolean"},follow:{type:"boolean"},json:{type:"boolean"}}),s=y(o,"mcp-use deployments logs <deployment-id>"),{api:r}=await m();if(t.build===!0)await S(r,s,t.follow===!0,n);else{let i=await r.request(`/deployments/${encodeURIComponent(s)}/logs?lines=500`);n?a({deploymentId:s,logs:i.logs},!0):process.stdout.write(i.logs.endsWith(`
|
|
54
|
+
`)?i.logs:`${i.logs}
|
|
55
|
+
`)}return 0}async function D(e,n){let{values:t,positionals:o}=g(e,{branch:{type:"string"},follow:{type:"boolean"},json:{type:"boolean"}}),s=y(o,"mcp-use deployments restart <deployment-id>"),{api:r}=await m(),i=await r.request(`/deployments/${encodeURIComponent(s)}`);if(i.serverId===void 0||i.serverId===null)throw new u(`Deployment ${s} is not attached to a server.`);let d=await r.request("/deployments",{method:"POST",body:JSON.stringify({serverId:i.serverId,branch:t.branch??i.gitBranch??void 0,trigger:"redeploy"})});return t.follow===!0?await S(r,d.id,!0,n):a(d,n,`Restarted as deployment ${d.id}.`),0}async function O(e,n){return R(e,n,"stop")}async function k(e,n){return R(e,n,"delete")}async function R(e,n,t){let{values:o,positionals:s}=g(e,{yes:{type:"boolean"},json:{type:"boolean"}}),r=y(s,`mcp-use deployments ${t} <deployment-id>`);if(!await b(`${t==="stop"?"Stop":"Delete"} deployment ${r}?`,{yes:o.yes===!0,json:n}))return 0;let{api:i}=await m();return await i.request(`/deployments/${encodeURIComponent(r)}${t==="stop"?"/stop":""}`,{method:t==="stop"?"POST":"DELETE"}),a({[t==="stop"?"stopped":"deleted"]:r},n,`${t==="stop"?"Stopped":"Deleted"} ${r}.`),0}async function S(e,n,t,o){let s=0,r="pending",i="",d=new Set(["running","failed","stopped"]),f=!0;for(;f;){let p=await e.request(`/deployments/${encodeURIComponent(n)}/build-logs?offset=${s}`);p.logs!==""&&(i+=p.logs,o||process.stdout.write(p.logs.endsWith(`
|
|
56
|
+
`)?p.logs:`${p.logs}
|
|
57
|
+
`)),s=p.offset,r=p.status,f=t&&!d.has(p.status),f&&await new Promise(P=>setTimeout(P,1e3))}o&&a({deploymentId:n,offset:s,logs:i,status:r},!0)}function g(e,n){return E({args:[...e],allowPositionals:!0,strict:!0,options:n})}function y(e,n){if(e.length!==1)throw new u(`Usage: ${n}`);return e[0]}function $(e,n,t,o=Number.MAX_SAFE_INTEGER){let s=Number(e);if(!Number.isInteger(s)||s<t||s>o)throw new u(`${n} must be an integer from ${t} to ${o}.`);return s}function L(e){let n=c(e)&&Array.isArray(e.items)?e.items.filter(c):[];return n.length===0?"No deployments.":["DEPLOYMENT SERVER STATUS TRIGGER BRANCH CREATED ERROR",...n.map(o=>[q(l(o,"id")),l(o,"serverId")??"-",l(o,"status")??"-",l(o,"deploymentTrigger")??"-",l(o,"gitBranch")??"-",l(o,"createdAt")??"-",I(l(o,"error"))].join(" "))].join(`
|
|
58
|
+
`)}function B(e){if(!c(e))return String(e);let n=l(e,"id")??"-",t=l(e,"error");return[`Deployment: ${n}`,`Server: ${l(e,"serverId")??"-"}`,`Status: ${l(e,"status")??"-"}`,`Trigger: ${l(e,"deploymentTrigger")??"-"}`,`Branch: ${l(e,"gitBranch")??"-"}`,`Created: ${l(e,"createdAt")??"-"}`,...t!==void 0?[`Error: ${I(t)}`,`Build logs: mcp-use deployments logs ${n} --build`]:[]].join(`
|
|
59
|
+
`)}function l(e,n){if(!c(e))return;let t=e[n];return typeof t=="string"&&t!==""?t:void 0}function q(e){return e===void 0?"-":e.slice(0,8)}function I(e){if(e===void 0)return"-";let n=e.split(/\r?\n/,1)[0]??e;return n.length>100?`${n.slice(0,97)}...`:n}function c(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}export{x as runDeployments};
|