api_get_endpoint_info
Retrieve detailed information about specific API endpoints from Swagger 2.0 specifications, including parameters and methods, to enable direct REST API calls through AI assistants.
Instructions
获取示例API API特定端点的详细信息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | Yes | HTTP方法 | |
| path | Yes | API路径 |
Implementation Reference
- src/index.js:654-694 (handler)The main handler function for the 'api_get_endpoint_info' tool. It validates input, retrieves endpoint information using getEndpointInfo, formats the details including parameters and responses, and returns the content.
async function getEndpointDetails(args) { const { method, path } = args || {}; if (!method || !path) { throw new McpError(ErrorCode.InvalidParams, "method和path参数是必需的"); } try { const info = getEndpointInfo(method, path); const paramInfo = info.parameters .map( (p) => ` - ${p.name} (${p.in}): ${p.type} ${ p.required ? "[必需]" : "[可选]" }\n ${p.description || "无描述"}` ) .join("\n"); return { content: [ { type: "text", text: `端点详情: ${info.method} ${info.path}\n\n` + `摘要: ${info.summary}\n` + `描述: ${info.description}\n` + `操作ID: ${info.operationId}\n` + `标签: ${info.tags.join(", ")}\n\n` + `参数:\n${paramInfo || " 无参数"}\n\n` + `响应: ${JSON.stringify(info.responses, null, 2)}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `获取端点详情失败: ${error.message}` ); } } - src/index.js:326-344 (schema)The tool definition including name, description, and inputSchema for 'api_get_endpoint_info' used in tool listing.
{ name: "api_get_endpoint_info", description: `获取${swaggerDoc.info.title} API特定端点的详细信息`, inputSchema: { type: "object", properties: { method: { type: "string", enum: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"], description: "HTTP方法", }, path: { type: "string", description: "API路径", }, }, required: ["method", "path"], }, }, - src/index.js:832-852 (registration)The CallToolRequestSchema handler registration where the switch statement dispatches to getEndpointDetails for 'api_get_endpoint_info'.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case "api_call": return await executeUnifiedApiCall(args); case "api_list_endpoints": return await listEndpoints(args); case "api_get_endpoint_info": return await getEndpointDetails(args); default: throw new McpError(ErrorCode.InvalidRequest, `未知工具: ${name}`); } } catch (error) { if (error instanceof McpError) { throw error; } throw new McpError(ErrorCode.InternalError, error.message); } }); - src/index.js:439-469 (helper)Helper function that extracts detailed information about a specific endpoint from the Swagger document.
function getEndpointInfo(method, path) { const swaggerDoc = global.swaggerDoc; if ( !swaggerDoc.paths[path] || !swaggerDoc.paths[path][method.toLowerCase()] ) { throw new Error(`端点 ${method.toUpperCase()} ${path} 不存在`); } const operation = swaggerDoc.paths[path][method.toLowerCase()]; const params = operation.parameters || []; return { method: method.toUpperCase(), path: path, summary: operation.summary || "", description: operation.description || "", operationId: operation.operationId || "", tags: operation.tags || [], parameters: params.map((param) => ({ name: param.name, in: param.in, type: param.type, required: param.required || false, description: param.description || "", })), responses: operation.responses || {}, }; } - src/index.js:824-829 (registration)The ListToolsRequestSchema handler that returns the list of tools including 'api_get_endpoint_info' via createUnifiedApiTools().
server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = createUnifiedApiTools(); return { tools: tools, }; });