import{createMcpRequestHandler as v}from"./mcp-request-handler.js";import{createDocsMcpServer as M}from"../servers/docs-server.js";import{filterDefinitionsByRbac as D}from"../utils.js";import{createInternalServerError as h}from"./errors.js";import{McpServerType as y}from"../constants.js";import{telemetry as c}from"../../../telemetry/index.js";import{constructInvalidTokenResponse as R,constructUnauthorizedResponse as S,handleMcpAuth as w,shouldHandleMcpAuth as I}from"../auth/auth-handlers.js";async function T(t,r,o,s){try{c.initialize();const e=r,n=e?.props?.config?.openapiDefinitions||[],a=e?.props?.config?.outdir||"",p=e?.props?.config?.catalogName||"Docs MCP server",f=new URL(s.url).origin,{user:i,config:{rbac:m={},mcp:d={}}}=t,l=D(n,i,m,!!i?.isAuthenticated).map(({definition:g})=>g),u=d.docs?.name||p;return await M(l,u,f,o,a)}catch(e){throw c.sendMcpErrorMessage({server_type:"docs",message:e?.message||"",stack:e?.stack||""}),h(e?.message||"Internal server error mcp docs")}}const U=v({createServerInstance:T,serverType:y.Docs}),b=async(t,r,o)=>{if(I(r)){const{isAuthenticated:s,isTokenValid:e,currentUser:n}=await w(t,r);if(!s)return S(new URL(t.url).origin);if(!e)return R();n&&(r.user=n)}return U(t,r,o)};var B=b;export{B as default};
