@smithery/cli 1.1.63 → 1.1.64
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).`,Gv=async(e,t)=>{k(`Saving settings to ${t}`),k(`Settings data: ${JSON.stringify(e,null,2)}`);try{try{k(`Ensuring directory exists: ${t}`),await n4.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:$v(t,"write")};throw n}let r=(0,Ss.join)(t,"settings.json");return k(`Writing settings to file: ${r}`),await n4.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"?$v(t,"write"):`Failed to save settings: ${r instanceof Error?r.message:String(r)}`}}},qwe=async e=>{k(`Loading settings from ${e}`);try{let t=(0,Ss.join)(e,"settings.json");k(`Reading settings file: ${t}`);try{let r=await n4.promises.readFile(t,"utf-8");k("Settings file content loaded");let n=JSON.parse(r);if(k(`Settings parsed: ${JSON.stringify(n,null,2)}`),!Twe(n)){k("Settings validation failed, fixing settings");let i={...Wv(),...n};return i.analyticsConsent&&(i.askedConsent=!0),k(`Fixed settings: ${JSON.stringify(i,null,2)}`),await Gv(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=Wv();return k(`Default settings: ${JSON.stringify(n,null,2)}`),await Gv(n,e)}if(r.code==="EACCES")return{success:!1,error:$v(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)}`}}},As=async()=>{if(Uv&&ma)return{success:!0,data:ma};try{let e=kj(),t=await qwe(e);return t.success&&t.data&&(ma=t.data),Uv=!0,t}catch(e){return ma=Wv(),Uv=!0,{success:!0,data:ma,error:`Warning: Running in memory-only mode - ${e instanceof Error?e.message:String(e)}`}}};var i4=async()=>{let e=await As();return!e.success||!e.data?(console.warn("[Config] Failed to load analytics settings:",e.error),!1):e.data.analyticsConsent},Mj=async e=>{let t=await As();return!t.success||!t.data?t:(ma={...t.data,analyticsConsent:e,askedConsent:!0},await Gv(ma,kj()))},Lj=async()=>(await As(),ma?.askedConsent||!1);async function Wj(){let e=await As();if(!e.success){console.warn("[Analytics] Failed to initialize settings:",e.error);return}if(await i4())return;if(!await Lj())try{let{EnableAnalytics:n}=await Vj.default.prompt([{type:"confirm",name:"EnableAnalytics",message:`Would you like to help improve Smithery by sending anonymized usage data?
|
|
106
|
-
For information on Smithery's data policy, please visit: ${Uj.default.blue("https://smithery.ai/docs/data-policy")}`,default:!0}]),i=await Mj(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 $j=ie(j1()),Gj=require("node:child_process"),zj=require("node:util"),oi=(0,zj.promisify)(Gj.exec);async function Bwe(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 Pwe(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 a4(e){if(!e||!await Bwe(e))return!1;let{shouldRestart:r}=await $j.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 Pwe(e)),r}process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function Hj(e,t,r,n){k(`Starting installation of ${e} for client ${t}`),k(`Resolving package: ${e}`);let i,a;n?(k("API key provided, fetching server details and saved config"),i=Y6(e,n).then(p=>(a=p.config,p.server)).catch(p=>(console.warn(e0.default.yellow("[Install] Failed to fetch config with API key:"),p instanceof Error?p.message:String(p)),k("Falling back to standard package resolution"),Cs(e)))):i=Cs(e);try{k("Checking analytics consent..."),await Wj(),k("Analytics consent check completed")}catch(p){console.warn(e0.default.yellow("[Analytics] Failed to check consent:"),p instanceof Error?p.message:String(p)),k(`Analytics consent check error details: ${JSON.stringify(p)}`)}let u=bn(`Resolving ${e}...`).start();try{k("Awaiting package resolution...");let p=await i;k(`Package resolved successfully: ${p.qualifiedName}`),u.succeed(`Successfully resolved ${e}`),k("Choosing connection type...");let l=Y1(p);k(`Selected connection: ${JSON.stringify(l,null,2)}`),await Sj(l),await Aj(l),Oj(p);let c=a?{...a,...r||{}}:r,h=await J6(l,c),b=!!r;k(`Config values: ${JSON.stringify(h,null,2)}`),k(`Using config flag: ${b}`),k("Formatting server configuration...");let F=wj(e,h,n,b);k(`Formatted server config: ${JSON.stringify(F,null,2)}`),k(`Reading configuration for client: ${t}`);let A=X1(t);k("Normalizing server ID...");let w=Ej(e);k(`Normalized server ID: ${w}`),k("Updating client configuration..."),A.mcpServers[w]=F,k("Writing updated configuration..."),e4(A,t),k("Configuration successfully written"),console.log(e0.default.green(`${e} successfully installed for ${t}`)),k("Prompting for client restart..."),await a4(t),k("Installation process completed")}catch(p){u.fail(`Failed to install ${e}`),k(`Installation error: ${p instanceof Error?p.stack:JSON.stringify(p)}`),p instanceof Error?console.error(e0.default.red(`Error: ${p.message}`)):console.error(e0.default.red("An unexpected error occurred during installation")),process.exit(1)}}var ha=ie(We());async function Kj(e,t){switch(e){case"clients":console.log(ha.default.bold("Available clients:")),Qs.forEach(r=>console.log(` ${ha.default.green(r)}`));break;case"servers":{if(J1(t).type==="command"){console.log(ha.default.yellow(`Listing servers is currently not supported for ${t}`));return}let n=X1(t),i=Object.keys(n.mcpServers);if(i?.length>0)console.log(ha.default.bold(`Installed servers for ${t}:`)),i.sort().forEach(a=>{console.log(`${ha.default.green(a)}`)});else{let a=`No installed servers found for ${t}`;console.log(`${ha.default.red(a)}`)}break}default:console.log(ha.default.yellow("Please specify what to list. Available options:")),console.log(" clients List available clients"),console.log(" servers List installed servers"),process.exit(1)}}var Yj=ie(qv()),Zj=ie(A8());var Jj=async(e,t,r,n)=>{let i="",a=!1,u=!1,p=null,l=(A,w)=>(console.error(`[Runner] ${w}:`,A.message),A),c=async A=>{if(i+=A.toString("utf8"),!a)return;let w=i.split(/\r?\n/);i=w.pop()??"";for(let C of w.filter(Boolean))try{let q=JSON.parse(C);if(n&&r&&t8){let{data:P,error:G}=h8.safeParse(q);G||(0,Yj.default)(t8,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({eventName:"tool_call",payload:{connectionType:"stdio",serverQualifiedName:e.qualifiedName,toolParams:P?(0,Zj.pick)(P.params,"name"):{}}})}).catch(pe=>{console.error("[Runner] Analytics error:",pe)})}await p?.send(q)}catch(q){l(q,"Failed to send message to child process")}},h=async()=>{console.error("[Runner] Starting child process setup...");let A=e.connections.find(me=>me.type==="stdio");if(!A)throw new Error("No STDIO connection found");let w=await Z6(A,t),C=await bj(e.qualifiedName,w);if(!C||"type"in C)throw new Error("Failed to get valid stdio server configuration");let{command:q,args:P=[],env:G={}}=C,pe=X6(G);k(`[Runner] Using environment: ${JSON.stringify(pe,null,2)}`);let re=q,te=P;re==="npx"&&(console.error("[Runner] Using npx path:",re),process.platform==="win32"&&(console.error("[Runner] Windows platform detected, using cmd /c for npx"),te=["/c","npx",...te],re="cmd")),console.error("[Runner] Executing:",{command:re,args:te});try{p=new lo({command:re,args:te,env:pe})}catch(me){throw console.error("For more help, see: https://smithery.ai/docs/faq/users"),me}p.onmessage=me=>{try{if("error"in me){let rt=me;rt.error.code!==rn.MethodNotFound&&console.error("[Runner] Child process error:",rt.error)}console.log(JSON.stringify(me))}catch(rt){l(rt,"Error handling message")}},p.onclose=()=>{console.error("[Runner] Child process terminated"),a&&!u&&(console.error("[Runner] Process terminated unexpectedly while running"),F().catch(me=>{console.error("[Runner] Error during exit cleanup:",me),process.exit(1)}))},p.onerror=me=>{console.error("[Runner] Child process error:",me.message),me.message.includes("spawn")?console.error("[Runner] Failed to spawn child process - check if the command exists and is executable"):me.message.includes("permission")&&console.error("[Runner] Permission error when running child process"),F().catch(rt=>{console.error("[Runner] Error during error cleanup:",rt),process.exit(1)})},await p.start(),a=!0,await c(Buffer.from(""))},b=async()=>{if(u){console.error("[Runner] Cleanup already in progress, skipping...");return}if(console.error("[Runner] Starting cleanup..."),u=!0,p){try{console.error("[Runner] Attempting to close transport..."),await Promise.race([p.close(),new Promise((A,w)=>setTimeout(()=>w(new Error("Transport close timeout")),3e3))]),console.error("[Runner] Transport closed successfully")}catch(A){console.error("[Runner] Error during transport cleanup:",A)}p=null}console.error("[Runner] Cleanup completed")},F=async()=>{console.error("[Runner] Exit handler triggered, starting shutdown..."),await b(),u||process.exit(0)};return process.on("SIGINT",F),process.on("SIGTERM",F),process.on("beforeExit",F),process.on("exit",()=>{console.error("[Runner] Final cleanup on exit")}),process.stdin.on("end",()=>{console.error("[Runner] STDIN closed (client disconnected)"),F().catch(A=>{console.error("[Runner] Error during stdin close cleanup:",A),process.exit(1)})}),process.stdin.on("error",A=>{console.error("[Runner] STDIN error:",A),F().catch(w=>{console.error("[Runner] Error during stdin error cleanup:",w),process.exit(1)})}),process.stdin.on("data",A=>c(A).catch(w=>l(w,"Error processing message"))),await h(),b};var Nwe="mcp",s4=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,Nwe),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=wd.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 Xj(e,t,r){let n=new URL(e);if(t){let i=typeof window<"u"?btoa(JSON.stringify(t)):Buffer.from(JSON.stringify(t)).toString("base64");n.searchParams.set("config",i)}return r&&n.searchParams.set("api_key",r),n}var oCe=ie(fM(),1),uCe=ie(dx(),1),pCe=ie(fx(),1),EM=ie(_4(),1),dCe=ie(yM(),1);var wM=EM.default;global.WebSocket=wM;var Dx=3,lCe=1e3,FM=(e,t,r)=>{let n=`${e.replace(/^http/,"ws")}${e.endsWith("/")?"":"/"}ws`,i=Xj(n,t,r);return new s4(i)},cCe=(e,t)=>{switch(e.error.code){case-32e3:console.error("[Runner] Connection closed by server - attempting to reconnect..."),t.close();return;case-32700:case-32600:case-32601:case-32602:case-32603:console.error(e.error.message);return;default:console.error(`[Runner] Unexpected error: ${JSON.stringify(e.error)}`),process.exit(1)}},CM=async(e,t,r)=>{let n=0,i="",a=!1,u=!1,p=!1,l=FM(e,t,r),c=(w,C)=>(console.error(`${C}:`,w.message),w),h=async w=>{if(i+=w.toString("utf8"),!a)return;let C=i.split(/\r?\n/);i=C.pop()??"";for(let q of C.filter(Boolean))try{await l.send(JSON.parse(q))}catch(P){if(P instanceof Error&&P.message.includes("CLOSED"))throw new Error("WebSocket closed");c(P,"Failed to send message")}},b=async()=>{console.error(`[Runner] Connecting to WebSocket endpoint: ${e}`),l.onclose=async()=>{if(console.error("[Runner] WebSocket connection closed"),a=!1,!p&&n++<Dx){console.error(`[Runner] Unexpected disconnect, attempting reconnect (attempt ${n} of ${Dx})...`);let w=Math.random()*1e3,C=lCe*Math.pow(2,n)+w;await new Promise(q=>setTimeout(q,C)),l=FM(e,t,r),await b()}else p?(console.error("[Runner] Clean shutdown, not attempting reconnect"),process.exit(0)):(console.error(`[Runner] Max reconnection attempts (${Dx}) reached`),process.exit(1))},l.onerror=w=>{if(w.message.includes("502")){console.error("[Runner] Server returned 502, attempting to reconnect...");return}c(w,"WebSocket connection error"),process.exit(1)},l.onmessage=w=>{try{"error"in w&&cCe(w,l),console.log(JSON.stringify(w))}catch(C){c(C,"Error handling message"),console.error("[Runner] Message:",JSON.stringify(w)),console.log(JSON.stringify(w))}},await l.start(),a=!0,console.error("[Runner] WebSocket connection initiated"),await h(Buffer.from("")),console.error("[Runner] WebSocket connection established")},F=async()=>{if(u){console.error("[Runner] Cleanup already in progress, skipping...");return}console.error("[Runner] Starting cleanup..."),u=!0,p=!0;try{console.error("[Runner] Attempting to close transport..."),await Promise.race([l.close(),new Promise((w,C)=>setTimeout(()=>C(new Error("[Runner] Transport close timeout")),3e3))]),console.error("[Runner] Transport closed successfully")}catch(w){c(w,"[Runner] Error during cleanup")}console.error("[Runner] Cleanup completed")},A=async()=>{console.error("[Runner] Shutting down WS Runner..."),p=!0,await F(),u||process.exit(0)};return process.on("SIGINT",A),process.on("SIGTERM",A),process.on("beforeExit",A),process.on("exit",()=>{console.error("[Runner] Final cleanup on exit")}),process.stdin.on("end",()=>{console.error("STDIN closed (client disconnected)"),A().catch(w=>{console.error("[Runner] Error during stdin close cleanup:",w),process.exit(1)})}),process.stdin.on("error",w=>{console.error("[Runner] STDIN error:",w),A().catch(C=>{console.error("[Runner] Error during stdin error cleanup:",C),process.exit(1)})}),process.stdin.on("data",w=>h(w).catch(C=>c(C,"[Runner] Error processing message"))),await b(),F};async function SM(e,t,r){try{let n=await As();n.success||console.warn("[Runner] Settings initialization warning:",n.error);let i=null,a=t;if(r)try{let p=await Y6(e,r);i=p.server,a={...p.config,...t},console.error("[Runner] Using saved configuration")}catch(p){console.error("[Runner] Failed to fetch config with API key:",p),console.error("[Runner] Falling back to standard resolution"),i=null}if(i||(i=await Cs(e)),!i)throw new Error(`Could not resolve server: ${e}`);console.error("[Runner] Connecting to server:",{id:i.qualifiedName,connectionTypes:i.connections.map(p=>p.type)});let u=await i4();await fCe(i,a,r,u)}catch(n){console.error("[Runner] Fatal error:",n),process.exit(1)}}async function fCe(e,t,r,n){let i=Y1(e);if(i.type==="ws"){if(!i.deploymentUrl)throw new Error("Missing deployment URL");await CM(i.deploymentUrl,t,r)}else if(i.type==="stdio")await Jj(e,t,r,n);else throw new Error(`Unsupported connection type: ${i.type}`)}var s0=ie(We());process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function AM(e,t){try{if(J1(t).type==="command"){console.log(s0.default.yellow(`Uninstallation is currently not supported for ${t}`));return}let n=X1(t);if(!n.mcpServers[e]){console.log(s0.default.red(`Server ${e} is not installed for ${t}`));return}delete n.mcpServers[e],e4(n,t),console.log(s0.default.green(`${e} successfully uninstalled from ${t}`)),await a4(t)}catch(r){r instanceof Error?console.error(s0.default.red(`Error: ${r.message}`)):console.error(s0.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var wx=process.argv[2],Fn=process.argv[3],mCe=process.argv.indexOf("--client"),Ex=process.argv.indexOf("--config"),OM=process.argv.indexOf("--key"),hCe=process.argv.includes("--verbose"),vCe=process.argv.includes("--help");gj(hCe);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(" --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(" list servers List installed servers"),console.log(""),console.log("Global options:"),console.log(" --help Show this help message"),console.log(" --verbose Show detailed logs"),process.exit(0)};(vCe||!wx)&&BM();var xCe=(e,t)=>{if(["run","inspect"].includes(e)||e==="list"&&Fn==="clients")return;t===-1&&(console.error(D4.default.yellow(`Please specify a client using --client. Valid options are: ${Qs.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return Qs.includes(r)||(console.error(D4.default.yellow(`Invalid client "${r}". Valid options are: ${Qs.join(", ")}`)),process.exit(1)),r},yx=xCe(wx,mCe),TM=Ex!==-1?(()=>{try{let e=JSON.parse(process.argv[Ex+1]);return typeof e=="string"&&(e=JSON.parse(e)),e}catch(e){let t=e instanceof Error?e.message:String(e);console.error(D4.default.red(`Error parsing config: ${t}`)),process.exit(1)}})():{},qM=OM!==-1?process.argv[OM+1]:void 0;async function gCe(){switch(wx){case"inspect":Fn||(console.error("Please provide a server ID to inspect"),process.exit(1)),await Tj(Fn);break;case"install":Fn||(console.error("Please provide a server ID to install"),process.exit(1)),await Hj(Fn,yx,Ex!==-1?TM:void 0,qM);break;case"uninstall":Fn||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await AM(Fn,yx);break;case"run":Fn||(console.error("Please provide a server ID to run"),process.exit(1)),await SM(Fn,TM,qM);break;case"list":await Kj(Fn,yx);break;default:BM()}}gCe();
|
|
106
|
+
For information on Smithery's data policy, please visit: ${Uj.default.blue("https://smithery.ai/docs/data-policy")}`,default:!0}]),i=await Mj(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 $j=ie(j1()),Gj=require("node:child_process"),zj=require("node:util"),oi=(0,zj.promisify)(Gj.exec);async function Bwe(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 Pwe(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 a4(e){if(!e||!await Bwe(e))return!1;let{shouldRestart:r}=await $j.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 Pwe(e)),r}process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function Hj(e,t,r,n){k(`Starting installation of ${e} for client ${t}`),k(`Resolving package: ${e}`);let i,a;n?(k("API key provided, fetching server details and saved config"),i=Y6(e,n).then(p=>(a=p.config,p.server)).catch(p=>(console.warn(e0.default.yellow("[Install] Failed to fetch config with API key:"),p instanceof Error?p.message:String(p)),k("Falling back to standard package resolution"),Cs(e)))):i=Cs(e);try{k("Checking analytics consent..."),await Wj(),k("Analytics consent check completed")}catch(p){console.warn(e0.default.yellow("[Analytics] Failed to check consent:"),p instanceof Error?p.message:String(p)),k(`Analytics consent check error details: ${JSON.stringify(p)}`)}let u=bn(`Resolving ${e}...`).start();try{k("Awaiting package resolution...");let p=await i;k(`Package resolved successfully: ${p.qualifiedName}`),u.succeed(`Successfully resolved ${e}`),k("Choosing connection type...");let l=Y1(p);k(`Selected connection: ${JSON.stringify(l,null,2)}`),await Sj(l),await Aj(l),Oj(p);let c=a?{...a,...r||{}}:r,h=await J6(l,c),b=!!r;k(`Config values: ${JSON.stringify(h,null,2)}`),k(`Using config flag: ${b}`),k("Formatting server configuration...");let F=wj(e,h,n,b);k(`Formatted server config: ${JSON.stringify(F,null,2)}`),k(`Reading configuration for client: ${t}`);let A=X1(t);k("Normalizing server ID...");let w=Ej(e);k(`Normalized server ID: ${w}`),k("Updating client configuration..."),A.mcpServers[w]=F,k("Writing updated configuration..."),e4(A,t),k("Configuration successfully written"),console.log(e0.default.green(`${e} successfully installed for ${t}`)),k("Prompting for client restart..."),await a4(t),k("Installation process completed")}catch(p){u.fail(`Failed to install ${e}`),k(`Installation error: ${p instanceof Error?p.stack:JSON.stringify(p)}`),p instanceof Error?console.error(e0.default.red(`Error: ${p.message}`)):console.error(e0.default.red("An unexpected error occurred during installation")),process.exit(1)}}var ha=ie(We());async function Kj(e,t){switch(e){case"clients":console.log(ha.default.bold("Available clients:")),Qs.forEach(r=>console.log(` ${ha.default.green(r)}`));break;case"servers":{if(J1(t).type==="command"){console.log(ha.default.yellow(`Listing servers is currently not supported for ${t}`));return}let n=X1(t),i=Object.keys(n.mcpServers);if(i?.length>0)console.log(ha.default.bold(`Installed servers for ${t}:`)),i.sort().forEach(a=>{console.log(`${ha.default.green(a)}`)});else{let a=`No installed servers found for ${t}`;console.log(`${ha.default.red(a)}`)}break}default:console.log(ha.default.yellow("Please specify what to list. Available options:")),console.log(" clients List available clients"),console.log(" servers List installed servers"),process.exit(1)}}var Yj=ie(qv()),Zj=ie(A8());var Jj=async(e,t,r,n)=>{let i="",a=!1,u=!1,p=null,l=(A,w)=>(console.error(`[Runner] ${w}:`,A.message),A),c=async A=>{if(i+=A.toString("utf8"),!a)return;let w=i.split(/\r?\n/);i=w.pop()??"";for(let C of w.filter(Boolean))try{let q=JSON.parse(C);if(n&&r&&t8){let{data:P,error:G}=h8.safeParse(q);G||(0,Yj.default)(t8,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({eventName:"tool_call",payload:{connectionType:"stdio",serverQualifiedName:e.qualifiedName,toolParams:P?(0,Zj.pick)(P.params,"name"):{}}})}).catch(pe=>{console.error("[Runner] Analytics error:",pe)})}await p?.send(q)}catch(q){l(q,"Failed to send message to child process")}},h=async()=>{console.error("[Runner] Starting child process setup...");let A=e.connections.find(me=>me.type==="stdio");if(!A)throw new Error("No STDIO connection found");let w=await Z6(A,t),C=await bj(e.qualifiedName,w);if(!C||"type"in C)throw new Error("Failed to get valid stdio server configuration");let{command:q,args:P=[],env:G={}}=C,pe=X6(G);k(`[Runner] Using environment: ${JSON.stringify(pe,null,2)}`);let re=q,te=P;re==="npx"&&(console.error("[Runner] Using npx path:",re),process.platform==="win32"&&(console.error("[Runner] Windows platform detected, using cmd /c for npx"),te=["/c","npx",...te],re="cmd")),console.error("[Runner] Executing:",{command:re,args:te});try{p=new lo({command:re,args:te,env:pe})}catch(me){throw console.error("For more help, see: https://smithery.ai/docs/faq/users"),me}p.onmessage=me=>{try{if("error"in me){let rt=me;rt.error.code!==rn.MethodNotFound&&console.error("[Runner] Child process error:",rt.error)}console.log(JSON.stringify(me))}catch(rt){l(rt,"Error handling message")}},p.onclose=()=>{console.error("[Runner] Child process terminated"),a&&!u&&(console.error("[Runner] Process terminated unexpectedly while running"),F().catch(me=>{console.error("[Runner] Error during exit cleanup:",me),process.exit(1)}))},p.onerror=me=>{console.error("[Runner] Child process error:",me.message),me.message.includes("spawn")?console.error("[Runner] Failed to spawn child process - check if the command exists and is executable"):me.message.includes("permission")&&console.error("[Runner] Permission error when running child process"),F().catch(rt=>{console.error("[Runner] Error during error cleanup:",rt),process.exit(1)})},await p.start(),a=!0,await c(Buffer.from(""))},b=async()=>{if(u){console.error("[Runner] Cleanup already in progress, skipping...");return}if(console.error("[Runner] Starting cleanup..."),u=!0,p){try{console.error("[Runner] Attempting to close transport..."),await Promise.race([p.close(),new Promise((A,w)=>setTimeout(()=>w(new Error("Transport close timeout")),3e3))]),console.error("[Runner] Transport closed successfully")}catch(A){console.error("[Runner] Error during transport cleanup:",A)}p=null}console.error("[Runner] Cleanup completed")},F=async()=>{console.error("[Runner] Exit handler triggered, starting shutdown..."),await b(),u||process.exit(0)};return process.on("SIGINT",F),process.on("SIGTERM",F),process.on("beforeExit",F),process.on("exit",()=>{console.error("[Runner] Final cleanup on exit")}),process.stdin.on("end",()=>{console.error("[Runner] STDIN closed (client disconnected)"),F().catch(A=>{console.error("[Runner] Error during stdin close cleanup:",A),process.exit(1)})}),process.stdin.on("error",A=>{console.error("[Runner] STDIN error:",A),F().catch(w=>{console.error("[Runner] Error during stdin error cleanup:",w),process.exit(1)})}),process.stdin.on("data",A=>c(A).catch(w=>l(w,"Error processing message"))),await h(),b};var Nwe="mcp",s4=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,Nwe),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=wd.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 Xj(e,t,r){let n=new URL(e);if(t){let i=typeof window<"u"?btoa(JSON.stringify(t)):Buffer.from(JSON.stringify(t)).toString("base64");n.searchParams.set("config",i)}return r&&n.searchParams.set("api_key",r),n}var oCe=ie(fM(),1),uCe=ie(dx(),1),pCe=ie(fx(),1),EM=ie(_4(),1),dCe=ie(yM(),1);var wM=EM.default;global.WebSocket=wM;var Dx=3,lCe=1e3,FM=(e,t,r)=>{let n=`${e.replace(/^http/,"ws")}${e.endsWith("/")?"":"/"}ws`,i=Xj(n,t,r);return new s4(i)},cCe=(e,t)=>{switch(e.error.code){case-32e3:console.error("[Runner] Connection closed by server - attempting to reconnect..."),t.close();return;case-32700:case-32600:case-32601:case-32602:case-32603:console.error(e.error.message);return;default:console.error(`[Runner] Unexpected error: ${JSON.stringify(e.error)}`),process.exit(1)}},CM=async(e,t,r)=>{let n=0,i="",a=!1,u=!1,p=!1,l=FM(e,t,r),c=(w,C)=>(console.error(`${C}:`,w.message),w),h=async w=>{if(i+=w.toString("utf8"),!a)return;let C=i.split(/\r?\n/);i=C.pop()??"";for(let q of C.filter(Boolean))try{await l.send(JSON.parse(q))}catch(P){if(P instanceof Error&&P.message.includes("CLOSED"))throw new Error("WebSocket closed");c(P,"Failed to send message")}},b=async()=>{console.error(`[Runner] Connecting to WebSocket endpoint: ${e}`),l.onclose=async()=>{if(console.error("[Runner] WebSocket connection closed"),a=!1,!p&&n++<Dx){console.error(`[Runner] Unexpected disconnect, attempting reconnect (attempt ${n} of ${Dx})...`);let w=Math.random()*1e3,C=lCe*Math.pow(2,n)+w;await new Promise(q=>setTimeout(q,C)),l=FM(e,t,r),await b()}else p?(console.error("[Runner] Clean shutdown, not attempting reconnect"),process.exit(0)):(console.error(`[Runner] Max reconnection attempts (${Dx}) reached`),process.exit(1))},l.onerror=w=>{if(w.message.includes("502")){console.error("[Runner] Server returned 502, attempting to reconnect...");return}c(w,"WebSocket connection error"),process.exit(1)},l.onmessage=w=>{try{"error"in w&&cCe(w,l),console.log(JSON.stringify(w))}catch(C){c(C,"Error handling message"),console.error("[Runner] Message:",JSON.stringify(w)),console.log(JSON.stringify(w))}},await l.start(),a=!0,console.error("[Runner] WebSocket connection initiated"),await h(Buffer.from("")),console.error("[Runner] WebSocket connection established")},F=async()=>{if(u){console.error("[Runner] Cleanup already in progress, skipping...");return}console.error("[Runner] Starting cleanup..."),u=!0,p=!0;try{console.error("[Runner] Attempting to close transport..."),await Promise.race([l.close(),new Promise((w,C)=>setTimeout(()=>C(new Error("[Runner] Transport close timeout")),3e3))]),console.error("[Runner] Transport closed successfully")}catch(w){c(w,"[Runner] Error during cleanup")}console.error("[Runner] Cleanup completed")},A=async()=>{console.error("[Runner] Shutting down WS Runner..."),p=!0,await F(),u||process.exit(0)};return process.on("SIGINT",A),process.on("SIGTERM",A),process.on("beforeExit",A),process.on("exit",()=>{console.error("[Runner] Final cleanup on exit")}),process.stdin.on("end",()=>{console.error("STDIN closed (client disconnected)"),A().catch(w=>{console.error("[Runner] Error during stdin close cleanup:",w),process.exit(1)})}),process.stdin.on("error",w=>{console.error("[Runner] STDIN error:",w),A().catch(C=>{console.error("[Runner] Error during stdin error cleanup:",C),process.exit(1)})}),process.stdin.on("data",w=>h(w).catch(C=>c(C,"[Runner] Error processing message"))),await b(),F};async function SM(e,t,r){try{let n=await As();n.success||console.warn("[Runner] Settings initialization warning:",n.error);let i=null,a=t;if(r)try{let p=await Y6(e,r);i=p.server,a={...p.config,...t},console.error("[Runner] Using saved configuration")}catch(p){console.error("[Runner] Failed to fetch config with API key:",p),console.error("[Runner] Falling back to standard resolution"),i=null}if(i||(i=await Cs(e)),!i)throw new Error(`Could not resolve server: ${e}`);console.error("[Runner] Connecting to server:",{id:i.qualifiedName,connectionTypes:i.connections.map(p=>p.type)});let u=await i4();await fCe(i,a,r,u)}catch(n){console.error("[Runner] Fatal error:",n),process.exit(1)}}async function fCe(e,t,r,n){let i=Y1(e);if(i.type==="ws"){if(!i.deploymentUrl)throw new Error("Missing deployment URL");await CM(i.deploymentUrl,t,r)}else if(i.type==="stdio")await Jj(e,t,r,n);else throw new Error(`Unsupported connection type: ${i.type}`)}var s0=ie(We());process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function AM(e,t){try{if(J1(t).type==="command"){console.log(s0.default.yellow(`Uninstallation is currently not supported for ${t}`));return}let n=X1(t);if(!n.mcpServers[e]){console.log(s0.default.red(`Server ${e} is not installed for ${t}`));return}delete n.mcpServers[e],e4(n,t),console.log(s0.default.green(`${e} successfully uninstalled from ${t}`)),await a4(t)}catch(r){r instanceof Error?console.error(s0.default.red(`Error: ${r.message}`)):console.error(s0.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var wx=process.argv[2],Fn=process.argv[3],mCe=process.argv.indexOf("--client"),Ex=process.argv.indexOf("--config"),OM=process.argv.indexOf("--key"),hCe=process.argv.includes("--verbose"),vCe=process.argv.includes("--help");gj(hCe);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(" --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(" list servers List installed servers"),console.log(""),console.log("Global options:"),console.log(" --help Show this help message"),console.log(" --verbose Show detailed logs"),process.exit(0)};(vCe||!wx)&&BM();var xCe=(e,t)=>{if(["run","inspect"].includes(e)||e==="list"&&Fn==="clients")return;t===-1&&(console.error(D4.default.yellow(`Please specify a client using --client. Valid options are: ${Qs.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return Qs.includes(r)||(console.error(D4.default.yellow(`Invalid client "${r}". Valid options are: ${Qs.join(", ")}`)),process.exit(1)),r},yx=xCe(wx,mCe),TM=Ex!==-1?(()=>{try{let e=process.argv[Ex+1];e.startsWith("'")&&e.endsWith("'")&&(e=e.slice(1,-1));let t=JSON.parse(e);return typeof t=="string"&&(t=JSON.parse(t)),t}catch(e){let t=e instanceof Error?e.message:String(e);console.error(D4.default.red(`Error parsing config: ${t}`)),process.exit(1)}})():{},qM=OM!==-1?process.argv[OM+1]:void 0;async function gCe(){switch(wx){case"inspect":Fn||(console.error("Please provide a server ID to inspect"),process.exit(1)),await Tj(Fn);break;case"install":Fn||(console.error("Please provide a server ID to install"),process.exit(1)),await Hj(Fn,yx,Ex!==-1?TM:void 0,qM);break;case"uninstall":Fn||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await AM(Fn,yx);break;case"run":Fn||(console.error("Please provide a server ID to run"),process.exit(1)),await SM(Fn,TM,qM);break;case"list":await Kj(Fn,yx);break;default:BM()}}gCe();
|
|
107
107
|
/*! Bundled license information:
|
|
108
108
|
|
|
109
109
|
lodash/lodash.js:
|