@mcp-use/cli 4.0.0-beta.5 → 4.0.0-beta.6
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 +4 -4
- package/dist/chunk-OVFUQAEG.js +1 -0
- package/dist/commands/dev.js +2 -2
- package/dist/commands/start.js +4 -4
- package/dist/tunnel-AQ2WE7EL.js +1 -0
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as
|
|
2
|
+
import{a as c}from"./chunk-USIKTT3N.js";import{readFileSync as a}from"fs";import{resolve as s}from"path";var i=`mcp-use \u2014 run MCP servers built with mcp-use
|
|
3
3
|
|
|
4
4
|
Usage: mcp-use <command> [options]
|
|
5
5
|
|
|
@@ -30,10 +30,10 @@ Options:
|
|
|
30
30
|
--inline Embed view JS and CSS in MCP resources (build only)
|
|
31
31
|
-- <tsc options> Forward remaining options to TypeScript (typecheck only)
|
|
32
32
|
--with-inspector Mount Inspector on the production listener (start only)
|
|
33
|
-
--tunnel Expose the
|
|
33
|
+
--tunnel Expose the server through a public tunnel (dev/start only)
|
|
34
34
|
--no-open Do not auto-open the inspector in a browser (dev only)
|
|
35
35
|
--no-inspector Start dev without loading the optional Inspector
|
|
36
36
|
-h, --help Show this help
|
|
37
|
-
-v, --version Print the version`;async function
|
|
37
|
+
-v, --version Print the version`;async function l(n){if(n.length===1&&["--version","-v"].includes(n[0]??""))return console.log(u()),0;if(n.some(t=>t==="--help"||t==="-h")){let t=n[0];if(t===void 0||t==="--help"||t==="-h")return console.log(i),0}let e=n[0];if(e==="login"||e==="logout"||e==="whoami"){let{runIdentity:t}=await import("./commands/identity.js");return t(e,n.slice(1))}if(e==="org"){let{runOrganizations:t}=await import("./commands/organizations.js");return t(n.slice(1))}if(e==="servers"){let{runServers:t}=await import("./commands/servers.js");return t(n.slice(1))}if(e==="deployments"){let{runDeployments:t}=await import("./commands/deployments.js");return t(n.slice(1))}if(e==="deploy"){let{runDeploy:t}=await import("./commands/deploy.js");return t(n.slice(1))}if(e==="client"){let{runClient:t}=await import("./commands/client.js");return t(n.slice(1))}if(e==="skills"){let{runSkills:t}=await import("./commands/skills.js");return t(n.slice(1))}if(e==="screenshot"){let{runScreenshot:t}=await import("./commands/screenshot.js");return t(n.slice(1))}let r;try{r=c(n)}catch(t){return console.error(t instanceof Error?t.message:String(t)),2}if(r.version)return console.log(u()),0;if(r.help)return console.log(i),0;switch(r.command){case"start":return d(r);case"dev":case"build":return m(r.command,r);case"typecheck":return p(r);case void 0:return console.error(i),2;default:return console.error(`Unknown command: ${r.command}
|
|
38
38
|
|
|
39
|
-
${
|
|
39
|
+
${i}`),2}}async function p(n){try{let{runTypecheck:e}=await import("./commands/typecheck.js");return await e({cwd:s(process.cwd(),n.path??"."),...n.entry!==void 0&&{entry:n.entry},...n.mcpDir!==void 0&&{mcpDir:n.mcpDir},...n.passthrough.length>0&&{tscArgs:n.passthrough}})}catch(e){return console.error(e instanceof Error?e.message:String(e)),1}}async function d(n){let e;try{let{runStart:o}=await import("./commands/start.js");e=await o({cwd:s(process.cwd(),n.path??"."),port:n.port,host:n.host,...n.inspector===!0&&{withInspector:!0},tunnel:n.tunnel})}catch(o){return console.error(o instanceof Error?o.message:String(o)),1}console.log(`mcp-use server running at ${e.url}`),e.tunnelUrl!==void 0&&console.log(`mcp-use public MCP URL: ${e.tunnelUrl}`);let r=!1,t=()=>{r||(r=!0,e.close().then(()=>process.exit(0),o=>{console.error(o instanceof Error?o.message:String(o)),process.exit(1)}))};return process.once("SIGINT",t),process.once("SIGTERM",t),0}async function m(n,e){let r={cwd:s(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(n==="dev"){let{runDev:t}=await import("./commands/dev.js");await t(r)}else{let{runBuild:t}=await import("./commands/build.js");await t(r)}return 0}catch(t){return console.error(t instanceof Error?t.message:String(t)),1}}function u(){return"2.0.0-beta.29"}l(process.argv.slice(2)).then(n=>{process.exitCode=n},n=>{console.error(n instanceof Error?n.message:String(n)),process.exitCode=1});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mkdir as U,readFile as L,writeFile as O}from"fs/promises";import{spawn as R}from"child_process";import{dirname as z}from"path";var D="https://local.mcp-use.run";function W(){return process.env.MCP_USE_TUNNEL_API??D}var y=1e3,q=3e4;function H(h){let i,o=null,u,l,d=!1,c,m=y,M=e=>new Promise(n=>{setTimeout(n,e)}),$=()=>{i!==void 0&&"markShutdown"in i&&typeof i.markShutdown=="function"&&i.markShutdown()},b=async e=>{try{await fetch(`${W()}/api/tunnels/${e}`,{method:"DELETE",signal:AbortSignal.timeout(2e3)})}catch{}},P=async()=>{try{let e=await L(h,"utf8"),n=JSON.parse(e);return typeof n.subdomain=="string"?n.subdomain:void 0}catch{return}},_=async e=>{try{await U(z(h),{recursive:!0}),await O(h,JSON.stringify({subdomain:e},null,2),"utf8")}catch(n){console.warn(`[mcp-use] failed to save tunnel subdomain: ${n instanceof Error?n.message:String(n)}`)}},E=()=>{},w=(e,n)=>new Promise((t,f)=>{console.log(`[mcp-use] starting tunnel for port ${e}\u2026`);let k=process.env.npm_config_user_agent??"",[F,x]=k.startsWith("pnpm/")?["pnpm",["--silent","dlx","@mcp-use/tunnel",String(e)]]:k.startsWith("bun/")?["bunx",["@mcp-use/tunnel",String(e)]]:["npx",["--yes","--prefer-offline","@mcp-use/tunnel",String(e)]];n!==void 0&&x.push("--subdomain",n);let a=R(F,x,{stdio:["ignore","pipe","pipe"],shell:process.platform==="win32"}),p=!1,S=!1,I=()=>{S=!0};a.markShutdown=I,a.stdout.on("data",r=>{let s=r.toString(),N=s.includes("Shutting down")||s.includes("\u{1F6D1}"),C=s.includes("\u2716")||s.includes("Error:");!S&&!N&&!C&&process.stdout.write(s);let v=s.match(/https?:\/\/([a-z0-9-]+\.[a-z0-9.-]+)/i);if(v!==null&&!p){let B=v[0],A=v[1]??"",g=A.match(/^([a-z0-9-]+)\./i)?.[1]??A.split(".")[0]??"";/^[a-z0-9-]+$/i.test(g)||(console.warn(`[mcp-use] warning: extracted subdomain "${g}" does not match expected format`),g=""),p=!0,clearTimeout(T),t({url:B,subdomain:g,process:a})}}),a.stderr.on("data",r=>{let s=r.toString();!S&&!s.includes("INFO")&&!s.includes("bore_cli")&&!s.includes("Shutting down")&&!/npm warn Unknown (?:env|project|user|builtin) config/.test(s)&&process.stderr.write(r)}),a.on("error",r=>{p||(clearTimeout(T),f(new Error(`Failed to start tunnel: ${r.message}`)))}),a.on("exit",r=>{r!==0&&r!==null&&!p&&(clearTimeout(T),f(new Error(`Tunnel process exited with code ${r}`))),i===a&&(i=void 0,o=null,d?u=void 0:E())});let T=setTimeout(()=>{p||(a.kill(),f(new Error("Tunnel setup timed out")))},3e4)});return E=()=>{d||l===void 0||o!==null||c===void 0&&(c=(async()=>{for(;!d&&l!==void 0&&o===null;){console.log("[mcp-use] tunnel disconnected, restarting\u2026");let e=u??await P();try{e!==void 0&&await b(e);let n;try{n=await w(l,e)}catch(t){if(e!==void 0)console.log(`[mcp-use] subdomain "${e}" unavailable, requesting a new one\u2026`),n=await w(l,void 0);else throw t}i=n.process,o=n.url,u=n.subdomain,await _(n.subdomain),m=y;return}catch(n){console.warn(`[mcp-use] tunnel restart failed: ${n instanceof Error?n.message:String(n)}`),await M(m),m=Math.min(m*2,q)}}})().finally(()=>{c=void 0}))},{status(){return{url:o}},async start(e){if(d=!1,l=e,o!==null)return{url:o,subdomain:u??""};let n=await P();n!==void 0&&(console.log(`[mcp-use] found existing subdomain: ${n}`),await b(n));let t;try{t=await w(e,n)}catch(f){if(n!==void 0)console.log(`[mcp-use] subdomain "${n}" unavailable, requesting a new one\u2026`),t=await w(e,void 0);else throw f}return i=t.process,o=t.url,u=t.subdomain,await _(t.subdomain),{url:t.url,subdomain:t.subdomain}},async stop(){d=!0,$(),c!==void 0&&await c,u!==void 0&&await b(u),i!==void 0&&(i.kill("SIGINT"),i=void 0),l=void 0,o=null,u=void 0,m=y}}}export{W as a,H as b};
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as ne,b as te}from"../chunk-N7BU45K6.js";import{b as Q,c as Z}from"../chunk-USIKTT3N.js";import{a as se,b as ie,c as ae,d as G,f as q,g as ce,i as le}from"../chunk-ALPMVGHI.js";import{b as re,c as oe,d as W}from"../chunk-7G4TXPP4.js";import{a as V,b as ee}from"../chunk-DB3E6LBX.js";import{spawn as Ne}from"child_process";import{createServer as Be}from"http";import{networkInterfaces as Ve}from"os";import{join as We,resolve as Ge}from"path";import qe from"@tailwindcss/vite";import ze from"@vitejs/plugin-react";import{createServer as Je,createServerModuleRunner as Ke}from"vite";import{InMemoryServerEventBus as Xe,localhostAllowedHostnames as Ye,localhostAllowedOrigins as Qe,validateHostHeader as Ze,validateOriginHeader as en}from"@modelcontextprotocol/server";import{connect as Me,createServer as Re}from"net";var ue=100,Ie=300,_e=new Set(["127.0.0.1","localhost","::1"]);function ke(e,r){return new Promise(o=>{let t=Re();t.unref(),t.once("error",()=>o(!1)),t.listen({port:e,host:r},()=>{t.close(()=>o(!0))})})}function de(e,r){return new Promise(o=>{let t=Me({port:e,host:r});t.setTimeout(Ie),t.once("connect",()=>{t.destroy(),o(!0)}),t.once("timeout",()=>{t.destroy(),o(!1)}),t.once("error",()=>{t.destroy(),o(!1)})})}async function Te(e){return await de(e,"127.0.0.1")||await de(e,"::1")}async function pe(e,r){for(let o=e;o<e+ue;o++)if(await ke(o,r)&&!(_e.has(r)&&await Te(o)))return{port:o,requested:e};throw new Error(`No free port found between ${e} and ${e+ue-1} on ${r}.`)}function fe(e,r){let o=()=>{let t=e.getBasePath(),{url:c}=e.tunnel.status();return{mcpUrl:c!==null?`${c.replace(/\/+$/,"")}${t}`:null,port:e.port,fromCli:!0,tunnelUrl:c}};return async t=>{let c=e.getBasePath(),u=`${c}/inspector/api/dev/info`,d=`${c}/inspector/api/dev/start-tunnel`,p=`${c}/inspector/api/dev/stop-tunnel`,R=new URL(t.url).pathname;if(t.method==="GET"&&R===u)return Response.json(o());if(t.method==="POST"&&R===d)try{return await e.tunnel.start(e.port),Response.json({ok:!0,restarting:!1})}catch(k){let T=k instanceof Error?k.message:"Failed to start tunnel";return Response.json({error:T},{status:500})}return t.method==="POST"&&R===p?(await e.tunnel.stop(),Response.json({ok:!0})):r(t)}}import{readFileSync as Ee}from"fs";import{createRequire as $e}from"module";import{join as De}from"path";import{pathToFileURL as Oe}from"url";async function he(e){let r=De(e,"package.json"),o=JSON.parse(Ee(r,"utf8"));if([o.dependencies,o.devDependencies,o.optionalDependencies].some(u=>u!==null&&typeof u=="object"&&"@mcp-use/inspector"in u)){let u=$e(r);try{let d=u.resolve("@mcp-use/inspector");return me(await import(Oe(d).href))}catch(d){if(!we(d))throw d}}try{return me(await import("@mcp-use/inspector"))}catch(u){if(we(u))return{installed:!1};throw u}}function me(e){if(typeof e.mountInspector!="function")throw new Error("The installed @mcp-use/inspector is incompatible: its package entry does not export mountInspector(). Update the development dependency.");return{installed:!0,module:e}}function we(e){let r=e!==null&&typeof e=="object"&&"code"in e?String(e.code):void 0;return r==="ERR_MODULE_NOT_FOUND"||r==="MODULE_NOT_FOUND"}import{mkdir as xe,readFile as He,writeFile as Ae}from"fs/promises";import{spawn as Ce}from"child_process";import{dirname as Ue}from"path";var Le="https://local.mcp-use.run";function je(){return process.env.MCP_USE_TUNNEL_API??Le}var z=1e3,Fe=3e4;function ve(e){let r,o=null,t,c,u=!1,d,p=z,R=a=>new Promise(i=>{setTimeout(i,a)}),k=()=>{r!==void 0&&"markShutdown"in r&&typeof r.markShutdown=="function"&&r.markShutdown()},T=async a=>{try{await fetch(`${je()}/api/tunnels/${a}`,{method:"DELETE",signal:AbortSignal.timeout(2e3)})}catch{}},U=async()=>{try{let a=await He(e,"utf8"),i=JSON.parse(a);return typeof i.subdomain=="string"?i.subdomain:void 0}catch{return}},H=async a=>{try{await xe(Ue(e),{recursive:!0}),await Ae(e,JSON.stringify({subdomain:a},null,2),"utf8")}catch(i){console.warn(`[mcp-use] failed to save tunnel subdomain: ${i instanceof Error?i.message:String(i)}`)}},E=()=>{},m=(a,i)=>new Promise((g,b)=>{console.log(`[mcp-use] starting tunnel for port ${a}\u2026`);let I=process.env.npm_config_user_agent??"",[P,A]=I.startsWith("pnpm/")?["pnpm",["--silent","dlx","@mcp-use/tunnel",String(a)]]:I.startsWith("bun/")?["bunx",["@mcp-use/tunnel",String(a)]]:["npx",["--yes","--prefer-offline","@mcp-use/tunnel",String(a)]];i!==void 0&&A.push("--subdomain",i);let h=Ce(P,A,{stdio:["ignore","pipe","pipe"],shell:process.platform==="win32"}),_=!1,$=!1,y=()=>{$=!0};h.markShutdown=y,h.stdout.on("data",w=>{let v=w.toString(),F=v.includes("Shutting down")||v.includes("\u{1F6D1}"),L=v.includes("\u2716")||v.includes("Error:");!$&&!F&&!L&&process.stdout.write(v);let O=v.match(/https?:\/\/([a-z0-9-]+\.[a-z0-9.-]+)/i);if(O!==null&&!_){let N=O[0],C=O[1]??"",S=C.match(/^([a-z0-9-]+)\./i)?.[1]??C.split(".")[0]??"";/^[a-z0-9-]+$/i.test(S)||(console.warn(`[mcp-use] warning: extracted subdomain "${S}" does not match expected format`),S=""),_=!0,clearTimeout(D),g({url:N,subdomain:S,process:h})}}),h.stderr.on("data",w=>{let v=w.toString();!$&&!v.includes("INFO")&&!v.includes("bore_cli")&&!v.includes("Shutting down")&&!/npm warn Unknown (?:env|project|user|builtin) config/.test(v)&&process.stderr.write(w)}),h.on("error",w=>{_||(clearTimeout(D),b(new Error(`Failed to start tunnel: ${w.message}`)))}),h.on("exit",w=>{w!==0&&w!==null&&!_&&(clearTimeout(D),b(new Error(`Tunnel process exited with code ${w}`))),r===h&&(r=void 0,o=null,u?t=void 0:E())});let D=setTimeout(()=>{_||(h.kill(),b(new Error("Tunnel setup timed out")))},3e4)});return E=()=>{u||c===void 0||o!==null||d===void 0&&(d=(async()=>{for(;!u&&c!==void 0&&o===null;){console.log("[mcp-use] tunnel disconnected, restarting\u2026");let a=t??await U();try{a!==void 0&&await T(a);let i;try{i=await m(c,a)}catch(g){if(a!==void 0)console.log(`[mcp-use] subdomain "${a}" unavailable, requesting a new one\u2026`),i=await m(c,void 0);else throw g}r=i.process,o=i.url,t=i.subdomain,await H(i.subdomain),p=z;return}catch(i){console.warn(`[mcp-use] tunnel restart failed: ${i instanceof Error?i.message:String(i)}`),await R(p),p=Math.min(p*2,Fe)}}})().finally(()=>{d=void 0}))},{status(){return{url:o}},async start(a){if(u=!1,c=a,o!==null)return{url:o,subdomain:t??""};let i=await U();i!==void 0&&(console.log(`[mcp-use] found existing subdomain: ${i}`),await T(i));let g;try{g=await m(a,i)}catch(b){if(i!==void 0)console.log(`[mcp-use] subdomain "${i}" unavailable, requesting a new one\u2026`),g=await m(a,void 0);else throw b}return r=g.process,o=g.url,t=g.subdomain,await H(g.subdomain),{url:g.url,subdomain:g.subdomain}},async stop(){u=!0,k(),d!==void 0&&await d,t!==void 0&&await T(t),r!==void 0&&(r.kill("SIGINT"),r=void 0),c=void 0,o=null,t=void 0,p=z}}}function nn(e){let[r,o]=process.platform==="darwin"?["open",[e]]:process.platform==="win32"?["cmd",["/c","start","",e]]:["xdg-open",[e]];try{let t=Ne(r,o,{stdio:"ignore",detached:!0});t.on("error",()=>{}),t.unref()}catch{}}function tn(){for(let e of Object.values(Ve()))for(let r of e??[])if(!r.internal&&r.family==="IPv4")return r.address}function rn(e){if(e!==void 0)try{return new URL(`http://${e}`).hostname.replace(/^\[|\]$/g,"")}catch{return}}function on(e){let r=e.getHeader("Vary"),o=typeof r=="string"?r:Array.isArray(r)?r.join(", "):r!==void 0?String(r):"";o.split(",").map(t=>t.trim().toLowerCase()).includes("origin")||e.setHeader("Vary",o===""?"Origin":`${o}, Origin`)}function sn(e,r,o){if(o.tunnelActive){r.setHeader("Access-Control-Allow-Origin","*");return}if(!o.localhostBind)return;let t=e.headers.origin;if(t==="null"){r.setHeader("Access-Control-Allow-Origin","null");return}if(typeof t!="string"||t==="")return;let c=en(t,Qe());!c.ok||c.origin===void 0||(r.setHeader("Access-Control-Allow-Origin",c.origin),on(r))}function an(e){let r=e.default;if(r===null||typeof r!="object")throw new Error("The server entry must default-export the MCPServer instance (`export default server`) and never call listen() itself \u2014 `mcp-use dev` owns the socket.");let o=r;if(typeof o.fetch!="function")throw new Error("The entry's default export has no fetch() \u2014 it must be the MCPServer instance (`export default server`).");return o}async function cn(e){process.env.MCP_USE_DEV_CLI="1";let r=ae(e.cwd),o=new Xe(n=>{console.error("[mcp-use] notification delivery failed:",n)});oe(e.cwd,"development");let t=Z(e.host),c=["127.0.0.1","localhost","::1"].includes(t),u=t==="0.0.0.0"||t==="::",d=Be(),{port:p,requested:R}=await pe(Q(e.port),t);p!==R&&console.log(`[mcp-use] port ${R} is taken, using ${p}`),process.env.PORT=String(p);let k=process.env.MCP_URL===void 0&&(t==="127.0.0.1"||t==="localhost"||t==="::1")?`http://localhost:${p}`:void 0,T=e.mcpDir===void 0?e.cwd:Ge(e.cwd,e.mcpDir),U=e.entry===void 0?V(T):V(e.cwd,e.entry),H=await ee(e.cwd,U);(H==="created"||H==="updated")&&console.log(`[mcp-use] ${H} mcp-env.d.ts`);let E=e.viewsDir??(e.mcpDir===void 0?void 0:We(e.mcpDir,"views")),m=G(e.cwd,E),a=m.length>0,i=se(e.cwd),b=["127.0.0.1","localhost","0.0.0.0","::","::1"].includes(t)?"localhost":t,I=`http://${b.includes(":")?`[${b}]`:b}:${p}`,P=await Je({root:e.cwd,configFile:a?i:!1,envDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:{tailwindcss:ie()}},plugins:a?[W(e.cwd),qe(),le({getViews:()=>m,dev:{reactRefresh:!0}}),ze()]:[W(e.cwd)],server:{middlewareMode:!0,...a&&{origin:I},cors:!1,hmr:a?{server:d}:!1},ssr:{...re(e.cwd)}}),A=P.environments.ssr,h=Ke(A,{hmr:!1,sourcemapInterceptor:"node"}),_=async()=>{let n=async()=>{let l=await h.import(U),f=an(l);if(m.length>0){let M=ce(m);if(typeof f.__primeViews!="function")throw new Error("Loaded MCPServer instance does not support __primeViews.");f.__primeViews(M,{dev:!0,projectRoot:e.cwd})}return f};if(k===void 0)return n();let s=process.env.MCP_URL;try{return process.env.MCP_URL=k,await n()}finally{s===void 0?delete process.env.MCP_URL:process.env.MCP_URL=s}},$,y;try{let n=await _();n.__setEventBus(o),n.__mount(),$=async s=>n.fetch(s),y=n.basePath??"/mcp"}catch(n){throw await h.close(),await P.close(),n}let D,w,v,F=n=>{if(D===void 0||v===n)return;let s=D.mountInspector({basePath:n,autoConnectUrl:`${I}${n}`,oauthProxyAllowLoopback:c||u,devMode:!0});if(typeof s!="function")throw new Error("The installed @mcp-use/inspector is incompatible: mountInspector() did not return a Fetch handler.");w=s,v=n};try{if(e.inspector!==!1){let n=await he(e.cwd);n.installed&&(D=n.module,F(y))}}catch(n){throw await h.close(),await P.close(),n}let L=!1,O=!1,N=()=>{if(L){O=!0;return}L=!0,(async()=>{do{O=!1;try{h.evaluatedModules.clear();let n=await _();n.__setEventBus(o),n.__mount();let s=async f=>n.fetch(f),l=n.basePath??"/mcp";F(l),$=s,y=l,o.publish({kind:"tools_list_changed"}),o.publish({kind:"prompts_list_changed"}),o.publish({kind:"resources_list_changed"}),console.log("[mcp-use] reloaded server entry")}catch(n){console.error(`[mcp-use] reload failed \u2014 keeping the previous server:
|
|
2
|
-
`,
|
|
1
|
+
import{b as te}from"../chunk-OVFUQAEG.js";import{a as Y,b as Q}from"../chunk-N7BU45K6.js";import{b as z,c as K}from"../chunk-USIKTT3N.js";import{a as ne,b as re,c as oe,d as T,f as A,g as se,i as ie}from"../chunk-ALPMVGHI.js";import{b as Z,c as ee,d as x}from"../chunk-7G4TXPP4.js";import{a as C,b as X}from"../chunk-DB3E6LBX.js";import{spawn as ke}from"child_process";import{createServer as $e}from"http";import{networkInterfaces as Ee}from"os";import{join as Le,resolve as Ue}from"path";import Ce from"@tailwindcss/vite";import xe from"@vitejs/plugin-react";import{createServer as Te,createServerModuleRunner as Ae}from"vite";import{InMemoryServerEventBus as Ve,localhostAllowedHostnames as Fe,localhostAllowedOrigins as Be,validateHostHeader as Ne,validateOriginHeader as We}from"@modelcontextprotocol/server";import{connect as be,createServer as Re}from"net";var ae=100,Me=300,Ie=new Set(["127.0.0.1","localhost","::1"]);function Se(e,r){return new Promise(o=>{let n=Re();n.unref(),n.once("error",()=>o(!1)),n.listen({port:e,host:r},()=>{n.close(()=>o(!0))})})}function ce(e,r){return new Promise(o=>{let n=be({port:e,host:r});n.setTimeout(Me),n.once("connect",()=>{n.destroy(),o(!0)}),n.once("timeout",()=>{n.destroy(),o(!1)}),n.once("error",()=>{n.destroy(),o(!1)})})}async function _e(e){return await ce(e,"127.0.0.1")||await ce(e,"::1")}async function le(e,r){for(let o=e;o<e+ae;o++)if(await Se(o,r)&&!(Ie.has(r)&&await _e(o)))return{port:o,requested:e};throw new Error(`No free port found between ${e} and ${e+ae-1} on ${r}.`)}function de(e,r){let o=()=>{let n=e.getBasePath(),{url:c}=e.tunnel.status();return{mcpUrl:c!==null?`${c.replace(/\/+$/,"")}${n}`:null,port:e.port,fromCli:!0,tunnelUrl:c}};return async n=>{let c=e.getBasePath(),l=`${c}/inspector/api/dev/info`,d=`${c}/inspector/api/dev/start-tunnel`,u=`${c}/inspector/api/dev/stop-tunnel`,w=new URL(n.url).pathname;if(n.method==="GET"&&w===l)return Response.json(o());if(n.method==="POST"&&w===d)try{return await e.tunnel.start(e.port),Response.json({ok:!0,restarting:!1})}catch(g){let _=g instanceof Error?g.message:"Failed to start tunnel";return Response.json({error:_},{status:500})}return n.method==="POST"&&w===u?(await e.tunnel.stop(),Response.json({ok:!0})):r(n)}}import{readFileSync as He}from"fs";import{createRequire as De}from"module";import{join as Oe}from"path";import{pathToFileURL as je}from"url";async function fe(e){let r=Oe(e,"package.json"),o=JSON.parse(He(r,"utf8"));if([o.dependencies,o.devDependencies,o.optionalDependencies].some(l=>l!==null&&typeof l=="object"&&"@mcp-use/inspector"in l)){let l=De(r);try{let d=l.resolve("@mcp-use/inspector");return ue(await import(je(d).href))}catch(d){if(!pe(d))throw d}}try{return ue(await import("@mcp-use/inspector"))}catch(l){if(pe(l))return{installed:!1};throw l}}function ue(e){if(typeof e.mountInspector!="function")throw new Error("The installed @mcp-use/inspector is incompatible: its package entry does not export mountInspector(). Update the development dependency.");return{installed:!0,module:e}}function pe(e){let r=e!==null&&typeof e=="object"&&"code"in e?String(e.code):void 0;return r==="ERR_MODULE_NOT_FOUND"||r==="MODULE_NOT_FOUND"}function Ge(e){let[r,o]=process.platform==="darwin"?["open",[e]]:process.platform==="win32"?["cmd",["/c","start","",e]]:["xdg-open",[e]];try{let n=ke(r,o,{stdio:"ignore",detached:!0});n.on("error",()=>{}),n.unref()}catch{}}function qe(){for(let e of Object.values(Ee()))for(let r of e??[])if(!r.internal&&r.family==="IPv4")return r.address}function Je(e){if(e!==void 0)try{return new URL(`http://${e}`).hostname.replace(/^\[|\]$/g,"")}catch{return}}function ze(e){let r=e.getHeader("Vary"),o=typeof r=="string"?r:Array.isArray(r)?r.join(", "):r!==void 0?String(r):"";o.split(",").map(n=>n.trim().toLowerCase()).includes("origin")||e.setHeader("Vary",o===""?"Origin":`${o}, Origin`)}function Ke(e,r,o){if(o.tunnelActive){r.setHeader("Access-Control-Allow-Origin","*");return}if(!o.localhostBind)return;let n=e.headers.origin;if(n==="null"){r.setHeader("Access-Control-Allow-Origin","null");return}if(typeof n!="string"||n==="")return;let c=We(n,Be());!c.ok||c.origin===void 0||(r.setHeader("Access-Control-Allow-Origin",c.origin),ze(r))}function Xe(e){let r=e.default;if(r===null||typeof r!="object")throw new Error("The server entry must default-export the MCPServer instance (`export default server`) and never call listen() itself \u2014 `mcp-use dev` owns the socket.");let o=r;if(typeof o.fetch!="function")throw new Error("The entry's default export has no fetch() \u2014 it must be the MCPServer instance (`export default server`).");return o}async function Ye(e){process.env.MCP_USE_DEV_CLI="1";let r=oe(e.cwd),o=new Ve(t=>{console.error("[mcp-use] notification delivery failed:",t)});ee(e.cwd,"development");let n=K(e.host),c=["127.0.0.1","localhost","::1"].includes(n),l=n==="0.0.0.0"||n==="::",d=$e(),{port:u,requested:w}=await le(z(e.port),n);u!==w&&console.log(`[mcp-use] port ${w} is taken, using ${u}`),process.env.PORT=String(u);let g=process.env.MCP_URL===void 0&&(n==="127.0.0.1"||n==="localhost"||n==="::1")?`http://localhost:${u}`:void 0,_=e.mcpDir===void 0?e.cwd:Ue(e.cwd,e.mcpDir),V=e.entry===void 0?C(_):C(e.cwd,e.entry),H=await X(e.cwd,V);(H==="created"||H==="updated")&&console.log(`[mcp-use] ${H} mcp-env.d.ts`);let I=e.viewsDir??(e.mcpDir===void 0?void 0:Le(e.mcpDir,"views")),p=T(e.cwd,I),P=p.length>0,me=ne(e.cwd),D=["127.0.0.1","localhost","0.0.0.0","::","::1"].includes(n)?"localhost":n,y=`http://${D.includes(":")?`[${D}]`:D}:${u}`,f=await Te({root:e.cwd,configFile:P?me:!1,envDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:{tailwindcss:re()}},plugins:P?[x(e.cwd),Ce(),ie({getViews:()=>p,dev:{reactRefresh:!0}}),xe()]:[x(e.cwd)],server:{middlewareMode:!0,...P&&{origin:y},cors:!1,hmr:P?{server:d}:!1},ssr:{...Z(e.cwd)}}),O=f.environments.ssr,b=Ae(O,{hmr:!1,sourcemapInterceptor:"node"}),F=async()=>{let t=async()=>{let i=await b.import(V),a=Xe(i);if(p.length>0){let v=se(p);if(typeof a.__primeViews!="function")throw new Error("Loaded MCPServer instance does not support __primeViews.");a.__primeViews(v,{dev:!0,projectRoot:e.cwd})}return a};if(g===void 0)return t();let s=process.env.MCP_URL;try{return process.env.MCP_URL=g,await t()}finally{s===void 0?delete process.env.MCP_URL:process.env.MCP_URL=s}},j,m;try{let t=await F();t.__setEventBus(o),t.__mount(),j=async s=>t.fetch(s),m=t.basePath??"/mcp"}catch(t){throw await b.close(),await f.close(),t}let k,R,B,N=t=>{if(k===void 0||B===t)return;let s=k.mountInspector({basePath:t,autoConnectUrl:`${y}${t}`,oauthProxyAllowLoopback:c||l,devMode:!0});if(typeof s!="function")throw new Error("The installed @mcp-use/inspector is incompatible: mountInspector() did not return a Fetch handler.");R=s,B=t};try{if(e.inspector!==!1){let t=await fe(e.cwd);t.installed&&(k=t.module,N(m))}}catch(t){throw await b.close(),await f.close(),t}let $=!1,E=!1,W=()=>{if($){E=!0;return}$=!0,(async()=>{do{E=!1;try{b.evaluatedModules.clear();let t=await F();t.__setEventBus(o),t.__mount();let s=async a=>t.fetch(a),i=t.basePath??"/mcp";N(i),j=s,m=i,o.publish({kind:"tools_list_changed"}),o.publish({kind:"prompts_list_changed"}),o.publish({kind:"resources_list_changed"}),console.log("[mcp-use] reloaded server entry")}catch(t){console.error(`[mcp-use] reload failed \u2014 keeping the previous server:
|
|
2
|
+
`,t)}}while(E);$=!1})()},L=t=>{if(A(t,e.cwd,I))return;let s=O.moduleGraph.getModulesByFile(t);if(!(s===void 0||s.size===0)){for(let i of s)O.moduleGraph.invalidateModule(i);W()}},ve=t=>{if(!A(t,e.cwd,I))return;let s=p;p=T(e.cwd,I),(s.length!==p.length||s.some((a,v)=>a.name!==p[v]?.name||a.entryPath!==p[v]?.entryPath))&&W()},S=t=>{ve(t),L(t)};f.watcher.on("change",L),f.watcher.on("add",S),f.watcher.on("unlink",S);let h=te(r.tunnel);d.prependListener("upgrade",t=>{let s=h.status().url;if(s===null)return;let i=new URL(s).hostname;t.headers.host?.split(":")[0]===i&&(t.headers.host=`localhost:${u}`)});let he=(t,s)=>{let i=h.status().url,a=i!==null?new URL(i).hostname:null,v=a!==null?[a]:[],M=Ne(t.headers.host,[...Fe(),...v]);return M.ok?!1:(s.writeHead(403,{"content-type":"application/json"}),s.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:M.message},id:null})),!0)},G=async()=>{f.watcher.off("change",L),f.watcher.off("add",S),f.watcher.off("unlink",S),await h.stop(),await new Promise(t=>d.close(()=>t())),await b.close(),await f.close()},we=de({getBasePath:()=>m,port:u,tunnel:h},t=>R!==void 0&&Y(t,m)?R(t):j(t)),{toNodeHandler:ge}=await import("../node-bridge-JJIA6K5P.js"),q=ge({fetch:we}),Pe=(t,s)=>{if(c&&he(t,s))return;let i=t.url??"/",a=new URL(i,"http://127.0.0.1").pathname,v=h.status().url,M=v===null?null:new URL(v).hostname,U=Je(t.headers.host);if((M!==null&&U===M||l&&U!==void 0&&!["localhost","127.0.0.1","::1"].includes(U))&&Q(a,m)){s.writeHead(404,{"content-type":"text/plain; charset=utf-8"}),s.end("Not Found");return}let J=P&&p.length>0,ye=t.method==="GET"&&(a.startsWith("/@")||a.startsWith("/node_modules/")||a.startsWith("/.mcp-use/")||J&&a.startsWith("/views/"));J&&ye?(Ke(t,s,{tunnelActive:h.status().url!==null,localhostBind:c}),f.middlewares(t,s,()=>{q(t,s)})):q(t,s)};if(d.on("request",Pe),await new Promise((t,s)=>{d.once("error",s),d.listen(u,n,()=>t())}),console.log("[mcp-use] dev server ready"),p.length>0&&console.log(` \u279C Views: ${p.map(t=>t.name).join(", ")}`),console.log(` \u279C MCP endpoint: ${y}${m}`),R!==void 0?console.log(` \u279C Inspector: ${y}${m}/inspector`):e.inspector!==!1&&console.warn("[mcp-use] Built-in Inspector is unavailable; reinstall mcp-use to restore visual testing."),n==="0.0.0.0"||n==="::"){let t=qe();t!==void 0&&console.log(` \u279C Network: http://${t}:${u}${m}`)}if(c||console.warn(`[mcp-use] --host ${n} serves beyond this machine without Host validation or authentication \u2014 anyone with network access can call the MCP endpoint and dev routes.`),e.tunnel===!0)try{let{url:t}=await h.start(u);console.log(` \u279C Tunnel: ${t}${m}`)}catch(t){throw await G(),t}R!==void 0&&e.open!==!1&&process.stdout.isTTY===!0&&Ge(`${y}${m}/inspector`),await new Promise(t=>{let s=!1,i=()=>{s||(s=!0,process.off("SIGINT",i),process.off("SIGTERM",i),(async()=>(await G(),t()))())};process.on("SIGINT",i),process.on("SIGTERM",i),e.signal!==void 0&&(e.signal.aborted?i():e.signal.addEventListener("abort",i,{once:!0}))})}export{Ye as runDev};
|
package/dist/commands/start.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
Run \`mcp-use build\` first, then \`mcp-use start\`.`)}let
|
|
3
|
-
Re-run \`mcp-use build\`.`)}process.env.NODE_ENV??="production",
|
|
4
|
-
The server entry must \`export default\` its MCPServer instance (see the mcp-use entry contract).`);let
|
|
1
|
+
import{a as v}from"../chunk-N7BU45K6.js";import{b as g,c as S}from"../chunk-USIKTT3N.js";import{c as E}from"../chunk-7G4TXPP4.js";import{readFile as x}from"fs/promises";import{join as d}from"path";import{pathToFileURL as R}from"url";var I=".mcp-use",L="build",U="manifest.json";async function N(t){let o=d(t.cwd,I,L),s=d(o,U),c;try{c=await x(s,"utf8")}catch{throw new Error(`No production build found (missing ${s}).
|
|
2
|
+
Run \`mcp-use build\` first, then \`mcp-use start\`.`)}let i;try{let n=JSON.parse(c);if(typeof n.entryPoint!="string"||n.entryPoint==="")throw new Error("missing entryPoint");i=n.entryPoint}catch(n){let r=n instanceof Error?n.message:String(n);throw new Error(`Invalid build manifest at ${s} (${r}).
|
|
3
|
+
Re-run \`mcp-use build\`.`)}process.env.NODE_ENV??="production",E(t.cwd,"production");let a=d(o,i),u=await import(R(a).href);if(!("default"in u)||u.default===void 0)throw new Error(`The built entry (${a}) has no default export.
|
|
4
|
+
The server entry must \`export default\` its MCPServer instance (see the mcp-use entry contract).`);let e=u.default;if(!D(e))throw new Error(`The default export of ${a} is not an MCPServer: it has no listen() method. Export the MCPServer instance as the default export.`);let k=typeof e.port=="number"?e.port:void 0,M=typeof e.host=="string"?e.host:void 0,h=g(t.port,process.env,k),y=S(t.host,process.env,M),l=await(t.withInspector===!0?O(e,h,y):e.listen(h,{host:y})),m=typeof l?.port=="number"?l.port:h,b=typeof l?.url=="string"?l.url:`http://localhost:${m}`,p,w;if(t.tunnel===!0)try{let{createTunnelManager:n}=await import("../tunnel-AQ2WE7EL.js");p=n(d(t.cwd,I,"state","tunnel.json"));let r=await p.start(m),P=new URL(b);w=new URL(`${P.pathname}${P.search}`,`${r.url}/`).toString()}catch(n){try{await p?.stop()}catch{}try{await e.close?.()}catch{}throw n}return{port:m,url:b,...w!==void 0&&{tunnelUrl:w},close:async()=>{let n;try{await p?.stop()}catch(r){n=r}try{await e.close?.()}catch(r){n??=r}if(n!==void 0)throw n}}}async function O(t,o,s){let{mountInspector:c}=await _(),i=typeof t.basePath=="string"?t.basePath:"/mcp",a=c({basePath:i,devMode:!1,oauthProxyAllowLoopback:!1});return t.app.use("*",async(f,u)=>{if(v(f.req.raw,i))return a(f.req.raw);await u()}),t.listen(o,{host:s})}async function _(){let t;try{t=await import("@mcp-use/inspector")}catch(o){throw F(o)?new Error("Built-in Inspector is unavailable; reinstall mcp-use to restore it."):o}if(typeof t.mountInspector!="function")throw new Error("The installed @mcp-use/inspector is incompatible: its package entry does not export mountInspector(). Reinstall mcp-use.");return{mountInspector:t.mountInspector}}function D(t){return typeof t=="object"&&t!==null&&typeof t.listen=="function"}function F(t){return t!==null&&typeof t=="object"&&"code"in t&&(t.code==="ERR_MODULE_NOT_FOUND"||t.code==="MODULE_NOT_FOUND")}export{N as runStart};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"./chunk-OVFUQAEG.js";export{b as createTunnelManager,a as tunnelApiBase};
|
package/package.json
CHANGED