@mcp-use/cli 4.0.0-beta.1 → 4.0.0-beta.11

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 ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{a as n}from"./chunk-FTF3BR6T.js";import"./chunk-USIKTT3N.js";n(process.argv.slice(2),{frameworkVersion:"4.0.0-beta.11"}).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 o,i as g,j as c,k as l,l as f}from"./chunk-VSIT62BK.js";import{join as C}from"path";var d=C(f,"config.json");function p(){return(process.env.MCP_USE_CLOUD_API_URL??"https://cloud.manufact.com/api/v1").replace(/\/+$/,"").replace(/\/api\/v1$/,"")+"/api/v1"}function z(){return p().replace(/\/api\/v1$/,"")}async function m(){return g(d,{})}async function I(i){await c(d,i)}async function O(){await l(d)}function _(i,t){let n=i.filter(e=>e.id===t||e.slug===t);if(n.length!==1)throw new o(n.length===0?"organization_not_found":"organization_ambiguous",`Organization not found: ${t}`);return n[0]}var s=class i{#n;#t;constructor(t,n){this.#n=t,this.#t=n}static async create(t){let n=await m(),e=process.env.MCP_USE_API_KEY??n.apiKey;if(e===void 0||e==="")throw new o("not_authenticated","Not logged in. Run `mcp-use login`.");return new i(e,t??n.orgId)}static withApiKey(t){return new i(t)}async request(t,n={}){let e=n.organizationId??this.#t,r=await fetch(`${p()}${t}`,{...n,headers:{Accept:"application/json","x-api-key":this.#n,...e!==void 0?{"x-profile-id":e}:{},...n.body!==void 0?{"Content-Type":"application/json"}:{},...n.headers}}),u=await r.text(),a;try{a=u===""?void 0:JSON.parse(u)}catch{a=u}if(!r.ok)throw new o(r.status===401?"not_authenticated":r.status===403?"forbidden":"cloud_api_error",h(a)??`Cloud API request failed (${r.status}).`,{status:r.status});return a}async identity(){let t=await this.request("/test-auth");return{userId:t.user_id,email:t.email,organizations:t.profiles.map(n=>({id:n.id,name:n.profile_name,slug:n.slug,role:n.role})),defaultOrganizationId:t.default_profile_id}}async setDefaultOrganization(t){await this.request(`/organizations/${t}/set-default`,{method:"POST"})}};async function P(i){let t=await m(),n=await(await s.create()).identity(),e=i!==void 0?_(n.organizations,i):n.organizations.find(r=>r.id===(t.orgId??n.defaultOrganizationId));if(e===void 0)throw new o("organization_required","No active organization. Run `mcp-use org use <id-or-slug>`.");return{api:await s.create(e.id),organizationId:e.id}}function h(i){if(typeof i=="string"&&i!=="")return i;if(!(i===null||typeof i!="object"))for(let t of["message","error","detail"]){let n=i[t];if(typeof n=="string"&&n!=="")return n}}export{z as a,m as b,I as c,O as d,_ as e,s as f,P as g};
@@ -0,0 +1,37 @@
1
+ import{a,b as g,c as x,d,e as L,f as $,g as N,h,i as k,j as w,l as R}from"./chunk-VSIT62BK.js";import{createHash as ie}from"crypto";import{rm as J}from"fs/promises";import{join as C}from"path";import{createInterface as ae}from"readline/promises";import{parseArgs as b}from"util";import{spawn as q}from"child_process";import{readFileSync as z}from"fs";import{chmod as K,mkdir as W}from"fs/promises";import{dirname as V,join as y,resolve as Y}from"path";import{pathToFileURL as M}from"url";var v=y(R,"client-sdk"),m="@mcp-use/client",Z="^2.0.0-alpha.0",Q=[`[mcp-use] ${m} 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(`
2
+ `);async function X(e){let t=Y(e);for(;;){if(await h(y(t,"package.json")))return t;let n=V(t);if(n===t)return;t=n}}async function D(){try{return await oe()}catch(e){if(!U(e))throw e;let t=await ee();try{return t.location==="sandbox"?await se():await re(t.projectRoot)}catch(n){throw U(n)?new a(Q):n}}}async function ee(){let e=ne(),t=`${m}@${e}`,n=await X(process.cwd());if(process.stderr.write(`[mcp-use] installing ${m}\u2026
3
+ `),n!==void 0){let[s,c]=te(t);if(await I(s,c,n)!==0)throw new g("client_install_failed",`Failed to install ${m}.`);return{location:"project",projectRoot:n}}await W(v,{recursive:!0,mode:448}),await K(v,448);let o=y(v,"package.json");if(await h(o)||await w(o,{private:!0,dependencies:{[m]:e}}),await I("npm",["install",t],v)!==0)throw new g("client_install_failed",`Failed to install ${m}.`);return{location:"sandbox"}}function te(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 ne(){for(let e of["../package.json","../../package.json"])try{let t=z(new URL(e,import.meta.url),"utf8"),n=JSON.parse(t);if(n.name!=="mcp-use")continue;let o=n.peerDependencies?.[m];if(typeof o=="string"&&o.length>0)return o}catch{}return Z}async function oe(){return import("@mcp-use/client")}async function re(e){let t=M(y(e,"package.json")).href;return import(await import.meta.resolve(m,t))}async function se(){let e=y(v,"node_modules",m,"dist","index.js");return await import(M(e).href)}function U(e){if(!(e instanceof Error))return!1;let t=e.code;return t==="ERR_MODULE_NOT_FOUND"||t==="MODULE_NOT_FOUND"?e.message.includes(m)||e.message.includes("Cannot find package"):!1}function I(e,t,n){return new Promise((o,r)=>{let s=q(e,t,{cwd:n,stdio:"inherit",shell:process.platform==="win32"});s.once("error",r),s.once("exit",(c,u)=>{o(u==="SIGINT"?130:c??1)})})}var B=C(R,"client"),_=C(B,"servers.json"),ce=`Usage: mcp-use client <command> [options]
4
+
5
+ Commands:
6
+ connect <name> <url> Connect and save an HTTP(S) MCP server
7
+ list [--json] List saved servers
8
+ remove <name> [--yes] Remove a saved server
9
+ <name> Invoke tools/resources/prompts on a saved server
10
+
11
+ Connect options:
12
+ -H, --header <"Key: Value"> Static header (repeatable)
13
+ --no-oauth Skip OAuth on authorization challenges
14
+ --auth-timeout <ms> OAuth wait timeout (default: 300000)
15
+ --protocol <auto|2026-07-28|2025-11-25>
16
+ --no-open Print the OAuth URL only
17
+ --json Emit machine-readable output
18
+
19
+ Saved server commands:
20
+ mcp-use client <name> tools list [--json]
21
+ mcp-use client <name> tools describe <tool> [--json]
22
+ mcp-use client <name> tools call <tool> [args...] [--timeout <ms>] [--json]
23
+ mcp-use client <name> resources list [--json]
24
+ mcp-use client <name> resources read <uri> [--json]
25
+ mcp-use client <name> prompts list [--json]
26
+ mcp-use client <name> prompts get <prompt> [args...] [--json]
27
+ mcp-use client <name> auth status [--json]
28
+ mcp-use client <name> auth logout [--yes] [--json]
29
+
30
+ Examples:
31
+ mcp-use client connect linear https://mcp.linear.app/mcp
32
+ mcp-use client linear tools list
33
+ mcp-use client linear tools call search_issues query="open bugs"`;async function xe(e){if(e.includes("--help")||e.includes("-h"))return console.log(ce),0;let t=x(e),n=e.filter(s=>s!=="--json"),o=n[0],r=t&&o!=="remove";try{if(o==="connect")return await le(n.slice(1),t);if(o==="list")return await ue(n.slice(1),t);if(o==="remove"){if(t)throw new a("mcp-use client remove does not support --json.");return await pe(n.slice(1))}if(o===void 0)throw new a("Usage: mcp-use client <connect|list|remove|name>");return await de(o,n.slice(1),t)}catch(s){return L(s instanceof TypeError?new a(s.message):s,r)}}async function le(e,t){let{values:n,positionals:o}=b({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;he(r);let c=new URL(s);if(!["http:","https:"].includes(c.protocol))throw new a("Client URLs must use http or https.");let u=ge(n.protocol),l=G(n["auth-timeout"]??"300000","--auth-timeout"),i=await S();if(i.servers[r]!==void 0)throw new a(`Saved server already exists: ${r}`);let p={headers:we(n.header??[])},f={url:c.href,oauth:n["no-oauth"]!==!0,protocol:u};return await(await E(r,f,p,l,H({noOpen:n["no-open"]===!0,json:t}))).disconnect(),i.servers[r]=f,await w(_,i),await w(A(r),p),d({name:r,url:f.url,protocol:u},t,`Connected and saved ${r}.`),0}async function ue(e,t){P(e);let n=await S(),o=Object.entries(n.servers).map(([r,s])=>({name:r,...s}));return d(o,t,o.map(r=>`${r.name} ${r.url}`).join(`
34
+ `)||"No saved servers."),0}async function pe(e){let{values:t,positionals:n}=b({args:[...e],allowPositionals:!0,strict:!0,options:{yes:{type:"boolean"}}}),o=T(n,"mcp-use client remove <name>");if(!await $(`Remove saved server ${o}?`,{yes:t.yes===!0,json:!1}))return 0;let r=await S();return delete r.servers[o],await w(_,r),await J(j(o),{recursive:!0,force:!0}),d({removed:o},!1,`Removed ${o}.`),0}async function de(e,t,n){let r=(await S()).servers[e];if(r===void 0)throw new a(`Unknown saved server: ${e}. Run \`mcp-use client connect ${e} <url>\`.`);let s=t[0],c=t[1];if(s==="auth"){if(c==="status"){P(t.slice(2));let i=await h(O(e));return d({name:e,oauth:r.oauth,authenticated:i},n,i?"Authenticated.":"No saved OAuth session."),0}if(c==="logout"){let{values:i,positionals:p}=b({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 $(`Delete OAuth credentials for ${e}?`,{yes:i.yes===!0,json:n})&&(await J(O(e),{recursive:!0,force:!0}),d({loggedOut:e},n,`Logged out ${e}.`)),0}}let u=await k(A(e),{}),l=await E(e,r,u,3e5,H({noOpen:!1,json:n}));try{if(s==="tools"){if(c==="list"){P(t.slice(2));let i=await l.listTools();return d(i,n,i.map(p=>p.description?`${p.name} - ${p.description}`:p.name).join(`
35
+ `)),0}if(c==="describe"){let i=T(t.slice(2),`mcp-use client ${e} tools describe <tool>`),p=(await l.listTools()).find(f=>f.name===i);if(p===void 0)throw new a(`Tool not found: ${i}`);return d(p,n),0}if(c==="call")return await me(l,e,t.slice(2),n)}if(s==="resources"){if(c==="list"){P(t.slice(2));let i=await l.listResources();return d(i,n),0}if(c==="read"){let i=T(t.slice(2),`mcp-use client ${e} resources read <uri>`);return d(await l.readResource(i),n),0}}if(s==="prompts"){if(c==="list")return P(t.slice(2)),d(await l.listPrompts(),n),0;if(c==="get"){let i=t[2];if(i===void 0)throw new a(`Usage: mcp-use client ${e} prompts get <prompt> [args]`);return d(await l.getPrompt(i,F(t.slice(3))),n),0}}throw new a(`Usage: mcp-use client ${e} <tools|resources|prompts|auth> ...`)}finally{await l.disconnect()}}async function me(e,t,n,o){let r=n[0];if(r===void 0)throw new a(`Usage: mcp-use client ${t} tools call <tool> [args]`);let{values:s,positionals:c}=b({args:[...n.slice(1)],allowPositionals:!0,strict:!0,options:{timeout:{type:"string",default:"30000"}}}),u=G(s.timeout,"--timeout"),l=await e.callTool(r,F(c),{timeout:u});if(l.isError===!0)throw new g("tool_error",`Tool ${r} returned an error.`,l);return d(l,o),0}async function E(e,t,n,o,r=process.stdin.isTTY?"ask":"never"){let{createOAuthProvider:s,MCPClient:c}=await D(),u=O(e),l=t.oauth?await s(t.url,{baseDir:u,authTimeoutMs:o,storageKeyPrefix:`mcp-use-cli:${e}`,openBrowser:async f=>{if(r==="never"){process.stderr.write(`Open this URL to authenticate:
36
+ ${f}
37
+ `);return}await fe(),N(f)}}):void 0,i=t.protocol==="auto"?"auto":{pin:t.protocol};return new c({mcpServers:{[e]:{url:t.url,...n.headers!==void 0?{headers:n.headers}:{},...l!==void 0?{authProvider:l}:{oauth:!1},protocolNegotiation:i}}}).connect(e)}async function Le(e,t=3e5){let o=(await S()).servers[e];if(o===void 0)throw new a(`Unknown saved server: ${e}`);let r=await k(A(e),{});return E(e,o,r,t)}async function Ne(e,t){return E("screenshot",{url:e,oauth:!1,protocol:"auto"},{headers:t},3e5)}function F(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,c=o>=0?2:1;if(s<=0)throw new a(`Expected key=value or key:=<json>, received: ${n}`);let u=n.slice(0,s).replace(/^--/,""),l=n.slice(s+c);t[u]=o>=0?JSON.parse(l):l}return t}function H(e){return e.json||e.noOpen||!process.stdin.isTTY?"never":"ask"}async function fe(){let e=ae({input:process.stdin,output:process.stderr});try{await e.question("This server requires OAuth. Press Enter to open your browser.")}finally{e.close()}}function we(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 ge(e){if(e!=="auto"&&e!=="2026-07-28"&&e!=="2025-11-25")throw new a(`Invalid protocol: ${e}`);return e}function G(e,t){let n=Number(e);if(!Number.isInteger(n)||n<=0)throw new a(`${t} must be a positive integer.`);return n}function he(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.")}async function S(){return k(_,{servers:{}})}function j(e){return C(B,"credentials",ie("sha256").update(e).digest("hex"))}function A(e){return C(j(e),"credentials.json")}function O(e){return C(j(e),"oauth")}function P(e){b({args:[...e],allowPositionals:!1,strict:!0,options:{}})}function T(e,t){if(e.length!==1)throw new a(`Usage: ${t}`);return e[0]}export{xe as a,Le as b,Ne as c,F as d};
@@ -0,0 +1 @@
1
+ import{existsSync as p,readFileSync as d}from"fs";import{join as a}from"path";import{fileURLToPath as c}from"url";var i=new Set(["server-only","client-only","next/cache","next/headers","next/navigation","next/server"]);function x(e){let n=c(new URL("./next-server-shims.js",import.meta.url));return r(e)?[...i].map(t=>({find:t,replacement:n})):[]}function v(e){return r(e)?{noExternal:[...i]}:{external:!0}}function r(e){try{let n=JSON.parse(d(a(e,"package.json"),"utf8"));return n.dependencies?.next!==void 0||n.devDependencies?.next!==void 0}catch{return!1}}function g(e,n){let t=r(e)?[`.env.${n}.local`,".env.local",`.env.${n}`,".env"]:[".env"];for(let o of t){let s=a(e,o);p(s)&&process.loadEnvFile(s)}}function h(e){let n=r(e),t=c(new URL("./next-server-shims.js",import.meta.url));return{name:"mcp-use-next-standalone-compat",enforce:"pre",resolveId(o,s,l){return n&&l.ssr&&i.has(o)?{id:t,external:!1}:void 0}}}export{x as a,v as b,g as c,h as d};
@@ -0,0 +1,3 @@
1
+ import{a as p,b as f,d as l}from"./chunk-7G4TXPP4.js";import{existsSync as v}from"fs";import{join as w}from"path";import{fileURLToPath as V}from"url";var h=["vite.config.ts","vite.config.js","vite.config.mts","vite.config.cjs"];function W(t){for(let e of h){let r=w(t,e);if(v(r))return r}return!1}function b(){return V(import.meta.resolve("tailwindcss/index.css"))}import{join as s}from"path";var I=".mcp-use",x="manifest.json";function U(t){let e=s(t,I),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,x),tunnel:s(e,"state","tunnel.json")}}import{existsSync as m,readdirSync as D}from"fs";import{isAbsolute as _,join as y,resolve as E}from"path";var P="views",a="virtual:mcp-use/views/",c=`\0${a}`;function d(t,e){let r=e??P;return _(r)?r:E(t,r)}function C(t,e){let r=d(t,e);if(!m(r))return[];let n=[];for(let i of D(r,{withFileTypes:!0})){if(!i.isDirectory())continue;let o=y(r,i.name,"view.tsx");m(o)&&n.push({name:i.name,entryPath:o})}return n.sort((i,o)=>i.name.localeCompare(o.name)),n}function R(t){return`${a}${t}`}function S(t){return`/@id/__x00__${a}${t}`}function F(t,e,r){let n=d(e,r);return t===n||t.startsWith(`${n}/`)}function B(t){let e={};for(let r of t)e[r.name]={kind:"external",entry:S(r.name),css:[],scripts:["/@vite/client"]};return e}async function X(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:p(t)},plugins:[l(t)],server:{middlewareMode:!0,hmr:!1},ssr:{...f(t)}})}var u="virtual:mcp-use/tailwind.css",g=`\0${u}`;function K(t){return{name:"mcp-use-views",applyToEnvironment(e){return e.name==="client"},resolveId(e){if(e===u)return g;if(e.startsWith(a))return`\0${e}`},load(e){if(e===g)return['@import "tailwindcss";',"@custom-variant dark (&:where(.dark, .dark *, [data-theme=dark], [data-theme=dark] *));"].join(`
2
+ `);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 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(`
3
+ `)}}}export{W as a,b,U as c,C as d,R as e,F as f,B as g,X as h,K as i};
@@ -0,0 +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 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,37 @@
1
+ import{a as c}from"./chunk-USIKTT3N.js";import{resolve as s}from"path";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 Delete local cloud credentials
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 the current GitHub project
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`;async function u(t,n={frameworkVersion:"unknown"}){if(t.length===1&&["--version","-v"].includes(t[0]??""))return console.log(n.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 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 r;try{r=c(t)}catch(e){return console.error(e instanceof Error?e.message:String(e)),2}if(r.version)return console.log(n.frameworkVersion),0;if(r.help)return console.log(i),0;switch(r.command){case"start":return p(r);case"dev":case"build":return a(r.command,r);case"typecheck":return l(r);case void 0:return console.error(i),2;default:return console.error(`Unknown command: ${r.command}
36
+
37
+ ${i}`),2}}async function l(t){try{let{runTypecheck:n}=await import("./commands/typecheck.js");return await n({cwd:s(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(n){return console.error(n instanceof Error?n.message:String(n)),1}}async function p(t){let n;try{let{runStart:e}=await import("./commands/start.js");n=await e({cwd:s(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 ${n.url}`),n.tunnelUrl!==void 0&&console.log(`mcp-use public MCP URL: ${n.tunnelUrl}`);let o=!1,r=()=>{o||(o=!0,n.close().then(()=>process.exit(0),e=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)}))};return process.once("SIGINT",r),process.once("SIGTERM",r),0}async function a(t,n){let o={cwd:s(process.cwd(),n.path??"."),...n.entry!==void 0&&{entry:n.entry},...n.mcpDir!==void 0&&{mcpDir:n.mcpDir},...n.viewsDir!==void 0&&{viewsDir:n.viewsDir},...n.port!==void 0&&{port:n.port},...n.host!==void 0&&{host:n.host},...n.tunnel&&{tunnel:!0},...!n.open&&{open:!1},...n.inspector===!1&&{inspector:!1},...n.sourceMaps&&{sourceMaps:!0},...n.inline&&{inline:!0}};try{if(t==="dev"){let{runDev:r}=await import("./commands/dev.js");await r(o)}else{let{runBuild:r}=await import("./commands/build.js");await r(o)}return 0}catch(r){return console.error(r instanceof Error?r.message:String(r)),1}}export{u as a};
@@ -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 @@
1
+ function s(t,n){return r(new URL(t.url).pathname,n)}function r(t,n){let e=`${n}/inspector`;return t===e||t.startsWith(`${e}/`)}export{s as a,r as b};
@@ -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};
@@ -0,0 +1 @@
1
+ var f="127.0.0.1";function u(n,e,t=process.env){if(n!==void 0)return n;let r=t.HOST?.trim();return r!==void 0&&r!==""?r:e??f}function a(n,e,t=process.env){if(n!==void 0)return n;let r=c(t.PORT);return r!==void 0?r:e??3e3}function c(n){if(n===void 0||n.trim()==="")return;let e=Number(n);return Number.isInteger(e)&&e>=0&&e<=65535?e:void 0}function m(n){let e={command:void 0,port:void 0,entry:void 0,path:void 0,mcpDir:void 0,viewsDir:void 0,host:void 0,tunnel:!1,open:!0,inspector:void 0,sourceMaps:!1,inline:!1,help:!1,version:!1,passthrough:[]};for(let t=0;t<n.length;t++){let r=n[t];if(r===void 0)continue;if(r==="--"){if(e.command!=="typecheck")throw new Error("TypeScript argument forwarding is only available for typecheck");e.passthrough=n.slice(t+1);break}let i=r,d;if(r.startsWith("--")){let s=r.indexOf("=");s!==-1&&(i=r.slice(0,s),d=r.slice(s+1))}let o=()=>{if(d!==void 0)return d;let s=n[++t];if(s===void 0||s.startsWith("-"))throw new Error(`Missing value for ${i}`);return s};switch(i){case"-h":case"--help":e.help=!0;break;case"-v":case"--version":e.version=!0;break;case"-p":case"--port":e.port=p(o());break;case"--entry":e.entry=o();break;case"--path":e.path=o();break;case"--mcp-dir":e.mcpDir=o();break;case"--views-dir":e.viewsDir=o();break;case"--host":e.host=o();break;case"--tunnel":e.tunnel=!0;break;case"--no-open":e.open=!1;break;case"--no-inspector":e.inspector=!1;break;case"--with-inspector":e.inspector=!0;break;case"--source-maps":e.sourceMaps=!0;break;case"--inline":e.inline=!0;break;default:if(i.startsWith("-"))throw new Error(`Unknown option: ${i}`);if(e.command!==void 0)throw new Error(`Unexpected argument: ${i}`);e.command=i}}return e}function h(n,e=process.env,t){return a(n,t,e)}function k(n,e=process.env,t){return u(n,t,e)}function p(n){let e=Number(n);if(!l(e))throw new Error(`Invalid port: ${n}`);return e}function l(n){return Number.isInteger(n)&&n>=0&&n<=65535}export{m as a,h as b,k as c};
@@ -0,0 +1,8 @@
1
+ import{a}from"./chunk-LNASFQWW.js";import{constants as f}from"fs";import{access as p,chmod as c,mkdir as l,readFile as m,rename as w,rm as y,writeFile as g}from"fs/promises";import{homedir as x}from"os";import{dirname as $,join as d}from"path";import{createInterface as E}from"readline/promises";var r=class extends Error{exitCode=2},s=class extends Error{code;details;constructor(n,t,o){super(t),this.code=n,this.details=o}};function P(e){return e.includes("--json")}function k(e,n,t){n?process.stdout.write(`${JSON.stringify(e)}
2
+ `):t!==void 0?process.stdout.write(`${t}
3
+ `):typeof e=="string"?process.stdout.write(`${e}
4
+ `):process.stdout.write(`${JSON.stringify(e,null,2)}
5
+ `)}function _(e,n){let t=e instanceof r,o=e instanceof s,u=o?e.code:t?"usage_error":"command_failed",i=e instanceof Error?e.message:String(e);return n?process.stderr.write(`${JSON.stringify({error:{code:u,message:i,...o&&e.details!==void 0?{details:e.details}:{}}})}
6
+ `):process.stderr.write(`${i}
7
+ `),t?2:1}async function v(e,n){if(n.yes)return!0;if(n.json||!process.stdin.isTTY)throw new r(`${e} Pass --yes to confirm.`);let t=E({input:process.stdin,output:process.stdout});try{return(await t.question(`${e} [y/N] `)).trim().toLowerCase()==="y"}finally{t.close()}}function h(e){a(e)}async function j(e){try{return await p(e,f.F_OK),!0}catch{return!1}}async function B(e,n){try{return JSON.parse(await m(e,"utf8"))}catch(t){if(t.code==="ENOENT")return n;throw new s("invalid_state",`Could not read ${e}.`,{cause:t instanceof Error?t.message:String(t)})}}async function F(e,n){let t=$(e);await l(t,{recursive:!0,mode:448}),await c(t,448);let o=d(t,`.${e.slice(e.lastIndexOf("/")+1)}.${process.pid}.${Date.now()}.tmp`);await g(o,`${JSON.stringify(n,null,2)}
8
+ `,{mode:384}),await w(o,e),await c(e,384)}async function I(e){await y(e,{force:!0})}var L=d(x(),".mcp-use");export{r as a,s as b,P as c,k as d,_ as e,v as f,h as g,j as h,B as i,F as j,I as k,L as l};
@@ -0,0 +1,5 @@
1
+ import{a as U,b as V,c as P,d as C,e as L,h as N,i as j}from"../chunk-ALPMVGHI.js";import{a as x,b as R,c as B,d as S}from"../chunk-7G4TXPP4.js";import{a as $,b as _}from"../chunk-FLGSKQGU.js";import{randomBytes as H}from"crypto";import{existsSync as Z}from"fs";import{cp as ee,mkdir as v,rm as te,writeFile as E}from"fs/promises";import{join as f,relative as w,resolve as re}from"path";import ne from"@tailwindcss/vite";import ie from"@vitejs/plugin-react";import{build as D}from"vite";import{createServerModuleRunner as O}from"vite";var K="/mcp",Q="http://localhost:3000";async function F(e,t){let i=O(e,{hmr:!1,sourcemapInterceptor:"node"}),n=process.env.MCP_URL;try{n===void 0&&(process.env.MCP_URL=Q);let r=(await i.import(t)).default;if(r===null||typeof r!="object")throw new Error("The server entry must default-export the MCPServer instance.");return r.basePath??K}finally{n===void 0?delete process.env.MCP_URL:process.env.MCP_URL=n,await i.close()}}async function T(e,t,i){let n=O(e,{hmr:!1,sourcemapInterceptor:"node"});try{let r=(await n.import(t)).default;if(r===null||typeof r!="object")throw new Error("The server entry must default-export the MCPServer instance.");if(typeof r.__primeViews!="function")throw new Error("The entry's default export does not support __primeViews.");r.__primeViews(i),r.__mount()}finally{await n.close()}}function X(e){return e.replace(/\/+$/,"")}function k(e){return X(e)}import{hostHeaderValidationResponse as we,originValidationResponse as he}from"@modelcontextprotocol/server";function I(e,t){let i=t.replace(/^\/+/,"");return e==="/"?`/${i}`:`${e}/${i}`}function q(e,t){return`${I(e,`_mcp-use/views/${t}`)}/`}var p="index.js",se="entry-wrapper.ts",oe=100*1024*1024;async function W(e,t){let i=f(e,"public");Z(i)&&await ee(i,t,{recursive:!0})}async function ae(e,t,i){let n=f(e,se);await v(e,{recursive:!0});let s=JSON.stringify(i);return await E(n,[`import server from ${JSON.stringify(t)};`,'import { registerViews } from "mcp-use";',`server[registerViews](${s});`,"export default server;",""].join(`
2
+ `)),n}function ce(){let e=process.env.MCP_ASSETS_URL;if(!(e===void 0||e.trim()===""))try{return k(new URL(e).href.replace(/\/$/,""))}catch{return}}function A(e,t,i,n){let s=e.replace(/^\/+/,"");return`${i}${q(n,t)}${s}`}function ue(e,t,i,n){return e.kind!=="external"?e:{...e,entry:A(e.entry,t,i,n),css:e.css.map(s=>A(s,t,i,n)),...e.scripts!==void 0&&{scripts:e.scripts.map(s=>A(s,t,i,n))}}}async function le(e,t){let i=f(t.viewsOutDir,e.name),n=await D({root:t.cwd,configFile:t.userViteConfig,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:t.cacheDir,resolve:{tsconfigPaths:!0,alias:{tailwindcss:V()}},plugins:[ne(),ie(),j({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:oe,rollupOptions:{input:{[e.name]:L(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(n)?n[0]:n;if(s===void 0||!("output"in s))throw new Error(`Client build for view "${e.name}" produced no output.`);let r=s.output,b=Array.isArray(r)?r:Object.values(r),c,m,u,l=[];for(let a of b){if(typeof a!="object"||a===null||!("fileName"in a)||typeof a.fileName!="string")continue;let o=a;o.type==="chunk"&&o.isEntry===!0?(c=o.fileName,u=o.code):o.type==="asset"&&o.fileName.endsWith(".css")&&(m=o.fileName,typeof o.source=="string"?l.push(o.source):o.source instanceof Uint8Array&&l.push(new TextDecoder().decode(o.source)))}if(c===void 0)throw new Error(`Client build produced no entry chunk for view "${e.name}".`);if(t.inline){if(u===void 0)throw new Error(`Client build produced no entry source for view "${e.name}".`);return{kind:"inline",js:u,css:l.join(`
3
+ `)}}return{kind:"external",entry:c.replace(/^\/+/,""),css:m!==void 0?[m.replace(/^\/+/,"")]:[]}}async function de(e){let t=performance.now();B(e.cwd,"production");let i=e.mcpDir===void 0?e.cwd:re(e.cwd,e.mcpDir),n=e.entry===void 0?$(i):$(e.cwd,e.entry),s=await _(e.cwd,n);(s==="created"||s==="updated")&&console.log(`[mcp-use] ${s} mcp-env.d.ts`);let r=P(e.cwd),b=e.viewsDir??(e.mcpDir===void 0?void 0:f(e.mcpDir,"views")),c=C(e.cwd,b),m=U(e.cwd),u=e.sourceMaps===!0,l=e.inline===!0;if(c.length===0){await D({root:e.cwd,configFile:!1,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:x(e.cwd)},plugins:[S(e.cwd)],build:{ssr:n,outDir:r.build,emptyOutDir:!0,target:"node22",sourcemap:u,minify:!1,rollupOptions:{output:{format:"es",entryFileNames:p}}},ssr:{...R(e.cwd),target:"node"}}),await W(e.cwd,f(r.build,"views/public"));let d={buildId:H(8).toString("hex"),entryPoint:p,createdAt:new Date().toISOString(),views:{}};await v(r.build,{recursive:!0}),await E(r.buildManifest,`${JSON.stringify(d,null,2)}
4
+ `);let g=Math.round(performance.now()-t);console.log(`[mcp-use] built ${w(e.cwd,n)} \u2192 ${w(e.cwd,r.build)}/${p} (${g}ms)`);return}await te(r.build,{recursive:!0,force:!0});let a=f(r.build,"views");await v(a,{recursive:!0});let h=await N(e.cwd,r.cache,!1),o,y={},M=ce();try{o=await F(h.environments.ssr,n);for(let d of c){let g=await le(d,{cwd:e.cwd,cacheDir:r.cache,viewsOutDir:a,userViteConfig:m,sourceMaps:u,inline:l});M!==void 0&&!l&&(g=ue(g,d.name,M,o)),y[d.name]=g}M!==void 0&&!l&&(console.log(`[mcp-use] MCP_ASSETS_URL set \u2014 manifest uses CDN URLs; upload ${w(e.cwd,a)}/ to your asset host.`),o!=="/mcp"&&console.log(`[mcp-use] CDN manifest uses basePath ${o} from server entry`)),await W(e.cwd,f(a,"public")),await T(h.environments.ssr,n,y)}finally{await h.close()}let J=await ae(r.cache,n,y);await D({root:e.cwd,configFile:!1,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:x(e.cwd)},plugins:[S(e.cwd)],build:{ssr:J,outDir:r.build,emptyOutDir:!1,target:"node22",sourcemap:u,minify:!1,rollupOptions:{output:{format:"es",entryFileNames:p}}},ssr:{...R(e.cwd),target:"node"}});let z={buildId:H(8).toString("hex"),entryPoint:p,createdAt:new Date().toISOString(),views:y};await v(r.build,{recursive:!0}),await E(r.buildManifest,`${JSON.stringify(z,null,2)}
5
+ `);let Y=Math.round(performance.now()-t),G=c.map(d=>d.name).join(", ");console.log(`[mcp-use] built ${w(e.cwd,n)} + views (${G}) \u2192 ${w(e.cwd,r.build)}/${p} (${Y}ms)`)}export{de as runBuild};
@@ -0,0 +1 @@
1
+ import{a,b,c,d}from"../chunk-4JB4S4BZ.js";import"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";export{c as openDirectConnection,b as openSavedConnection,d as parseMcpArguments,a as runClient};
@@ -0,0 +1 @@
1
+ import{g as O}from"../chunk-3TSFYSEY.js";import{a as c,b as d,c as k,d as R,e as _,f as E,g as U,h as j,i as A,j as L}from"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";import{execFile as N}from"child_process";import{readFile as D}from"fs/promises";import{basename as J,isAbsolute as S,join as F,relative as H,resolve as v}from"path";import{promisify as G,parseArgs as M}from"util";var W=G(N);async function nt(n){let e=k(n);try{let{values:t,positionals:o}=M({args:[...n],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"},new:{type:"boolean"},open:{type:"boolean"},yes:{type:"boolean"},json:{type:"boolean"}}});if(o.length>1)throw new c("Usage: mcp-use deploy [path] [options]");let r=v(o[0]??process.cwd()),a=await b(r,["rev-parse","--show-toplevel"]),i=await b(a,["remote","get-url","origin"]),s=B(i),g=t.branch??await b(a,["branch","--show-current"]);if(g==="")throw new d("detached_head","Cannot infer a branch from detached HEAD; pass --branch.");z(a,t["root-dir"],"--root-dir"),z(a,t.dockerfile,"--dockerfile");let{api:l,organizationId:f}=await O(t.org),I=F(r,".mcp-use","cloud","link.json"),p=await A(I,null),q=t.new===!0||p===null;if(t.new===!0&&!await E("Create a new cloud server for this project?",{yes:t.yes===!0,json:e}))return 0;let u,w,h;if(!q&&p!==null){if(p.organizationId!==f)throw new d("organization_mismatch","The linked server belongs to another organization. Pass --new to create one.");u=p.serverId,w=p.serverSlug,h=(await l.request("/deployments",{method:"POST",body:JSON.stringify({serverId:u,branch:g,trigger:"manual"})})).id}else{let y=await l.request(`/github/installations?organizationId=${encodeURIComponent(f)}`),$=await K(l,y.installations,s);if($===void 0)throw new d("github_access_required",`The mcp-use GitHub App cannot access ${s}. Configure repository access in the cloud dashboard and retry.`);let P=await Q(r,t["env-file"],t.env??[]),m=await l.request("/servers",{method:"POST",body:JSON.stringify({type:"github",organizationId:f,installationId:$.installationId,name:t.name??J(s),repoFullName:s,branch:g,...t["root-dir"]!==void 0?{rootDir:t["root-dir"]}:{},...t.region!==void 0?{region:t.region}:{},...t["build-command"]!==void 0?{buildCommand:t["build-command"]}:{},...t["start-command"]!==void 0?{startCommand:t["start-command"]}:{},...t.dockerfile!==void 0?{dockerfilePath:t.dockerfile}:{},...Object.keys(P).length>0?{env:P}:{}})});if(m.deploymentId===null)throw new d("deployment_not_created","Server was created but no deployment was started.",{serverId:m.server.id});u=m.server.id,w=m.server.slug,h=m.deploymentId,await L(I,{organizationId:f,serverId:u,serverSlug:w,repository:s})}let C=`${process.env.MCP_USE_CLOUD_WEB_URL??"https://manufact.com"}/${encodeURIComponent(w??u)}`,x={serverId:u,deploymentId:h,status:"pending",webUrl:C};return t.open===!0&&U(C),R(x,e,`Deployment ${h} started for ${s}.`),0}catch(t){return _(t instanceof TypeError?new c(t.message):t,e)}}async function b(n,e){try{let{stdout:t}=await W("git",e,{cwd:n});return t.trim()}catch{throw new d("git_required",`Could not run git ${e.join(" ")} in ${n}.`)}}function B(n){let e=n.match(/github\.com[/:]([^/\s]+)\/([^/\s]+?)(?:\.git)?$/);if(e?.[1]===void 0||e[2]===void 0)throw new d("unsupported_remote","The origin remote must be a GitHub repository.");return`${e[1]}/${e[2]}`}async function K(n,e,t){let[o,r]=t.split("/"),a=[...e].sort((i,s)=>{let g=i.account?.login?.toLowerCase()===o.toLowerCase(),l=s.account?.login?.toLowerCase()===o.toLowerCase();return Number(l)-Number(g)});for(let i of a)try{if((await n.request(`/github/installations/${encodeURIComponent(i.installationId)}/repos/${encodeURIComponent(o)}/${encodeURIComponent(r)}/access`)).hasAccess)return i}catch{}}function z(n,e,t){if(e===void 0)return;if(S(e))throw new c(`${t} must be repository-relative.`);let o=v(n,e),r=H(n,o);if(r.startsWith("..")||S(r))throw new c(`${t} must not escape the repository.`)}async function Q(n,e,t){let o={};if(e!==void 0){let r=v(n,e);if(!await j(r))throw new c(`Environment file not found: ${e}`);for(let a of(await D(r,"utf8")).split(/\r?\n/)){let i=a.trim();i===""||i.startsWith("#")||T(o,i)}}for(let r of t)T(o,r);return o}function T(n,e){let t=e.indexOf("=");if(t<=0)throw new c(`Invalid environment value: ${e}`);n[e.slice(0,t)]=e.slice(t+1)}export{nt as runDeploy};
@@ -0,0 +1,6 @@
1
+ import{g as d}from"../chunk-3TSFYSEY.js";import{a,c as m,d as u,e as g,f as y}from"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";import{parseArgs as w}from"util";async function T(n){let t=m(n);try{let e=n[0];if(e==="list")return await I(n.slice(1),t);if(e==="get")return await P(n.slice(1),t);if(e==="logs")return await S(n.slice(1),t);if(e==="restart")return await v(n.slice(1),t);if(e==="stop")return await R(n.slice(1),t);if(e==="delete")return await E(n.slice(1),t);throw new a("Usage: mcp-use deployments <list|get|logs|restart|stop|delete>")}catch(e){return g(e instanceof TypeError?new a(e.message):e,t)}}async function I(n,t){let{values:e}=w({args:[...n],allowPositionals:!1,strict:!0,options:{org:{type:"string"},server:{type:"string"},limit:{type:"string",default:"30"},skip:{type:"string",default:"0"},json:{type:"boolean"}}}),i=f(e.limit,"--limit",1,100),s=f(e.skip,"--skip",0),o=new URLSearchParams({limit:String(i),skip:String(s),...e.server!==void 0?{serverId:e.server}:{}}),{api:r}=await d(e.org),l=await r.request(`/deployments?${o}`);return u(l,t),0}async function P(n,t){let{positionals:e}=p(n,{json:{type:"boolean"}}),i=c(e,"mcp-use deployments get <deployment-id>"),{api:s}=await d(),o=await s.request(`/deployments/${encodeURIComponent(i)}`);return u(o,t),0}async function S(n,t){let{values:e,positionals:i}=p(n,{build:{type:"boolean"},follow:{type:"boolean"},json:{type:"boolean"}}),s=c(i,"mcp-use deployments logs <deployment-id>"),{api:o}=await d();if(e.build===!0)await $(o,s,e.follow===!0,t);else{let r=await o.request(`/deployments/${encodeURIComponent(s)}/logs?lines=500`);t?u({deploymentId:s,logs:r.logs},!0):process.stdout.write(r.logs.endsWith(`
2
+ `)?r.logs:`${r.logs}
3
+ `)}return 0}async function v(n,t){let{values:e,positionals:i}=p(n,{branch:{type:"string"},follow:{type:"boolean"},json:{type:"boolean"}}),s=c(i,"mcp-use deployments restart <deployment-id>"),{api:o}=await d(),r=await o.request(`/deployments/${encodeURIComponent(s)}`);if(r.serverId===void 0||r.serverId===null)throw new a(`Deployment ${s} is not attached to a server.`);let l=await o.request("/deployments",{method:"POST",body:JSON.stringify({serverId:r.serverId,branch:e.branch??r.gitBranch??void 0,trigger:"redeploy"})});return e.follow===!0?await $(o,l.id,!0,t):u(l,t,`Restarted as deployment ${l.id}.`),0}async function R(n,t){return b(n,t,"stop")}async function E(n,t){return b(n,t,"delete")}async function b(n,t,e){let{values:i,positionals:s}=p(n,{yes:{type:"boolean"},json:{type:"boolean"}}),o=c(s,`mcp-use deployments ${e} <deployment-id>`);if(!await y(`${e==="stop"?"Stop":"Delete"} deployment ${o}?`,{yes:i.yes===!0,json:t}))return 0;let{api:r}=await d();return await r.request(`/deployments/${encodeURIComponent(o)}${e==="stop"?"/stop":""}`,{method:e==="stop"?"POST":"DELETE"}),u({[e==="stop"?"stopped":"deleted"]:o},t,`${e==="stop"?"Stopped":"Deleted"} ${o}.`),0}async function $(n,t,e,i){let s=0,o=new Set(["running","failed","stopped"]),r=!0;for(;r;){let l=await n.request(`/deployments/${encodeURIComponent(t)}/build-logs?offset=${s}`);l.logs!==""&&(i?process.stdout.write(`${JSON.stringify({deploymentId:t,offset:s,logs:l.logs,status:l.status})}
4
+ `):process.stdout.write(l.logs.endsWith(`
5
+ `)?l.logs:`${l.logs}
6
+ `)),s=l.offset,r=e&&!o.has(l.status),r&&await new Promise(h=>setTimeout(h,1e3))}}function p(n,t){return w({args:[...n],allowPositionals:!0,strict:!0,options:t})}function c(n,t){if(n.length!==1)throw new a(`Usage: ${t}`);return n[0]}function f(n,t,e,i=Number.MAX_SAFE_INTEGER){let s=Number(n);if(!Number.isInteger(s)||s<e||s>i)throw new a(`${t} must be an integer from ${e} to ${i}.`);return s}export{T as runDeployments};
@@ -0,0 +1,2 @@
1
+ import{b as ne}from"../chunk-OVFUQAEG.js";import{a as Q,b as Z}from"../chunk-N7BU45K6.js";import{b as z,c as K}from"../chunk-USIKTT3N.js";import{a as re,b as oe,c as se,d as T,f as x,g as ie,i as ae}from"../chunk-ALPMVGHI.js";import{b as ee,c as te,d as A}from"../chunk-7G4TXPP4.js";import{a as L,b as Y}from"../chunk-FLGSKQGU.js";import{a as X}from"../chunk-LNASFQWW.js";import{createServer as ke}from"http";import{networkInterfaces as Ce}from"os";import{join as $e,resolve as Ee}from"path";import Le from"@tailwindcss/vite";import Ae from"@vitejs/plugin-react";import{createServer as Te,createServerModuleRunner as xe}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 Me}from"net";var ce=100,Ie=300,Se=new Set(["127.0.0.1","localhost","::1"]);function _e(e,r){return new Promise(s=>{let n=Me();n.unref(),n.once("error",()=>s(!1)),n.listen({port:e,host:r},()=>{n.close(()=>s(!0))})})}function le(e,r){return new Promise(s=>{let n=be({port:e,host:r});n.setTimeout(Ie),n.once("connect",()=>{n.destroy(),s(!0)}),n.once("timeout",()=>{n.destroy(),s(!1)}),n.once("error",()=>{n.destroy(),s(!1)})})}async function He(e){return await le(e,"127.0.0.1")||await le(e,"::1")}async function de(e,r){for(let s=e;s<e+ce;s++)if(await _e(s,r)&&!(Se.has(r)&&await He(s)))return{port:s,requested:e};throw new Error(`No free port found between ${e} and ${e+ce-1} on ${r}.`)}function ue(e,r){let s=()=>{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(s());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 De}from"fs";import{createRequire as Oe}from"module";import{join as Ue}from"path";import{pathToFileURL as je}from"url";async function me(e){let r=Ue(e,"package.json"),s=JSON.parse(De(r,"utf8"));if([s.dependencies,s.devDependencies,s.optionalDependencies].some(l=>l!==null&&typeof l=="object"&&"@mcp-use/inspector"in l)){let l=Oe(r);try{let d=l.resolve("@mcp-use/inspector");return pe(await import(je(d).href))}catch(d){if(!fe(d))throw d}}try{return pe(await import("@mcp-use/inspector"))}catch(l){if(fe(l))return{installed:!1};throw l}}function pe(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 fe(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){X(e)}function qe(){for(let e of Object.values(Ce()))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"),s=typeof r=="string"?r:Array.isArray(r)?r.join(", "):r!==void 0?String(r):"";s.split(",").map(n=>n.trim().toLowerCase()).includes("origin")||e.setHeader("Vary",s===""?"Origin":`${s}, Origin`)}function Ke(e,r,s){if(s.tunnelActive){r.setHeader("Access-Control-Allow-Origin","*");return}if(!s.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 s=r;if(typeof s.fetch!="function")throw new Error("The entry's default export has no fetch() \u2014 it must be the MCPServer instance (`export default server`).");return s}async function Ye(e){process.env.MCP_USE_DEV_CLI="1";let r=se(e.cwd),s=new Ve(t=>{console.error("[mcp-use] notification delivery failed:",t)});te(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=ke(),{port:u,requested:w}=await de(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:Ee(e.cwd,e.mcpDir),V=e.entry===void 0?L(_):L(e.cwd,e.entry),H=await Y(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:$e(e.mcpDir,"views")),p=T(e.cwd,I),P=p.length>0,ve=re(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?ve:!1,envDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:{tailwindcss:oe()}},plugins:P?[A(e.cwd),Le(),ae({getViews:()=>p,dev:{reactRefresh:!0}}),Ae()]:[A(e.cwd)],server:{middlewareMode:!0,...P&&{origin:y},cors:!1,hmr:P?{server:d}:!1},ssr:{...ee(e.cwd)}}),O=f.environments.ssr,R=xe(O,{hmr:!1,sourcemapInterceptor:"node"}),F=async()=>{let t=async()=>{let i=await R.import(V),a=Xe(i);if(p.length>0){let v=ie(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 o=process.env.MCP_URL;try{return process.env.MCP_URL=g,await t()}finally{o===void 0?delete process.env.MCP_URL:process.env.MCP_URL=o}},U,m;try{let t=await F();t.__setEventBus(s),t.__mount(),U=async o=>t.fetch(o),m=t.basePath??"/mcp"}catch(t){throw await R.close(),await f.close(),t}let j,b,B,N=t=>{if(j===void 0||B===t)return;let o=j.mountInspector({basePath:t,autoConnectUrl:`${y}${t}`,oauthProxyAllowLoopback:c||l,devMode:!0,manufactChatUrl:process.env.MANUFACT_CHAT_URL});if(typeof o!="function")throw new Error("The installed @mcp-use/inspector is incompatible: mountInspector() did not return a Fetch handler.");b=o,B=t};try{if(e.inspector!==!1){let t=await me(e.cwd);t.installed&&(j=t.module,N(m))}}catch(t){throw await R.close(),await f.close(),t}let k=!1,C=!1,W=()=>{if(k){C=!0;return}k=!0,(async()=>{do{C=!1;try{R.evaluatedModules.clear();let t=await F();t.__setEventBus(s),t.__mount();let o=async a=>t.fetch(a),i=t.basePath??"/mcp";N(i),U=o,m=i,s.publish({kind:"tools_list_changed"}),s.publish({kind:"prompts_list_changed"}),s.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(C);k=!1})()},$=t=>{if(x(t,e.cwd,I))return;let o=O.moduleGraph.getModulesByFile(t);if(!(o===void 0||o.size===0)){for(let i of o)O.moduleGraph.invalidateModule(i);W()}},he=t=>{if(!x(t,e.cwd,I))return;let o=p;p=T(e.cwd,I),(o.length!==p.length||o.some((a,v)=>a.name!==p[v]?.name||a.entryPath!==p[v]?.entryPath))&&W()},S=t=>{he(t),$(t)};f.watcher.on("change",$),f.watcher.on("add",S),f.watcher.on("unlink",S);let h=ne(r.tunnel);d.prependListener("upgrade",t=>{let o=h.status().url;if(o===null)return;let i=new URL(o).hostname;t.headers.host?.split(":")[0]===i&&(t.headers.host=`localhost:${u}`)});let we=(t,o)=>{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:(o.writeHead(403,{"content-type":"application/json"}),o.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:M.message},id:null})),!0)},G=async()=>{f.watcher.off("change",$),f.watcher.off("add",S),f.watcher.off("unlink",S),await h.stop(),await new Promise(t=>d.close(()=>t())),await R.close(),await f.close()},ge=ue({getBasePath:()=>m,port:u,tunnel:h},t=>b!==void 0&&Q(t,m)?b(t):U(t)),{toNodeHandler:Pe}=await import("../node-bridge-JJIA6K5P.js"),q=Pe({fetch:ge}),ye=(t,o)=>{if(c&&we(t,o))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,E=Je(t.headers.host);if((M!==null&&E===M||l&&E!==void 0&&!["localhost","127.0.0.1","::1"].includes(E))&&Z(a,m)){o.writeHead(404,{"content-type":"text/plain; charset=utf-8"}),o.end("Not Found");return}let J=P&&p.length>0,Re=t.method==="GET"&&(a.startsWith("/@")||a.startsWith("/node_modules/")||a.startsWith("/.mcp-use/")||J&&a.startsWith("/views/"));J&&Re?(Ke(t,o,{tunnelActive:h.status().url!==null,localhostBind:c}),f.middlewares(t,o,()=>{q(t,o)})):q(t,o)};if(d.on("request",ye),await new Promise((t,o)=>{d.once("error",o),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}`),b!==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}b!==void 0&&e.open!==!1&&process.stdout.isTTY===!0&&Ge(`${y}${m}/inspector`),await new Promise(t=>{let o=!1,i=()=>{o||(o=!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};
@@ -0,0 +1,13 @@
1
+ import{a as u,b as _,c as C,d as b,e as k,f as p}from"../chunk-3TSFYSEY.js";import{a as c,b as s,c as y,d as l,e as w,f as h,g as v}from"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";import{parseArgs as g}from"util";var P="mcp-use-cli",I=1800*1e3,T=`Usage: mcp-use login [options]
2
+
3
+ Authenticate the cloud CLI.
4
+
5
+ Options:
6
+ --api-key <key> Authenticate with an API key
7
+ --device-code <code> Redeem a pre-approved device code
8
+ --org <id-or-slug> Select the active organization
9
+ --no-open Do not open the verification URL
10
+ --json Emit machine-readable output
11
+ -h, --help Show this help`;async function N(n,o){if(n==="login"&&o.some(e=>e==="--help"||e==="-h"))return process.stdout.write(`${T}
12
+ `),0;let i=y(o);try{return n==="login"?await E(o,i):n==="logout"?await O(o,i):await $(o,i)}catch(e){return w(e instanceof TypeError?new c(e.message):e,i)}}async function E(n,o){let{values:i}=g({args:[...n],allowPositionals:!1,strict:!0,options:{"api-key":{type:"string"},"device-code":{type:"string"},org:{type:"string"},"no-open":{type:"boolean"},json:{type:"boolean"}}});if(i["api-key"]!==void 0&&i["device-code"]!==void 0)throw new c("--api-key and --device-code cannot be used together.");let e=i["device-code"]?.trim();if(i["device-code"]!==void 0&&e==="")throw new c("--device-code must not be empty.");let t=e===void 0?i["api-key"]??process.env.MCP_USE_API_KEY:void 0;t===void 0&&(t=e===void 0?await A(i["no-open"]===!0||!process.stdout.isTTY):await L(e));let a=await p.withApiKey(t).identity(),r=i.org!==void 0?k(a.organizations,i.org):a.organizations.find(d=>d.id===a.defaultOrganizationId);return await C({apiKey:t,...r!==void 0?{orgId:r.id,orgName:r.name,...r.slug!==null?{orgSlug:r.slug}:{}}:{}}),l({email:a.email,organization:r??null},o,`Logged in as ${a.email}${r!==void 0?` (${r.name})`:""}.`),0}async function O(n,o){let{values:i}=g({args:[...n],allowPositionals:!1,strict:!0,options:{yes:{type:"boolean"},json:{type:"boolean"}}});return await h("Delete local cloud credentials?",{yes:i.yes===!0,json:o})&&(await b(),l({loggedOut:!0},o,"Logged out.")),0}async function $(n,o){g({args:[...n],allowPositionals:!1,strict:!0,options:{json:{type:"boolean"}}});let i=await _(),e=await(await p.create()).identity(),t=e.organizations.find(r=>r.id===i.orgId)??null,a={userId:e.userId,email:e.email,organization:t};return l(a,o,`${e.email}${t!==null?` \u2014 ${t.name}`:""}`),0}async function A(n){let o=u(),i=await fetch(`${o}/api/auth/device/code`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:P,scope:"openid profile email"})});if(!i.ok)throw new s("login_failed",`Could not start device login (${i.status}).`);let e=await i.json(),t=e.verification_uri_complete??e.verification_uri;return process.stderr.write(`Open ${t} and enter code ${e.user_code}.
13
+ `),n||v(t),D(o,e.device_code,Math.max(e.interval,1),Date.now()+e.expires_in*1e3)}async function L(n){return D(u(),n,2,Date.now()+I)}async function D(n,o,i,e){let t=i,a=!0;for(;Date.now()<e;){a||await z(t*1e3),a=!1;let d=await(await fetch(`${n}/api/auth/device/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:o,client_id:P})})).json();if(d.access_token!==void 0){let f=await fetch(`${n}/api/auth/api-key/create`,{method:"POST",headers:{Authorization:`Bearer ${d.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({name:"CLI",prefix:"mcp_"})});if(!f.ok)throw new s("login_failed","Could not create a CLI API key.");let m=await f.json();if(typeof m.key!="string")throw new s("login_failed","Cloud returned an invalid API key.");return m.key}if(d.error!=="authorization_pending"){if(d.error==="slow_down"){t+=5;continue}throw j(d)}}throw new s("login_timeout","Device login expired.")}function j(n){return n.error==="access_denied"?new s("login_failed","Device login was denied."):n.error==="expired_token"?new s("login_failed","Device code has expired."):new s("login_failed","Device code is invalid, expired, or has already been redeemed.")}function z(n){return new Promise(o=>setTimeout(o,n))}export{N as runIdentity};
@@ -0,0 +1,2 @@
1
+ import{b as m,c as p,e as w,f as y}from"../chunk-3TSFYSEY.js";import{a as s,c as g,d as l,e as f}from"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";import{parseArgs as $}from"util";async function I(o){let a=g(o);try{let r=o[0];if(!["list","current","use"].includes(r??""))throw new s("Usage: mcp-use org <list|current|use>");let c=await y.create(),t=await c.identity(),u=await m();if(r==="list"){z(o.slice(1));let e=t.organizations.map(n=>({...n,active:n.id===(u.orgId??t.defaultOrganizationId??void 0)}));return l(e,a,e.map(n=>`${n.active?"* ":" "}${n.name} (${n.slug??n.id}) [${n.role}]`).join(`
2
+ `)||"No organizations."),0}if(r==="current"){z(o.slice(1));let e=t.organizations.find(n=>n.id===(u.orgId??t.defaultOrganizationId))??null;if(e===null)throw new s("No active organization. Run `mcp-use org use <id-or-slug>`.");return l(e,a,`${e.name} (${e.slug??e.id})`),0}let d=o[1];if(d===void 0||o.length!==2)throw new s("Usage: mcp-use org use <id-or-slug>");let i=w(t.organizations,d);await p({...u.apiKey!==void 0?{apiKey:u.apiKey}:{},orgId:i.id,orgName:i.name,...i.slug!==null?{orgSlug:i.slug}:{}});try{await c.setDefaultOrganization(i.id)}catch{}return l(i,a,`Using ${i.name} (${i.slug??i.id}).`),0}catch(r){return f(r instanceof TypeError?new s(r.message):r,a)}}function z(o){$({args:[...o],allowPositionals:!1,strict:!0,options:{json:{type:"boolean"}}})}export{I as runOrganizations};
@@ -0,0 +1,5 @@
1
+ import{b as M,c as $,d as x}from"../chunk-4JB4S4BZ.js";import{a as c,b as s,c as _,d as k,e as R}from"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";import{spawn as H}from"child_process";import{access as N,mkdtemp as j,rm as A,writeFile as F}from"fs/promises";import{createServer as G}from"net";import{tmpdir as J}from"os";import{basename as V,join as q,resolve as W}from"path";import{parseArgs as z}from"util";import{fileURLToPath as K}from"url";async function Pe(r){let n=_(r),e,t,i;try{let{values:o,positionals:a}=z({args:[...r],allowPositionals:!0,strict:!0,options:{server:{type:"string"},mcp:{type:"string"},tool:{type:"string"},header:{type:"string",short:"H",multiple:!0},output:{type:"string"},width:{type:"string",default:"1280"},height:{type:"string",default:"720"},"device-scale-factor":{type:"string",default:"1"},theme:{type:"string",default:"light"},inspector:{type:"string"},"cdp-url":{type:"string"},"wait-for":{type:"string"},delay:{type:"string",default:"0"},timeout:{type:"string",default:"30000"},json:{type:"boolean"}}});if(o.server===void 0==(o.mcp===void 0))throw new c("Exactly one of --server or --mcp is required.");if(o.tool===void 0)throw new c("--tool is required.");if(o.server!==void 0&&o.header!==void 0)throw new c("--header is valid only with --mcp.");if(o.theme!=="light"&&o.theme!=="dark")throw new c("--theme must be light or dark.");let w=h(o.width,"--width"),y=h(o.height,"--height"),u=Number(o["device-scale-factor"]);if(!Number.isFinite(u)||u<=0||u>4)throw new c("--device-scale-factor must be greater than 0 and at most 4.");let l=h(o.timeout,"--timeout"),b=de(o.delay,"--delay"),U=ce(o.header??[]);e=o.server!==void 0?await M(o.server):await $(new URL(o.mcp).href,U);let P=(await e.listTools()).find(O=>O.name===o.tool);if(P===void 0)throw new s("tool_not_found",`Tool not found: ${o.tool}`);let m=Z(P),C=x(a),f=await e.callTool(o.tool,C,{timeout:l});if(f.isError===!0)throw new s("tool_failed",`Tool ${o.tool} returned an error.`,f);let I=await e.readResource(m);ee(I),i=o.inspector===void 0?await X(l):void 0;let E=(o.inspector??i.origin).replace(/\/+$/,"");await B(E,l);let S=te(m),p=new URL(`${E}/inspector/preview/${encodeURIComponent(S)}`);p.searchParams.set("protocol","1"),p.searchParams.set("theme",o.theme),p.searchParams.set("width",String(w)),t=o["cdp-url"]!==void 0?await re(o["cdp-url"]):await ne(),await t.cdp.send("Emulation.setDeviceMetricsOverride",{width:w,height:y,deviceScaleFactor:u,mobile:!1},t.sessionId),await t.cdp.send("Page.enable",{},t.sessionId),await t.cdp.send("Runtime.enable",{},t.sessionId),await t.cdp.send("Page.addScriptToEvaluateOnNewDocument",{source:`globalThis.__mcpUsePreviewBundle = ${ue({resourceUri:m,resourceContents:I,toolInput:C,toolOutput:f})};`},t.sessionId),await t.cdp.send("Page.navigate",{url:p.href},t.sessionId),await oe(t,l),await ie(t,o["wait-for"],l),b>0&&await d(b);let T=await t.cdp.send("Page.captureScreenshot",{format:"png",captureBeyondViewport:!1},t.sessionId);if(typeof T.data!="string")throw new s("capture_failed","Chrome returned no screenshot data.");let g=W(o.output??`${S}-${new Date().toISOString().replace(/[:.]/g,"-")}.png`);return await F(g,Buffer.from(T.data,"base64")),k({path:g,width:w,height:y,deviceScaleFactor:u},n,g),0}catch(o){return R(o instanceof TypeError?new c(o.message):o,n)}finally{await t?.close().catch(()=>{}),await i?.close().catch(()=>{}),await e?.disconnect().catch(()=>{})}}async function X(r){let n=await D(),e=import.meta.resolve("@mcp-use/inspector"),t=K(new URL("../cli.js",e)),i=H(process.execPath,[t,"--port",String(n),"--no-open"],{stdio:"ignore"}),o=`http://127.0.0.1:${n}`;try{await Q(o,i,Math.min(r,1e4))}catch(a){throw i.kill("SIGTERM"),a}return{origin:o,async close(){await Y(i)}}}async function Q(r,n,e){let t=Date.now()+e;for(;Date.now()<t;){if(n.exitCode!==null)throw new s("inspector_start_failed",`Packaged Inspector exited before becoming ready (code ${n.exitCode}).`);try{await B(r,Math.min(1e3,e));return}catch{await d(100)}}throw new s("inspector_start_failed","Packaged Inspector did not start in time.")}async function Y(r){r.exitCode===null&&(r.kill("SIGTERM"),await Promise.race([new Promise(n=>r.once("exit",()=>n())),d(2e3)]),r.exitCode===null&&r.kill("SIGKILL"))}async function B(r,n){let e=await fetch(`${r}/inspector/health`,{signal:AbortSignal.timeout(n)});if(!e.ok)throw new s("incompatible_inspector",`Inspector health check failed (${e.status}).`);let t=await e.json();if(t.status!=="ok"||t.protocol!=="mcp-use-inspector-preview"||t.version!==1||!t.capabilities?.includes("view-preview"))throw new s("incompatible_inspector","Inspector does not support mcp-use-inspector-preview version 1.")}function Z(r){let n=r!==null&&typeof r=="object"?r._meta:void 0,t=(n?.ui!==null&&typeof n?.ui=="object"?n.ui.resourceUri:void 0)??n?.["ui/resourceUri"];if(typeof t!="string")throw new s("missing_view","Tool does not advertise an MCP Apps UI resource.");return t}function ee(r){let n=r!==null&&typeof r=="object"?r.contents:void 0;if(!Array.isArray(n))throw new s("invalid_view","View resource has no contents.");let e=n.find(t=>t!==null&&typeof t=="object"&&typeof t.text=="string");if(e===void 0)throw new s("invalid_view","View resource has no HTML document.");return e.text}function te(r){let n=new URL(r);return V(n.pathname).replace(/\.html$/,"")||n.hostname}async function ne(){let r=await se(),n=await D(),e=await j(q(J(),"mcp-use-chrome-")),t=H(r,[`--remote-debugging-port=${n}`,`--user-data-dir=${e}`,"--headless=new","--no-first-run","--no-default-browser-check","about:blank"],{stdio:"ignore"});try{let i=await ae(`http://127.0.0.1:${n}/json/version`,1e4),o=await L(i.webSocketDebuggerUrl);return{...o,async close(){await o.close(),t.kill("SIGTERM"),await A(e,{recursive:!0,force:!0})}}}catch(i){throw t.kill("SIGTERM"),await A(e,{recursive:!0,force:!0}),i}}async function re(r){return L(r)}async function L(r){let n=await v.connect(r),e=await n.send("Target.createTarget",{url:"about:blank"}),t=await n.send("Target.attachToTarget",{targetId:e.targetId,flatten:!0});return{cdp:n,sessionId:t.sessionId,async close(){await n.send("Target.closeTarget",{targetId:e.targetId}).catch(()=>{}),n.close()}}}async function oe(r,n){let e=Date.now()+n;for(;Date.now()<e;){if((await r.cdp.send("Runtime.evaluate",{expression:"document.readyState",returnByValue:!0},r.sessionId)).result?.value==="complete")return;await d(100)}throw new s("browser_timeout","Inspector page did not load in time.")}async function ie(r,n,e){let t=Date.now()+e;for(;Date.now()<t;){let i=`(() => ({
2
+ ready: document.body?.dataset.viewReady === "true",
3
+ error: document.body?.dataset.viewError || null,
4
+ selector: ${JSON.stringify(n)} === undefined || !!document.querySelector(${JSON.stringify(n??"")})
5
+ }))()`,a=(await r.cdp.send("Runtime.evaluate",{expression:i,returnByValue:!0},r.sessionId)).result?.value;if(a?.error)throw new s("preview_failed",`Inspector preview failed: ${a.error}`);if(a?.ready===!0&&a.selector===!0)return;await d(100)}throw new s("browser_timeout","View did not become ready in time.")}var v=class r{#t;#n=1;#e=new Map;constructor(n){this.#t=n,n.addEventListener("message",e=>{let t=JSON.parse(String(e.data));if(t.id===void 0)return;let i=this.#e.get(t.id);i!==void 0&&(this.#e.delete(t.id),t.error!==void 0?i.reject(new Error(t.error.message??"CDP command failed.")):i.resolve(t.result))}),n.addEventListener("close",()=>{for(let e of this.#e.values())e.reject(new Error("Chrome DevTools connection closed."));this.#e.clear()})}static async connect(n){let e=new WebSocket(n);return await new Promise((t,i)=>{e.addEventListener("open",()=>t(),{once:!0}),e.addEventListener("error",()=>i(new Error("Could not connect to Chrome DevTools.")),{once:!0})}),new r(e)}send(n,e={},t){let i=this.#n++;return new Promise((o,a)=>{this.#e.set(i,{resolve:o,reject:a}),this.#t.send(JSON.stringify({id:i,method:n,params:e,...t!==void 0?{sessionId:t}:{}}))})}close(){this.#t.close()}};async function se(){let n=[process.env.MCP_USE_CHROME_PATH??process.env.PUPPETEER_EXECUTABLE_PATH??process.env.CHROME_PATH,...process.platform==="darwin"?["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Chromium.app/Contents/MacOS/Chromium","/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"]:process.platform==="win32"?[`${process.env.PROGRAMFILES??""}\\Google\\Chrome\\Application\\chrome.exe`,`${process.env.LOCALAPPDATA??""}\\Google\\Chrome\\Application\\chrome.exe`]:["/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium","/usr/bin/chromium-browser"]].filter(e=>e!==void 0&&e!=="");for(let e of n)try{return await N(e),e}catch{}throw new s("chrome_not_found","Chrome, Chromium, Edge, or Brave was not found. Set MCP_USE_CHROME_PATH.")}function D(){return new Promise((r,n)=>{let e=G();e.once("error",n),e.listen(0,"127.0.0.1",()=>{let t=e.address(),i=typeof t=="object"&&t!==null?t.port:0;e.close(o=>o?n(o):r(i))})})}async function ae(r,n){let e=Date.now()+n;for(;Date.now()<e;){try{let t=await fetch(r);if(t.ok)return await t.json()}catch{}await d(100)}throw new s("chrome_start_failed","Chrome DevTools did not start.")}function ce(r){let n={};for(let e of r){let t=e.indexOf(":");if(t<=0)throw new c(`Invalid header: ${e}`);n[e.slice(0,t).trim()]=e.slice(t+1).trim()}return n}function h(r,n){let e=Number(r);if(!Number.isFinite(e)||e<=0)throw new c(`${n} must be positive.`);return e}function de(r,n){let e=Number(r);if(!Number.isFinite(e)||e<0)throw new c(`${n} must be non-negative.`);return e}function ue(r){return JSON.stringify(r).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function d(r){return new Promise(n=>setTimeout(n,r))}export{Pe as runScreenshot};
@@ -0,0 +1,2 @@
1
+ import{g as d}from"../chunk-3TSFYSEY.js";import{a as u,c as k,d as l,e as P,f as y}from"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";import{parseArgs as m}from"util";async function x(n){let t=k(n);try{let e=n[0];if(e==="list")return await $(n.slice(1),t);if(e==="get")return await E(n.slice(1),t);if(e==="update")return await C(n.slice(1),t);if(e==="delete")return await A(n.slice(1),t);if(e==="env")return await I(n.slice(1),t);throw new u("Usage: mcp-use servers <list|get|update|delete|env>")}catch(e){return P(e instanceof TypeError?new u(e.message):e,t)}}async function $(n,t){let{values:e}=m({args:[...n],allowPositionals:!1,strict:!0,options:S()}),{api:s,organizationId:r}=await d(e.org),{limit:i,skip:a}=N(e.limit,e.skip),c=new URLSearchParams({organizationId:r,limit:String(i),skip:String(a)}),o=await s.request(`/servers?${c}`);return l(o,t),0}async function E(n,t){let{values:e,positionals:s}=m({args:[...n],allowPositionals:!0,strict:!0,options:p()}),r=b(s,"mcp-use servers get <id-or-slug>"),{api:i}=await d(e.org),a=await i.request(`/servers/${encodeURIComponent(r)}`);return l(a,t),0}async function C(n,t){let{values:e,positionals:s}=m({args:[...n],allowPositionals:!0,strict:!0,options:{...p(),name:{type:"string"},description:{type:"string"},branch:{type:"string"},"root-dir":{type:"string"},"build-command":{type:"string"},"start-command":{type:"string"}}}),r=b(s,"mcp-use servers update <id-or-slug>"),i={...e["root-dir"]!==void 0?{rootDir:e["root-dir"]||null}:{},...e["build-command"]!==void 0?{buildCommand:e["build-command"]||null}:{},...e["start-command"]!==void 0?{startCommand:e["start-command"]||null}:{}},a={...e.name!==void 0?{name:e.name}:{},...e.description!==void 0?{description:e.description}:{},...e.branch!==void 0?{productionBranch:e.branch}:{},...Object.keys(i).length>0?{config:i}:{}};if(Object.keys(a).length===0)throw new u("servers update requires at least one mutation option.");let{api:c}=await d(e.org),o=await c.request(`/servers/${encodeURIComponent(r)}`,{method:"PATCH",body:JSON.stringify(a)});return l(o,t,`Updated ${r}.`),0}async function A(n,t){let{values:e,positionals:s}=m({args:[...n],allowPositionals:!0,strict:!0,options:{...p(),yes:{type:"boolean"}}}),r=b(s,"mcp-use servers delete <id-or-slug>");if(!await y(`Delete server ${r}?`,{yes:e.yes===!0,json:t}))return 0;let{api:i}=await d(e.org);return await i.request(`/servers/${encodeURIComponent(r)}`,{method:"DELETE"}),l({deleted:r},t,`Deleted ${r}.`),0}async function I(n,t){let e=n[0];if(e==="list")return O(n.slice(1),t);if(e==="set")return R(n.slice(1),t);if(e==="unset")return q(n.slice(1),t);throw new u("Usage: mcp-use servers env <list|set|unset>")}async function O(n,t){let{values:e,positionals:s}=m({args:[...n],allowPositionals:!0,strict:!0,options:{...p(),branch:{type:"string"}}}),r=b(s,"mcp-use servers env list <server>"),{api:i}=await d(e.org),c=(await f(i,r,e.branch)).map(o=>({id:o.id,key:o.key,branch:o.branch??null,environments:o.environments??[],sensitive:o.sensitive===!0,createdAt:o.createdAt,updatedAt:o.updatedAt}));return l(c,t,c.map(o=>o.key).join(`
2
+ `)||"No environment variables."),0}async function R(n,t){let{values:e,positionals:s}=m({args:[...n],allowPositionals:!0,strict:!0,options:{...p(),branch:{type:"string"},secret:{type:"boolean"}}});if(s.length!==2)throw new u("Usage: mcp-use servers env set <server> <KEY=VALUE>");let[r,i]=s,a=i.indexOf("=");if(a<=0)throw new u("Environment value must be KEY=VALUE.");let c=i.slice(0,a),o=i.slice(a+1),{api:g}=await d(e.org),v=(await f(g,r,e.branch)).find(h=>h.key===c&&(h.branch??void 0)===e.branch),w={key:c,value:o,branch:e.branch??null,environments:e.branch===void 0?["production"]:["preview"],sensitive:e.secret===!0},U=v===void 0?await g.request(`/servers/${encodeURIComponent(r)}/env-variables`,{method:"POST",body:JSON.stringify(w)}):await g.request(`/servers/${encodeURIComponent(r)}/env-variables/${encodeURIComponent(v.id)}`,{method:"PATCH",body:JSON.stringify(w)});return l(U,t,`Set ${c}.`),0}async function q(n,t){let{values:e,positionals:s}=m({args:[...n],allowPositionals:!0,strict:!0,options:{...p(),branch:{type:"string"},yes:{type:"boolean"}}});if(s.length!==2)throw new u("Usage: mcp-use servers env unset <server> <key>");let[r,i]=s;if(!await y(`Delete environment variable ${i}?`,{yes:e.yes===!0,json:t}))return 0;let{api:a}=await d(e.org),o=(await f(a,r,e.branch)).find(g=>g.key===i&&(g.branch??void 0)===e.branch);return o!==void 0&&await a.request(`/servers/${encodeURIComponent(r)}/env-variables/${encodeURIComponent(o.id)}`,{method:"DELETE"}),l({deleted:i},t,`Deleted ${i}.`),0}async function f(n,t,e){let s=e===void 0?"":`?branch=${encodeURIComponent(e)}`;return n.request(`/servers/${encodeURIComponent(t)}/env-variables${s}`)}function p(){return{org:{type:"string"},json:{type:"boolean"}}}function S(){return{...p(),limit:{type:"string",default:"30"},skip:{type:"string",default:"0"}}}function b(n,t){if(n.length!==1)throw new u(`Usage: ${t}`);return n[0]}function N(n,t){let e=Number(n??"30"),s=Number(t??"0");if(!Number.isInteger(e)||e<1||e>100)throw new u("--limit must be an integer from 1 to 100.");if(!Number.isInteger(s)||s<0)throw new u("--skip must be a non-negative integer.");return{limit:e,skip:s}}export{x as runServers};
@@ -0,0 +1 @@
1
+ async function e(t){return(await import("../start-CGEGBZOH.js")).runStart(t)}export{e as runStart};
@@ -0,0 +1 @@
1
+ import{a as i,b as o}from"../chunk-FLGSKQGU.js";import{spawn as d}from"child_process";import{createRequire as l}from"module";import{dirname as u,join as p,resolve as y}from"path";async function f(e){let c=e.mcpDir===void 0?e.cwd:y(e.cwd,e.mcpDir),n=e.entry===void 0?i(c):i(e.cwd,e.entry),r=await o(e.cwd,n);r==="created"||r==="updated"?console.log(`[mcp-use] ${r} mcp-env.d.ts`):r==="user-owned"&&console.warn("[mcp-use] mcp-env.d.ts is user-owned; leaving it unchanged");let t=g(e.cwd);return w(t,e.cwd,e.tscArgs??[])}function g(e){let c=l(p(e,"package.json"));try{let n=c.resolve("typescript/package.json");return p(u(n),"bin","tsc")}catch{throw new Error(`TypeScript is not installed in ${e}. Install it with npm install --save-dev typescript.`)}}function w(e,c,n){return new Promise((r,t)=>{let s=d(process.execPath,[e,...n,"--noEmit"],{cwd:c,stdio:"inherit"});s.once("error",t),s.once("close",(a,m)=>{r(a??(m==="SIGINT"?130:1))})})}export{f as runTypecheck};
package/dist/index.js CHANGED
@@ -1,10 +1 @@
1
- #!/usr/bin/env node
2
-
3
- // src/index.ts
4
- try {
5
- const frameworkEntry = new URL(import.meta.resolve("mcp-use"));
6
- await import(new URL("./bin.js", frameworkEntry).href);
7
- } catch (error) {
8
- console.error(error instanceof Error ? error.message : String(error));
9
- process.exitCode = 1;
10
- }
1
+ import{a}from"./chunk-FTF3BR6T.js";import"./chunk-USIKTT3N.js";export{a as main};
@@ -0,0 +1 @@
1
+ function a(){}function d(){}function u(){}function l(){}function p(){}function x(e){return e}async function f(){return new Headers}var i={get:()=>{},getAll:()=>[],has:()=>!1,set:()=>{},delete:()=>{}};async function g(){return i}async function R(){return{isEnabled:!1,enable(){},disable(){}}}function c(e){let n=new Error(`redirect(${String(e)}) called outside Next.js`);throw Object.assign(n,{digest:`NEXT_REDIRECT;${String(e)}`}),n}var w=c;function h(){let e=new Error("notFound() called outside Next.js");throw Object.assign(e,{digest:"NEXT_NOT_FOUND"}),e}var v={push:"push",replace:"replace"},o=class e extends Response{static json(n,t){let r=new Headers(t?.headers);return r.set("content-type","application/json"),new e(JSON.stringify(n),{...t,headers:r})}static redirect(n,t=302){return new e(null,{status:t,headers:{location:String(n)}})}static next(){return new e(null)}static rewrite(){return new e(null)}},s=class extends Request{nextUrl;cookies=i;constructor(n,t){super(n,t),this.nextUrl=new URL(typeof n=="string"?n:n instanceof URL?n.href:n.url)}};function y(){return{ua:"",browser:{},device:{},engine:{},os:{},cpu:{},isBot:!1}}export{s as NextRequest,o as NextResponse,v as RedirectType,g as cookies,R as draftMode,f as headers,h as notFound,w as permanentRedirect,c as redirect,a as revalidatePath,d as revalidateTag,x as unstable_cache,l as unstable_cacheLife,p as unstable_cacheTag,u as unstable_noStore,y as userAgent};
@@ -0,0 +1 @@
1
+ function b(e,c){return async(a,i,d)=>{typeof d=="function"&&(d=void 0);let l=!1,t=new AbortController;i.on("close",()=>{l||t.abort()}),i.destroyed===!0&&t.abort();let s;try{let n=await w(a,d,{signal:t.signal});s=await e.fetch(n,{...a.auth!==void 0&&{authInfo:a.auth},...d!==void 0&&{parsedBody:d}})}catch(n){try{c?.onerror?.(n instanceof Error?n:new Error(String(n)))}catch{}s=y(m(d))}let r={};for(let[n,f]of s.headers)r[n]=f;if(i.writeHead(s.status,r),s.body===null){l=!0,i.end();return}let o,u=()=>{o?.(),o=void 0},h=()=>new Promise(n=>{o=n});i.on("drain",u);let p=new Promise(n=>{t.signal.addEventListener("abort",()=>n(),{once:!0})});try{for await(let n of s.body){if(t.signal.aborted)break;let f=n instanceof Uint8Array?n:new Uint8Array(n);i.write(f)===!1&&await Promise.race([h(),p])}}catch{}l=!0,i.end()}}async function w(e,c,a){let i=(e.method??"GET").toUpperCase(),l=`http://${g(e.headers.host)??g(e.headers[":authority"])??"localhost"}${e.url??"/"}`,t=new Headers;for(let[r,o]of Object.entries(e.headers))if(!(o===void 0||r.startsWith(":")))if(Array.isArray(o))for(let u of o)t.append(r,u);else t.set(r,o);let s;if(i!=="GET"&&i!=="HEAD")if(c===void 0){let r=new TextDecoder,o="";for await(let u of e)o+=typeof u=="string"?u:r.decode(u,{stream:!0});o+=r.decode(),o.length>0&&(s=o)}else{let r=JSON.stringify(c);t.delete("content-encoding"),t.delete("transfer-encoding"),r===void 0?t.delete("content-length"):(s=r,t.set("content-length",String(new TextEncoder().encode(r).byteLength)))}return new Request(l,{method:i,headers:t,...a?.signal!==void 0&&{signal:a.signal},...s!==void 0&&{body:s}})}function g(e){return Array.isArray(e)?e[0]:e}function m(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let{method:c,id:a}=e;return typeof c!="string"?null:typeof a=="string"||typeof a=="number"?a:null}function y(e){return Response.json({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:e},{status:500})}export{b as toNodeHandler,w as toWebRequest};
@@ -0,0 +1,4 @@
1
+ import{a as E}from"./chunk-N7BU45K6.js";import{b as g,c as v}from"./chunk-USIKTT3N.js";import{c as I}from"./chunk-7G4TXPP4.js";import{readFile as M}from"fs/promises";import{join as d}from"path";import{pathToFileURL as R}from"url";var k=".mcp-use",L="build",N="manifest.json";async function H(t){let o=d(t.cwd,k,L),s=d(o,N),c;try{c=await M(s,"utf8")}catch{throw new Error(`No production build found (missing ${s}).
2
+ Run \`mcp-use build\` first, then \`mcp-use start\`.`)}let a;try{let n=JSON.parse(c);if(typeof n.entryPoint!="string"||n.entryPoint==="")throw new Error("missing entryPoint");a=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",I(t.cwd,"production");let i=d(o,a),u=await import(R(i).href);if(!("default"in u)||u.default===void 0)throw new Error(`The built entry (${i}) 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(!A(e))throw new Error(`The default export of ${i} is not an MCPServer: it has no listen() method. Export the MCPServer instance as the default export.`);let S=typeof e.port=="number"?e.port:void 0,U=typeof e.host=="string"?e.host:void 0,h=g(t.port,process.env,S),y=v(t.host,process.env,U),l=await(t.withInspector===!0?_(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,k,"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 _(t,o,s){let{mountInspector:c}=await x(),a=typeof t.basePath=="string"?t.basePath:"/mcp",i=c({basePath:a,devMode:!1,oauthProxyAllowLoopback:!1,manufactChatUrl:process.env.MANUFACT_CHAT_URL});return t.app.use("*",async(f,u)=>{if(E(f.req.raw,a))return i(f.req.raw);await u()}),t.listen(o,{host:s})}async function x(){let t;try{t=await import("@mcp-use/inspector")}catch(o){throw O(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 A(t){return typeof t=="object"&&t!==null&&typeof t.listen=="function"}function O(t){return t!==null&&typeof t=="object"&&"code"in t&&(t.code==="ERR_MODULE_NOT_FOUND"||t.code==="MODULE_NOT_FOUND")}export{H as runStart};
@@ -0,0 +1 @@
1
+ import{a,b}from"./chunk-OVFUQAEG.js";export{b as createTunnelManager,a as tunnelApiBase};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@mcp-use/cli",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.1",
5
- "description": "Compatibility proxy for the CLI included in mcp-use v2",
4
+ "version": "4.0.0-beta.11",
5
+ "description": "Prebuilt CLI, development server, and build pipeline for mcp-use",
6
6
  "author": "mcp-use, Inc.",
7
7
  "license": "MIT",
8
8
  "homepage": "https://github.com/mcp-use/mcp-use#readme",
@@ -20,18 +20,44 @@
20
20
  "cli"
21
21
  ],
22
22
  "bin": {
23
- "mcp-use": "./dist/index.js"
23
+ "mcp-use": "./dist/bin.js"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "types": "./types/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ },
30
+ "./vite-client": {
31
+ "types": "./types/vite-client.d.ts"
32
+ }
24
33
  },
25
34
  "files": [
26
- "dist"
35
+ "dist",
36
+ "types"
27
37
  ],
28
38
  "engines": {
29
39
  "node": ">=22.22.2"
30
40
  },
31
41
  "dependencies": {
32
- "mcp-use": "^2.0.0-beta.12"
42
+ "@tailwindcss/vite": "^4.2.0",
43
+ "@vitejs/plugin-react": "^6.0.3",
44
+ "tailwindcss": "^4.2.0",
45
+ "vite": "^8.0.16"
46
+ },
47
+ "peerDependencies": {
48
+ "@mcp-use/client": "^2.0.0-alpha.0",
49
+ "@mcp-use/inspector": "^20.0.0-beta.0"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "@mcp-use/client": {
53
+ "optional": true
54
+ },
55
+ "@mcp-use/inspector": {
56
+ "optional": true
57
+ }
33
58
  },
34
59
  "devDependencies": {
60
+ "@modelcontextprotocol/server": "2.0.0-beta.5",
35
61
  "rimraf": "^6.1.3",
36
62
  "tsup": "^8.5.1",
37
63
  "typescript": "^5.9.3"
@@ -40,7 +66,7 @@
40
66
  "access": "public"
41
67
  },
42
68
  "scripts": {
43
- "build": "rimraf dist && tsup src/index.ts --format esm --target node22 && tsc --emitDeclarationOnly --declaration",
69
+ "build": "rimraf dist && tsup --config tsup.config.ts && node scripts/verify-package.mjs",
44
70
  "test": "node --test tests/proxy.test.mjs"
45
71
  }
46
72
  }
@@ -0,0 +1,18 @@
1
+ /** Options supplied by the public framework binary. @internal */
2
+ export interface CliMainOptions {
3
+ /** Version reported by the binary that owns the CLI invocation. */
4
+ frameworkVersion: string;
5
+ }
6
+
7
+ /**
8
+ * Run the prebuilt mcp-use command dispatcher without process side effects.
9
+ *
10
+ * @param argv - Command-line arguments excluding the executable and script.
11
+ * @param options - Invocation metadata owned by the calling package.
12
+ * @returns The process exit code.
13
+ * @internal
14
+ */
15
+ export declare function main(
16
+ argv: readonly string[],
17
+ options: CliMainOptions
18
+ ): Promise<number>;
@@ -0,0 +1,3 @@
1
+ import "vite/client";
2
+
3
+ export {};
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}