import{u as y,d as C,t as e}from"./index-oE_2MbI2.js";import{u as g}from"./use-binding-CD2rnHew.js";import{a as S,b as v}from"./use-connection-7qXdMybp.js";import{e as B}from"./extract-connection-data-BWxoMBxo.js";import{f as I,c as P,e as _}from"./registry-utils-BcBIgH2H.js";function w(t){return t.startsWith("@")?t:`@${t}`}function F(){const{org:t}=y(),{data:s}=C.useSession(),i=S(),l=v(),u=g(l);return{installByBinding:async r=>{if(!t||!s?.user?.id){e.error("Not authenticated");return}const d=w(r),a=(await Promise.all(u.map(async o=>{const c=I(o.tools);if(!c)return null;try{const h=await P(o.id,t.id,c,{where:{appName:d}});return _(h??[])[0]??null}catch{return null}}))).find(o=>o!==null);if(!a){e.error(`MCP Server not found in registry: ${r}`);return}const n=B(a,t.id,s.user.id),m=n.connection_type==="STDIO",f=!!n.connection_url,p=m&&n.connection_headers&&typeof n.connection_headers=="object"&&"command"in n.connection_headers;if(!f&&!p){e.error("This MCP Server cannot be connected: no connection method available");return}return await i.create.mutateAsync(n),{id:n.id,connection:n}},isInstalling:i.create.isPending}}export{F as u};
