api_get_endpoint_info
Retrieve detailed information about specific API endpoints from Swagger 2.0 specifications to understand parameters, responses, and HTTP methods.
Instructions
获取示例API API特定端点的详细信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | Yes | HTTP方法 | |
| path | Yes | API路径 |
Implementation Reference
- src/index.js:654-694 (handler)The primary handler function that executes the logic for the 'api_get_endpoint_info' tool. It extracts method and path from args, retrieves endpoint info using getEndpointInfo, formats parameters and details, and returns a formatted text response.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 input schema definition for the 'api_get_endpoint_info' tool, specifying required 'method' and 'path' parameters, defined within the createUnifiedApiTools function.{ 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:824-829 (registration)Registration handler for ListToolsRequestSchema, which provides the tool list including the schema for 'api_get_endpoint_info' via createUnifiedApiTools().server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = createUnifiedApiTools(); return { tools: tools, }; });
- src/index.js:832-852 (registration)The CallToolRequestSchema handler registration, containing the switch statement that dispatches 'api_get_endpoint_info' calls to the getEndpointDetails handler.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-468 (helper)Helper function that extracts detailed information about a specific endpoint from the global Swagger documentation, used by the tool handler.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 || {}, }; }