@mcp-use/cli 4.0.0-beta.10 → 4.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +1 -1
- package/dist/chunk-2N6PJAKM.js +8 -0
- package/dist/{chunk-DB3E6LBX.js → chunk-FLGSKQGU.js} +2 -2
- package/dist/chunk-NFT6Z2DG.js +37 -0
- package/dist/commands/build.js +5 -5
- package/dist/commands/client.js +1 -1
- package/dist/commands/dev.js +2 -2
- package/dist/commands/screenshot.js +1 -1
- package/dist/commands/start.js +1 -1
- package/dist/commands/typecheck.js +1 -1
- package/dist/index.js +1 -1
- package/dist/start-3KGZXHWI.js +4 -0
- package/package.json +4 -1
- package/types/vite-client.d.ts +3 -0
- package/dist/chunk-4JB4S4BZ.js +0 -37
- package/dist/chunk-ALPMVGHI.js +0 -3
- package/dist/start-CGEGBZOH.js +0 -4
- /package/dist/{chunk-7JXZ37OF.js → chunk-XIPXOMHU.js} +0 -0
package/dist/bin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as n}from"./chunk-
|
|
2
|
+
import{a as n}from"./chunk-XIPXOMHU.js";import"./chunk-USIKTT3N.js";n(process.argv.slice(2),{frameworkVersion:"4.0.0-beta.12"}).then(e=>{process.exitCode=e},e=>{console.error(e instanceof Error?e.message:String(e)),process.exitCode=1});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{a as w,b as v,d as h}from"./chunk-7G4TXPP4.js";import{existsSync as _}from"fs";import{join as b}from"path";import{fileURLToPath as P}from"url";var S=["vite.config.ts","vite.config.js","vite.config.mts","vite.config.cjs"];function ee(e){for(let t of S){let n=b(e,t);if(_(n))return n}return!1}function te(){return P(import.meta.resolve("tailwindcss/index.css"))}import{join as u}from"path";var W=".mcp-use",A="manifest.json";function re(e){let t=u(e,W),n=u(t,"build");return{projectRoot:e,workspace:t,build:n,generated:u(t,"generated"),cache:u(t,"cache"),state:u(t,"state"),cloud:u(t,"cloud"),buildManifest:u(n,A),tunnel:u(t,"state","tunnel.json")}}import{readFile as L}from"fs/promises";import{dirname as T,resolve as U}from"path";var p="virtual:mcp-use/legacy-widget-metadata:",x=`\0${p}`;function ce(e){return`${p}${encodeURIComponent(e)}`}function V(){return{name:"mcp-use-legacy-widget-metadata",resolveId(e){if(e.startsWith(p))return`\0${e}`},async load(e){if(!e.startsWith(x))return;let t=decodeURIComponent(e.slice(x.length));this.addWatchFile(t);let n=await L(t,"utf8");return j(n,t)}}}function j(e,t){let n=/\bexport\s+const\s+widgetMetadata\b/g.exec(e);if(n===null)return`export const widgetMetadata = undefined;
|
|
2
|
+
`;let r=C(e,n.index+n[0].length);if(r===-1)throw new Error(`Could not read widgetMetadata from ${t}: expected an exported const initializer.`);let i=k(e,r+1),o=e.slice(r+1,i).trim();if(o==="")throw new Error(`Could not read widgetMetadata from ${t}: the initializer is empty.`);return`${N(e,o,t).join(`
|
|
3
|
+
`)}
|
|
4
|
+
export const widgetMetadata = ${o};
|
|
5
|
+
`}function C(e,t){for(let n=t;n<e.length;n+=1)if(e[n]==="="&&e[n+1]!==">")return n;return-1}function k(e,t){let n=[],r,i=!1,o=!1,c=!1;for(let a=t;a<e.length;a+=1){let s=e[a],d=e[a+1];if(o){s===`
|
|
6
|
+
`&&(o=!1);continue}if(c){s==="*"&&d==="/"&&(c=!1,a+=1);continue}if(r!==void 0){i?i=!1:s==="\\"?i=!0:s===r&&(r=void 0);continue}if(s==="/"&&d==="/"){o=!0,a+=1;continue}if(s==="/"&&d==="*"){c=!0,a+=1;continue}if(s==="'"||s==='"'||s==="`"){r=s;continue}if(s==="("||s==="["||s==="{"){n.push(s);continue}if(s===")"||s==="]"||s==="}"){n.pop();continue}if(s===";"&&n.length===0)return a}return e.length}function N(e,t,n){let r=[],i=/\bimport\s+([\s\S]*?)\s+from\s+(["'])([^"']+)\2\s*(?:with\s*\{[^}]*\})?\s*;?/g;for(let o of e.matchAll(i)){let c=o[0],a=o[1]??"",s=o[3]??"";if(!O(a).some(D=>F(t,D)))continue;let R=s.startsWith(".")?U(T(n),s):s;r.push(c.replace(s,R))}return r}function O(e){let t=[],n=e.replace(/^\s*type\s+/,"").trim(),r=/\*\s+as\s+([A-Za-z_$][\w$]*)/.exec(n);r?.[1]!==void 0&&t.push(r[1]);let i=/\{([\s\S]*?)\}/.exec(n)?.[1];if(i!==void 0)for(let c of i.split(",")){let a=c.trim().replace(/^type\s+/,"");if(a==="")continue;let s=/\bas\s+([A-Za-z_$][\w$]*)$/.exec(a)?.[1];t.push(s??a.split(/\s+/)[0])}let o=n.split(/[,{*]/,1)[0]?.trim();return o!==void 0&&/^[A-Za-z_$][\w$]*$/.test(o)&&t.push(o),t}function F(e,t){return new RegExp(`(^|[^\\w$])${z(t)}([^\\w$]|$)`).test(e)}function z(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}import{existsSync as y,readdirSync as X}from"fs";import{dirname as $,isAbsolute as B,join as q,resolve as f}from"path";import Z from"@vitejs/plugin-react";var J="views",l="virtual:mcp-use/views/",m=`\0${l}`;function E(e,t){let n=t??J;return B(n)?n:f(e,n)}function ge(e,t,n){let r=E(e,t),i=t===void 0?f(e,"resources"):f($(r),"resources"),o=new Map;I(r,"view.tsx",!1,o),n?.includeLegacy===!0&&I(i,"widget.tsx",!0,o);let c=[...o.values()];return c.sort((a,s)=>a.name.localeCompare(s.name)),c}function I(e,t,n,r){if(y(e))for(let i of X(e,{withFileTypes:!0})){if(!i.isDirectory())continue;let o=q(e,i.name,t);if(y(o)){if(n&&r.has(i.name)){console.warn(`[mcp-use] Both native and legacy view entries exist for "${i.name}"; using views/${i.name}/view.tsx.`);continue}r.set(i.name,{name:i.name,entryPath:o,...n&&{legacy:!0}})}}}function G(e){return`${l}${e}`}function K(e){return`/@id/__x00__${l}${e}`}function we(e,t,n){let r=E(t,n),i=n===void 0?f(t,"resources"):f($(r),"resources");return e===r||e.startsWith(`${r}/`)||e===i||e.startsWith(`${i}/`)}function ve(e){let t={};for(let n of e)t[n.name]={kind:"external",entry:K(n.name),css:[],scripts:["/@vite/client"]};return t}async function he(e,t,n){let{createServer:r}=await import("vite");return r({root:e,configFile:n,envDir:!1,logLevel:"warn",cacheDir:t,resolve:{tsconfigPaths:!0,alias:w(e)},oxc:{jsx:{runtime:"automatic"}},plugins:[h(e),V(),Z()],server:{middlewareMode:!0,hmr:!1,ws:!1},ssr:{...v(e)}})}var g="virtual:mcp-use/tailwind.css",M=`\0${g}`;function ye(e){return{name:"mcp-use-views",applyToEnvironment(t){return t.name==="client"},resolveId(t){if(t===g)return M;if(t.startsWith(l))return`\0${t}`},load(t){if(t===M)return['@import "tailwindcss";',"@custom-variant dark (&:where(.dark, .dark *, [data-theme=dark], [data-theme=dark] *));"].join(`
|
|
7
|
+
`);if(!t.startsWith(m))return;let n=t.slice(m.length),r=e.getViews().find(o=>o.name===n);if(r===void 0)return;let i=[];return e.dev?.reactRefresh===!0&&i.push('import "@vitejs/plugin-react/preamble";'),i.push(`import ${JSON.stringify(g)};`),i.push('import { bootstrapView } from "mcp-use/react";'),i.push(`import * as viewModule from ${JSON.stringify(r.entryPath)};`),r.legacy===!0?i.push("const legacyMetadata = viewModule.widgetMetadata?.metadata;","bootstrapView({ ...viewModule, viewConfig: {"," ...(legacyMetadata?.autoResize !== undefined && { autoResize: legacyMetadata.autoResize }),","} });"):i.push("bootstrapView(viewModule);"),e.dev!==void 0&&i.push("if (import.meta.hot) {"," import.meta.hot.accept();","}"),i.push(""),i.join(`
|
|
8
|
+
`)}}}export{ee as a,te as b,re as c,ce as d,V as e,E as f,ge as g,G as h,we as i,ve as j,he as k,ye as l};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{existsSync as s}from"fs";import{isAbsolute as p,join as f,resolve as d}from"path";var i=["src/index.ts","src/index.tsx","src/server.ts","src/server.tsx","index.ts","index.tsx","server.ts","server.tsx"];function j(t,e){if(e!==void 0){let n=p(e)?e:d(t,e);if(!s(n))throw new Error(`Entry not found: ${n} (from --entry "${e}")`);return n}for(let n of i){let r=f(t,n);if(s(r))return r}throw new Error(`No server entry found in ${t}. Looked for: ${i.join(", ")}. Create one of these (default-exporting your MCPServer instance) or pass --entry <path>.`)}import{readFile as l,writeFile as
|
|
2
|
-
`)}async function
|
|
1
|
+
import{existsSync as s}from"fs";import{isAbsolute as p,join as f,resolve as d}from"path";var i=["src/index.ts","src/index.tsx","src/server.ts","src/server.tsx","index.ts","index.tsx","server.ts","server.tsx"];function j(t,e){if(e!==void 0){let n=p(e)?e:d(t,e);if(!s(n))throw new Error(`Entry not found: ${n} (from --entry "${e}")`);return n}for(let n of i){let r=f(t,n);if(s(r))return r}throw new Error(`No server entry found in ${t}. Looked for: ${i.join(", ")}. Create one of these (default-exporting your MCPServer instance) or pass --entry <path>.`)}import{readFile as l,writeFile as c}from"fs/promises";import{extname as m,join as E,relative as g,sep as x}from"path";var h="mcp-env.d.ts",u="// Generated by mcp-use. Do not edit.",y=["// mcp-use generated env declaration","// mcp-use auto-generated typing"];function A(t,e){let n=g(t,e).split(x).join("/"),r=m(n),o=r===".mts"?".mjs":r===".cts"?".cjs":r===".ts"||r===".tsx"?".js":r;return r!==o&&(n=`${n.slice(0,-r.length)}${o}`),n.startsWith(".")?n:`./${n}`}function D(t,e){let n=A(t,e);return[u,'import "mcp-use/vite-client";',"",'declare module "mcp-use/react" {'," interface Register {",` tools: typeof import(${JSON.stringify(n)});`," }","}","","export {};",""].join(`
|
|
2
|
+
`)}async function v(t,e){let n=E(t,h),r=D(t,e);try{let o=await l(n,"utf8");return o===r?"unchanged":N(o)?(await c(n,r,"utf8"),"updated"):"user-owned"}catch(o){if(!a(o,"ENOENT"))throw o}try{return await c(n,r,{encoding:"utf8",flag:"wx"}),"created"}catch(o){if(!a(o,"EEXIST"))throw o;return v(t,e)}}function N(t){return[u,...y].some(e=>t.startsWith(e))}function a(t,e){return t!==null&&typeof t=="object"&&"code"in t&&t.code===e}export{j as a,v as b};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import{a as c,b as g,c as j,d as p,e as x,f as L,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 n=Y(e);for(;;){if(await h(y(n,"package.json")))return n;let t=V(n);if(t===n)return;n=t}}async function D(){try{return await oe()}catch(e){if(!U(e))throw e;let n=await ee();try{return n.location==="sandbox"?await se():await re(n.projectRoot)}catch(t){throw U(t)?new c(Q):t}}}async function ee(){let e=ne(),n=`${m}@${e}`,t=await X(process.cwd());if(process.stderr.write(`[mcp-use] installing ${m}\u2026
|
|
3
|
+
`),t!==void 0){let[s,i]=te(n);if(await I(s,i,t)!==0)throw new g("client_install_failed",`Failed to install ${m}.`);return{location:"project",projectRoot:t}}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",n],v)!==0)throw new g("client_install_failed",`Failed to install ${m}.`);return{location:"sandbox"}}function te(e){let n=process.env.npm_config_user_agent??"";return n.startsWith("pnpm/")?["pnpm",["add",e]]:n.startsWith("bun/")?["bun",["add",e]]:["npm",["install",e]]}function ne(){for(let e of["../package.json","../../package.json"])try{let n=z(new URL(e,import.meta.url),"utf8"),t=JSON.parse(n);if(t.name!=="mcp-use")continue;let o=t.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 n=M(y(e,"package.json")).href;return import(await import.meta.resolve(m,n))}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 n=e.code;return n==="ERR_MODULE_NOT_FOUND"||n==="MODULE_NOT_FOUND"?e.message.includes(m)||e.message.includes("Cannot find package"):!1}function I(e,n,t){return new Promise((o,r)=>{let s=q(e,n,{cwd:t,stdio:"inherit",shell:process.platform==="win32"});s.once("error",r),s.once("exit",(i,u)=>{o(u==="SIGINT"?130:i??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> 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 n=j(e),t=e.filter(s=>s!=="--json"),o=t[0],r=n&&o!=="remove";try{if(o==="connect")return await le(t.slice(1),n);if(o==="list")return await ue(t.slice(1),n);if(o==="remove"){let s=e.indexOf("remove");return await de(e.filter((i,u)=>u!==s))}if(o===void 0)throw new c("Usage: mcp-use client <connect|list|remove|name>");return await pe(o,t.slice(1),n)}catch(s){return x(s instanceof TypeError?new c(s.message):s,r)}}async function le(e,n){let{values:t,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 c("Usage: mcp-use client connect <name> <url>");let[r,s]=o;he(r);let i=new URL(s);if(!["http:","https:"].includes(i.protocol))throw new c("Client URLs must use http or https.");let u=ge(t.protocol),l=G(t["auth-timeout"]??"300000","--auth-timeout"),a=await S();if(a.servers[r]!==void 0)throw new c(`Saved server already exists: ${r}`);let d={headers:we(t.header??[])},f={url:i.href,oauth:t["no-oauth"]!==!0,protocol:u};return await(await E(r,f,d,l,H({noOpen:t["no-open"]===!0,json:n}))).disconnect(),a.servers[r]=f,await w(_,a),await w(A(r),d),p({name:r,url:f.url,protocol:u},n,`Connected and saved ${r}.`),0}async function ue(e,n){P(e);let t=await S(),o=Object.entries(t.servers).map(([r,s])=>({name:r,...s}));return p(o,n,o.map(r=>`${r.name} ${r.url}`).join(`
|
|
34
|
+
`)||"No saved servers."),0}async function de(e){let{positionals:n}=b({args:[...e],allowPositionals:!0,strict:!0,options:{}}),t=O(n,"mcp-use client remove <name>"),o=await S();return delete o.servers[t],await w(_,o),await J(T(t),{recursive:!0,force:!0}),p({removed:t},!1,`Removed ${t}.`),0}async function pe(e,n,t){let r=(await S()).servers[e];if(r===void 0)throw new c(`Unknown saved server: ${e}. Run \`mcp-use client connect ${e} <url>\`.`);let s=n[0],i=n[1];if(s==="auth"){if(i==="status"){P(n.slice(2));let a=await h($(e));return p({name:e,oauth:r.oauth,authenticated:a},t,a?"Authenticated.":"No saved OAuth session."),0}if(i==="logout"){let{values:a,positionals:d}=b({args:[...n.slice(2)],allowPositionals:!0,strict:!0,options:{yes:{type:"boolean"}}});if(d.length!==0)throw new c(`Usage: mcp-use client ${e} auth logout`);return await L(`Delete OAuth credentials for ${e}?`,{yes:a.yes===!0,json:t})&&(await J($(e),{recursive:!0,force:!0}),p({loggedOut:e},t,`Logged out ${e}.`)),0}}let u=await k(A(e),{}),l=await E(e,r,u,3e5,H({noOpen:!1,json:t}));try{if(s==="tools"){if(i==="list"){P(n.slice(2));let a=await l.listTools();return p(a,t,a.map(d=>d.description?`${d.name} - ${d.description}`:d.name).join(`
|
|
35
|
+
`)),0}if(i==="describe"){let a=O(n.slice(2),`mcp-use client ${e} tools describe <tool>`),d=(await l.listTools()).find(f=>f.name===a);if(d===void 0)throw new c(`Tool not found: ${a}`);return p(d,t),0}if(i==="call")return await me(l,e,n.slice(2),t)}if(s==="resources"){if(i==="list"){P(n.slice(2));let a=await l.listResources();return p(a,t),0}if(i==="read"){let a=O(n.slice(2),`mcp-use client ${e} resources read <uri>`);return p(await l.readResource(a),t),0}}if(s==="prompts"){if(i==="list")return P(n.slice(2)),p(await l.listPrompts(),t),0;if(i==="get"){let a=n[2];if(a===void 0)throw new c(`Usage: mcp-use client ${e} prompts get <prompt> [args]`);return p(await l.getPrompt(a,F(n.slice(3))),t),0}}throw new c(`Usage: mcp-use client ${e} <tools|resources|prompts|auth> ...`)}finally{await l.disconnect()}}async function me(e,n,t,o){let r=t[0];if(r===void 0)throw new c(`Usage: mcp-use client ${n} tools call <tool> [args]`);let{values:s,positionals:i}=b({args:[...t.slice(1)],allowPositionals:!0,strict:!0,options:{timeout:{type:"string",default:"30000"}}}),u=G(s.timeout,"--timeout"),l=await e.callTool(r,F(i),{timeout:u});if(l.isError===!0)throw new g("tool_error",`Tool ${r} returned an error.`,l);return p(l,o),0}async function E(e,n,t,o,r=process.stdin.isTTY?"ask":"never"){let{createOAuthProvider:s,MCPClient:i}=await D(),u=$(e),l=n.oauth?await s(n.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,a=n.protocol==="auto"?"auto":{pin:n.protocol};return new i({mcpServers:{[e]:{url:n.url,...t.headers!==void 0?{headers:t.headers}:{},...l!==void 0?{authProvider:l}:{oauth:!1},protocolNegotiation:a}}}).connect(e)}async function Le(e,n=3e5){let o=(await S()).servers[e];if(o===void 0)throw new c(`Unknown saved server: ${e}`);let r=await k(A(e),{});return E(e,o,r,n)}async function Ne(e,n){return E("screenshot",{url:e,oauth:!1,protocol:"auto"},{headers:n},3e5)}function F(e){if(e.length===0)return{};if(e.length===1&&e[0]?.trimStart().startsWith("{")){let t=JSON.parse(e[0]);if(t===null||Array.isArray(t)||typeof t!="object")throw new c("The JSON argument must be an object.");return t}let n={};for(let t of e){let o=t.indexOf(":="),r=t.indexOf("="),s=o>=0?o:r,i=o>=0?2:1;if(s<=0)throw new c(`Expected key=value or key:=<json>, received: ${t}`);let u=t.slice(0,s).replace(/^--/,""),l=t.slice(s+i);n[u]=o>=0?JSON.parse(l):l}return n}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 n={};for(let t of e){let o=t.indexOf(":");if(o<=0)throw new c(`Invalid header: ${t}`);n[t.slice(0,o).trim()]=t.slice(o+1).trim()}return n}function ge(e){if(e!=="auto"&&e!=="2026-07-28"&&e!=="2025-11-25")throw new c(`Invalid protocol: ${e}`);return e}function G(e,n){let t=Number(e);if(!Number.isInteger(t)||t<=0)throw new c(`${n} must be a positive integer.`);return t}function he(e){if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(e))throw new c("Server names must be 1-64 filesystem-safe letters, numbers, dots, dashes, or underscores.")}async function S(){return k(_,{servers:{}})}function T(e){return C(B,"credentials",ie("sha256").update(e).digest("hex"))}function A(e){return C(T(e),"credentials.json")}function $(e){return C(T(e),"oauth")}function P(e){b({args:[...e],allowPositionals:!1,strict:!0,options:{}})}function O(e,n){if(e.length!==1)throw new c(`Usage: ${n}`);return e[0]}export{xe as a,Le as b,Ne as c,F as d};
|
package/dist/commands/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
`)),
|
|
3
|
-
`)}}return{kind:"external",entry:c.replace(/^\/+/,""),css:
|
|
4
|
-
`);let g=Math.round(performance.now()-t);console.log(`[mcp-use] built ${
|
|
5
|
-
`);let
|
|
1
|
+
import{a as O,b as N,c as j,d as b,e as k,f as F,g as W,h as q,k as S,l as H}from"../chunk-2N6PJAKM.js";import{a as C,b as E,c as I,d as L}from"../chunk-7G4TXPP4.js";import{a as $,b as T}from"../chunk-FLGSKQGU.js";import{randomBytes as Z}from"crypto";import{existsSync as re}from"fs";import{cp as de,mkdir as P,rm as fe,writeFile as D}from"fs/promises";import{join as w,relative as v,resolve as pe}from"path";import me from"@tailwindcss/vite";import ge from"@vitejs/plugin-react";import{build as B}from"vite";import{createServerModuleRunner as J}from"vite";var ce="/mcp",z="http://localhost:3000",h="__mcpUseV1CompatServer";function G(){return globalThis[h]}async function ue(e,t,o){let n=o.filter(r=>r.legacy===!0);if(n.length===0)return;if(typeof t.__registerLegacyViews!="function")throw new Error("Legacy resources/*/widget.tsx views require the temporary mcp-use/server compatibility entry.");let i={};for(let r of n)i[r.name]=await e.import(b(r.entryPath));t.__registerLegacyViews(i)}async function V(e,t){let o=J(e,{hmr:!1,sourcemapInterceptor:"node"}),n=process.env.MCP_URL,i=process.env.MCP_USE_CLI_IMPORT;try{process.env.MCP_USE_CLI_IMPORT="1",n===void 0&&(process.env.MCP_URL=z),delete globalThis[h];let a=(await o.import(t)).default??G();if(a===null||typeof a!="object")throw new Error("The server entry must default-export the MCPServer instance.");return{basePath:a.basePath??ce,supportsLegacyViews:typeof a.__registerLegacyViews=="function"}}finally{delete globalThis[h],n===void 0?delete process.env.MCP_URL:process.env.MCP_URL=n,i===void 0?delete process.env.MCP_USE_CLI_IMPORT:process.env.MCP_USE_CLI_IMPORT=i,await o.close()}}async function Y(e,t){return(await V(e,t)).basePath}async function A(e,t,o,n=[]){let i=J(e,{hmr:!1,sourcemapInterceptor:"node"}),r=process.env.MCP_USE_CLI_IMPORT,a=process.env.MCP_URL;try{process.env.MCP_USE_CLI_IMPORT="1",a===void 0&&(process.env.MCP_URL=z),delete globalThis[h];let s=(await i.import(t)).default??G();if(s===null||typeof s!="object")throw new Error("The server entry must default-export the MCPServer instance.");if(typeof s.__primeViews!="function")throw new Error("The entry's default export does not support __primeViews.");await ue(i,s,n),s.__primeViews(o),s.__mount()}finally{delete globalThis[h],r===void 0?delete process.env.MCP_USE_CLI_IMPORT:process.env.MCP_USE_CLI_IMPORT=r,a===void 0?delete process.env.MCP_URL:process.env.MCP_URL=a,await i.close()}}function le(e){return e.replace(/\/+$/,"")}function K(e){return le(e)}import{hostHeaderValidationResponse as $e,originValidationResponse as Ce}from"@modelcontextprotocol/server";function Q(e,t){let o=t.replace(/^\/+/,"");return e==="/"?`/${o}`:`${e}/${o}`}function X(e,t){return`${Q(e,`_mcp-use/views/${t}`)}/`}var y="index.js",we="entry-wrapper.ts",ye=100*1024*1024;async function ee(e,t){let o=w(e,"public");re(o)&&await de(o,t,{recursive:!0})}async function te(e,t,o,n){let i=w(e,we);await P(e,{recursive:!0});let r=JSON.stringify(o),a=n.filter(s=>s.legacy===!0),c=a.length>0?[`import ${JSON.stringify(t)};`,'import { registerViews } from "mcp-use";']:[`import * as serverModule from ${JSON.stringify(t)};`,'import { registerViews } from "mcp-use";'];if(a.forEach((s,f)=>{c.push(`import * as legacyWidget${f} from ${JSON.stringify(b(s.entryPath))};`)}),c.push(a.length>0?"const server = globalThis.__mcpUseV1CompatServer;":"const server = serverModule.default;",'if (!server) throw new Error("The server entry must default-export MCPServer or use the deprecated mcp-use/server compatibility entry.");'),a.length>0){let s=a.map((f,p)=>`${JSON.stringify(f.name)}: legacyWidget${p}`).join(", ");c.push(`server.__registerLegacyViews?.({ ${s} });`)}return c.push(`server[registerViews] ? server[registerViews](${r}) : server.__primeViews(${r});`,"export default server;",""),await D(i,c.join(`
|
|
2
|
+
`)),i}function he(){let e=process.env.MCP_ASSETS_URL;if(!(e===void 0||e.trim()===""))try{return K(new URL(e).href.replace(/\/$/,""))}catch{return}}function U(e,t,o,n){let i=e.replace(/^\/+/,"");return`${o}${X(n,t)}${i}`}function ve(e,t,o,n){return e.kind!=="external"?e:{...e,entry:U(e.entry,t,o,n),css:e.css.map(i=>U(i,t,o,n)),...e.scripts!==void 0&&{scripts:e.scripts.map(i=>U(i,t,o,n))}}}async function Me(e,t){let o=w(t.viewsOutDir,e.name),n=await B({root:t.cwd,configFile:t.userViteConfig,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:t.cacheDir,resolve:{tsconfigPaths:!0,alias:{tailwindcss:N()}},oxc:{jsx:{runtime:"automatic"}},plugins:[me(),ge(),H({getViews:()=>[e]})],build:{outDir:o,emptyOutDir:!0,write:!t.inline,target:"es2022",sourcemap:t.inline?!1:t.sourceMaps,minify:!0,cssCodeSplit:!1,chunkSizeWarningLimit:1e3,assetsInlineLimit:ye,rollupOptions:{input:{[e.name]:q(e.name)},output:{format:"es",codeSplitting:!t.inline,entryFileNames:"assets/[name]-[hash].js",chunkFileNames:"assets/[name]-[hash].js",assetFileNames:"assets/[name]-[hash][extname]"}}},base:"./"}),i=Array.isArray(n)?n[0]:n;if(i===void 0||!("output"in i))throw new Error(`Client build for view "${e.name}" produced no output.`);let r=i.output,a=Array.isArray(r)?r:Object.values(r),c,s,f,p=[];for(let m of a){if(typeof m!="object"||m===null||!("fileName"in m)||typeof m.fileName!="string")continue;let u=m;u.type==="chunk"&&u.isEntry===!0?(c=u.fileName,f=u.code):u.type==="asset"&&u.fileName.endsWith(".css")&&(s=u.fileName,typeof u.source=="string"?p.push(u.source):u.source instanceof Uint8Array&&p.push(new TextDecoder().decode(u.source)))}if(c===void 0)throw new Error(`Client build produced no entry chunk for view "${e.name}".`);if(t.inline){if(f===void 0)throw new Error(`Client build produced no entry source for view "${e.name}".`);return{kind:"inline",js:f,css:p.join(`
|
|
3
|
+
`)}}return{kind:"external",entry:c.replace(/^\/+/,""),css:s!==void 0?[s.replace(/^\/+/,"")]:[]}}async function _e(e){let t=performance.now();I(e.cwd,"production");let o=e.mcpDir===void 0?e.cwd:pe(e.cwd,e.mcpDir),n=e.entry===void 0?$(o):$(e.cwd,e.entry),i=await T(e.cwd,n);(i==="created"||i==="updated")&&console.log(`[mcp-use] ${i} mcp-env.d.ts`);let r=j(e.cwd),a=e.viewsDir??(e.mcpDir===void 0?void 0:w(e.mcpDir,"views"));re(F(e.cwd,a))||console.log("[mcp-use] views directory not configured.");let c=W(e.cwd,a,{includeLegacy:!0}),s=c,f=O(e.cwd),p=e.sourceMaps===!0,m=e.inline===!0,d,u;if(c.some(l=>l.legacy===!0)){d=await S(e.cwd,r.cache,!1);let l;try{l=await V(d.environments.ssr,n)}catch(g){throw await d.close(),g}u=l.basePath,l.supportsLegacyViews||(s=c.filter(g=>g.legacy!==!0))}if(s.length===0){d??=await S(e.cwd,r.cache,!1);try{await A(d.environments.ssr,n,{},s);let ae=await te(r.cache,n,{},s);await B({root:e.cwd,configFile:!1,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:C(e.cwd)},plugins:[L(e.cwd)],build:{ssr:ae,outDir:r.build,emptyOutDir:!0,target:"node22",sourcemap:p,minify:!1,rollupOptions:{output:{format:"es",entryFileNames:y}}},ssr:{...E(e.cwd),target:"node"}})}finally{await d?.close()}await ee(e.cwd,w(r.build,"views/public"));let l={buildId:Z(8).toString("hex"),entryPoint:y,createdAt:new Date().toISOString(),views:{}};await P(r.build,{recursive:!0}),await D(r.buildManifest,`${JSON.stringify(l,null,2)}
|
|
4
|
+
`);let g=Math.round(performance.now()-t);console.log(`[mcp-use] built ${v(e.cwd,n)} \u2192 ${v(e.cwd,r.build)}/${y} (${g}ms)`);return}await fe(r.build,{recursive:!0,force:!0});let M=w(r.build,"views");await P(M,{recursive:!0}),d??=await S(e.cwd,r.cache,!1);let _,R={},x=he();try{_=u??await Y(d.environments.ssr,n);for(let l of s){let g=await Me(l,{cwd:e.cwd,cacheDir:r.cache,viewsOutDir:M,userViteConfig:f,sourceMaps:p,inline:m});x!==void 0&&!m&&(g=ve(g,l.name,x,_)),R[l.name]=g}x!==void 0&&!m&&(console.log(`[mcp-use] MCP_ASSETS_URL set \u2014 manifest uses CDN URLs; upload ${v(e.cwd,M)}/ to your asset host.`),_!=="/mcp"&&console.log(`[mcp-use] CDN manifest uses basePath ${_} from server entry`)),await ee(e.cwd,w(M,"public")),await A(d.environments.ssr,n,R,s)}finally{await d.close()}let ne=await te(r.cache,n,R,s);await B({root:e.cwd,configFile:!1,envDir:!1,publicDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:C(e.cwd)},oxc:{jsx:{runtime:"automatic"}},plugins:[L(e.cwd),k()],build:{ssr:ne,outDir:r.build,emptyOutDir:!1,target:"node22",sourcemap:p,minify:!1,rollupOptions:{output:{format:"es",entryFileNames:y}}},ssr:{...E(e.cwd),target:"node"}});let ie={buildId:Z(8).toString("hex"),entryPoint:y,createdAt:new Date().toISOString(),views:R};await P(r.build,{recursive:!0}),await D(r.buildManifest,`${JSON.stringify(ie,null,2)}
|
|
5
|
+
`);let se=Math.round(performance.now()-t),oe=s.map(l=>l.name).join(", ");console.log(`[mcp-use] built ${v(e.cwd,n)} + views (${oe}) \u2192 ${v(e.cwd,r.build)}/${y} (${se}ms)`)}export{_e as runBuild};
|
package/dist/commands/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d}from"../chunk-
|
|
1
|
+
import{a,b,c,d}from"../chunk-NFT6Z2DG.js";import"../chunk-VSIT62BK.js";import"../chunk-LNASFQWW.js";export{c as openDirectConnection,b as openSavedConnection,d as parseMcpArguments,a as runClient};
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as
|
|
2
|
-
`,t)}}while(
|
|
1
|
+
import{b as ie}from"../chunk-OVFUQAEG.js";import{a as ne,b as re}from"../chunk-N7BU45K6.js";import{b as Q,c as Z}from"../chunk-USIKTT3N.js";import{a as ae,b as ce,c as le,d as de,e as ue,f as pe,g as H,i as F,j as fe,l as me}from"../chunk-2N6PJAKM.js";import{b as oe,c as se,d as A}from"../chunk-7G4TXPP4.js";import{a as x,b as te}from"../chunk-FLGSKQGU.js";import{a as ee}from"../chunk-LNASFQWW.js";import{existsSync as Ve}from"fs";import{createServer as xe}from"http";import{networkInterfaces as Ae}from"os";import{join as Fe,resolve as Be}from"path";import Ne from"@tailwindcss/vite";import We from"@vitejs/plugin-react";import{createServer as Ge,createServerModuleRunner as qe}from"vite";import{InMemoryServerEventBus as Je,localhostAllowedHostnames as ze,localhostAllowedOrigins as Ke,validateHostHeader as Xe,validateOriginHeader as Ye}from"@modelcontextprotocol/server";import{connect as Ce,createServer as Oe}from"net";var ve=100,He=300,Ue=new Set(["127.0.0.1","localhost","::1"]);function ke(e,r){return new Promise(s=>{let n=Oe();n.unref(),n.once("error",()=>s(!1)),n.listen({port:e,host:r},()=>{n.close(()=>s(!0))})})}function we(e,r){return new Promise(s=>{let n=Ce({port:e,host:r});n.setTimeout(He),n.once("connect",()=>{n.destroy(),s(!0)}),n.once("timeout",()=>{n.destroy(),s(!1)}),n.once("error",()=>{n.destroy(),s(!1)})})}async function De(e){return await we(e,"127.0.0.1")||await we(e,"::1")}async function he(e,r){for(let s=e;s<e+ve;s++)if(await ke(s,r)&&!(Ue.has(r)&&await De(s)))return{port:s,requested:e};throw new Error(`No free port found between ${e} and ${e+ve-1} on ${r}.`)}function ge(e,r){let s=()=>{let n=e.getBasePath(),{url:a}=e.tunnel.status();return{mcpUrl:a!==null?`${a.replace(/\/+$/,"")}${n}`:null,port:e.port,fromCli:!0,tunnelUrl:a}};return async n=>{let a=e.getBasePath(),u=`${a}/inspector/api/dev/info`,p=`${a}/inspector/api/dev/start-tunnel`,f=`${a}/inspector/api/dev/stop-tunnel`,y=new URL(n.url).pathname;if(n.method==="GET"&&y===u)return Response.json(s());if(n.method==="POST"&&y===p)try{return await e.tunnel.start(e.port),Response.json({ok:!0,restarting:!1})}catch(M){let U=M instanceof Error?M.message:"Failed to start tunnel";return Response.json({error:U},{status:500})}return n.method==="POST"&&y===f?(await e.tunnel.stop(),Response.json({ok:!0})):r(n)}}import{readFileSync as Ee}from"fs";import{createRequire as je}from"module";import{join as Te}from"path";import{pathToFileURL as $e}from"url";async function Re(e){let r=Te(e,"package.json"),s=JSON.parse(Ee(r,"utf8"));if([s.dependencies,s.devDependencies,s.optionalDependencies].some(u=>u!==null&&typeof u=="object"&&"@mcp-use/inspector"in u)){let u=je(r);try{let p=u.resolve("@mcp-use/inspector");return ye(await import($e(p).href))}catch(p){if(!Pe(p))throw p}}try{return ye(await import("@mcp-use/inspector"))}catch(u){if(Pe(u))return{installed:!1};throw u}}function ye(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"}var _e="__mcpUseV1CompatServer";function Qe(e){ee(e)}function Ze(){for(let e of Object.values(Ae()))for(let r of e??[])if(!r.internal&&r.family==="IPv4")return r.address}function et(e){if(e!==void 0)try{return new URL(`http://${e}`).hostname.replace(/^\[|\]$/g,"")}catch{return}}function tt(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 nt(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 a=Ye(n,Ke());!a.ok||a.origin===void 0||(r.setHeader("Access-Control-Allow-Origin",a.origin),tt(r))}function rt(e){let r=e.default??globalThis[_e];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 ot(e){process.env.MCP_USE_DEV_CLI="1";let r=le(e.cwd),s=new Je(t=>{console.error("[mcp-use] notification delivery failed:",t)});se(e.cwd,"development");let n=Z(e.host),a=["127.0.0.1","localhost","::1"].includes(n),u=n==="0.0.0.0"||n==="::",p=xe(),{port:f,requested:y}=await he(Q(e.port),n);f!==y&&console.log(`[mcp-use] port ${y} is taken, using ${f}`),process.env.PORT=String(f);let M=process.env.MCP_URL===void 0&&(n==="127.0.0.1"||n==="localhost"||n==="::1")?`http://localhost:${f}`:void 0,U=e.mcpDir===void 0?e.cwd:Be(e.cwd,e.mcpDir),B=e.entry===void 0?x(U):x(e.cwd,e.entry),k=await te(e.cwd,B);(k==="created"||k==="updated")&&console.log(`[mcp-use] ${k} mcp-env.d.ts`);let P=e.viewsDir??(e.mcpDir===void 0?void 0:Fe(e.mcpDir,"views"));Ve(pe(e.cwd,P))||console.log("[mcp-use] views directory not configured.");let d=H(e.cwd,P,{includeLegacy:!0}),L=!1,R=d.length>0,Me=ae(e.cwd),D=["127.0.0.1","localhost","0.0.0.0","::","::1"].includes(n)?"localhost":n,b=`http://${D.includes(":")?`[${D}]`:D}:${f}`,m=await Ge({root:e.cwd,configFile:R?Me:!1,envDir:!1,logLevel:"warn",cacheDir:r.cache,resolve:{tsconfigPaths:!0,alias:{tailwindcss:ce()}},oxc:{jsx:{runtime:"automatic"}},plugins:R?[A(e.cwd),ue(),Ne(),me({getViews:()=>d,dev:{reactRefresh:!0}}),We()]:[A(e.cwd)],server:{middlewareMode:!0,...R&&{origin:b},cors:!1,hmr:R?{server:p}:!1,...!R&&{ws:!1}},ssr:{...oe(e.cwd)}}),E=m.environments.ssr,_=qe(E,{hmr:!1,sourcemapInterceptor:"node"}),N=async()=>{let t=async()=>{delete globalThis[_e];let i=process.env.MCP_USE_CLI_IMPORT,l;try{process.env.MCP_USE_CLI_IMPORT="1",l=await _.import(B)}finally{i===void 0?delete process.env.MCP_USE_CLI_IMPORT:process.env.MCP_USE_CLI_IMPORT=i}let c=rt(l);L=typeof c.__registerLegacyViews=="function",d=H(e.cwd,P,{includeLegacy:L});let w=d.filter(g=>g.legacy===!0);if(w.length>0){if(typeof c.__registerLegacyViews!="function")throw new Error("Legacy resources/*/widget.tsx views require the temporary mcp-use/server compatibility entry.");let g={};for(let O of w)g[O.name]=await _.import(de(O.entryPath));c.__registerLegacyViews(g)}let S=fe(d);if(typeof c.__primeViews!="function")throw new Error("Loaded MCPServer instance does not support __primeViews.");return c.__primeViews(S,{dev:!0,projectRoot:e.cwd}),c};if(M===void 0)return t();let o=process.env.MCP_URL;try{return process.env.MCP_URL=M,await t()}finally{o===void 0?delete process.env.MCP_URL:process.env.MCP_URL=o}},j,v;try{let t=await N();t.__setEventBus(s),t.__mount(),j=async o=>t.fetch(o),v=t.basePath??"/mcp"}catch(t){throw await _.close(),await m.close(),t}let T,I,W,G=t=>{if(T===void 0||W===t)return;let o=T.mountInspector({basePath:t,autoConnectUrl:`${b}${t}`,oauthProxyAllowLoopback:a||u,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.");I=o,W=t};try{if(e.inspector!==!1){let t=await Re(e.cwd);t.installed&&(T=t.module,G(v))}}catch(t){throw await _.close(),await m.close(),t}let $=!1,V=!1,q=()=>{if($){V=!0;return}$=!0,(async()=>{do{V=!1;try{_.evaluatedModules.clear();let t=await N();t.__setEventBus(s),t.__mount();let o=async l=>t.fetch(l),i=t.basePath??"/mcp";G(i),j=o,v=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(V);$=!1})()},J=t=>{if(F(t,e.cwd,P))return;let o=E.moduleGraph.getModulesByFile(t);if(!(o===void 0||o.size===0)){for(let i of o)E.moduleGraph.invalidateModule(i);q()}},z=t=>{if(!F(t,e.cwd,P))return;let o=d;d=H(e.cwd,P,{includeLegacy:L});let i=o.length!==d.length||o.some((c,w)=>c.name!==d[w]?.name||c.entryPath!==d[w]?.entryPath),l=L&&d.some(c=>c.legacy===!0&&c.entryPath===t);(i||l)&&q()},K=t=>{z(t),J(t)},C=t=>{z(t),J(t)};m.watcher.on("change",K),m.watcher.on("add",C),m.watcher.on("unlink",C);let h=ie(r.tunnel);p.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:${f}`)});let be=(t,o)=>{let i=h.status().url,l=i!==null?new URL(i).hostname:null,c=l!==null?[l]:[],w=Xe(t.headers.host,[...ze(),...c]);return w.ok?!1:(o.writeHead(403,{"content-type":"application/json"}),o.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:w.message},id:null})),!0)},X=async()=>{m.watcher.off("change",K),m.watcher.off("add",C),m.watcher.off("unlink",C),await h.stop(),await new Promise(t=>p.close(()=>t())),await _.close(),await m.close()},Ie=ge({getBasePath:()=>v,port:f,tunnel:h},t=>I!==void 0&&ne(t,v)?I(t):j(t)),{toNodeHandler:Se}=await import("../node-bridge-JJIA6K5P.js"),Y=Se({fetch:Ie}),Le=(t,o)=>{if(a&&be(t,o))return;let i=t.url??"/",l=new URL(i,"http://127.0.0.1").pathname,c=h.status().url,w=c===null?null:new URL(c).hostname,S=et(t.headers.host);if((w!==null&&S===w||u&&S!==void 0&&!["localhost","127.0.0.1","::1"].includes(S))&&re(l,v)){o.writeHead(404,{"content-type":"text/plain; charset=utf-8"}),o.end("Not Found");return}let g=R&&d.length>0,O=t.method==="GET"&&(l.startsWith("/@")||l.startsWith("/node_modules/")||l.startsWith("/.mcp-use/")||g&&l.startsWith("/views/"));g&&O?(nt(t,o,{tunnelActive:h.status().url!==null,localhostBind:a}),m.middlewares(t,o,()=>{Y(t,o)})):Y(t,o)};if(p.on("request",Le),await new Promise((t,o)=>{p.once("error",o),p.listen(f,n,()=>t())}),console.log("[mcp-use] dev server ready"),d.length>0&&console.log(` \u279C Views: ${d.map(t=>t.name).join(", ")}`),console.log(` \u279C MCP endpoint: ${b}${v}`),I!==void 0?console.log(` \u279C Inspector: ${b}${v}/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=Ze();t!==void 0&&console.log(` \u279C Network: http://${t}:${f}${v}`)}if(a||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(f);console.log(` \u279C Tunnel: ${t}${v}`)}catch(t){throw await X(),t}I!==void 0&&e.open!==!1&&process.stdout.isTTY===!0&&Qe(`${b}${v}/inspector`),await new Promise(t=>{let o=!1,i=()=>{o||(o=!0,process.off("SIGINT",i),process.off("SIGTERM",i),(async()=>(await X(),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{ot as runDev};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as M,c as $,d as x}from"../chunk-
|
|
1
|
+
import{b as M,c as $,d as x}from"../chunk-NFT6Z2DG.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
2
|
ready: document.body?.dataset.viewReady === "true",
|
|
3
3
|
error: document.body?.dataset.viewError || null,
|
|
4
4
|
selector: ${JSON.stringify(n)} === undefined || !!document.querySelector(${JSON.stringify(n??"")})
|
package/dist/commands/start.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
async function e(t){return(await import("../start-
|
|
1
|
+
async function e(t){return(await import("../start-3KGZXHWI.js")).runStart(t)}export{e as runStart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as i,b as o}from"../chunk-
|
|
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 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-XIPXOMHU.js";import"./chunk-USIKTT3N.js";export{a as main};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{a as M}from"./chunk-N7BU45K6.js";import{b as v,c as E}from"./chunk-USIKTT3N.js";import{c as S}from"./chunk-7G4TXPP4.js";import{readFile as C}from"fs/promises";import{join as f}from"path";import{pathToFileURL as L}from"url";var k=".mcp-use",T="build",O="manifest.json";async function V(t){let o=f(t.cwd,k,T),s=f(o,O),c;try{c=await C(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",S(t.cwd,"production");let a=f(o,i),u=L(a).href,l="__mcpUseV1CompatServer";delete globalThis[l];let y=process.env.MCP_USE_CLI_IMPORT,P;try{process.env.MCP_USE_CLI_IMPORT="1",P=await import(u)}finally{y===void 0?delete process.env.MCP_USE_CLI_IMPORT:process.env.MCP_USE_CLI_IMPORT=y}let b=P.default??globalThis[l];if(b===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=b;if(!A(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 U=typeof e.port=="number"?e.port:void 0,R=typeof e.host=="string"?e.host:void 0,h=v(t.port,process.env,U),g=E(t.host,process.env,R),p=await(t.withInspector===!0?x(e,h,g):e.listen(h,{host:g})),m=typeof p?.port=="number"?p.port:h,I=typeof p?.url=="string"?p.url:`http://localhost:${m}`,d,w;if(t.tunnel===!0)try{let{createTunnelManager:n}=await import("./tunnel-AQ2WE7EL.js");d=n(f(t.cwd,k,"state","tunnel.json"));let r=await d.start(m),_=new URL(I);w=new URL(`${_.pathname}${_.search}`,`${r.url}/`).toString()}catch(n){try{await d?.stop()}catch{}try{await e.close?.()}catch{}throw n}return{port:m,url:I,...w!==void 0&&{tunnelUrl:w},close:async()=>{let n;try{await d?.stop()}catch(r){n=r}try{await e.close?.()}catch(r){n??=r}if(n!==void 0)throw n}}}async function x(t,o,s){let{mountInspector:c}=await N(),i=typeof t.basePath=="string"?t.basePath:"/mcp",a=c({basePath:i,devMode:!1,oauthProxyAllowLoopback:!1,manufactChatUrl:process.env.MANUFACT_CHAT_URL});return t.app.use("*",async(u,l)=>{if(M(u.req.raw,i))return a(u.req.raw);await l()}),t.listen(o,{host:s})}async function N(){let t;try{t=await import("@mcp-use/inspector")}catch(o){throw D(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 D(t){return t!==null&&typeof t=="object"&&"code"in t&&(t.code==="ERR_MODULE_NOT_FOUND"||t.code==="MODULE_NOT_FOUND")}export{V as runStart};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-use/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.12",
|
|
5
5
|
"description": "Prebuilt CLI, development server, and build pipeline for mcp-use",
|
|
6
6
|
"author": "mcp-use, Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./types/index.d.ts",
|
|
28
28
|
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./vite-client": {
|
|
31
|
+
"types": "./types/vite-client.d.ts"
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
34
|
"files": [
|
package/dist/chunk-4JB4S4BZ.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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};
|
package/dist/chunk-ALPMVGHI.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
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};
|
package/dist/start-CGEGBZOH.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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};
|
|
File without changes
|