@smithery/cli 1.1.78 → 1.1.79

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -100,7 +100,7 @@ For information on Smithery's data policy, please visit: ${MI.default.blue("http
100
100
  `;break;case"id":p=A.includes("\0")?void 0:A;break;case"retry":/^\d+$/.test(A)?n(parseInt(A,10)):r(new Pf(`Invalid \`retry\` value: "${A}"`,{type:"invalid-retry",value:A,line:P}));break;default:r(new Pf(`Unknown field "${S.length>20?`${S.slice(0,20)}\u2026`:S}"`,{type:"unknown-field",field:S,value:A,line:P}));break}}function q(){l.length>0&&t({id:p,event:c||void 0,data:l.endsWith(`
101
101
  `)?l.slice(0,-1):l}),p=void 0,l="",c=""}function C(S={}){a&&S.consume&&_(a),p=void 0,l="",c="",a=""}return{feed:h,reset:C}}function Fye(e){let t=[],r="",n=e.length;for(let i=0;i<n;i++){let a=e[i];a==="\r"&&e[i+1]===`
102
102
  `?(t.push(r),r="",i++):a==="\r"||a===`
103
- `?(t.push(r),r=""):r+=a}return[t,r]}var Bf=class extends TransformStream{constructor({onError:t,onRetry:r,onComment:n}={}){let i;super({start(a){i=QI({onEvent:u=>{a.enqueue(u)},onError(u){t==="terminate"?a.error(u):typeof t=="function"&&t(u)},onRetry:r,onComment:n})},transform(a){i.feed(a)}})}};var Cye={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},Vu=class extends Error{constructor(t,r){super(`Streamable HTTP error: ${r}`),this.code=t}},Rf=class{constructor(t,r){var n;this._url=t,this._requestInit=r?.requestInit,this._authProvider=r?.authProvider,this._sessionId=r?.sessionId,this._reconnectionOptions=(n=r?.reconnectionOptions)!==null&&n!==void 0?n:Cye}async _authThenStart(){var t;if(!this._authProvider)throw new aa("No auth provider");let r;try{r=await Tf(this._authProvider,{serverUrl:this._url})}catch(n){throw(t=this.onerror)===null||t===void 0||t.call(this,n),n}if(r!=="AUTHORIZED")throw new aa;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){var t;let r={};if(this._authProvider){let n=await this._authProvider.tokens();n&&(r.Authorization=`Bearer ${n.access_token}`)}return this._sessionId&&(r["mcp-session-id"]=this._sessionId),new Headers({...r,...(t=this._requestInit)===null||t===void 0?void 0:t.headers})}async _startOrAuthSse(t){var r,n;let{resumptionToken:i}=t;try{let a=await this._commonHeaders();a.set("Accept","text/event-stream"),i&&a.set("last-event-id",i);let u=await fetch(this._url,{method:"GET",headers:a,signal:(r=this._abortController)===null||r===void 0?void 0:r.signal});if(!u.ok){if(u.status===401&&this._authProvider)return await this._authThenStart();if(u.status===405)return;throw new Vu(u.status,`Failed to open SSE stream: ${u.statusText}`)}this._handleSseStream(u.body,t)}catch(a){throw(n=this.onerror)===null||n===void 0||n.call(this,a),a}}_getNextReconnectionDelay(t){let r=this._reconnectionOptions.initialReconnectionDelay,n=this._reconnectionOptions.reconnectionDelayGrowFactor,i=this._reconnectionOptions.maxReconnectionDelay;return Math.min(r*Math.pow(n,t),i)}_scheduleReconnection(t,r=0){var n;let i=this._reconnectionOptions.maxRetries;if(i>0&&r>=i){(n=this.onerror)===null||n===void 0||n.call(this,new Error(`Maximum reconnection attempts (${i}) exceeded.`));return}let a=this._getNextReconnectionDelay(r);setTimeout(()=>{this._startOrAuthSse(t).catch(u=>{var p;(p=this.onerror)===null||p===void 0||p.call(this,new Error(`Failed to reconnect SSE stream: ${u instanceof Error?u.message:String(u)}`)),this._scheduleReconnection(t,r+1)})},a)}_handleSseStream(t,r){if(!t)return;let{onresumptiontoken:n,replayMessageId:i}=r,a;(async()=>{var p,l,c,h;try{let _=t.pipeThrough(new TextDecoderStream).pipeThrough(new Bf).getReader();for(;;){let{value:w,done:q}=await _.read();if(q)break;if(w.id&&(a=w.id,n?.(w.id)),!w.event||w.event==="message")try{let C=z1.parse(JSON.parse(w.data));i!==void 0&&vs(C)&&(C.id=i),(p=this.onmessage)===null||p===void 0||p.call(this,C)}catch(C){(l=this.onerror)===null||l===void 0||l.call(this,C)}}}catch(_){if((c=this.onerror)===null||c===void 0||c.call(this,new Error(`SSE stream disconnected: ${_}`)),this._abortController&&!this._abortController.signal.aborted&&a!==void 0)try{this._scheduleReconnection({resumptionToken:a,onresumptiontoken:n,replayMessageId:i},0)}catch(w){(h=this.onerror)===null||h===void 0||h.call(this,new Error(`Failed to reconnect: ${w instanceof Error?w.message:String(w)}`))}}})()}async start(){if(this._abortController)throw new Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");this._abortController=new AbortController}async finishAuth(t){if(!this._authProvider)throw new aa("No auth provider");if(await Tf(this._authProvider,{serverUrl:this._url,authorizationCode:t})!=="AUTHORIZED")throw new aa("Failed to authorize")}async close(){var t,r;(t=this._abortController)===null||t===void 0||t.abort(),(r=this.onclose)===null||r===void 0||r.call(this)}async send(t,r){var n,i,a;try{let{resumptionToken:u,onresumptiontoken:p}=r||{};if(u){this._startOrAuthSse({resumptionToken:u,replayMessageId:Yp(t)?t.id:void 0}).catch(S=>{var A;return(A=this.onerror)===null||A===void 0?void 0:A.call(this,S)});return}let l=await this._commonHeaders();l.set("content-type","application/json"),l.set("accept","application/json, text/event-stream");let c={...this._requestInit,method:"POST",headers:l,body:JSON.stringify(t),signal:(n=this._abortController)===null||n===void 0?void 0:n.signal},h=await fetch(this._url,c),_=h.headers.get("mcp-session-id");if(_&&(this._sessionId=_),!h.ok){if(h.status===401&&this._authProvider){if(await Tf(this._authProvider,{serverUrl:this._url})!=="AUTHORIZED")throw new aa;return this.send(t)}let S=await h.text().catch(()=>null);throw new Error(`Error POSTing to endpoint (HTTP ${h.status}): ${S}`)}if(h.status===202){GD(t)&&this._startOrAuthSse({resumptionToken:void 0}).catch(S=>{var A;return(A=this.onerror)===null||A===void 0?void 0:A.call(this,S)});return}let q=(Array.isArray(t)?t:[t]).filter(S=>"method"in S&&"id"in S&&S.id!==void 0).length>0,C=h.headers.get("content-type");if(q)if(C?.includes("text/event-stream"))this._handleSseStream(h.body,{onresumptiontoken:p});else if(C?.includes("application/json")){let S=await h.json(),A=Array.isArray(S)?S.map(P=>z1.parse(P)):[z1.parse(S)];for(let P of A)(i=this.onmessage)===null||i===void 0||i.call(this,P)}else throw new Vu(-1,`Unexpected content type: ${C}`)}catch(u){throw(a=this.onerror)===null||a===void 0||a.call(this,u),u}}get sessionId(){return this._sessionId}async terminateSession(){var t,r;if(this._sessionId)try{let n=await this._commonHeaders(),i={...this._requestInit,method:"DELETE",headers:n,signal:(t=this._abortController)===null||t===void 0?void 0:t.signal},a=await fetch(this._url,i);if(!a.ok&&a.status!==405)throw new Vu(a.status,`Failed to terminate session: ${a.statusText}`);this._sessionId=void 0}catch(n){throw(r=this.onerror)===null||r===void 0||r.call(this,n),n}}};function ej(e,t,r){let n=new URL(e);if(r){let i=JSON.stringify(r);n.searchParams.set("config",Buffer.from(i).toString("base64"))}return n.searchParams.set("api_key",t),n}var tj=(e,t,r)=>{let n=ej(e,t,r);return z(`[Runner] Connecting to Streamable HTTP endpoint: ${e}`),new Rf(n)},rj=async(e,t,r)=>{let n=0,i="",a=!1,u=!1,p=!1,l=tj(e,t,r),c=(A,P)=>(z(`${P}: ${A.message}`),A),h=async()=>{z("[Runner] Received exit signal, initiating shutdown..."),p=!0,await S(),u||process.exit(0)},_=GI(h),w=HI(A=>l.send(A),()=>a),q=async A=>{if(_.updateActivity(),i+=A.toString("utf8"),!a)return;let P=i.split(/\r?\n/);i=P.pop()??"";for(let $ of P.filter(Boolean))try{let G=JSON.parse($);await l.send(G)}catch(G){if(G instanceof Error&&G.message.includes("CLOSED"))throw new Error("Streamable HTTP connection closed");c(G,"Failed to send message")}},C=async()=>{l.onclose=async()=>{if(z("[Runner] Streamable HTTP connection closed"),a=!1,w.stop(),!p&&n++<Af){let A=Math.random()*1e3,P=zI*Math.pow(2,n)+A;z(`[Runner] Unexpected disconnect, attempting reconnect in ${Math.round(P)}ms (attempt ${n} of ${Af})...`),await new Promise($=>setTimeout($,P)),l=tj(e,t,r),z("[Runner] Created new transport instance after disconnect"),await C()}else p?(z("[Runner] Clean shutdown detected, performing graceful exit"),process.exit(0)):(z(`[Runner] Max reconnection attempts (${Af}) reached - giving up`),process.exit(1))},l.onerror=A=>{if(A.message.includes("502")){z("[Runner] Server returned 502 Bad Gateway");return}z(`[Runner] Streamable HTTP error: ${A.message}`)},l.onmessage=A=>{"method"in A&&!(A.method==="ping"||A.method==="pong")&&_.updateActivity();try{"error"in A&&Of(A),console.log(JSON.stringify(A))}catch(P){c(P,"Error handling message"),z(`[Runner] Message: ${JSON.stringify(A)}`),console.log(JSON.stringify(A))}},await Promise.race([l.start(),new Promise((A,P)=>setTimeout(()=>P(new Error("[Runner] Transport connection timeout after 10s")),1e4))]),a=!0,n=0,z("[Runner] Streamable HTTP connection initiated"),w.start(),_.start(),await q(Buffer.from("")),z("[Runner] Streamable HTTP connection established")},S=async()=>{if(u){z("[Runner] Cleanup already in progress, skipping...");return}z("[Runner] Starting cleanup process..."),u=!0,p=!0,w.stop(),_.stop();try{if(l.sessionId){let A=`${l.sessionId.substring(0,12)}...`;z(`[Runner] Terminating session with ID: ${A}`);try{await l.terminateSession(),z("[Runner] Session terminated successfully"),l.sessionId?(z("[Runner] Server responded with 405 Method Not Allowed (session termination not supported)"),z(`[Runner] Session ID is still active: ${A}`)):z("[Runner] Session ID has been cleared")}catch(P){z(`[Runner] Error terminating session: ${P.message}`)}}z("[Runner] Attempting to close transport (3s timeout)..."),await Promise.race([l.close(),new Promise((A,P)=>setTimeout(()=>P(new Error("[Runner] Transport close timeout after 3s")),3e3))]),z("[Runner] Transport closed successfully")}catch(A){z(`[Runner] Error during transport cleanup: ${A.message}`)}z("[Runner] Cleanup completed")};return process.on("SIGINT",h),process.on("SIGTERM",h),process.on("beforeExit",h),process.on("exit",()=>{z("[Runner] Final cleanup on exit")}),process.stdin.on("end",()=>{z("[Runner] STDIN closed (client disconnected)"),h().catch(A=>{z(`[Runner] Error during stdin close cleanup: ${A}`),process.exit(1)})}),process.stdin.on("error",A=>{z(`[Runner] STDIN error: ${A.message}`),h().catch(P=>{z(`[Runner] Error during stdin error cleanup: ${P}`),process.exit(1)})}),process.stdin.on("data",A=>q(A).catch(P=>c(P,"[Runner] Error processing message"))),await C(),S};async function nj(e,t,r){try{let n=await h1();n.success||z(`[Runner] Settings initialization warning: ${n.error}`);let i=await Bo(e);if(!i)throw new Error(`Could not resolve server: ${e}`);z(`[Runner] Connecting to server: ${JSON.stringify({id:i.qualifiedName,connectionTypes:i.connections.map(u=>u.type)})}`);let a=await Cf();await Sye(i,t,a,r)}catch(n){z(`[Runner] Error: ${n instanceof Error?n.message:n}`),process.exit(1)}}async function Sye(e,t,r,n){let i=Ro(e);if(i.type==="http"){if(!i.deploymentUrl)throw new Error("Missing deployment URL");if(!n)throw new Error("API key is required for remote connections");await rj(i.deploymentUrl,n,t)}else if(i.type==="stdio")await ZI(e,t,n,r);else throw new Error(`Unsupported connection type: ${i.type}`)}var Mo=ce($e());process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function ij(e,t){try{if(No(t).type==="command"){console.log(Mo.default.yellow(`Uninstallation is currently not supported for ${t}`));return}let n=Io(t);if(!n.mcpServers[e]){console.log(Mo.default.red(`Server ${e} is not installed for ${t}`));return}delete n.mcpServers[e],yf(n,t),console.log(Mo.default.green(`${e} successfully uninstalled from ${t}`)),await Sf(t)}catch(r){r instanceof Error?console.error(Mo.default.red(`Error: ${r.message}`)):console.error(Mo.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var cv=process.argv[2],gn=process.argv[3],Aye=process.argv.indexOf("--client"),lv=process.argv.indexOf("--config"),aj=process.argv.indexOf("--key"),Oye=process.argv.includes("--verbose"),Tye=process.argv.includes("--help");fI(Oye);var uj=()=>{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 (required)"),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)};(Tye||!cv)&&uj();var qye=(e,t)=>{if(["run","inspect"].includes(e)||e==="list"&&gn==="clients")return;t===-1&&(console.error(Nf.default.yellow(`Please specify a client using --client. Valid options are: ${I1.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return I1.includes(r)||(console.error(Nf.default.yellow(`Invalid client "${r}". Valid options are: ${I1.join(", ")}`)),process.exit(1)),r},dv=qye(cv,Aye),oj=lv!==-1?(()=>{try{let e=process.argv[lv+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(Nf.default.red(`Error parsing config: ${t}`)),process.exit(1)}})():{},sj=aj!==-1?process.argv[aj+1]:void 0;async function Pye(){switch(cv){case"inspect":gn||(console.error("Please provide a server ID to inspect"),process.exit(1)),await CI(gn);break;case"install":gn||(console.error("Please provide a server ID to install"),process.exit(1)),await $I(gn,dv,lv!==-1?oj:void 0,sj);break;case"uninstall":gn||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await ij(gn,dv);break;case"run":gn||(console.error("Please provide a server ID to run"),process.exit(1)),await nj(gn,oj,sj);break;case"list":await WI(gn,dv);break;default:uj()}}Pye();
103
+ `?(t.push(r),r=""):r+=a}return[t,r]}var Bf=class extends TransformStream{constructor({onError:t,onRetry:r,onComment:n}={}){let i;super({start(a){i=QI({onEvent:u=>{a.enqueue(u)},onError(u){t==="terminate"?a.error(u):typeof t=="function"&&t(u)},onRetry:r,onComment:n})},transform(a){i.feed(a)}})}};var Cye={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},Vu=class extends Error{constructor(t,r){super(`Streamable HTTP error: ${r}`),this.code=t}},Rf=class{constructor(t,r){var n;this._url=t,this._requestInit=r?.requestInit,this._authProvider=r?.authProvider,this._sessionId=r?.sessionId,this._reconnectionOptions=(n=r?.reconnectionOptions)!==null&&n!==void 0?n:Cye}async _authThenStart(){var t;if(!this._authProvider)throw new aa("No auth provider");let r;try{r=await Tf(this._authProvider,{serverUrl:this._url})}catch(n){throw(t=this.onerror)===null||t===void 0||t.call(this,n),n}if(r!=="AUTHORIZED")throw new aa;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){var t;let r={};if(this._authProvider){let n=await this._authProvider.tokens();n&&(r.Authorization=`Bearer ${n.access_token}`)}return this._sessionId&&(r["mcp-session-id"]=this._sessionId),new Headers({...r,...(t=this._requestInit)===null||t===void 0?void 0:t.headers})}async _startOrAuthSse(t){var r,n;let{resumptionToken:i}=t;try{let a=await this._commonHeaders();a.set("Accept","text/event-stream"),i&&a.set("last-event-id",i);let u=await fetch(this._url,{method:"GET",headers:a,signal:(r=this._abortController)===null||r===void 0?void 0:r.signal});if(!u.ok){if(u.status===401&&this._authProvider)return await this._authThenStart();if(u.status===405)return;throw new Vu(u.status,`Failed to open SSE stream: ${u.statusText}`)}this._handleSseStream(u.body,t)}catch(a){throw(n=this.onerror)===null||n===void 0||n.call(this,a),a}}_getNextReconnectionDelay(t){let r=this._reconnectionOptions.initialReconnectionDelay,n=this._reconnectionOptions.reconnectionDelayGrowFactor,i=this._reconnectionOptions.maxReconnectionDelay;return Math.min(r*Math.pow(n,t),i)}_scheduleReconnection(t,r=0){var n;let i=this._reconnectionOptions.maxRetries;if(i>0&&r>=i){(n=this.onerror)===null||n===void 0||n.call(this,new Error(`Maximum reconnection attempts (${i}) exceeded.`));return}let a=this._getNextReconnectionDelay(r);setTimeout(()=>{this._startOrAuthSse(t).catch(u=>{var p;(p=this.onerror)===null||p===void 0||p.call(this,new Error(`Failed to reconnect SSE stream: ${u instanceof Error?u.message:String(u)}`)),this._scheduleReconnection(t,r+1)})},a)}_handleSseStream(t,r){if(!t)return;let{onresumptiontoken:n,replayMessageId:i}=r,a;(async()=>{var p,l,c,h;try{let _=t.pipeThrough(new TextDecoderStream).pipeThrough(new Bf).getReader();for(;;){let{value:w,done:q}=await _.read();if(q)break;if(w.id&&(a=w.id,n?.(w.id)),!w.event||w.event==="message")try{let C=z1.parse(JSON.parse(w.data));i!==void 0&&vs(C)&&(C.id=i),(p=this.onmessage)===null||p===void 0||p.call(this,C)}catch(C){(l=this.onerror)===null||l===void 0||l.call(this,C)}}}catch(_){if((c=this.onerror)===null||c===void 0||c.call(this,new Error(`SSE stream disconnected: ${_}`)),this._abortController&&!this._abortController.signal.aborted&&a!==void 0)try{this._scheduleReconnection({resumptionToken:a,onresumptiontoken:n,replayMessageId:i},0)}catch(w){(h=this.onerror)===null||h===void 0||h.call(this,new Error(`Failed to reconnect: ${w instanceof Error?w.message:String(w)}`))}}})()}async start(){if(this._abortController)throw new Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");this._abortController=new AbortController}async finishAuth(t){if(!this._authProvider)throw new aa("No auth provider");if(await Tf(this._authProvider,{serverUrl:this._url,authorizationCode:t})!=="AUTHORIZED")throw new aa("Failed to authorize")}async close(){var t,r;(t=this._abortController)===null||t===void 0||t.abort(),(r=this.onclose)===null||r===void 0||r.call(this)}async send(t,r){var n,i,a;try{let{resumptionToken:u,onresumptiontoken:p}=r||{};if(u){this._startOrAuthSse({resumptionToken:u,replayMessageId:Yp(t)?t.id:void 0}).catch(S=>{var A;return(A=this.onerror)===null||A===void 0?void 0:A.call(this,S)});return}let l=await this._commonHeaders();l.set("content-type","application/json"),l.set("accept","application/json, text/event-stream");let c={...this._requestInit,method:"POST",headers:l,body:JSON.stringify(t),signal:(n=this._abortController)===null||n===void 0?void 0:n.signal},h=await fetch(this._url,c),_=h.headers.get("mcp-session-id");if(_&&(this._sessionId=_),!h.ok){if(h.status===401&&this._authProvider){if(await Tf(this._authProvider,{serverUrl:this._url})!=="AUTHORIZED")throw new aa;return this.send(t)}let S=await h.text().catch(()=>null);throw new Error(`Error POSTing to endpoint (HTTP ${h.status}): ${S}`)}if(h.status===202){GD(t)&&this._startOrAuthSse({resumptionToken:void 0}).catch(S=>{var A;return(A=this.onerror)===null||A===void 0?void 0:A.call(this,S)});return}let q=(Array.isArray(t)?t:[t]).filter(S=>"method"in S&&"id"in S&&S.id!==void 0).length>0,C=h.headers.get("content-type");if(q)if(C?.includes("text/event-stream"))this._handleSseStream(h.body,{onresumptiontoken:p});else if(C?.includes("application/json")){let S=await h.json(),A=Array.isArray(S)?S.map(P=>z1.parse(P)):[z1.parse(S)];for(let P of A)(i=this.onmessage)===null||i===void 0||i.call(this,P)}else throw new Vu(-1,`Unexpected content type: ${C}`)}catch(u){throw(a=this.onerror)===null||a===void 0||a.call(this,u),u}}get sessionId(){return this._sessionId}async terminateSession(){var t,r;if(this._sessionId)try{let n=await this._commonHeaders(),i={...this._requestInit,method:"DELETE",headers:n,signal:(t=this._abortController)===null||t===void 0?void 0:t.signal},a=await fetch(this._url,i);if(!a.ok&&a.status!==405)throw new Vu(a.status,`Failed to terminate session: ${a.statusText}`);this._sessionId=void 0}catch(n){throw(r=this.onerror)===null||r===void 0||r.call(this,n),n}}};function ej(e,t,r){let n=new URL(e);if(process.env.NODE_ENV==="development"){let i=new URL(process.env.LOCAL_SERVER_URL||"http://localhost:8080");n.protocol=i.protocol,n.hostname=i.hostname,n.port=i.port}if(r){let i=JSON.stringify(r);n.searchParams.set("config",Buffer.from(i).toString("base64"))}return n.searchParams.set("api_key",t),n}var tj=(e,t,r)=>{let n=ej(e,t,r);return z(`[Runner] Connecting to Streamable HTTP endpoint: ${e}`),new Rf(n)},rj=async(e,t,r)=>{let n=0,i="",a=!1,u=!1,p=!1,l=tj(e,t,r),c=(A,P)=>(z(`${P}: ${A.message}`),A),h=async()=>{z("[Runner] Received exit signal, initiating shutdown..."),p=!0,await S(),u||process.exit(0)},_=GI(h),w=HI(A=>l.send(A),()=>a),q=async A=>{if(_.updateActivity(),i+=A.toString("utf8"),!a)return;let P=i.split(/\r?\n/);i=P.pop()??"";for(let $ of P.filter(Boolean))try{let G=JSON.parse($);await l.send(G)}catch(G){if(G instanceof Error&&G.message.includes("CLOSED"))throw new Error("Streamable HTTP connection closed");c(G,"Failed to send message")}},C=async()=>{l.onclose=async()=>{if(z("[Runner] Streamable HTTP connection closed"),a=!1,w.stop(),!p&&n++<Af){let A=Math.random()*1e3,P=zI*Math.pow(2,n)+A;z(`[Runner] Unexpected disconnect, attempting reconnect in ${Math.round(P)}ms (attempt ${n} of ${Af})...`),await new Promise($=>setTimeout($,P)),l=tj(e,t,r),z("[Runner] Created new transport instance after disconnect"),await C()}else p?(z("[Runner] Clean shutdown detected, performing graceful exit"),process.exit(0)):(z(`[Runner] Max reconnection attempts (${Af}) reached - giving up`),process.exit(1))},l.onerror=A=>{if(A.message.includes("502")){z("[Runner] Server returned 502 Bad Gateway");return}z(`[Runner] Streamable HTTP error: ${A.message}`)},l.onmessage=A=>{"method"in A&&!(A.method==="ping"||A.method==="pong")&&_.updateActivity();try{"error"in A&&Of(A),console.log(JSON.stringify(A))}catch(P){c(P,"Error handling message"),z(`[Runner] Message: ${JSON.stringify(A)}`),console.log(JSON.stringify(A))}},l.start(),a=!0,n=0,z("[Runner] Streamable HTTP connection initiated"),await q(Buffer.from("")),z("[Runner] Streamable HTTP connection established"),w.start(),_.start()},S=async()=>{if(u){z("[Runner] Cleanup already in progress, skipping...");return}z("[Runner] Starting cleanup process..."),u=!0,p=!0,w.stop(),_.stop();try{if(l.sessionId){let A=`${l.sessionId.substring(0,12)}...`;z(`[Runner] Terminating session with ID: ${A}`);try{await l.terminateSession(),z("[Runner] Session terminated successfully"),l.sessionId?(z("[Runner] Server responded with 405 Method Not Allowed (session termination not supported)"),z(`[Runner] Session ID is still active: ${A}`)):z("[Runner] Session ID has been cleared")}catch(P){z(`[Runner] Error terminating session: ${P.message}`)}}z("[Runner] Attempting to close transport (3s timeout)..."),await Promise.race([l.close(),new Promise((A,P)=>setTimeout(()=>P(new Error("[Runner] Transport close timeout after 3s")),3e3))]),z("[Runner] Transport closed successfully")}catch(A){z(`[Runner] Error during transport cleanup: ${A.message}`)}z("[Runner] Cleanup completed")};return process.on("SIGINT",h),process.on("SIGTERM",h),process.on("beforeExit",h),process.on("exit",()=>{z("[Runner] Final cleanup on exit")}),process.stdin.on("end",()=>{z("[Runner] STDIN closed (client disconnected)"),h().catch(A=>{z(`[Runner] Error during stdin close cleanup: ${A}`),process.exit(1)})}),process.stdin.on("error",A=>{z(`[Runner] STDIN error: ${A.message}`),h().catch(P=>{z(`[Runner] Error during stdin error cleanup: ${P}`),process.exit(1)})}),process.stdin.on("data",A=>q(A).catch(P=>c(P,"[Runner] Error processing message"))),await C(),S};async function nj(e,t,r){try{let n=await h1();n.success||z(`[Runner] Settings initialization warning: ${n.error}`);let i=await Bo(e);if(!i)throw new Error(`Could not resolve server: ${e}`);z(`[Runner] Connecting to server: ${JSON.stringify({id:i.qualifiedName,connectionTypes:i.connections.map(u=>u.type)})}`);let a=await Cf();await Sye(i,t,a,r)}catch(n){z(`[Runner] Error: ${n instanceof Error?n.message:n}`),process.exit(1)}}async function Sye(e,t,r,n){let i=Ro(e);if(i.type==="http"){if(!i.deploymentUrl)throw new Error("Missing deployment URL");if(!n)throw new Error("API key is required for remote connections");await rj(i.deploymentUrl,n,t)}else if(i.type==="stdio")await ZI(e,t,n,r);else throw new Error(`Unsupported connection type: ${i.type}`)}var Mo=ce($e());process.removeAllListeners("warning");process.on("warning",e=>{e.name==="DeprecationWarning"&&e.message.includes("punycode")||console.warn(e)});async function ij(e,t){try{if(No(t).type==="command"){console.log(Mo.default.yellow(`Uninstallation is currently not supported for ${t}`));return}let n=Io(t);if(!n.mcpServers[e]){console.log(Mo.default.red(`Server ${e} is not installed for ${t}`));return}delete n.mcpServers[e],yf(n,t),console.log(Mo.default.green(`${e} successfully uninstalled from ${t}`)),await Sf(t)}catch(r){r instanceof Error?console.error(Mo.default.red(`Error: ${r.message}`)):console.error(Mo.default.red("An unexpected error occurred during uninstallation")),process.exit(1)}}var cv=process.argv[2],gn=process.argv[3],Aye=process.argv.indexOf("--client"),lv=process.argv.indexOf("--config"),aj=process.argv.indexOf("--key"),Oye=process.argv.includes("--verbose"),Tye=process.argv.includes("--help");fI(Oye);var uj=()=>{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 (required)"),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)};(Tye||!cv)&&uj();var qye=(e,t)=>{if(["run","inspect"].includes(e)||e==="list"&&gn==="clients")return;t===-1&&(console.error(Nf.default.yellow(`Please specify a client using --client. Valid options are: ${I1.join(", ")}`)),process.exit(1));let r=process.argv[t+1];return I1.includes(r)||(console.error(Nf.default.yellow(`Invalid client "${r}". Valid options are: ${I1.join(", ")}`)),process.exit(1)),r},dv=qye(cv,Aye),oj=lv!==-1?(()=>{try{let e=process.argv[lv+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(Nf.default.red(`Error parsing config: ${t}`)),process.exit(1)}})():{},sj=aj!==-1?process.argv[aj+1]:void 0;async function Pye(){switch(cv){case"inspect":gn||(console.error("Please provide a server ID to inspect"),process.exit(1)),await CI(gn);break;case"install":gn||(console.error("Please provide a server ID to install"),process.exit(1)),await $I(gn,dv,lv!==-1?oj:void 0,sj);break;case"uninstall":gn||(console.error("Please provide a server ID to uninstall"),process.exit(1)),await ij(gn,dv);break;case"run":gn||(console.error("Please provide a server ID to run"),process.exit(1)),await nj(gn,oj,sj);break;case"list":await WI(gn,dv);break;default:uj()}}Pye();
104
104
  /*! Bundled license information:
105
105
 
106
106
  lodash/lodash.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithery/cli",
3
- "version": "1.1.78",
3
+ "version": "1.1.79",
4
4
  "type": "commonjs",
5
5
  "private": false,
6
6
  "homepage": "https://smithery.ai/",