@smithery/cli 1.1.54 → 1.1.55
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/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ Input Schema:`)),console.dir(a.value.inputSchema,{depth:null,colors:!0}),console
|
|
|
103
103
|
Fix with: chmod 700 "${e}"
|
|
104
104
|
Or use: export SMITHERY_CONFIG_PATH="/custom/path"
|
|
105
105
|
Running in memory-only mode (settings won't persist).`,Pv=async(e,t)=>{M(`Saving settings to ${t}`),M(`Settings data: ${JSON.stringify(e,null,2)}`);try{try{M(`Ensuring directory exists: ${t}`),await Jf.promises.mkdir(t,{recursive:!0}),M("Directory check completed")}catch(n){if(M(`Directory creation error: ${JSON.stringify(n)}`),n instanceof Error&&"code"in n&&n.code==="EACCES")return{success:!1,error:Bv(t,"write")};throw n}let r=(0,Cs.join)(t,"settings.json");return M(`Writing settings to file: ${r}`),await Jf.promises.writeFile(r,JSON.stringify(e,null,2)),M("Settings successfully written"),{success:!0,data:e}}catch(r){return M(`Settings save error: ${JSON.stringify(r)}`),{success:!1,error:r instanceof Error&&"code"in r&&r.code==="EACCES"?Bv(t,"write"):`Failed to save settings: ${r instanceof Error?r.message:String(r)}`}}},iEe=async e=>{M(`Loading settings from ${e}`);try{let t=(0,Cs.join)(e,"settings.json");M(`Reading settings file: ${t}`);try{let r=await Jf.promises.readFile(t,"utf-8");M("Settings file content loaded");let n=JSON.parse(r);if(M(`Settings parsed: ${JSON.stringify(n,null,2)}`),!nEe(n)){M("Settings validation failed, fixing settings");let i={...Xf(),...n};return i.analyticsConsent&&(i.askedConsent=!0),M(`Fixed settings: ${JSON.stringify(i,null,2)}`),await Pv(i,e),{success:!0,data:i}}return{success:!0,data:n}}catch(r){if(M(`Settings read error: ${JSON.stringify(r)}`),r instanceof Error&&"code"in r){if(r.code==="ENOENT"){M("Settings file not found, creating default settings");let n=Xf();return M(`Default settings: ${JSON.stringify(n,null,2)}`),await Pv(n,e)}if(r.code==="EACCES")return{success:!1,error:Bv(e,"read")}}throw r}}catch(t){return M(`Settings load error: ${JSON.stringify(t)}`),{success:!1,error:`Failed to load settings: ${t instanceof Error?t.message:String(t)}`}}},ha=async()=>{if(qv&&si)return{success:!0,data:si};try{let e=jI(),t=await iEe(e);return t.success&&t.data&&(si=t.data),qv=!0,t}catch(e){return si=Xf(),qv=!0,{success:!0,data:si,error:`Warning: Running in memory-only mode - ${e instanceof Error?e.message:String(e)}`}}},MI=async()=>(await ha(),si?.userId||Xf().userId),Qf=async()=>{let e=await ha();return!e.success||!e.data?(console.warn("[Config] Failed to load analytics settings:",e.error),!1):e.data.analyticsConsent},kI=async e=>{let t=await ha();return!t.success||!t.data?t:(si={...t.data,analyticsConsent:e,askedConsent:!0},await Pv(si,jI()))},LI=async()=>(await ha(),si?.askedConsent||!1);async function WI(){let e=await ha();if(!e.success){console.warn("[Analytics] Failed to initialize settings:",e.error);return}if(await Qf())return;if(!await LI())try{let{EnableAnalytics:n}=await VI.default.prompt([{type:"confirm",name:"EnableAnalytics",message:`Would you like to help improve Smithery by sending anonymous usage data?
|
|
106
|
-
For information on Smithery's data policy, please visit: ${UI.default.blue("https://smithery.ai/docs/data-policy")}`,default:!0}]),i=await kI(n);i.success||console.warn("[Smithery] Failed to save preference:",i.error)}catch(n){console.warn("[Smithery] Failed to prompt for consent:",n instanceof Error?n.message:String(n))}}var $I=ae(N1()),GI=require("node:child_process"),zI=require("node:util"),oi=(0,zI.promisify)(GI.exec);async function aEe(e){if(!e)return!1;try{let t=process.platform,r={claude:"Claude"}[e]||e;if(t==="win32"){let{stdout:n}=await oi(`tasklist /FI "IMAGENAME eq ${r}.exe" /NH`);return n.includes(`${r}.exe`)}else if(t==="darwin"){let{stdout:n}=await oi(`pgrep -x "${r}"`);return!!n.trim()}else if(t==="linux"){let{stdout:n}=await oi(`pgrep -f "${r.toLowerCase()}"`);return!!n.trim()}return!1}catch{return!1}}async function sEe(e){let t={claude:"Claude"}[e]||e;try{let r=process.platform;r==="win32"?await oi(`taskkill /F /IM "${t}.exe" && start "" "${t}.exe"`):r==="darwin"?await oi(`killall "${t}" && open -a "${t}"`):r==="linux"&&await oi(`pkill -f "${t.toLowerCase()}" && ${t.toLowerCase()}`),await new Promise(n=>setTimeout(n,2e3)),r==="win32"?await oi(`start "" "${t}.exe"`):r==="darwin"?await oi(`open -a "${t}"`):r==="linux"&&await oi(t.toLowerCase()),console.log(`${t} has been restarted.`)}catch(r){console.error(`Failed to restart ${t}:`,r)}}async function e4(e){if(!e||!await aEe(e))return!1;let{shouldRestart:r}=await $I.default.prompt([{type:"confirm",name:"shouldRestart",message:`Would you like to restart the ${e} app to apply changes?`,default:!0}]);return r&&(console.log(`Restarting ${e} app...`),await sEe(e)),r}process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function HI(e,t,r,n){M(`Starting installation of ${e} for client ${t}`),M(`Resolving package: ${e}`);let i,a;n?(M("API key provided, fetching server details and saved config"),i=Uf(e,n).then(p=>(a=p.config,p.server)).catch(p=>(console.warn(Y1.default.yellow("[Install] Failed to fetch config with API key:"),p instanceof Error?p.message:String(p)),M("Falling back to standard package resolution"),Fs(e)))):i=Fs(e);try{M("Checking analytics consent..."),await WI(),M("Analytics consent check completed")}catch(p){console.warn(Y1.default.yellow("[Analytics] Failed to check consent:"),p instanceof Error?p.message:String(p)),M(`Analytics consent check error details: ${JSON.stringify(p)}`)}let u=Dr(`Resolving ${e}...`).start();try{M("Awaiting package resolution...");let p=await i;M(`Package resolved successfully: ${p.qualifiedName}`),u.succeed(`Successfully resolved ${e}`),M("Choosing connection type...");let l=z1(p);M(`Selected connection: ${JSON.stringify(l,null,2)}`),await CI(l),await SI(l),AI(p);let c=a?{...a,...r||{}}:r,h=await $f(l,c),b=!!r;M(`Config values: ${JSON.stringify(h,null,2)}`),M(`Using config flag: ${b}`),M("Formatting server configuration...");let E=EI(e,h,n,b);M(`Formatted server config: ${JSON.stringify(E,null,2)}`),M(`Reading configuration for client: ${t}`);let T=Hf(t);M("Normalizing server ID...");let S=yI(e);M(`Normalized server ID: ${S}`),M("Updating client configuration..."),T.mcpServers[S]=E,M("Writing updated configuration..."),Kf(T,t),M("Configuration successfully written"),console.log(Y1.default.green(`${e} successfully installed for ${t}`)),M("Prompting for client restart..."),await e4(t),M("Installation process completed")}catch(p){u.fail(`Failed to install ${e}`),M(`Installation error: ${p instanceof Error?p.stack:JSON.stringify(p)}`),p instanceof Error?console.error(Y1.default.red(`Error: ${p.message}`)):console.error(Y1.default.red("An unexpected error occurred during installation")),process.exit(1)}}var t4=ae(We());async function KI(e){switch(e){case"clients":console.log(t4.default.bold("Available clients:")),Js.forEach(t=>console.log(` ${t4.default.green(t)}`));break;default:console.log(t4.default.yellow("Please specify what to list. Available options:")),console.log(" clients List available clients"),process.exit(1)}}var Pwe=ae(pM(),1),Nwe=ae(Xv(),1),Rwe=ae(tx(),1),_M=ae(m4(),1),Iwe=ae(gM(),1);var bM=_M.default;var jwe="mcp",v4=class{constructor(t){this._url=t}start(){if(this._socket)throw new Error("WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically.");return new Promise((t,r)=>{this._socket=new WebSocket(this._url,jwe),this._socket.onerror=n=>{var i;let a="error"in n?n.error:new Error(`WebSocket error: ${JSON.stringify(n)}`);r(a),(i=this.onerror)===null||i===void 0||i.call(this,a)},this._socket.onopen=()=>{t()},this._socket.onclose=()=>{var n;(n=this.onclose)===null||n===void 0||n.call(this)},this._socket.onmessage=n=>{var i,a;let u;try{u=gd.parse(JSON.parse(n.data))}catch(p){(i=this.onerror)===null||i===void 0||i.call(this,p);return}(a=this.onmessage)===null||a===void 0||a.call(this,u)}})}async close(){var t;(t=this._socket)===null||t===void 0||t.close()}send(t){return new Promise((r,n)=>{var i;if(!this._socket){n(new Error("Not connected"));return}(i=this._socket)===null||i===void 0||i.send(JSON.stringify(t)),r()})}};function DM(e,t){let r=new URL(e);if(t){let n=typeof window<"u"?btoa(JSON.stringify(t)):Buffer.from(JSON.stringify(t)).toString("base64");r.searchParams.set("config",n)}return r}var Mwe={idleTimeout:60*1e3,maxBuffer:100},x4=class{constructor(t,r,n=Mwe){this.baseUrl=t;this.config=r;this.options=n;this.realTransport=null;this.messageBuffer=[];this.idleTimer=null;this.isConnecting=!1;this.connectionPromise=null}resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>this.disconnect(),this.options.idleTimeout)}async ensureConnected(){if(this.realTransport){this.resetIdleTimer();return}if(this.connectionPromise)return this.connectionPromise;this.isConnecting=!0,this.connectionPromise=(async()=>{let t=`${this.baseUrl.replace(/^http/,"ws")}${this.baseUrl.endsWith("/")?"":"/"}ws`,r=DM(t,this.config);console.error("ProxyTransport: Creating new WebSocket connection...");let n=new v4(r);for(n.onmessage=i=>this.onmessage?.(i),n.onerror=i=>this.onerror?.(i),n.onclose=()=>{this.realTransport=null},await n.start(),this.realTransport=n,this.resetIdleTimer(),console.error("ProxyTransport: Connection established, processing buffer...");this.messageBuffer.length>0;){let i=this.messageBuffer.shift();await this.realTransport.send(i)}})();try{await this.connectionPromise}finally{this.isConnecting=!1,this.connectionPromise=null}}async disconnect(){this.realTransport&&(console.error("ProxyTransport: Closing idle connection"),await this.realTransport.close(),this.realTransport=null)}async start(){}async send(t){if(!this.realTransport&&!this.isConnecting){if(this.messageBuffer.length>=this.options.maxBuffer)throw new Error("Message buffer full");this.messageBuffer.push(t),await this.ensureConnected()}else this.isConnecting?this.messageBuffer.push(t):(await this.realTransport.send(t),this.resetIdleTimer())}async close(){await this.disconnect(),this.onclose&&this.onclose()}};global.WebSocket=bM;var yM=3,kwe=1e3,EM=(e,t)=>new x4(e,t,{idleTimeout:5*60*1e3,maxBuffer:100}),wM=async(e,t)=>{let r=0,n="",i=!1,a=EM(e,t),u=(b,E)=>(console.error(`${E}:`,b.message),b),p=async b=>{if(n+=b.toString("utf8"),!i)return;let E=n.split(/\r?\n/);n=E.pop()??"";for(let T of E.filter(Boolean))try{await a.send(JSON.parse(T))}catch(S){if(S instanceof Error&&S.message.includes("CLOSED"))throw new Error("WebSocket closed");u(S,"Failed to send message")}},l=async()=>{console.error(`Connecting to WebSocket endpoint: ${e}`),a.onclose=async()=>{console.error("WebSocket connection closed"),i=!1,r++<yM?(await new Promise(b=>setTimeout(b,kwe*Math.pow(2,r))),a=EM(e,t),await l()):(console.error(`Max reconnection attempts (${yM}) reached`),process.exit(1))},a.onerror=b=>{if(b.message.includes("502")){console.error("Server returned 502, attempting to reconnect...");return}u(b,"WebSocket connection error"),process.exit(1)},a.onmessage=b=>{try{if("error"in b){let E=b;if(console.error(`[Runner] WebSocket error: ${JSON.stringify(E.error)}`),E.error.code===-32e3){console.error("[Runner] Connection closed by server - attempting to reconnect..."),a.close();return}(E.error.code===-32602||E.error.code===-32600)&&console.error(`[Runner] Protocol error: ${E.error.message}`)}console.log(JSON.stringify(b))}catch(E){u(E,"Error handling message"),console.error("Raw message data:",JSON.stringify(b)),console.log(JSON.stringify(b))}},await a.start(),i=!0,console.error("WebSocket connection established successfully"),await p(Buffer.from(""))},c=async()=>{console.error("Starting cleanup..."),await a.close().catch(b=>u(b,"Error during cleanup")),console.error("Cleanup completed")},h=async()=>{console.error("Shutting down WS Runner..."),await c(),process.exit(0)};return process.on("SIGINT",h),process.on("SIGTERM",h),process.stdin.on("data",b=>p(b).catch(E=>u(E,"Error processing message"))),await l(),c};var FM=ae(bv());var CM=ae(x8());var SM=async(e,t,r)=>{let n="",i=!1,a=!1,u=null,p=(E,T)=>(console.error(`[Runner] ${T}:`,E.message),E),l=async E=>{if(n+=E.toString("utf8"),!i)return;let T=n.split(/\r?\n/);n=T.pop()??"";for(let S of T.filter(Boolean))try{let C=JSON.parse(S);if(r&&Qm){let{data:q,error:P}=f8.safeParse(C);P||(0,FM.default)(Qm,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({eventName:"tool_call",payload:{connectionType:"stdio",serverQualifiedName:e.qualifiedName,toolParams:q?(0,CM.pick)(q.params,"name"):{}}})}).catch(G=>{console.error("[Runner] Analytics error:",G)})}await u?.send(C)}catch(C){p(C,"Failed to send message to child process")}},c=async()=>{console.error("[Runner] Starting child process setup...");let E=e.connections.find(Z=>Z.type==="stdio");if(!E)throw new Error("No STDIO connection found");let T=await Wf(E,t),S=await gI(e.qualifiedName,T);if(!S||"type"in S)throw new Error("Failed to get valid stdio server configuration");let{command:C,args:q=[],env:P={}}=S,G=Gf(P);M(`[Runner] Using environment: ${JSON.stringify(G,null,2)}`);let se=C,ne=q;se==="npx"&&(console.error("[Runner] Using npx path:",se),process.platform==="win32"&&(console.error("[Runner] Windows platform detected, using cmd /c for npx"),ne=["/c","npx",...ne],se="cmd")),console.error("[Runner] Executing:",{command:se,args:ne});try{u=new oo({command:se,args:ne,env:G})}catch(Z){throw console.error("For more help, see: https://smithery.ai/docs/faq/users"),Z}u.onmessage=Z=>{try{if("error"in Z){let Se=Z;Se.error.code!==Mn.MethodNotFound&&console.error("[Runner] Child process error:",Se.error)}console.log(JSON.stringify(Z))}catch(Se){p(Se,"Error handling message")}},u.onclose=()=>{console.error("[Runner] Child process terminated"),i&&!a&&(console.error("[Runner] Process terminated unexpectedly while running"),process.exit(1)),process.exit(0)},u.onerror=Z=>{console.error("[Runner] Child process error:",Z.message),Z.message.includes("spawn")?console.error("[Runner] Failed to spawn child process - check if the command exists and is executable"):Z.message.includes("permission")&&console.error("[Runner] Permission error when running child process"),process.exit(1)},await u.start(),i=!0,await l(Buffer.from(""))},h=async()=>{console.error("[Runner] Starting cleanup..."),u&&(a=!0,await u.close(),u=null),console.error("[Runner] Cleanup completed")},b=async()=>{console.error("[Runner] Shutting down STDIO Runner..."),await h(),process.exit(0)};return process.on("SIGINT",b),process.on("SIGTERM",b),process.on("beforeExit",b),process.on("exit",()=>{console.error("[Runner] Final cleanup on exit")}),process.stdin.on("data",E=>l(E).catch(T=>p(T,"Error processing message"))),await c(),h};async function AM(e,t,r){try{let n=await ha();n.success||console.warn("[Runner] Settings initialization warning:",n.error);let i=null,a=t;if(r)try{let l=await Uf(e,r);i=l.server,a={...l.config,...t},console.error("[Runner] Using saved configuration")}catch(l){console.error("[Runner] Failed to fetch config with API key:",l),console.error("[Runner] Falling back to standard resolution"),i=null}if(i||(i=await Fs(e)),!i)throw new Error(`Could not resolve server: ${e}`);console.error("[Runner] Connecting to server:",{id:i.qualifiedName,connectionTypes:i.connections.map(l=>l.type)});let p=await Qf()?await MI():void 0;await Lwe(i,a,p)}catch(n){console.error("[Runner] Fatal error:",n),process.exit(1)}}async function Lwe(e,t,r){let n=z1(e);if(n.type==="ws"){if(!n.deploymentUrl)throw new Error("Missing deployment URL");await wM(n.deploymentUrl,t)}else if(n.type==="stdio")await SM(e,t,r);else throw new Error(`Unsupported connection type: ${n.type}`)}var g4=ae(We());process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function OM(e,t){let r=Dr(`Uninstalling ${e}...`).start();try{let n=Hf(t),i=DI(e);if(!n.mcpServers[i]){r.fail(`Server ${e} is not installed for ${t}`);return}delete n.mcpServers[i],Kf(n,t),r.succeed(`Successfully uninstalled ${e}`),console.log(g4.default.green(`${e} successfully uninstalled from ${t}`)),await e4(t)}catch(n){r.fail(`Failed to uninstall ${e}`),n instanceof Error?console.error(g4.default.red(`Error: ${n.message}`)):console.error(g4.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var dx=process.argv[2],fi=process.argv[3],Vwe=process.argv.indexOf("--client"),px=process.argv.indexOf("--config"),TM=process.argv.indexOf("--key"),Uwe=process.argv.includes("--verbose"),Wwe=process.argv.includes("--help");vI(Uwe);var NM=()=>{console.log("Available commands:"),console.log(" install <server> Install a package"),console.log(" --client <name> Specify the AI client"),console.log(" --config <json> Provide configuration data as JSON (skips prompts)"),console.log(" --key <apikey> Provide an API key"),console.log(" uninstall <server> Uninstall a package"),console.log(" inspect <server> Inspect server from registry"),console.log(" run <server> Run a server"),console.log(" --config <json> Provide configuration as JSON"),console.log(" --key <apikey> Provide an API key"),console.log(" list clients List available clients"),console.log(""),console.log("Global options:"),console.log(" --help Show this help message"),console.log(" --verbose Show detailed logs"),process.exit(0)};(Wwe||!dx)&&NM();var $we=(e,t)=>{if(["run","inspect","list"].includes(e))return;t===-1&&(console.error(_4.default.yellow(`Please specify a client using --client. Valid options are: ${Js.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return Js.includes(r)||(console.error(_4.default.yellow(`Invalid client "${r}". Valid options are: ${Js.join(", ")}`)),process.exit(1)),r},qM=$we(dx,Vwe),BM=px!==-1?(()=>{try{let e=JSON.parse(process.argv[px+1]);return typeof e=="string"&&(e=JSON.parse(e)),e}catch(e){let t=e instanceof Error?e.message:String(e);console.error(_4.default.red(`Error parsing config: ${t}`)),process.exit(1)}})():{},PM=TM!==-1?process.argv[TM+1]:void 0;async function Gwe(){switch(dx){case"inspect":fi||(console.error("Please provide a server ID to inspect"),process.exit(1)),await OI(fi);break;case"install":fi||(console.error("Please provide a server ID to install"),process.exit(1)),await HI(fi,qM,px!==-1?BM:void 0,PM);break;case"uninstall":fi||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await OM(fi,qM);break;case"run":fi||(console.error("Please provide a server ID to run"),process.exit(1)),await AM(fi,BM,PM);break;case"list":await KI(fi);break;default:NM()}}Gwe();
|
|
106
|
+
For information on Smithery's data policy, please visit: ${UI.default.blue("https://smithery.ai/docs/data-policy")}`,default:!0}]),i=await kI(n);i.success||console.warn("[Smithery] Failed to save preference:",i.error)}catch(n){console.warn("[Smithery] Failed to prompt for consent:",n instanceof Error?n.message:String(n))}}var $I=ae(N1()),GI=require("node:child_process"),zI=require("node:util"),oi=(0,zI.promisify)(GI.exec);async function aEe(e){if(!e)return!1;try{let t=process.platform,r={claude:"Claude"}[e]||e;if(t==="win32"){let{stdout:n}=await oi(`tasklist /FI "IMAGENAME eq ${r}.exe" /NH`);return n.includes(`${r}.exe`)}else if(t==="darwin"){let{stdout:n}=await oi(`pgrep -x "${r}"`);return!!n.trim()}else if(t==="linux"){let{stdout:n}=await oi(`pgrep -f "${r.toLowerCase()}"`);return!!n.trim()}return!1}catch{return!1}}async function sEe(e){let t={claude:"Claude"}[e]||e;try{let r=process.platform;r==="win32"?await oi(`taskkill /F /IM "${t}.exe" && start "" "${t}.exe"`):r==="darwin"?await oi(`killall "${t}" && open -a "${t}"`):r==="linux"&&await oi(`pkill -f "${t.toLowerCase()}" && ${t.toLowerCase()}`),await new Promise(n=>setTimeout(n,2e3)),r==="win32"?await oi(`start "" "${t}.exe"`):r==="darwin"?await oi(`open -a "${t}"`):r==="linux"&&await oi(t.toLowerCase()),console.log(`${t} has been restarted.`)}catch(r){console.error(`Failed to restart ${t}:`,r)}}async function e4(e){if(!e||!await aEe(e))return!1;let{shouldRestart:r}=await $I.default.prompt([{type:"confirm",name:"shouldRestart",message:`Would you like to restart the ${e} app to apply changes?`,default:!0}]);return r&&(console.log(`Restarting ${e} app...`),await sEe(e)),r}process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function HI(e,t,r,n){M(`Starting installation of ${e} for client ${t}`),M(`Resolving package: ${e}`);let i,a;n?(M("API key provided, fetching server details and saved config"),i=Uf(e,n).then(p=>(a=p.config,p.server)).catch(p=>(console.warn(Y1.default.yellow("[Install] Failed to fetch config with API key:"),p instanceof Error?p.message:String(p)),M("Falling back to standard package resolution"),Fs(e)))):i=Fs(e);try{M("Checking analytics consent..."),await WI(),M("Analytics consent check completed")}catch(p){console.warn(Y1.default.yellow("[Analytics] Failed to check consent:"),p instanceof Error?p.message:String(p)),M(`Analytics consent check error details: ${JSON.stringify(p)}`)}let u=Dr(`Resolving ${e}...`).start();try{M("Awaiting package resolution...");let p=await i;M(`Package resolved successfully: ${p.qualifiedName}`),u.succeed(`Successfully resolved ${e}`),M("Choosing connection type...");let l=z1(p);M(`Selected connection: ${JSON.stringify(l,null,2)}`),await CI(l),await SI(l),AI(p);let c=a?{...a,...r||{}}:r,h=await $f(l,c),b=!!r;M(`Config values: ${JSON.stringify(h,null,2)}`),M(`Using config flag: ${b}`),M("Formatting server configuration...");let E=EI(e,h,n,b);M(`Formatted server config: ${JSON.stringify(E,null,2)}`),M(`Reading configuration for client: ${t}`);let T=Hf(t);M("Normalizing server ID...");let S=yI(e);M(`Normalized server ID: ${S}`),M("Updating client configuration..."),T.mcpServers[S]=E,M("Writing updated configuration..."),Kf(T,t),M("Configuration successfully written"),console.log(Y1.default.green(`${e} successfully installed for ${t}`)),M("Prompting for client restart..."),await e4(t),M("Installation process completed")}catch(p){u.fail(`Failed to install ${e}`),M(`Installation error: ${p instanceof Error?p.stack:JSON.stringify(p)}`),p instanceof Error?console.error(Y1.default.red(`Error: ${p.message}`)):console.error(Y1.default.red("An unexpected error occurred during installation")),process.exit(1)}}var t4=ae(We());async function KI(e){switch(e){case"clients":console.log(t4.default.bold("Available clients:")),Js.forEach(t=>console.log(` ${t4.default.green(t)}`));break;default:console.log(t4.default.yellow("Please specify what to list. Available options:")),console.log(" clients List available clients"),process.exit(1)}}var Pwe=ae(pM(),1),Nwe=ae(Xv(),1),Rwe=ae(tx(),1),_M=ae(m4(),1),Iwe=ae(gM(),1);var bM=_M.default;var jwe="mcp",v4=class{constructor(t){this._url=t}start(){if(this._socket)throw new Error("WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically.");return new Promise((t,r)=>{this._socket=new WebSocket(this._url,jwe),this._socket.onerror=n=>{var i;let a="error"in n?n.error:new Error(`WebSocket error: ${JSON.stringify(n)}`);r(a),(i=this.onerror)===null||i===void 0||i.call(this,a)},this._socket.onopen=()=>{t()},this._socket.onclose=()=>{var n;(n=this.onclose)===null||n===void 0||n.call(this)},this._socket.onmessage=n=>{var i,a;let u;try{u=gd.parse(JSON.parse(n.data))}catch(p){(i=this.onerror)===null||i===void 0||i.call(this,p);return}(a=this.onmessage)===null||a===void 0||a.call(this,u)}})}async close(){var t;(t=this._socket)===null||t===void 0||t.close()}send(t){return new Promise((r,n)=>{var i;if(!this._socket){n(new Error("Not connected"));return}(i=this._socket)===null||i===void 0||i.send(JSON.stringify(t)),r()})}};function DM(e,t){let r=new URL(e);if(t){let n=typeof window<"u"?btoa(JSON.stringify(t)):Buffer.from(JSON.stringify(t)).toString("base64");r.searchParams.set("config",n)}return r}var Mwe={idleTimeout:60*1e3,maxBuffer:100},x4=class{constructor(t,r,n=Mwe){this.baseUrl=t;this.config=r;this.options=n;this.realTransport=null;this.messageBuffer=[];this.idleTimer=null;this.isConnecting=!1;this.connectionPromise=null}resetIdleTimer(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>this.disconnect(),this.options.idleTimeout)}async ensureConnected(){if(this.realTransport){this.resetIdleTimer();return}if(this.connectionPromise)return this.connectionPromise;this.isConnecting=!0,this.connectionPromise=(async()=>{let t=`${this.baseUrl.replace(/^http/,"ws")}${this.baseUrl.endsWith("/")?"":"/"}ws`,r=DM(t,this.config);console.error("ProxyTransport: Creating new WebSocket connection...");let n=new v4(r);for(n.onmessage=i=>this.onmessage?.(i),n.onerror=i=>this.onerror?.(i),n.onclose=()=>{this.realTransport=null},await n.start(),this.realTransport=n,this.resetIdleTimer(),console.error("ProxyTransport: Connection established, processing buffer...");this.messageBuffer.length>0;){let i=this.messageBuffer.shift();await this.realTransport.send(i)}})();try{await this.connectionPromise}finally{this.isConnecting=!1,this.connectionPromise=null}}async disconnect(){this.realTransport&&(console.error("ProxyTransport: Closing idle connection"),await this.realTransport.close(),this.realTransport=null)}async start(){}async send(t){if(!this.realTransport&&!this.isConnecting){if(this.messageBuffer.length>=this.options.maxBuffer)throw new Error("Message buffer full");this.messageBuffer.push(t),await this.ensureConnected()}else this.isConnecting?this.messageBuffer.push(t):(await this.realTransport.send(t),this.resetIdleTimer())}async close(){await this.disconnect(),this.onclose&&this.onclose()}};global.WebSocket=bM;var yM=3,kwe=1e3,EM=(e,t)=>new x4(e,t,{idleTimeout:5*60*1e3,maxBuffer:100}),wM=async(e,t)=>{let r=0,n="",i=!1,a=EM(e,t),u=(b,E)=>(console.error(`${E}:`,b.message),b),p=async b=>{if(n+=b.toString("utf8"),!i)return;let E=n.split(/\r?\n/);n=E.pop()??"";for(let T of E.filter(Boolean))try{await a.send(JSON.parse(T))}catch(S){if(S instanceof Error&&S.message.includes("CLOSED"))throw new Error("WebSocket closed");u(S,"Failed to send message")}},l=async()=>{console.error(`Connecting to WebSocket endpoint: ${e}`),a.onclose=async()=>{console.error("WebSocket connection closed"),i=!1,r++<yM?(await new Promise(b=>setTimeout(b,kwe*Math.pow(2,r))),a=EM(e,t),await l()):(console.error(`Max reconnection attempts (${yM}) reached`),process.exit(1))},a.onerror=b=>{if(b.message.includes("502")){console.error("Server returned 502, attempting to reconnect...");return}u(b,"WebSocket connection error"),process.exit(1)},a.onmessage=b=>{try{if("error"in b){let E=b;if(E.error.code===-32e3){console.error("[Runner] Connection closed by server - attempting to reconnect..."),a.close();return}(E.error.code===-32602||E.error.code===-32600)&&console.error(`[Runner] Protocol error: ${E.error.message}`)}console.log(JSON.stringify(b))}catch(E){u(E,"Error handling message"),console.error("Raw message data:",JSON.stringify(b)),console.log(JSON.stringify(b))}},await a.start(),i=!0,console.error("WebSocket connection established successfully"),await p(Buffer.from(""))},c=async()=>{console.error("Starting cleanup..."),await a.close().catch(b=>u(b,"Error during cleanup")),console.error("Cleanup completed")},h=async()=>{console.error("Shutting down WS Runner..."),await c(),process.exit(0)};return process.on("SIGINT",h),process.on("SIGTERM",h),process.stdin.on("data",b=>p(b).catch(E=>u(E,"Error processing message"))),await l(),c};var FM=ae(bv());var CM=ae(x8());var SM=async(e,t,r)=>{let n="",i=!1,a=!1,u=null,p=(E,T)=>(console.error(`[Runner] ${T}:`,E.message),E),l=async E=>{if(n+=E.toString("utf8"),!i)return;let T=n.split(/\r?\n/);n=T.pop()??"";for(let S of T.filter(Boolean))try{let C=JSON.parse(S);if(r&&Qm){let{data:q,error:P}=f8.safeParse(C);P||(0,FM.default)(Qm,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({eventName:"tool_call",payload:{connectionType:"stdio",serverQualifiedName:e.qualifiedName,toolParams:q?(0,CM.pick)(q.params,"name"):{}}})}).catch(G=>{console.error("[Runner] Analytics error:",G)})}await u?.send(C)}catch(C){p(C,"Failed to send message to child process")}},c=async()=>{console.error("[Runner] Starting child process setup...");let E=e.connections.find(Z=>Z.type==="stdio");if(!E)throw new Error("No STDIO connection found");let T=await Wf(E,t),S=await gI(e.qualifiedName,T);if(!S||"type"in S)throw new Error("Failed to get valid stdio server configuration");let{command:C,args:q=[],env:P={}}=S,G=Gf(P);M(`[Runner] Using environment: ${JSON.stringify(G,null,2)}`);let se=C,ne=q;se==="npx"&&(console.error("[Runner] Using npx path:",se),process.platform==="win32"&&(console.error("[Runner] Windows platform detected, using cmd /c for npx"),ne=["/c","npx",...ne],se="cmd")),console.error("[Runner] Executing:",{command:se,args:ne});try{u=new oo({command:se,args:ne,env:G})}catch(Z){throw console.error("For more help, see: https://smithery.ai/docs/faq/users"),Z}u.onmessage=Z=>{try{if("error"in Z){let Se=Z;Se.error.code!==Mn.MethodNotFound&&console.error("[Runner] Child process error:",Se.error)}console.log(JSON.stringify(Z))}catch(Se){p(Se,"Error handling message")}},u.onclose=()=>{console.error("[Runner] Child process terminated"),i&&!a&&(console.error("[Runner] Process terminated unexpectedly while running"),process.exit(1)),process.exit(0)},u.onerror=Z=>{console.error("[Runner] Child process error:",Z.message),Z.message.includes("spawn")?console.error("[Runner] Failed to spawn child process - check if the command exists and is executable"):Z.message.includes("permission")&&console.error("[Runner] Permission error when running child process"),process.exit(1)},await u.start(),i=!0,await l(Buffer.from(""))},h=async()=>{console.error("[Runner] Starting cleanup..."),u&&(a=!0,await u.close(),u=null),console.error("[Runner] Cleanup completed")},b=async()=>{console.error("[Runner] Shutting down STDIO Runner..."),await h(),process.exit(0)};return process.on("SIGINT",b),process.on("SIGTERM",b),process.on("beforeExit",b),process.on("exit",()=>{console.error("[Runner] Final cleanup on exit")}),process.stdin.on("data",E=>l(E).catch(T=>p(T,"Error processing message"))),await c(),h};async function AM(e,t,r){try{let n=await ha();n.success||console.warn("[Runner] Settings initialization warning:",n.error);let i=null,a=t;if(r)try{let l=await Uf(e,r);i=l.server,a={...l.config,...t},console.error("[Runner] Using saved configuration")}catch(l){console.error("[Runner] Failed to fetch config with API key:",l),console.error("[Runner] Falling back to standard resolution"),i=null}if(i||(i=await Fs(e)),!i)throw new Error(`Could not resolve server: ${e}`);console.error("[Runner] Connecting to server:",{id:i.qualifiedName,connectionTypes:i.connections.map(l=>l.type)});let p=await Qf()?await MI():void 0;await Lwe(i,a,p)}catch(n){console.error("[Runner] Fatal error:",n),process.exit(1)}}async function Lwe(e,t,r){let n=z1(e);if(n.type==="ws"){if(!n.deploymentUrl)throw new Error("Missing deployment URL");await wM(n.deploymentUrl,t)}else if(n.type==="stdio")await SM(e,t,r);else throw new Error(`Unsupported connection type: ${n.type}`)}var g4=ae(We());process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function OM(e,t){let r=Dr(`Uninstalling ${e}...`).start();try{let n=Hf(t),i=DI(e);if(!n.mcpServers[i]){r.fail(`Server ${e} is not installed for ${t}`);return}delete n.mcpServers[i],Kf(n,t),r.succeed(`Successfully uninstalled ${e}`),console.log(g4.default.green(`${e} successfully uninstalled from ${t}`)),await e4(t)}catch(n){r.fail(`Failed to uninstall ${e}`),n instanceof Error?console.error(g4.default.red(`Error: ${n.message}`)):console.error(g4.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var dx=process.argv[2],fi=process.argv[3],Vwe=process.argv.indexOf("--client"),px=process.argv.indexOf("--config"),TM=process.argv.indexOf("--key"),Uwe=process.argv.includes("--verbose"),Wwe=process.argv.includes("--help");vI(Uwe);var NM=()=>{console.log("Available commands:"),console.log(" install <server> Install a package"),console.log(" --client <name> Specify the AI client"),console.log(" --config <json> Provide configuration data as JSON (skips prompts)"),console.log(" --key <apikey> Provide an API key"),console.log(" uninstall <server> Uninstall a package"),console.log(" inspect <server> Inspect server from registry"),console.log(" run <server> Run a server"),console.log(" --config <json> Provide configuration as JSON"),console.log(" --key <apikey> Provide an API key"),console.log(" list clients List available clients"),console.log(""),console.log("Global options:"),console.log(" --help Show this help message"),console.log(" --verbose Show detailed logs"),process.exit(0)};(Wwe||!dx)&&NM();var $we=(e,t)=>{if(["run","inspect","list"].includes(e))return;t===-1&&(console.error(_4.default.yellow(`Please specify a client using --client. Valid options are: ${Js.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return Js.includes(r)||(console.error(_4.default.yellow(`Invalid client "${r}". Valid options are: ${Js.join(", ")}`)),process.exit(1)),r},qM=$we(dx,Vwe),BM=px!==-1?(()=>{try{let e=JSON.parse(process.argv[px+1]);return typeof e=="string"&&(e=JSON.parse(e)),e}catch(e){let t=e instanceof Error?e.message:String(e);console.error(_4.default.red(`Error parsing config: ${t}`)),process.exit(1)}})():{},PM=TM!==-1?process.argv[TM+1]:void 0;async function Gwe(){switch(dx){case"inspect":fi||(console.error("Please provide a server ID to inspect"),process.exit(1)),await OI(fi);break;case"install":fi||(console.error("Please provide a server ID to install"),process.exit(1)),await HI(fi,qM,px!==-1?BM:void 0,PM);break;case"uninstall":fi||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await OM(fi,qM);break;case"run":fi||(console.error("Please provide a server ID to run"),process.exit(1)),await AM(fi,BM,PM);break;case"list":await KI(fi);break;default:NM()}}Gwe();
|
|
107
107
|
/*! Bundled license information:
|
|
108
108
|
|
|
109
109
|
lodash/lodash.js:
|