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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| specId | No |
Implementation Reference
- src/McpService.ts:99-115 (handler)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; } }
- src/McpService.ts:95-98 (schema)Input schema validation for the tool using Zod: requires 'query' string, optional 'specId' string.{ query: z.string(), specId: z.string().optional(), },
- src/McpService.ts:93-116 (registration)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; } } );
- src/core/SpecService.ts:328-381 (helper)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; }