list_endpoints
Retrieve and display all API endpoints by extracting Swagger documentation to simplify API integration and server modeling.
Instructions
List all available API endpoints after fetching Swagger documentation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/listEndpoints.ts:26-49 (handler)The MCP tool handler that executes the listEndpoints tool logic: logs input, calls the core service, formats endpoints as JSON text content or error.export async function handleListEndpoints(input: any) { logger.info('Calling swaggerService.listEndpoints()'); logger.info(`Input parameters: ${JSON.stringify(input)}`); try { const endpoints = await swaggerService.listEndpoints(input); logger.info(`Endpoints response: ${JSON.stringify(endpoints).substring(0, 200)}...`); return { content: [{ type: "text", text: JSON.stringify(endpoints, null, 2) }] }; } catch (error: any) { logger.error(`Error in listEndpoints handler: ${error.message}`); return { content: [{ type: "text", text: `Error retrieving endpoints: ${error.message}` }] }; } }
- src/tools/listEndpoints.ts:10-23 (schema)The tool schema definition for 'listEndpoints', including name, description, and input schema requiring swaggerFilePath.export const listEndpoints = { name: "listEndpoints", description: "Lists all endpoints from the Swagger definition including their HTTP methods and descriptions.", inputSchema: { type: "object", properties: { swaggerFilePath: { type: "string", description: "Path to the Swagger file. This should be the full file path that was saved in the .swagger-mcp file after calling getSwaggerDefinition. You can find this path in the .swagger-mcp file in the solution root with the format SWAGGER_FILEPATH=path/to/file.json." } }, required: ["swaggerFilePath"] } };
- src/tools/index.ts:13-19 (registration)Registration of the listEndpoints tool in the toolDefinitions array exported for MCP server listTools handler.export const toolDefinitions = [ getSwaggerDefinition, listEndpoints, listEndpointModels, generateModelCode, generateEndpointToolCode ];
- src/services/listEndpoints.ts:26-75 (helper)Core service function that reads Swagger file, parses paths and operations, extracts endpoint details (path, method, summary, etc.), returns Endpoint[] array.async function listEndpoints(params: SwaggerFileParams): Promise<Endpoint[]> { try { const { swaggerFilePath } = params; if (!swaggerFilePath) { throw new Error('Swagger file path is required'); } if (!fs.existsSync(swaggerFilePath)) { throw new Error(`Swagger file not found at ${swaggerFilePath}`); } // Read the Swagger file const swaggerContent = fs.readFileSync(swaggerFilePath, 'utf8'); const swaggerJson = JSON.parse(swaggerContent); // Check if it's OpenAPI or Swagger const isOpenApi = !!swaggerJson.openapi; const paths = swaggerJson.paths || {}; // Extract endpoints const endpoints: Endpoint[] = []; for (const path in paths) { const pathItem = paths[path]; for (const method in pathItem) { if (['get', 'post', 'put', 'delete', 'patch', 'options', 'head'].includes(method)) { const operation = pathItem[method]; endpoints.push({ path, method: method.toUpperCase(), summary: operation.summary, description: operation.description, operationId: operation.operationId, tags: operation.tags }); } } } return endpoints; } catch (error: any) { logger.error(`Error listing endpoints: ${error.message}`); throw error; } } export default listEndpoints;
- src/index.ts:118-119 (registration)Dispatcher switch case in MCP server's CallToolRequestSchema handler that routes to handleListEndpoints.case "listEndpoints": return await handleListEndpoints(input);