Skip to main content
Glama

search-api-operations

Search for API operations across multiple OpenAPI specifications to enable efficient discovery and integration within LLM-powered IDE tools like Cursor.

Instructions

Search for operations across specifications

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
specIdNo

Implementation Reference

  • Handler function for the 'search-api-operations' MCP tool. It invokes specExplorer.searchOperations with the provided query and optional specId, formats the results as YAML, and returns them in the MCP response format.
    async (args, extra) => { try { this.logger.debug('Searching API operations', { query: args.query, specId: args.specId }); const operations = await this.specExplorer.searchOperations( args.query, args.specId ); return { content: [ { type: "text", text: stringify({ operations }, { indent: 2 }) }, ], }; } catch (error) { this.logger.error('Failed to search API operations', { error, query: args.query }); throw error; } }
  • Input schema validation for the tool using Zod: requires 'query' string, optional 'specId' string.
    { query: z.string(), specId: z.string().optional(), },
  • Registration of the 'search-api-operations' tool on the MCP server, including name, description, input schema, and handler function.
    "search-api-operations", "Search for operations across specifications", { query: z.string(), specId: z.string().optional(), }, async (args, extra) => { try { this.logger.debug('Searching API operations', { query: args.query, specId: args.specId }); const operations = await this.specExplorer.searchOperations( args.query, args.specId ); return { content: [ { type: "text", text: stringify({ operations }, { indent: 2 }) }, ], }; } catch (error) { this.logger.error('Failed to search API operations', { error, query: args.query }); throw error; } } );
  • Core helper function implementing the operation search logic. Filters operations across specified or all specs by checking if the query substring matches in operationId, summary, description, or tags.
    async searchOperations( query: string, specId?: string ): Promise<LoadOperationResult[]> { const targetSpecs: SpecCatalogEntry[] = []; if (specId) { const spec = this.catalog.find((spec) => spec.uri.specId === specId); if (spec) { targetSpecs.push(spec); } } else { targetSpecs.push(...this.catalog); } const results: LoadOperationResult[] = []; for (const spec of targetSpecs) { const specDoc = this.specs[spec.uri.specId]; if (!specDoc?.paths) continue; for (const path in specDoc.paths) { const pathItem = specDoc.paths[path]; if (!pathItem) continue; for (const method in pathItem) { if (method === "parameters" || method === "$ref") continue; const operation = pathItem[method] as OpenAPIV3.OperationObject; if (!operation) continue; // Search in operationId, summary, description, and tags const searchText = [ operation.operationId, operation.summary, operation.description, ...(operation.tags || []), ] .filter(Boolean) .join(" ") .toLowerCase(); if (searchText.includes(query.toLowerCase())) { results.push({ path, method, operation, specId: spec.uri.specId, uri: `apis://${spec.uri.specId}/operations/${operation.operationId}`, }); } } } } return results; }

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/ReAPI-com/mcp-openapi'

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