import{fileURLToPath as m}from"node:url";import{dirname as f,join as l}from"node:path";import{logger as c}from"../../tools/notifiers/logger.js";import{reporter as g}from"../../tools/notifiers/reporter.js";import{filterIgnoredDefinitions as u,getCleanedUpDefinitions as h,isMcpInRedirects as v}from"./utils.js";import{telemetryTraceStep as D}from"../../../cli/telemetry/helpers/trace-step.js";const a="mcp-docs-server-handler",y=f(m(import.meta.url));async function C(){return{id:"mcp",async processContent(i,r){await D("build.plugin.mcp",async t=>{const o=await i.loadOpenApiDefinitions(r),n=await r.getConfig(),{mcp:e,redirects:s}=n;if(t?.setAttribute("config",JSON.stringify(e||{})),!(e?.hide||e?.docs?.hide)&&(v(s)&&g.panicOnBuildContentError('The reserved route "/mcp" cannot be used in redirect configuration. Please remove any redirects involving "/mcp" from your redocly.yaml config.'),!e?.docs?.hide)){c.info("Configuring MCP servers...");const d=l(y,"./handlers/docs-mcp-handler.js"),p=h(u(o,e?.docs?.ignore||[]));await P(i,d,p,e,i.outdir)}})}}}var H=C;async function P(i,r,t,o,n){i.createRequestHandler(a,r),i.addApiRoute({slug:"/mcp",requestHandlerId:a,httpMethod:"all",getStaticData:async()=>({props:{config:{openapiDefinitions:t.map(e=>({definition:e.definition,relativePath:e.relativePath})),outdir:n,catalogName:o?.docs?.name||"Docs MCP Server"}}})}),c.info("Registered Docs MCP Server endpoint at /mcp")}export{a as MCP_DOCS_SERVER_HANDLER_ID,H as default,C as mcpServerPlugin};
