Skip to main content
Glama
gulbaki

Swagger/OpenAPI MCP Server

by gulbaki

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
NameRequiredDescriptionDefault
apiIdYesID of the loaded API
patternYesSearch 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 method
    this.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 }; } } );
  • 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") },
  • 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 }; } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gulbaki/swagger-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server