@smithery/cli 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -105,7 +105,7 @@ Valid clients are: ${pr.join(", ")}`)),process.exit(1));let t=await ms(r,e);if(!
|
|
|
105
105
|
`,Kt.default.cyan(JSON.stringify(n,null,2).replace(/"(\w+)":/g,s=>Kt.default.green(s)).replace(/"([^"]+)"(?=,|\n|\})/g,s=>Kt.default.yellow(s))));let{action:i}=await Dx.default.prompt([{type:"list",name:"action",message:"What would you like to do?",choices:[{name:Kt.default.yellow("\u21A9 Back to primitives"),value:"back"},{name:Kt.default.red("\u2716 Exit"),value:"exit"}]}]);if(i==="exit")return"exit"}}var JP=ye(yn());async function XP(r){try{r&&!pr.includes(r)&&(console.error(Qa.default.red(`Invalid client: ${r}
|
|
106
106
|
Valid clients are: ${pr.join(", ")}`)),process.exit(1));let e=Rr.getInstalledServerIds(r);if(e.length===0){console.log(Qa.default.yellow(`
|
|
107
107
|
No MCP servers are currently installed.`));return}let t=Rr.readConfig(r);for(;;){let n=ex(e.map(u=>({qualifiedName:u,name:Rr.denormalizeServerId(u),isInstalled:!0,connections:[]})),!1,!0),{selectedId:i}=await JP.default.prompt([{type:"list",name:"selectedId",message:"Select a server to inspect:",choices:n}]);if(i==="exit"&&process.exit(0),!i)return;console.log(Qa.default.blue(`
|
|
108
|
-
Connecting to server...`));let s=t.mcpServers[i.id];if("command"in s){let u=await ZP(i.id,s);await YP(u)==="exit"&&process.exit(0)}else throw new Error("Only stdio connections are supported")}}catch(e){console.error(Qa.default.red("Error during inspection:")),console.error(Qa.default.red(e instanceof Error?e.message:String(e))),process.exit(1)}}var EDe="mcp",wx=class{constructor(e){this._url=e}start(){if(this._socket)throw new Error("WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically.");return new Promise((e,t)=>{this._socket=new WebSocket(this._url,EDe),this._socket.onerror=n=>{var i;let s="error"in n?n.error:new Error(`WebSocket error: ${JSON.stringify(n)}`);t(s),(i=this.onerror)===null||i===void 0||i.call(this,s)},this._socket.onopen=()=>{e()},this._socket.onclose=()=>{var n;(n=this.onclose)===null||n===void 0||n.call(this)},this._socket.onmessage=n=>{var i,s;let u;try{u=fx.parse(JSON.parse(n.data))}catch(c){(i=this.onerror)===null||i===void 0||i.call(this,c);return}(s=this.onmessage)===null||s===void 0||s.call(this,u)}})}async close(){var e;(e=this._socket)===null||e===void 0||e.close()}send(e){return new Promise((t,n)=>{var i;if(!this._socket){n(new Error("Not connected"));return}(i=this._socket)===null||i===void 0||i.send(JSON.stringify(e)),t()})}};function QP(r,e){let t=new URL(r);if(e){let n=typeof window<"u"?btoa(JSON.stringify(e)):Buffer.from(JSON.stringify(e)).toString("base64");t.searchParams.set("config",n)}return t}var Zwe=ye(nR(),1),Ywe=ye(qy(),1),Jwe=ye(Ry(),1),wI=ye(Ny(),1),Xwe=ye(DI(),1);var SI=wI.default;global.WebSocket=SI;var CI=3,Qwe=1e3,OI=(r,e)=>{let t
|
|
108
|
+
Connecting to server...`));let s=t.mcpServers[i.id];if("command"in s){let u=await ZP(i.id,s);await YP(u)==="exit"&&process.exit(0)}else throw new Error("Only stdio connections are supported")}}catch(e){console.error(Qa.default.red("Error during inspection:")),console.error(Qa.default.red(e instanceof Error?e.message:String(e))),process.exit(1)}}var EDe="mcp",wx=class{constructor(e){this._url=e}start(){if(this._socket)throw new Error("WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically.");return new Promise((e,t)=>{this._socket=new WebSocket(this._url,EDe),this._socket.onerror=n=>{var i;let s="error"in n?n.error:new Error(`WebSocket error: ${JSON.stringify(n)}`);t(s),(i=this.onerror)===null||i===void 0||i.call(this,s)},this._socket.onopen=()=>{e()},this._socket.onclose=()=>{var n;(n=this.onclose)===null||n===void 0||n.call(this)},this._socket.onmessage=n=>{var i,s;let u;try{u=fx.parse(JSON.parse(n.data))}catch(c){(i=this.onerror)===null||i===void 0||i.call(this,c);return}(s=this.onmessage)===null||s===void 0||s.call(this,u)}})}async close(){var e;(e=this._socket)===null||e===void 0||e.close()}send(e){return new Promise((t,n)=>{var i;if(!this._socket){n(new Error("Not connected"));return}(i=this._socket)===null||i===void 0||i.send(JSON.stringify(e)),t()})}};function QP(r,e){let t=new URL(r);if(e){let n=typeof window<"u"?btoa(JSON.stringify(e)):Buffer.from(JSON.stringify(e)).toString("base64");t.searchParams.set("config",n)}return t}var Zwe=ye(nR(),1),Ywe=ye(qy(),1),Jwe=ye(Ry(),1),wI=ye(Ny(),1),Xwe=ye(DI(),1);var SI=wI.default;global.WebSocket=SI;var CI=3,Qwe=1e3,OI=(r,e)=>{let t=`${r.replace(/^http/,"ws")}${r.endsWith("/")?"":"/"}ws`,n=QP(t,e);return new wx(n)},FI=async(r,e)=>{let t=0,n="",i=!1,s=OI(r,e),u=(g,w)=>(console.error(`${w}:`,g.message),g),c=async g=>{if(n+=g.toString("utf8"),!i)return;let w=n.split(/\r?\n/);n=w.pop()??"";for(let q of w.filter(Boolean))try{await s.send(JSON.parse(q))}catch(A){if(A instanceof Error&&A.message.includes("CLOSED"))throw new Error("WebSocket closed");u(A,"Failed to send message")}},f=async()=>{console.error(`Connecting to WebSocket endpoint: ${r}`),s.onclose=async()=>{console.error("WebSocket connection closed"),i=!1,t++<CI?(await new Promise(g=>setTimeout(g,Qwe*Math.pow(2,t))),s=OI(r,e),await f()):(console.error(`Max reconnection attempts (${CI}) reached`),process.exit(1))},s.onerror=g=>{u(g,"WebSocket connection error"),process.exit(1)},s.onmessage=g=>{try{"error"in g&&(console.error(`WebSocket error: ${JSON.stringify(g.error)}`),(g.error.message==="Missing configuration"||g.error.message==="Invalid configuration")&&process.exit(1)),console.log(JSON.stringify(g))}catch(w){u(w,"Error handling message"),console.error("Raw message data:",JSON.stringify(g)),console.log(JSON.stringify(g))}},await s.start(),i=!0,await c(Buffer.from(""))},d=async()=>{console.error("Starting cleanup..."),await s.close().catch(g=>u(g,"Error during cleanup")),console.error("Cleanup completed")},v=async()=>{console.error("Shutting down WS Runner..."),await d(),process.exit(0)};return process.on("SIGINT",v),process.on("SIGTERM",v),process.stdin.on("data",g=>c(g).catch(w=>u(w,"Error processing message"))),await f(),d};var qI=ye(AI()),TI=async(r,e,t)=>{let n="",i=!1,s=null,u=(g,w)=>(console.error(`[Runner] ${w}:`,g.message),g),c=async g=>{if(n+=g.toString("utf8"),!i)return;let w=n.split(/\r?\n/);n=w.pop()??"";for(let q of w.filter(Boolean))try{let A=JSON.parse(q);if(t&&W2){let{data:C,error:P}=cy.safeParse(A);P||fetch(W2,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({eventName:"tool_call",payload:{connectionType:"stdio",serverQualifiedName:r.qualifiedName,toolParams:C?(0,qI.pick)(C.params,"name"):{}}})}).catch(I=>{console.error("[Runner] Analytics error:",I)})}await s?.send(A)}catch(A){u(A,"Failed to send message to child process")}},f=async()=>{console.error("[Runner] Starting child process setup...");let g=r.connections.find(ee=>ee.type==="stdio");if(!g)throw new Error("No STDIO connection found");let w=await Gp(g,e),q=await oP(r.qualifiedName,w,"stdio");if(!q||"type"in q)throw new Error("Failed to get valid stdio server configuration");let{command:A,args:C=[],env:P={}}=q,I=A,K=C;if(process.platform==="win32")try{if(!require("path").isAbsolute(A)){let{execSync:ce}=require("child_process");I=ce(`where ${A}`,{encoding:"utf8"}).split(`
|
|
109
109
|
`)[0].trim()}I.includes(" ")&&(K=[I,...C],I=process.execPath)}catch(ee){console.error("[Runner] Could not resolve full path for command:",A,ee),I=A,K=C}console.error("[Runner] Executing:",{command:I,args:K}),s=new Xa({command:I,args:K,env:{...fy(),...P}}),s.onmessage=ee=>{try{if("error"in ee){let ce=ee;ce.error?.code!==Fn.MethodNotFound&&console.error("[Runner] Child process error:",ce.error)}console.log(JSON.stringify(ee))}catch(ce){u(ce,"Error handling message")}},s.onclose=()=>{console.error("[Runner] Child process terminated"),i&&(console.error("[Runner] Process terminated unexpectedly while running"),process.exit(1)),process.exit(0)},s.onerror=ee=>{console.error("[Runner] Child process error:",ee.message),ee.message.includes("spawn")?console.error("[Runner] Failed to spawn child process - check if the command exists and is executable"):ee.message.includes("permission")&&console.error("[Runner] Permission error when running child process"),process.exit(1)},await s.start(),i=!0,await c(Buffer.from(""))},d=async()=>{console.error("[Runner] Starting cleanup..."),s&&(await s.close(),s=null),console.error("[Runner] Cleanup completed")},v=async()=>{console.error("[Runner] Shutting down STDIO Runner..."),await d(),process.exit(0)};return process.on("SIGINT",v),process.on("SIGTERM",v),process.stdin.on("data",g=>c(g).catch(w=>u(w,"Error processing message"))),await f(),d};async function PI(r,e,t){let n=r.connections.some(s=>s.type==="ws"),i=r.connections.some(s=>s.type==="stdio");if(n){let s=r.connections.find(u=>u.type==="ws");if(!s?.deploymentUrl)throw new Error("Missing deployment URL");await FI(s.deploymentUrl,e)}else if(i)await TI(r,e,t);else throw new Error("No connection types found. Server not deployed.")}async function RI(r,e){try{let t=new Ma,[n]=await Promise.all([ms(r),t.initialize()]);if(!n)throw new Error(`Could not resolve server: ${r}`);console.error("[Runner] Connecting to server:",{id:n.qualifiedName,connectionTypes:n.connections.map(s=>s.type)});let i=t.getAnalyticsConsent()?t.getUserId():void 0;await PI(n,e,i)}catch(t){console.error("[Runner] Fatal error:",t),process.exit(1)}}var jI=ye(Re()),e8e=process.argv[2],Ws=process.argv[3],Wy=process.argv.indexOf("--client"),II=process.argv.indexOf("--config"),Xc=Wy!==-1?process.argv[Wy+1]:"claude",r8e=II!==-1?(()=>{let r=JSON.parse(process.argv[II+1]);return typeof r=="string"&&(r=JSON.parse(r)),r})():{};async function t8e(){switch(e8e){case"inspect":await XP(Xc);break;case"install":Ws||(console.error("Please provide a package name to install"),process.exit(1)),Wy===-1&&console.log(jI.default.yellow("Client not provided, defaulting to claude")),await fP(Ws,Xc);break;case"uninstall":await hP(Ws,Xc);break;case"installed":await tx(Xc);break;case"view":Ws||(console.error("Please provide a package ID to get details"),process.exit(1)),await SP(Ws,Xc);break;case"run":Ws||(console.error("Please provide a server ID to run"),process.exit(1)),await RI(Ws,r8e);break;default:console.log("Available commands:"),console.log(" install <package> Install a package"),console.log(" --client <name> Specify the AI client"),console.log(" uninstall [package] Uninstall a package"),console.log(" installed List installed packages"),console.log(" view <package> Get details for a specific package"),console.log(" inspect Inspect installed servers"),console.log(" run <server-id> Run a server"),process.exit(1)}}t8e();
|
|
110
110
|
/*! Bundled license information:
|
|
111
111
|
|