search_endpoints
Search API endpoint paths and descriptions using a specific pattern to quickly locate relevant endpoints in a Swagger/OpenAPI specification.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiId | Yes | ID of the loaded API | |
| pattern | Yes | Search pattern for endpoint paths or descriptions |
Implementation Reference
- src/index.ts:332-394 (registration)Registration of the 'search_endpoints' tool using this.server.tool() in the setupTools methodthis.server.tool( "search_endpoints", { apiId: z.string().describe("ID of the loaded API"), pattern: z.string().describe("Search pattern for endpoint paths or descriptions") }, async ({ apiId, pattern }) => { try { const api = this.apis.get(apiId); if (!api) { return { content: [{ type: "text", text: `API with ID '${apiId}' not found` }], isError: true }; } const matchingEndpoints: Array<{method: string, path: string, summary?: string, description?: string}> = []; const searchPattern = pattern.toLowerCase(); Object.entries(api.spec.paths || {}).forEach(([path, pathItem]) => { if (!pathItem) return; ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'].forEach(method => { const operation = (pathItem as any)[method] as OpenAPIV3.OperationObject; if (operation) { const matchesPath = path.toLowerCase().includes(searchPattern); const matchesSummary = operation.summary?.toLowerCase().includes(searchPattern); const matchesDescription = operation.description?.toLowerCase().includes(searchPattern); if (matchesPath || matchesSummary || matchesDescription) { matchingEndpoints.push({ method: method.toUpperCase(), path, summary: operation.summary, description: operation.description }); } } }); }); return { content: [{ type: "text", text: matchingEndpoints.length > 0 ? JSON.stringify(matchingEndpoints, null, 2) : `No endpoints found matching pattern: ${pattern}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error searching endpoints: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
- src/index.ts:334-337 (schema)Zod input schema defining apiId and pattern parameters for the tool{ apiId: z.string().describe("ID of the loaded API"), pattern: z.string().describe("Search pattern for endpoint paths or descriptions") },
- src/index.ts:338-393 (handler)Handler function that retrieves the API spec, iterates over paths and operations, matches against the pattern in path/summary/description, and returns matching endpoints as JSON or error message.async ({ apiId, pattern }) => { try { const api = this.apis.get(apiId); if (!api) { return { content: [{ type: "text", text: `API with ID '${apiId}' not found` }], isError: true }; } const matchingEndpoints: Array<{method: string, path: string, summary?: string, description?: string}> = []; const searchPattern = pattern.toLowerCase(); Object.entries(api.spec.paths || {}).forEach(([path, pathItem]) => { if (!pathItem) return; ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'].forEach(method => { const operation = (pathItem as any)[method] as OpenAPIV3.OperationObject; if (operation) { const matchesPath = path.toLowerCase().includes(searchPattern); const matchesSummary = operation.summary?.toLowerCase().includes(searchPattern); const matchesDescription = operation.description?.toLowerCase().includes(searchPattern); if (matchesPath || matchesSummary || matchesDescription) { matchingEndpoints.push({ method: method.toUpperCase(), path, summary: operation.summary, description: operation.description }); } } }); }); return { content: [{ type: "text", text: matchingEndpoints.length > 0 ? JSON.stringify(matchingEndpoints, null, 2) : `No endpoints found matching pattern: ${pattern}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error searching endpoints: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }