api_list_endpoints
List all available API endpoints from Swagger specifications to discover and understand available operations. Filter results by HTTP method or keywords to find specific endpoints quickly.
Instructions
列出示例API API的所有可用端点
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | 过滤端点的关键词(可选) | |
| method | No | 按HTTP方法过滤(可选) |
Implementation Reference
- src/index.js:622-652 (handler)The main handler function for the 'api_list_endpoints' tool. It invokes the helper to list endpoints with optional filters and formats the response as MCP content.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 input schema and metadata definition for the 'api_list_endpoints' tool, returned by createUnifiedApiTools().{ 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:839-840 (registration)Registration of the tool handler in the switch statement within the CallToolRequestSchema handler.case "api_list_endpoints": return await listEndpoints(args);
- src/index.js:400-434 (helper)Helper function that parses the Swagger document to extract API endpoints and applies filtering.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; }
- src/index.js:824-829 (registration)Registers the ListToolsRequestSchema handler, which provides the list of tools including 'api_list_endpoints' via createUnifiedApiTools().server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = createUnifiedApiTools(); return { tools: tools, }; });