import{findDefinitionByName as h,resolveParameters as T,resolveRequestBody as g,resolveResponses as P}from"../utils.js";import{checkEndpointAndDeleteXMcp as v}from"../../utils/xmcp-utils.js";import{telemetry as a}from"../../../../telemetry/index.js";const s="get-endpoint-info",c=["GET","POST","PUT","DELETE","PATCH","OPTIONS","HEAD","TRACE"],O={type:"object",required:["name","path","method"],additionalProperties:!1,properties:{name:{type:"string",description:"API name (or part of it)",minLength:1},path:{type:"string",description:"Endpoint path (e.g. /api/v1/users)",minLength:1},method:{type:"string",description:"HTTP method (GET, POST, PUT, DELETE, etc.)",enum:[...c,...c.map(n=>n.toLowerCase())],minLength:1}}};function M(n,d){n.tool(s,"Get comprehensive information about specific endpoint including parameters, security, and examples",O,async({name:i,path:o,method:p})=>{try{const e=h(d,i),m=o.startsWith("/")?o:`/${o}`;if(!e)return{content:[{type:"text",text:`No APIs found matching "${i}"`}]};const{title:l=""}=e.info||{},r=e.paths?.[m],u=p.toLowerCase();if(!r)return{content:[{type:"text",text:"Endpoint not found"}],isError:!0};const t=r[u];if(!t||!v(t,"docs"))return{content:[{type:"text",text:"Endpoint not found"}],isError:!0};const y=r?.parameters||[],E=t.parameters||[],f={...t,parameters:T({pathParams:y,opParams:E,definition:e}),requestBody:g(t.requestBody,e),responses:P(t.responses,e)};return a.sendMcpToolCalledMessage({server_type:"docs",tool:s}),{content:[{type:"text",text:JSON.stringify({api:l,version:e.info?.version||"",servers:e.servers||[],endpoint:{path:o,method:p.toUpperCase(),...f},globalSecurity:e.security||[],securitySchemes:e.components?.securitySchemes||[]},null,2)}]}}catch(e){throw a.sendMcpErrorMessage({server_type:"docs",tool:s,message:e?.message||"",stack:e?.stack||""}),e}})}export{M as registerGetEndpointTools};
