import{B as e,M as t,d as n,n as r,t as i}from"./server-DzOdtq8A.js";import{Dr as a,Pr as o}from"./paths-Ci1iwL5Y.js";import{E as s,O as c}from"./debug-otxXY3j-.js";import{o as l,s as u}from"./log-DSV4Ht5l.js";import{$D as d,$u as f,Ba as p,G as m,K as h,Qu as g,Uo as _,bD as v,cl as y,eO as b,fu as x,ho as S,mh as C,ph as w,pu as T,sl as E,yD as D,za as O}from"./loadAgentsDir-C_wFhytF.js";import{Qn as k,Xn as A,Zn as j}from"./prompt-6ZKyqv6z.js";import{a as M,o as N}from"./fileStateCache-BhVfo23e.js";import{n as P,t as F}from"./stdio-Cg20AQ5W.js";r(),P(),e(),v(),O(),k(),f(),b(),N(),l(),_(),o(),h(),w(),s(),T(),E();var I=[p];async function L(e,r,o){let s=M(100);C(e);let l=new i({name:`claude/tengu`,version:`2.7.1`},{capabilities:{tools:{}}});l.setRequestHandler(t,async()=>{let e=j(),t=g(e);return{tools:await Promise.all(t.map(async n=>{let r;if(n.outputSchema){let e=y(n.outputSchema);typeof e==`object`&&e&&`type`in e&&e.type===`object`&&(r=e)}return{...n,description:await n.prompt({getToolPermissionContext:async()=>e,tools:t,agents:[]}),inputSchema:y(n.inputSchema),outputSchema:r}}))}}),l.setRequestHandler(n,async({params:{name:e,arguments:t}})=>{let n=g(j()),i=A(n,e);if(!i)throw Error(`Tool ${e} not found`);let l={abortController:d(),options:{commands:I,tools:n,mainLoopModel:a(),thinkingConfig:{type:`disabled`},mcpClients:[],mcpResources:{},isNonInteractiveSession:!0,debug:r,verbose:o,agentDefinitions:{activeAgents:[],allAgents:[]}},getAppState:()=>D(),setAppState:()=>{},messages:[],readFileState:s,setInProgressToolUseIDs:()=>{},setResponseLength:()=>{},updateFileHistoryState:()=>{},updateAttributionState:()=>{}};try{if(!i.isEnabled())throw Error(`Tool ${e} is not enabled`);let n=await i.validateInput?.(t??{},l);if(n&&!n.result)throw Error(`Tool ${e} input is invalid: ${`message`in n?n.message:String(n)}`);let r=await i.call(t??{},l,m,S({content:[]}));return{content:[{type:`text`,text:typeof r==`string`?r:c(r.data)}]}}catch(e){return u(e),{isError:!0,content:[{type:`text`,text:(e instanceof Error?x(e):[String(e)]).filter(Boolean).join(`
`).trim()||`Error`}]}}});async function f(){let e=new F;await l.connect(e)}return await f()}export{L as startMCPServer};