import{o as e}from"./chunk-DR8-3Aex.js";import{n as t,t as n}from"./p-map-D7WEmnBE.js";import{Mt as r,Rn as i,T as a,b as o,f as s,g as c,h as ee,t as l,v as te,x as u}from"./src-Di342QoJ.js";import{t as d}from"./jsx-runtime-D-D469L8.js";import{Sc as f,dc as p,lc as m,yc as h}from"./paths-Ci1iwL5Y.js";import{K as g,U as _}from"./debug-otxXY3j-.js";import{n as v,r as y}from"./analytics-DqMQntaB.js";import{n as b,o as x}from"./process-DMKLUQIO.js";import{i as S,o as C}from"./platform-mh9ypxS8.js";import{s as w,u as ne}from"./types-KeqFPzY5.js";import{l as T,o as re}from"./stringUtils-KZoO4GUd.js";import{$C as ie,$x as ae,DC as oe,Dw as E,EC as D,Gw as O,Hy as k,Iw as A,Iy as j,Ly as M,Ow as N,QC as P,Rw as F,SE as I,Vw as L,Vy as R,XC as z,Yx as B,ZC as V,_w as H,cC as U,gw as W,jw as G,lC as K,rw as se,tS as ce,tw as le,wE as q,zw as ue}from"./loadAgentsDir-C_wFhytF.js";import{n as J,t as Y}from"./exit-DOBLl8jN.js";import{stat as de}from"fs/promises";import{cwd as fe}from"process";n();var X=e(i(),1);q(),b(),l(),L(),re(),oe(),k();var Z=d();function pe({servers:e,scope:t,onDone:n}){let r=Object.keys(e),[i,l]=(0,X.useState)({});(0,X.useEffect)(()=>{A().then(({servers:e})=>l(e))},[]);let d=r.filter(e=>i[e]!==void 0);async function f(n){let r=0;for(let a of n){let n=e[a];if(n){let e=a;if(i[e]!==void 0){let t=1;for(;i[`${a}_${t}`]!==void 0;)t++;e=`${a}_${t}`}await G(e,n,t),r++}}m(r)}let[p]=a(),m=(0,X.useCallback)(e=>{x(e>0?`\n${te(`success`,p)(`Successfully imported ${e} MCP ${T(e,`server`)} to ${t} config.`)}\n`:`
No servers were imported.`),n(),I()},[p,t,n]),h=(0,X.useCallback)(()=>{m(0)},[m]);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(s,{title:`Import MCP Servers from Claude Desktop`,subtitle:`Found ${r.length} MCP ${T(r.length,`server`)} in Claude Desktop.`,color:`success`,onCancel:h,hideInputGuide:!0,children:[d.length>0&&(0,Z.jsx)(o,{color:`warning`,children:`Note: Some servers already exist with the same name. If selected, they will be imported with a numbered suffix.`}),(0,Z.jsx)(o,{children:`Please select the servers you want to import:`}),(0,Z.jsx)(R,{options:r.map(e=>({label:`${e}${d.includes(e)?` (already exists)`:``}`,value:e})),defaultValue:r.filter(e=>!d.includes(e)),onSubmit:f,onCancel:h,hideIndexes:!0})]}),(0,Z.jsx)(u,{paddingX:1,children:(0,Z.jsx)(o,{dimColor:!0,italic:!0,children:(0,Z.jsxs)(ee,{children:[(0,Z.jsx)(c,{shortcut:`Space`,action:`select`}),(0,Z.jsx)(c,{shortcut:`Enter`,action:`confirm`}),(0,Z.jsx)(D,{action:`confirm:no`,context:`Confirmation`,fallback:`Esc`,description:`cancel`})]})})})]})}l(),M(),v(),ie(),ce(),L(),N(),K(),h(),_(),q(),w(),C();async function Q(e,t){try{let n=await B(e,t);return n.type===`connected`?`✓ Connected`:n.type===`needs-auth`?`! Needs authentication`:`✗ Failed to connect`}catch{return`✗ Connection error`}}async function me({debug:e,verbose:t}){let n=fe();y(`tengu_mcp_start`,{});try{await de(n)}catch(e){throw g(e)&&Y(`Error: Directory ${n} does not exist`),e}try{let{setup:r}=await import(`./setup-CDxkPTCq.js`);await r(n,`default`,!1,!1,void 0,!1);let{startMCPServer:i}=await import(`./mcp-CbDDqdzF.js`);await i(n,e??!1,t??!1)}catch(e){Y(`Error: Failed to start MCP server: ${e}`)}}async function he(e,t){let n=F(e),r=()=>{n&&(n.type===`sse`||n.type===`http`)&&(V(e,n),z(e,n))};try{if(t.scope){let n=H(t.scope);y(`tengu_mcp_delete`,{name:e,scope:n}),await O(e,n),r(),process.stdout.write(`Removed MCP server ${e} from ${n} config\n`),J(`File modified: ${W(n)}`)}let n=m(),i=p(),{servers:a}=ue(`project`),o=!!a[e],s=[];if(n.mcpServers?.[e]&&s.push(`local`),o&&s.push(`project`),i.mcpServers?.[e]&&s.push(`user`),s.length===0)Y(`No MCP server found with name: "${e}"`);else if(s.length===1){let t=s[0];y(`tengu_mcp_delete`,{name:e,scope:t}),await O(e,t),r(),process.stdout.write(`Removed MCP server "${e}" from ${t} config\n`),J(`File modified: ${W(t)}`)}else process.stderr.write(`MCP server "${e}" exists in multiple scopes:\n`),s.forEach(e=>{process.stderr.write(`  - ${E(e)} (${W(e)})\n`)}),process.stderr.write(`
To remove from a specific scope, use:
`),s.forEach(t=>{process.stderr.write(`  claude mcp remove "${e}" -s ${t}\n`)}),Y()}catch(e){Y(e.message)}}async function ge(){y(`tengu_mcp_list`,{});let{servers:e}=await A();if(Object.keys(e).length===0)console.log("No MCP servers configured. Use `claude mcp add` to add a server.");else{console.log(`Checking MCP server health...
`);let n=await t(Object.entries(e),async([e,t])=>({name:e,server:t,status:await Q(e,t)}),{concurrency:ae()});for(let{name:e,server:t,status:r}of n)if(t.type===`sse`)console.log(`${e}: ${t.url} (SSE) - ${r}`);else if(t.type===`http`)console.log(`${e}: ${t.url} (HTTP) - ${r}`);else if(t.type===`claudeai-proxy`)console.log(`${e}: ${t.url} - ${r}`);else if(!t.type||t.type===`stdio`){let n=t,i=Array.isArray(n.args)?n.args:[];console.log(`${e}: ${n.command} ${i.join(` `)} - ${r}`)}}await I(0)}async function $(e){y(`tengu_mcp_get`,{name:e});let t=F(e);t||Y(`No MCP server found with name: ${e}`),console.log(`${e}:`),console.log(`  Scope: ${E(t.scope)}`);let n=await Q(e,t);if(console.log(`  Status: ${n}`),t.type===`sse`){if(console.log(`  Type: sse`),console.log(`  URL: ${t.url}`),t.headers){console.log(`  Headers:`);for(let[e,n]of Object.entries(t.headers))console.log(`    ${e}: ${n}`)}if(t.oauth?.clientId||t.oauth?.callbackPort){let n=[];t.oauth.clientId&&(n.push(`client_id configured`),P(e,t)?.clientSecret&&n.push(`client_secret configured`)),t.oauth.callbackPort&&n.push(`callback_port ${t.oauth.callbackPort}`),console.log(`  OAuth: ${n.join(`, `)}`)}}else if(t.type===`http`){if(console.log(`  Type: http`),console.log(`  URL: ${t.url}`),t.headers){console.log(`  Headers:`);for(let[e,n]of Object.entries(t.headers))console.log(`    ${e}: ${n}`)}if(t.oauth?.clientId||t.oauth?.callbackPort){let n=[];t.oauth.clientId&&(n.push(`client_id configured`),P(e,t)?.clientSecret&&n.push(`client_secret configured`)),t.oauth.callbackPort&&n.push(`callback_port ${t.oauth.callbackPort}`),console.log(`  OAuth: ${n.join(`, `)}`)}}else if(t.type===`stdio`){console.log(`  Type: stdio`),console.log(`  Command: ${t.command}`);let e=Array.isArray(t.args)?t.args:[];if(console.log(`  Args: ${e.join(` `)}`),t.env){console.log(`  Environment:`);for(let[e,n]of Object.entries(t.env))console.log(`    ${e}=${n}`)}}console.log(`\nTo remove this server, run: claude mcp remove "${e}" -s ${t.scope}`),await I(0)}async function _e(e,t,n){try{let r=H(n.scope),i=ne(t),a=n.clientSecret&&i&&typeof i==`object`&&`type`in i&&(i.type===`sse`||i.type===`http`)&&`url`in i&&typeof i.url==`string`&&`oauth`in i&&i.oauth&&typeof i.oauth==`object`&&`clientId`in i.oauth?await le():void 0;await G(e,i,r);let o=i&&typeof i==`object`&&`type`in i?String(i.type||`stdio`):`stdio`;a&&i&&typeof i==`object`&&`type`in i&&(i.type===`sse`||i.type===`http`)&&`url`in i&&typeof i.url==`string`&&se(e,{type:i.type,url:i.url},a),y(`tengu_mcp_add`,{scope:r,source:`json`,type:o}),J(`Added ${o} MCP server ${e} to ${r} config`)}catch(e){Y(e.message)}}async function ve(e){try{let t=H(e.scope);y(`tengu_mcp_add`,{scope:t,platform:S(),source:`desktop`});let{readClaudeDesktopMcpServers:n}=await import(`./claudeDesktop-BqTW_pbB.js`),i=await n();Object.keys(i).length===0&&J(`No MCP servers found in Claude Desktop configuration or configuration file does not exist.`);let{unmount:a}=await r((0,Z.jsx)(U,{children:(0,Z.jsx)(j,{children:(0,Z.jsx)(pe,{servers:i,scope:t,onDone:()=>{a()}})})}),{exitOnCtrlC:!0})}catch(e){Y(e.message)}}async function ye(){y(`tengu_mcp_reset_mcpjson_choices`,{}),f(e=>({...e,enabledMcpjsonServers:[],disabledMcpjsonServers:[],enableAllProjectMcpServers:!1})),J(`All project-scoped (.mcp.json) server approvals and rejections have been reset.
You will be prompted for approval next time you start Claude Code.`)}export{ve as mcpAddFromDesktopHandler,_e as mcpAddJsonHandler,$ as mcpGetHandler,ge as mcpListHandler,he as mcpRemoveHandler,ye as mcpResetChoicesHandler,me as mcpServeHandler};