Skip to main content
Glama
search-endpoints.ts1.59 kB
import { z } from "zod"; import { getParsedOpenAPI } from "../parser.js"; export const searchEndpointsTool = { name: "search_endpoints", config: { title: "Search Endpoints", description: "Search for endpoints by path, summary, description, or operationId. Returns matching endpoints.", inputSchema: { query: z .string() .describe( "Search query to match against path, summary, description, or operationId" ), }, }, handler: async ({ query }: { query: string }) => { const parsed = getParsedOpenAPI(); const lowerQuery = query.toLowerCase(); const results = parsed.endpoints .filter((e) => { const searchFields = [ e.path, e.summary, e.description, e.operationId, ...(e.tags || []), ].filter(Boolean); return searchFields.some((field) => field?.toLowerCase().includes(lowerQuery) ); }) .map((e) => ({ path: e.path, method: e.method.toUpperCase(), operationId: e.operationId, summary: e.summary, tags: e.tags, })); if (results.length === 0) { return { content: [ { type: "text" as const, text: `No endpoints found matching "${query}". Try a different search term or use list_endpoints to see all.`, }, ], }; } return { content: [ { type: "text" as const, text: JSON.stringify(results, null, 2), }, ], }; }, };

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/teddy258/opa-mcp'

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