@smithery/cli 1.1.44 → 1.1.45
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/README.md +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npx @smithery/cli <command>
|
|
|
14
14
|
### Available Commands
|
|
15
15
|
|
|
16
16
|
- `install <package>` - Install a package
|
|
17
|
-
- `--client <name>` - Specify the AI client
|
|
17
|
+
- `--client <name>` - Specify the AI client
|
|
18
18
|
- `--config <json>` - Provide configuration data as JSON (skips prompts)
|
|
19
19
|
- `uninstall <package>` - Uninstall a package
|
|
20
20
|
- `--client <name>` - Specify the AI client
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ Fix with: chmod 700 "${e}"
|
|
|
103
103
|
Or use: export SMITHERY_CONFIG_PATH="/custom/path"
|
|
104
104
|
Running in memory-only mode (settings won't persist).`,qv=async(e,t)=>{k(`Saving settings to ${t}`),k(`Settings data: ${JSON.stringify(e,null,2)}`);try{try{k(`Ensuring directory exists: ${t}`),await Yf.promises.mkdir(t,{recursive:!0}),k("Directory check completed")}catch(n){if(k(`Directory creation error: ${JSON.stringify(n)}`),n instanceof Error&&"code"in n&&n.code==="EACCES")return{success:!1,error:Tv(t,"write")};throw n}let r=(0,Fs.join)(t,"settings.json");return k(`Writing settings to file: ${r}`),await Yf.promises.writeFile(r,JSON.stringify(e,null,2)),k("Settings successfully written"),{success:!0,data:e}}catch(r){return k(`Settings save error: ${JSON.stringify(r)}`),{success:!1,error:r instanceof Error&&"code"in r&&r.code==="EACCES"?Tv(t,"write"):`Failed to save settings: ${r instanceof Error?r.message:String(r)}`}}},Kye=async e=>{k(`Loading settings from ${e}`);try{let t=(0,Fs.join)(e,"settings.json");k(`Reading settings file: ${t}`);try{let r=await Yf.promises.readFile(t,"utf-8");k("Settings file content loaded");let n=JSON.parse(r);if(k(`Settings parsed: ${JSON.stringify(n,null,2)}`),!Hye(n)){k("Settings validation failed, fixing settings");let i={...Zf(),...n};return i.analyticsConsent&&(i.askedConsent=!0),k(`Fixed settings: ${JSON.stringify(i,null,2)}`),await qv(i,e),{success:!0,data:i}}return{success:!0,data:n}}catch(r){if(k(`Settings read error: ${JSON.stringify(r)}`),r instanceof Error&&"code"in r){if(r.code==="ENOENT"){k("Settings file not found, creating default settings");let n=Zf();return k(`Default settings: ${JSON.stringify(n,null,2)}`),await qv(n,e)}if(r.code==="EACCES")return{success:!1,error:Tv(e,"read")}}throw r}}catch(t){return k(`Settings load error: ${JSON.stringify(t)}`),{success:!1,error:`Failed to load settings: ${t instanceof Error?t.message:String(t)}`}}},ha=async()=>{if(Ov&&ai)return{success:!0,data:ai};try{let e=jI(),t=await Kye(e);return t.success&&t.data&&(ai=t.data),Ov=!0,t}catch(e){return ai=Zf(),Ov=!0,{success:!0,data:ai,error:`Warning: Running in memory-only mode - ${e instanceof Error?e.message:String(e)}`}}},MI=async()=>(await ha(),ai?.userId||Zf().userId),Jf=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:(ai={...t.data,analyticsConsent:e,askedConsent:!0},await qv(ai,jI()))},LI=async()=>(await ha(),ai?.askedConsent||!1);async function WI(){let e=await ha();if(!e.success){console.warn("[Analytics] Failed to initialize settings:",e.error);return}if(await Jf())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?
|
|
105
105
|
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(Po()),GI=require("node:child_process"),zI=require("node:util"),si=(0,zI.promisify)(GI.exec);async function Yye(e){if(!e)return!1;try{let t=process.platform,r={claude:"Claude"}[e]||e;if(t==="win32"){let{stdout:n}=await si(`tasklist /FI "IMAGENAME eq ${r}.exe" /NH`);return n.includes(`${r}.exe`)}else if(t==="darwin"){let{stdout:n}=await si(`pgrep -x "${r}"`);return!!n.trim()}else if(t==="linux"){let{stdout:n}=await si(`pgrep -f "${r.toLowerCase()}"`);return!!n.trim()}return!1}catch{return!1}}async function Zye(e){let t={claude:"Claude"}[e]||e;try{let r=process.platform;r==="win32"?await si(`taskkill /F /IM "${t}.exe" && start "" "${t}.exe"`):r==="darwin"?await si(`killall "${t}" && open -a "${t}"`):r==="linux"&&await si(`pkill -f "${t.toLowerCase()}" && ${t.toLowerCase()}`),await new Promise(n=>setTimeout(n,2e3)),r==="win32"?await si(`start "" "${t}.exe"`):r==="darwin"?await si(`open -a "${t}"`):r==="linux"&&await si(t.toLowerCase()),console.log(`${t} has been restarted.`)}catch(r){console.error(`Failed to restart ${t}:`,r)}}async function Xf(e){if(!e||!await Yye(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 Zye(e)),r}process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});function Jye(e,t){let r=JSON.stringify(JSON.stringify(t)),n=["-y","@smithery/cli@latest","run",e,"--config",r];return process.platform==="win32"?{command:"cmd",args:["/c","npx",...n]}:{command:"npx",args:n}}async function HI(e,t,r){k(`Starting installation of ${e} for client ${t}`),k(`Resolving package: ${e}`);let n=Go(e);try{k("Checking analytics consent..."),await WI(),k("Analytics consent check completed")}catch(a){console.warn(oi.default.yellow("[Analytics] Failed to check consent:"),a instanceof Error?a.message:String(a)),k(`Analytics consent check error details: ${JSON.stringify(a)}`)}let i=Dr(`Resolving ${e}...`).start();try{k("Awaiting package resolution...");let a=await n;k(`Package resolved successfully: ${a.qualifiedName}`),i.succeed(`Successfully resolved ${e}`),k("Choosing connection type...");let u=zo(a);k(`Selected connection: ${JSON.stringify(u,null,2)}`),FI(u)&&(k("UV installation check required"),await EI()||await wI()||console.warn(oi.default.yellow("UV is not installed. The server might fail to launch."))),AI(u)&&(k("Bun installation check required"),await CI()||await SI()||console.warn(oi.default.yellow("Bun is not installed. The server might fail to launch."))),a.connections.some(w=>w.type==="ws"&&"deploymentUrl"in w)&&a.remote!==!1&&(k("Remote server detected, showing security notice"),console.log(oi.default.blue(`Installing remote server. Please ensure you trust the server author, especially when sharing sensitive data.
|
|
106
|
-
For information on Smithery's data policy, please visit: ${oi.default.underline("https://smithery.ai/docs/data-policy")}`))),k(r?"Using provided config values":"Collecting config values from user");let l=await Vf(u,r);k(`Config values: ${JSON.stringify(l,null,2)}`),k("Formatting server configuration...");let c=Jye(e,l);k(`Formatted server config: ${JSON.stringify(c,null,2)}`),k(`Reading configuration for client: ${t}`);let h=Gf(t);k("Normalizing server ID...");let b=Uf(e);k(`Normalized server ID: ${b}`),k("Updating client configuration..."),h.mcpServers[b]=c,k("Writing updated configuration..."),zf(h,t),k("Configuration successfully written"),console.log(oi.default.green(`${e} successfully installed for ${t}`)),k("Prompting for client restart..."),await Xf(t),k("Installation process completed")}catch(a){i.fail(`Failed to install ${e}`),k(`Installation error: ${a instanceof Error?a.stack:JSON.stringify(a)}`),a instanceof Error?console.error(oi.default.red(`Error: ${a.message}`)):console.error(oi.default.red("An unexpected error occurred during installation")),process.exit(1)}}var Qf=ae(We());async function KI(e){switch(e){case"clients":console.log(Qf.default.bold("Available clients:")),Zs.forEach(t=>console.log(` ${Qf.default.green(t)}`));break;default:console.log(Qf.default.yellow("Please specify what to list. Available options:")),console.log(" clients List available clients"),process.exit(1)}}var wwe=ae(pM(),1),Fwe=ae(Zv(),1),Cwe=ae(Qv(),1),gM=ae(c4(),1),Swe=ae(_M(),1);var bM=gM.default;var Awe="mcp",m4=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,Awe),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=_d.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 Owe={idleTimeout:60*1e3,maxBuffer:100},h4=class{constructor(t,r,n=Owe){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 m4(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,Twe=1e3,EM=(e,t)=>new h4(e,t,{idleTimeout:5*60*1e3,maxBuffer:100}),wM=async(e,t)=>{let r=0,n="",i=!1,a=EM(e,t),u=(b,w)=>(console.error(`${w}:`,b.message),b),p=async b=>{if(n+=b.toString("utf8"),!i)return;let w=n.split(/\r?\n/);n=w.pop()??"";for(let T of w.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,Twe*Math.pow(2,r))),a=EM(e,t),await l()):(console.error(`Max reconnection attempts (${yM}) reached`),process.exit(1))},a.onerror=b=>{u(b,"WebSocket connection error"),process.exit(1)},a.onmessage=b=>{try{"error"in b&&(console.error(`WebSocket error: ${JSON.stringify(b.error)}`),(b.error.message==="Missing configuration"||b.error.message==="Invalid configuration")&&process.exit(1)),console.log(JSON.stringify(b))}catch(w){u(w,"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(w=>u(w,"Error processing message"))),await l(),c};var FM=ae(xv());var CM=ae(m8()),SM=async(e,t,r)=>{let n="",i=!1,a=!1,u=null,p=(w,T)=>(console.error(`[Runner] ${T}:`,w.message),w),l=async w=>{if(n+=w.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&&Zm){let{data:q,error:P}=d8.safeParse(C);P||(0,FM.default)(Zm,{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 w=e.connections.find(Z=>Z.type==="stdio");if(!w)throw new Error("No STDIO connection found");let T=await bI(w,t),S=await _I(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=Wf(P);console.error("[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 s1({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",w=>l(w).catch(T=>p(T,"Error processing message"))),await c(),h};async function AM(e,t){try{let r=await ha();r.success||console.warn("[Runner] Settings initialization warning:",r.error);let n=await Go(e);if(!n)throw new Error(`Could not resolve server: ${e}`);console.error("[Runner] Connecting to server:",{id:n.qualifiedName,connectionTypes:n.connections.map(u=>u.type)});let a=await Jf()?await MI():void 0;await qwe(n,t,a)}catch(r){console.error("[Runner] Fatal error:",r),process.exit(1)}}async function qwe(e,t,r){let n=zo(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 v4=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=Gf(t),i=Uf(e);if(!n.mcpServers[i]){r.fail(`Server ${e} is not installed for ${t}`);return}delete n.mcpServers[i],zf(n,t),r.succeed(`Successfully uninstalled ${e}`),console.log(v4.default.green(`${e} successfully uninstalled from ${t}`)),await Xf(t)}catch(n){r.fail(`Failed to uninstall ${e}`),n instanceof Error?console.error(v4.default.red(`Error: ${n.message}`)):console.error(v4.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var px=process.argv[2],fi=process.argv[3],Bwe=process.argv.indexOf("--client"),ux=process.argv.indexOf("--config"),Pwe=process.argv.includes("--verbose"),Nwe=process.argv.includes("--help");hI(Pwe);var BM=()=>{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(" 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(" 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)};(Nwe||!px)&&BM();var Rwe=(e,t)=>{if(["run","inspect","list"].includes(e))return;t===-1&&(console.error(ox.default.yellow(`Please specify a client using --client. Valid options are: ${Zs.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return Zs.includes(r)||(console.error(ox.default.yellow(`Invalid client "${r}". Valid options are: ${Zs.join(", ")}`)),process.exit(1)),r},TM=Rwe(px,Bwe),qM=ux!==-1?(()=>{let e=JSON.parse(process.argv[ux+1]);return typeof e=="string"&&(e=JSON.parse(e)),e})():{};async function Iwe(){switch(px){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,TM,ux!==-1?qM:void 0);break;case"uninstall":fi||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await OM(fi,TM);break;case"run":fi||(console.error("Please provide a server ID to run"),process.exit(1)),await AM(fi,qM);break;case"list":await KI(fi);break;default:BM()}}Iwe();
|
|
106
|
+
For information on Smithery's data policy, please visit: ${oi.default.underline("https://smithery.ai/docs/data-policy")}`))),k(r?"Using provided config values":"Collecting config values from user");let l=await Vf(u,r);k(`Config values: ${JSON.stringify(l,null,2)}`),k("Formatting server configuration...");let c=Jye(e,l);k(`Formatted server config: ${JSON.stringify(c,null,2)}`),k(`Reading configuration for client: ${t}`);let h=Gf(t);k("Normalizing server ID...");let b=Uf(e);k(`Normalized server ID: ${b}`),k("Updating client configuration..."),h.mcpServers[b]=c,k("Writing updated configuration..."),zf(h,t),k("Configuration successfully written"),console.log(oi.default.green(`${e} successfully installed for ${t}`)),k("Prompting for client restart..."),await Xf(t),k("Installation process completed")}catch(a){i.fail(`Failed to install ${e}`),k(`Installation error: ${a instanceof Error?a.stack:JSON.stringify(a)}`),a instanceof Error?console.error(oi.default.red(`Error: ${a.message}`)):console.error(oi.default.red("An unexpected error occurred during installation")),process.exit(1)}}var Qf=ae(We());async function KI(e){switch(e){case"clients":console.log(Qf.default.bold("Available clients:")),Zs.forEach(t=>console.log(` ${Qf.default.green(t)}`));break;default:console.log(Qf.default.yellow("Please specify what to list. Available options:")),console.log(" clients List available clients"),process.exit(1)}}var wwe=ae(pM(),1),Fwe=ae(Zv(),1),Cwe=ae(Qv(),1),gM=ae(c4(),1),Swe=ae(_M(),1);var bM=gM.default;var Awe="mcp",m4=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,Awe),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=_d.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 Owe={idleTimeout:60*1e3,maxBuffer:100},h4=class{constructor(t,r,n=Owe){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 m4(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,Twe=1e3,EM=(e,t)=>new h4(e,t,{idleTimeout:5*60*1e3,maxBuffer:100}),wM=async(e,t)=>{let r=0,n="",i=!1,a=EM(e,t),u=(b,w)=>(console.error(`${w}:`,b.message),b),p=async b=>{if(n+=b.toString("utf8"),!i)return;let w=n.split(/\r?\n/);n=w.pop()??"";for(let T of w.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,Twe*Math.pow(2,r))),a=EM(e,t),await l()):(console.error(`Max reconnection attempts (${yM}) reached`),process.exit(1))},a.onerror=b=>{u(b,"WebSocket connection error"),process.exit(1)},a.onmessage=b=>{try{"error"in b&&(console.error(`WebSocket error: ${JSON.stringify(b.error)}`),(b.error.message==="Missing configuration"||b.error.message==="Invalid configuration")&&process.exit(1)),console.log(JSON.stringify(b))}catch(w){u(w,"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(w=>u(w,"Error processing message"))),await l(),c};var FM=ae(xv());var CM=ae(m8());var SM=async(e,t,r)=>{let n="",i=!1,a=!1,u=null,p=(w,T)=>(console.error(`[Runner] ${T}:`,w.message),w),l=async w=>{if(n+=w.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&&Zm){let{data:q,error:P}=d8.safeParse(C);P||(0,FM.default)(Zm,{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 w=e.connections.find(Z=>Z.type==="stdio");if(!w)throw new Error("No STDIO connection found");let T=await bI(w,t),S=await _I(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=Wf(P);k("[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 s1({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",w=>l(w).catch(T=>p(T,"Error processing message"))),await c(),h};async function AM(e,t){try{let r=await ha();r.success||console.warn("[Runner] Settings initialization warning:",r.error);let n=await Go(e);if(!n)throw new Error(`Could not resolve server: ${e}`);console.error("[Runner] Connecting to server:",{id:n.qualifiedName,connectionTypes:n.connections.map(u=>u.type)});let a=await Jf()?await MI():void 0;await qwe(n,t,a)}catch(r){console.error("[Runner] Fatal error:",r),process.exit(1)}}async function qwe(e,t,r){let n=zo(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 v4=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=Gf(t),i=Uf(e);if(!n.mcpServers[i]){r.fail(`Server ${e} is not installed for ${t}`);return}delete n.mcpServers[i],zf(n,t),r.succeed(`Successfully uninstalled ${e}`),console.log(v4.default.green(`${e} successfully uninstalled from ${t}`)),await Xf(t)}catch(n){r.fail(`Failed to uninstall ${e}`),n instanceof Error?console.error(v4.default.red(`Error: ${n.message}`)):console.error(v4.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var px=process.argv[2],fi=process.argv[3],Bwe=process.argv.indexOf("--client"),ux=process.argv.indexOf("--config"),Pwe=process.argv.includes("--verbose"),Nwe=process.argv.includes("--help");hI(Pwe);var BM=()=>{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(" 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(" 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)};(Nwe||!px)&&BM();var Rwe=(e,t)=>{if(["run","inspect","list"].includes(e))return;t===-1&&(console.error(ox.default.yellow(`Please specify a client using --client. Valid options are: ${Zs.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return Zs.includes(r)||(console.error(ox.default.yellow(`Invalid client "${r}". Valid options are: ${Zs.join(", ")}`)),process.exit(1)),r},TM=Rwe(px,Bwe),qM=ux!==-1?(()=>{let e=JSON.parse(process.argv[ux+1]);return typeof e=="string"&&(e=JSON.parse(e)),e})():{};async function Iwe(){switch(px){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,TM,ux!==-1?qM:void 0);break;case"uninstall":fi||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await OM(fi,TM);break;case"run":fi||(console.error("Please provide a server ID to run"),process.exit(1)),await AM(fi,qM);break;case"list":await KI(fi);break;default:BM()}}Iwe();
|
|
107
107
|
/*! Bundled license information:
|
|
108
108
|
|
|
109
109
|
lodash/lodash.js:
|