api_list_endpoints
Lists all available endpoints from Swagger API specifications, with filtering by HTTP method or keywords to help developers explore and understand API capabilities.
Instructions
列出示例API API的所有可用端点
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | 过滤端点的关键词(可选) | |
| method | No | 按HTTP方法过滤(可选) |
Implementation Reference
- src/index.js:622-649 (handler)The main handler function for the 'api_list_endpoints' tool. It processes the input arguments (filter and method), retrieves the list of endpoints using the helper function, and returns a formatted text response listing all matching API endpoints.async function listEndpoints(args) { const { filter = "", method = "" } = args || {}; try { const endpoints = listApiEndpoints(filter, method); return { content: [ { type: "text", text: `找到 ${endpoints.length} 个API端点:\n\n${endpoints .map( (ep) => `${ep.method} ${ep.path}\n ${ ep.summary || ep.description || "无描述" }\n 标签: ${ep.tags.join(", ") || "无"}` ) .join("\n\n")}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `获取端点列表失败: ${error.message}` ); } }
- src/index.js:308-325 (schema)The tool definition including name, description, and input schema for 'api_list_endpoints'. Defines optional filter by keyword or HTTP method.{ name: "api_list_endpoints", description: `列出${swaggerDoc.info.title} API的所有可用端点`, inputSchema: { type: "object", properties: { filter: { type: "string", description: "过滤端点的关键词(可选)", }, method: { type: "string", enum: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"], description: "按HTTP方法过滤(可选)", }, }, }, },
- src/index.js:824-829 (registration)Registration of the ListToolsRequestHandler, which calls createUnifiedApiTools() to provide the list of available tools, including 'api_list_endpoints'.server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = createUnifiedApiTools(); return { tools: tools, }; });
- src/index.js:832-852 (registration)Registration of the CallToolRequestHandler, which dispatches calls to 'api_list_endpoints' to the listEndpoints handler function.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:400-434 (helper)Helper function that iterates over the Swagger paths and methods to build a list of endpoints, applying optional filters by keyword or HTTP method.function listApiEndpoints(filter = "", methodFilter = "") { const swaggerDoc = global.swaggerDoc; const endpoints = []; for (const [path, methods] of Object.entries(swaggerDoc.paths)) { for (const [method, operation] of Object.entries(methods)) { if (typeof operation !== "object" || !operation) continue; const endpoint = { method: method.toUpperCase(), path: path, summary: operation.summary || "", description: operation.description || "", operationId: operation.operationId || "", tags: operation.tags || [], }; // 应用过滤器 if ( filter && !JSON.stringify(endpoint).toLowerCase().includes(filter.toLowerCase()) ) { continue; } if (methodFilter && endpoint.method !== methodFilter.toUpperCase()) { continue; } endpoints.push(endpoint); } } return endpoints; }