@mcp-use/cli 4.0.2-canary.2 → 4.0.2-canary.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as o}from"./chunk-XHPZPKHH.js";import"./chunk-RXKUVCL7.js";import"./chunk-WOT6VMZA.js";import{readFileSync as i}from"fs";import{createRequire as a}from"module";import{dirname as t,join as c,parse as m}from"path";function p(){try{let e=a(import.meta.url).resolve("mcp-use"),n=t(e),s=m(n).root;for(;n!==s;){try{let r=JSON.parse(i(c(n,"package.json"),"utf8"));if(r.name==="mcp-use"&&typeof r.version=="string")return r.version}catch{}n=t(n)}}catch{}}o(process.argv.slice(2),{frameworkVersion:p()??"4.0.2-canary.2"}).then(e=>{process.exitCode=e},e=>{console.error(e instanceof Error?e.message:String(e)),process.exitCode=1});
2
+ import{a as o}from"./chunk-6Y2L4EIY.js";import"./chunk-RXKUVCL7.js";import"./chunk-WOT6VMZA.js";import{readFileSync as i}from"fs";import{createRequire as a}from"module";import{dirname as t,join as c,parse as m}from"path";function p(){try{let e=a(import.meta.url).resolve("mcp-use"),n=t(e),s=m(n).root;for(;n!==s;){try{let r=JSON.parse(i(c(n,"package.json"),"utf8"));if(r.name==="mcp-use"&&typeof r.version=="string")return r.version}catch{}n=t(n)}}catch{}}o(process.argv.slice(2),{frameworkVersion:p()??"4.0.2-canary.4"}).then(e=>{process.exitCode=e},e=>{console.error(e instanceof Error?e.message:String(e)),process.exitCode=1});
@@ -32,7 +32,7 @@ Options:
32
32
  --no-open Do not auto-open the inspector in a browser (dev only)
33
33
  --no-inspector Start dev without loading the optional Inspector
34
34
  -h, --help Show this help
35
- -v, --version Print the version`,m={dev:`Usage: mcp-use dev [options]
35
+ -v, --version Print the version`,h={dev:`Usage: mcp-use dev [options]
36
36
 
37
37
  Start the development MCP server with view hot reload.
38
38
 
@@ -84,7 +84,7 @@ Options:
84
84
  --tunnel Start a public tunnel
85
85
  -h, --help Show this help
86
86
 
87
- Exit codes: 0 started/help, 2 invalid arguments, 1 startup failure`};async function h(t,e={frameworkVersion:"unknown"}){if(t.length===1&&["--version","-v"].includes(t[0]??""))return console.log(e.frameworkVersion),0;if(t.some(r=>r==="--help"||r==="-h")){let r=t[0];if(r===void 0||r==="--help"||r==="-h")return console.log(s),0;let a=m[r];if(a!==void 0)return console.log(a),0}let o=t[0],i=p(t.slice(1));if(o==="login"||o==="logout"||o==="whoami"){let{runIdentity:r}=await import("./commands/identity.js");return r(o,i)}if(o==="org"){let{runOrganizations:r}=await import("./commands/organizations.js");return r(i)}if(o==="servers"){let{runServers:r}=await import("./commands/servers.js");return r(i)}if(o==="deployments"){let{runDeployments:r}=await import("./commands/deployments.js");return r(i)}if(o==="deploy"){let{runDeploy:r}=await import("./commands/deploy.js");return r(i)}if(o==="client"){let{runClient:r}=await import("./commands/client.js");return r(i)}if(o==="screenshot"){let{runScreenshot:r}=await import("./commands/screenshot.js");return r(i)}let n;try{n=l(t)}catch(r){return console.error(r instanceof Error?r.message:String(r)),2}if(n.version)return console.log(e.frameworkVersion),0;if(n.help)return console.log(s),0;switch(n.command){case"start":return y(n);case"dev":case"build":return w(n.command,n);case"typecheck":return f(n);case void 0:return console.error(s),2;default:return console.error(`Unknown command: ${n.command}
87
+ Exit codes: 0 started/help, 2 invalid arguments, 1 startup failure`};async function m(t,e={frameworkVersion:"unknown"}){if(t.length===1&&["--version","-v"].includes(t[0]??""))return console.log(e.frameworkVersion),0;if(t.some(r=>r==="--help"||r==="-h")){let r=t[0];if(r===void 0||r==="--help"||r==="-h")return console.log(s),0;let a=h[r];if(a!==void 0)return console.log(a),0}let o=t[0],i=p(t.slice(1));if(o==="login"||o==="logout"||o==="whoami"){let{runIdentity:r}=await import("./commands/identity.js");return r(o,i)}if(o==="org"){let{runOrganizations:r}=await import("./commands/organizations.js");return r(i)}if(o==="servers"){let{runServers:r}=await import("./commands/servers.js");return r(i)}if(o==="deployments"){let{runDeployments:r}=await import("./commands/deployments.js");return r(i)}if(o==="deploy"){let{runDeploy:r}=await import("./commands/deploy.js");return r(i)}if(o==="client"){let{runClient:r}=await import("./commands/client.js");return r(i)}if(o==="screenshot"){let{runScreenshot:r}=await import("./commands/screenshot.js");return r(i)}let n;try{n=l(t)}catch(r){return console.error(r instanceof Error?r.message:String(r)),2}if(n.version)return console.log(e.frameworkVersion),0;if(n.help)return console.log(s),0;switch(n.command){case"start":return y(n);case"dev":case"build":return w(n.command,n);case"typecheck":return f(n);case void 0:return console.error(s),2;default:return console.error(`Unknown command: ${n.command}
88
88
 
89
- ${s}`),2}}async function f(t){try{let{runTypecheck:e}=await import("./commands/typecheck.js");return await e({cwd:u(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(e){return console.error(d(e)),1}}async function y(t){let e;try{let{runStart:n}=await import("./commands/start.js");e=await n({cwd:u(process.cwd(),t.path??"."),port:t.port,host:t.host,...t.inspector===!0&&{withInspector:!0},tunnel:t.tunnel})}catch(n){return console.error(n instanceof Error?n.message:String(n)),1}console.log(`mcp-use server running at ${e.url}`),t.inspector===!0&&console.log(`mcp-use inspector at ${e.url.replace(/\/$/,"")}/inspector`),e.tunnelUrl!==void 0&&console.log(`mcp-use public MCP URL: ${e.tunnelUrl}`);let o=!1,i=()=>{o||(o=!0,e.close().then(()=>process.exit(0),n=>{console.error(n instanceof Error?n.message:String(n)),process.exit(1)}))};return process.once("SIGINT",i),process.once("SIGTERM",i),0}async function w(t,e){let o={cwd:u(process.cwd(),e.path??"."),...e.entry!==void 0&&{entry:e.entry},...e.mcpDir!==void 0&&{mcpDir:e.mcpDir},...e.viewsDir!==void 0&&{viewsDir:e.viewsDir},...e.port!==void 0&&{port:e.port},...e.host!==void 0&&{host:e.host},...e.tunnel&&{tunnel:!0},...!e.open&&{open:!1},...e.inspector===!1&&{inspector:!1},...e.sourceMaps&&{sourceMaps:!0},...e.inline&&{inline:!0}};try{if(t==="dev"){let{runDev:i}=await import("./commands/dev.js");await i(o)}else{let{runBuild:i}=await import("./commands/build.js");await i(o)}return 0}catch(i){return console.error(d(i)),1}}function d(t){let e=t instanceof Error?t.message:String(t);return/tunnel|bore connection/i.test(e)?["[tunnel_connection_timeout] Public tunnel could not establish a connection.",`Cause: ${e}`,"","Retry:"," mcp-use dev --tunnel","","Verify outbound network access and tunnel service status:"," https://local.mcp-use.run"].join(`
90
- `):e}export{h as a};
89
+ ${s}`),2}}async function f(t){try{let{runTypecheck:e}=await import("./commands/typecheck.js");return await e({cwd:u(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(e){return console.error(d(e)),1}}async function y(t){let e;try{let{runStart:n}=await import("./commands/start.js");e=await n({cwd:u(process.cwd(),t.path??"."),port:t.port,host:t.host,...t.inspector===!0&&{withInspector:!0},tunnel:t.tunnel})}catch(n){return console.error(n instanceof Error?n.message:String(n)),1}console.log(`mcp-use server running at ${e.url}`),t.inspector===!0&&console.log(`mcp-use inspector at ${e.url.replace(/\/$/,"")}/inspector`),e.tunnelUrl!==void 0&&console.log(`mcp-use public MCP URL: ${e.tunnelUrl}`);let o=!1,i=()=>{o||(o=!0,e.close().then(()=>process.exit(0),n=>{console.error(n instanceof Error?n.message:String(n)),process.exit(1)}))};return process.once("SIGINT",i),process.once("SIGTERM",i),0}async function w(t,e){let o={cwd:u(process.cwd(),e.path??"."),...e.entry!==void 0&&{entry:e.entry},...e.mcpDir!==void 0&&{mcpDir:e.mcpDir},...e.viewsDir!==void 0&&{viewsDir:e.viewsDir},...e.port!==void 0&&{port:e.port},...e.host!==void 0&&{host:e.host},...e.tunnel&&{tunnel:!0},...!e.open&&{open:!1},...e.inspector===!1&&{inspector:!1},...e.sourceMaps&&{sourceMaps:!0},...e.inline&&{inline:!0}};try{if(t==="dev"){let{runDev:i}=await import("./commands/dev.js");await i(o)}else{let{runBuild:i}=await import("./commands/build.js");await i(o)}return 0}catch(i){return console.error(d(i)),1}}function d(t){let e=t instanceof Error?t.message:String(t);return/tunnel/i.test(e)?["[tunnel_connection_timeout] Public tunnel could not establish a connection.",`Cause: ${e}`,"","Retry:"," mcp-use dev --tunnel","","Verify outbound network access and relay health:"," https://api.tunnel.mcp-use.run/health"].join(`
90
+ `):e}export{m as a};
@@ -0,0 +1 @@
1
+ import D from"http";import{mkdir as z,readFile as H,writeFile as K}from"fs/promises";import{dirname as J}from"path";var X="https://api.tunnel.mcp-use.run",Q=3e4,$=64*1024,m=256*1024,x=1024*1024,C=100,j=25e3,M=5,G=1,V=2,O=3,Z=4,ee=5,te=6,_=36;function Y(a){let i=a??process.env.MCP_USE_WS_RELAY??X,c=new URL(i);if(c.protocol!=="https:"&&c.protocol!=="http:")throw new Error("Tunnel relay URL must use HTTP or HTTPS");return c.toString()}var g=1e3,N=3e4,ne=new Set(["connection","keep-alive","proxy-authenticate","proxy-authorization","proxy-connection","te","trailer","transfer-encoding","upgrade"]);function W(a){return new Promise(i=>{setTimeout(i,a)})}function R(a){process.env.MCP_USE_TUNNEL_DEBUG==="1"&&console.log(`[mcp-use] ${a}`)}function A(a){return typeof a=="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(a)}function U(a,i=!1){let c={};for(let[r,u]of Object.entries(a)){let d=r.toLowerCase();u===void 0||ne.has(d)||i&&(d==="host"||d==="content-length")||(c[d]=typeof u=="number"?String(u):u)}return c}function P(a,i,c){let r=new TextEncoder().encode(i);if(r.byteLength!==_)throw new Error("Invalid tunnel request identifier");let u=new Uint8Array(1+_+c.byteLength);return u[0]=a,u.set(r,1),u.set(c,1+_),u}function re(a){let i=Buffer.from(a);if(i.byteLength<1+_||i.byteLength>1+_+m)return;let c=i.subarray(1,1+_).toString("ascii");if(A(c))return{kind:i[0]??0,requestId:c,body:i.subarray(1+_)}}function F(a){let i=new Uint8Array(a.byteLength);return i.set(a),i}async function oe(a){for(;a.readyState===WebSocket.OPEN&&a.bufferedAmount>x;)await W(5);if(a.readyState!==WebSocket.OPEN)throw new Error("Tunnel socket closed while applying backpressure")}function v(a,i){let c=JSON.stringify(i);if(Buffer.byteLength(c)>$)throw new Error("Tunnel control message exceeds 64 KiB");a.send(c)}async function ae(a){let i=await a.text(),c={};try{c=JSON.parse(i)}catch{}if(!a.ok)throw new Error(c.error??`Tunnel relay returned HTTP ${a.status}`);return c}async function ie(a,i){let c=await fetch(new URL("/api/tunnels/request",a),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i===void 0?{}:{subdomain:i}),signal:AbortSignal.timeout(1e4)}),r=await ae(c);if(typeof r.tunnel_id!="string"||typeof r.token!="string"||typeof r.connect_url!="string"||typeof r.public_url!="string")throw new Error("Tunnel relay returned an invalid reservation");return r}async function L(a,i){if(i.token!==void 0)try{await fetch(new URL(`/api/tunnels/${encodeURIComponent(i.subdomain)}`,a),{method:"DELETE",headers:{authorization:`Bearer ${i.token}`},signal:AbortSignal.timeout(2e3)})}catch{}}async function se(a,i,c){let r=new WebSocket(i.connect_url);r.binaryType="arraybuffer";let u=new Map,d=new Map,w=!1,S=!1,p=!1,b,h=(n,l)=>{let s=u.get(n);if(s!==void 0&&(u.delete(n),s.request.destroy(),s.response?.destroy(),r.readyState===WebSocket.OPEN))try{v(r,{type:"response-error",requestId:n,message:l instanceof Error?l.message:String(l)})}catch{}},q=n=>{if(!A(n.requestId)||u.has(n.requestId)||u.size>=C||typeof n.method!="string"||typeof n.path!="string"||!n.path.startsWith("/")){r.close(1008,"Invalid request");return}let l=U(n.headers,!0),s=n.headers["x-forwarded-host"];typeof s=="string"&&(l.host=s);let e=D.request({hostname:"127.0.0.1",port:a,method:n.method,path:n.path,headers:l}),o={request:e};u.set(n.requestId,o),e.on("response",t=>{o.response=t,(async()=>{v(r,{type:"response-start",requestId:n.requestId,status:t.statusCode??502,headers:U(t.headers)});for await(let f of t){let y=Buffer.from(f);for(let T=0;T<y.byteLength;T+=m)await oe(r),r.send(P(V,n.requestId,y.subarray(T,T+m)))}u.has(n.requestId)&&(u.delete(n.requestId),v(r,{type:"response-end",requestId:n.requestId}))})().catch(f=>{h(n.requestId,f)})}),e.on("error",t=>{h(n.requestId,t)})},E=(n,l=1e3,s="")=>{let e=d.get(n);if(e!==void 0){d.delete(n);try{e.socket.close(l,s.slice(0,123))}catch{e.socket.close()}}},I=(n,l,s)=>{let e=d.get(n);if(e!==void 0){if(!e.open){if(e.queuedBytes+s.byteLength>x){E(n,1009,"WebSocket buffer limit reached"),v(r,{type:"websocket-error",requestId:n,message:"WebSocket buffer limit reached"});return}e.queue.push({kind:l,body:s}),e.queuedBytes+=s.byteLength;return}e.socket.send(l===O?s.toString("utf8"):F(s))}},B=n=>{if(!A(n.requestId)||d.has(n.requestId)||u.size+d.size>=C||typeof n.path!="string"||!n.path.startsWith("/")||n.protocols!==void 0&&(!Array.isArray(n.protocols)||n.protocols.some(o=>typeof o!="string"||!/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(o)))){r.close(1008,"Invalid WebSocket request");return}let l=new URL(n.path,`ws://127.0.0.1:${a}`);if(l.origin!==`ws://127.0.0.1:${a}`){r.close(1008,"Invalid WebSocket path");return}let s=new WebSocket(l,n.protocols??[]);s.binaryType="arraybuffer";let e={socket:s,open:!1,queue:[],queuedBytes:0};d.set(n.requestId,e),s.addEventListener("open",()=>{if(d.get(n.requestId)===e){e.open=!0;for(let o of e.queue)s.send(o.kind===O?o.body.toString("utf8"):F(o.body));e.queue=[],e.queuedBytes=0,v(r,{type:"websocket-ready",requestId:n.requestId,...s.protocol!==""&&{protocol:s.protocol}})}}),s.addEventListener("message",o=>{if(r.readyState===WebSocket.OPEN){if(typeof o.data=="string"){let t=Buffer.from(o.data);if(t.byteLength>m){E(n.requestId,1009,"WebSocket message too large");return}r.send(P(ee,n.requestId,t))}else if(o.data instanceof ArrayBuffer){let t=Buffer.from(o.data);if(t.byteLength>m){E(n.requestId,1009,"WebSocket message too large");return}r.send(P(te,n.requestId,t))}}}),s.addEventListener("close",o=>{d.get(n.requestId)===e&&(d.delete(n.requestId),r.readyState===WebSocket.OPEN&&v(r,{type:"websocket-close",requestId:n.requestId,code:o.code,reason:o.reason}))}),s.addEventListener("error",()=>{d.get(n.requestId)===e&&r.readyState===WebSocket.OPEN&&v(r,{type:"websocket-error",requestId:n.requestId,message:"Local WebSocket connection failed"})})},k=new Promise((n,l)=>{let s=setTimeout(()=>{r.close(),l(new Error("Tunnel setup timed out"))},Q);r.addEventListener("open",()=>{v(r,{type:"authenticate",token:i.token})}),r.addEventListener("message",e=>{if(e.data instanceof ArrayBuffer){let y=re(e.data);if(y===void 0){r.close(1003,"Invalid body frame");return}y.kind===G?u.get(y.requestId)?.request.write(y.body):y.kind===O||y.kind===Z?I(y.requestId,y.kind,y.body):r.close(1003,"Invalid body frame");return}if(typeof e.data!="string"){r.close(1003,"Invalid message");return}let o=e.data;if(Buffer.byteLength(o)>$){r.close(1009,"Control message too large");return}let t;try{t=JSON.parse(o)}catch{r.close(1003,"Invalid JSON");return}if(t.type==="auth-required")return;if(t.type==="ready"){w||(w=!0,clearTimeout(s),t.keepalive===!0&&(b=setInterval(()=>{if(r.readyState===WebSocket.OPEN){if(p){r.close(1011,"Tunnel keepalive timed out");return}p=!0,v(r,{type:"ping"})}},j),b.unref()),n());return}if(t.type==="pong"){p=!1;return}if(t.type==="request-start"){q(t);return}if(t.type==="websocket-open"){B(t);return}if(!A(t.requestId)){r.close(1008,"Invalid request identifier");return}let f=u.get(t.requestId);if(t.type==="request-end")f?.request.end();else if(t.type==="cancel"&&f!==void 0)u.delete(t.requestId),f.request.destroy(),f.response?.destroy();else if(t.type==="websocket-close"){let y=Number.isInteger(t.code)&&(t.code??0)>=1e3&&(t.code??0)<=4999?t.code:1e3;E(t.requestId,y,t.reason??"")}else r.close(1003,"Unsupported message")}),r.addEventListener("error",()=>{w||(clearTimeout(s),l(new Error("Tunnel WebSocket connection failed")))},{once:!0})});return r.addEventListener("close",n=>{b!==void 0&&clearInterval(b);for(let[l,s]of u)u.delete(l),s.request.destroy(),s.response?.destroy();for(let l of d.keys())E(l,1011,"Tunnel disconnected");!S&&w&&c(n)}),await k,Object.defineProperty(r,"__mcpUseIntentionalClose",{value:()=>{S=!0}}),{url:i.public_url,subdomain:i.tunnel_id,token:i.token,socket:r,reservation:i}}function ue(a){let i=a.__mcpUseIntentionalClose;i?.()}function ce(a,i={}){let c=Y(i.relayUrl),r,u=null,d,w=!1,S,p=g,b,h=0,q=async()=>{try{let e=await H(a,"utf8"),o=JSON.parse(e);return typeof o.subdomain=="string"?{subdomain:o.subdomain,...typeof o.token=="string"&&{token:o.token},...typeof o.connect_url=="string"&&{connect_url:o.connect_url},...typeof o.public_url=="string"&&{public_url:o.public_url}}:void 0}catch{return}},E=async e=>{try{await z(J(a),{recursive:!0}),await K(a,JSON.stringify(e,null,2),{encoding:"utf8",mode:384})}catch(o){console.warn(`[mcp-use] failed to save tunnel state: ${o instanceof Error?o.message:String(o)}`)}},I=()=>{},B=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,k=e=>({subdomain:e.tunnel_id,token:e.token,connect_url:e.connect_url,public_url:e.public_url}),n=async e=>{await E(k(e.reservation))},l=async(e,o)=>se(e,o,t=>{r=void 0,u=null;let f=t.code===1008||t.reason==="Tunnel expired"||t.reason==="Tunnel deleted";b=f?void 0:o,R(`tunnel connection closed (${t.code}${t.reason===""?"":`: ${t.reason}`}); ${f?"allocating a replacement":"reattaching"}`),I()}),s=async(e,o)=>{console.log(`[mcp-use] starting tunnel for port ${e}\u2026`);let t=await ie(c,i.subdomain??o);return l(e,t)};return I=()=>{w||d===void 0||u!==null||S!==void 0||(S=(async()=>{for(;!w&&d!==void 0&&u===null;)try{if(b!==void 0&&h<M)try{let t=await l(d,b);r=t,u=t.url,h=0,p=g,await n(t),R("tunnel reattached");return}catch(t){if(h+=1,R(`tunnel reattach attempt ${h} failed: ${t instanceof Error?t.message:String(t)}`),h<M){await W(p),p=Math.min(p*2,N);continue}}let e=await q();e!==void 0&&await L(c,e),b=void 0,h=0;let o;try{o=await s(d,e?.subdomain)}catch(t){if(e?.subdomain===void 0)throw t;console.log(`[mcp-use] tunnel "${e.subdomain}" unavailable, requesting a new one\u2026`),o=await s(d)}r=o,u=o.url,await n(o),p=g;return}catch(e){console.warn(`[mcp-use] tunnel restart failed: ${e instanceof Error?e.message:String(e)}`),await W(p),p=Math.min(p*2,N)}})().finally(()=>{S=void 0}))},{status(){return{url:u}},async start(e){if(w=!1,d=e,r!==void 0&&u!==null)return{url:u,subdomain:r.subdomain};let o=await q(),t,f=B(o);if(f!==void 0&&(i.subdomain===void 0||f.tunnel_id===i.subdomain))try{t=await l(e,f)}catch{await L(c,k(f)),t=await s(e,f.tunnel_id).catch(async()=>(console.log(`[mcp-use] tunnel "${f.tunnel_id}" unavailable, requesting a new one\u2026`),s(e)))}else{o!==void 0&&await L(c,o);try{t=await s(e,o?.subdomain)}catch(y){if(o?.subdomain===void 0)throw y;console.log(`[mcp-use] tunnel "${o.subdomain}" unavailable, requesting a new one\u2026`),t=await s(e)}}return r=t,u=t.url,b=t.reservation,h=0,await n(t),{url:t.url,subdomain:t.subdomain}},async stop(){w=!0,S!==void 0&&await S;let e=r,o=e?.reservation??b;r=void 0,u=null,d=void 0,p=g,b=void 0,h=0,o!==void 0&&await L(c,k(o)),e!==void 0&&(ue(e.socket),e.socket.close(1e3,"Client shutdown"))}}}export{Y as a,ce as b};