import { SearchResult, SearchOptions } from './types.js'; /** * Core search service that provides fuzzy search functionality across all available MCP tools. * * This service handles searching through tools from multiple MCP servers with intelligent * scoring, caching, and pagination support. It automatically refreshes its cache when * server configurations change to ensure search results remain up-to-date. * * The search algorithm uses a weighted scoring system that prioritizes: * 1. Exact name matches (highest priority) * 2. Name prefix matches * 3. Name substring matches * 4. Description matches (lower weight) * * Usage scenarios include: * - Tool discovery in the web UI * - Command-line tool search * - API-based tool lookup * - Integration with other services requiring tool search capabilities */ export declare class SearchCoreService { private cacheService; private scorer; /** * Initializes the search core service and sets up event listeners for cache invalidation. * * Subscribes to server lifecycle events (SERVER_UPDATED, SERVER_ADDED, SERVER_DELETED) * to automatically clear the search cache when server configurations change, ensuring * that search results always reflect the current state of available tools. */ constructor(); /** * Performs a fuzzy search across all available tools from connected MCP servers. * * This method supports both empty queries (returns all tools) and search queries * with fuzzy matching. Results are scored based on relevance and returned in * descending order of score. * * @param query - The search query string. Empty or whitespace-only queries return all tools. * @param options - Optional search configuration including filters, pagination, and search mode. * @returns A promise that resolves to an array of SearchResult objects containing tools and their relevance scores. * * @example * // Search for tools containing "list" * const results = await searchCoreService.search("list"); * * // Get all tools with pagination * const allTools = await searchCoreService.search("", { limit: 20, offset: 0 }); * * @remarks * - Results are automatically cached to improve performance on subsequent identical searches * - Cache is invalidated when server configurations change * - Empty queries return all tools with a score of 1 * - Non-empty queries perform fuzzy matching with weighted scoring * - Results are automatically sorted by score (highest first) and paginated */ search(query: string, options?: Partial): Promise; /** * Retrieves all available tools with caching support. * * This method first checks if tools are available in the cache. If cached data exists, * it returns the cached tools immediately. Otherwise, it fetches tools from all connected * MCP servers, applies server-level filtering based on allowedTools configuration, * caches the result, and returns the filtered tools. * * @returns A promise that resolves to an array of Tool objects from all connected servers. * * @remarks * - Tools are filtered based on each server's allowedTools configuration * - If allowedTools is null or undefined, all tools from that server are included * - If allowedTools is an empty array, no tools from that server are included * - Tools are filtered using strict name matching against the allowedTools list */ private getToolsWithCache; /** * Applies search filters to the provided tools array. * * Currently, this method serves as a placeholder for future filter implementation. * The comment indicates that serverId and status fields have been removed from the * Tool interface, so alternative filtering methods will be needed in the future. * * @param tools - The array of tools to filter * @param filters - Optional filter criteria from SearchOptions * @returns The filtered array of tools (currently returns input unchanged) * * @todo Implement actual filtering logic once the Tool interface is updated */ private applyFilters; /** * Performs fuzzy search on the provided tools array using the configured scorer. * * This method iterates through all tools and calculates a relevance score for each * tool against the search query using the SearchScorer. Only tools with a score * greater than 0 are included in the results. * * @param tools - The array of tools to search through * @param query - The normalized search query string (lowercase, trimmed) * @returns An array of SearchResult objects containing tools with positive scores * * @remarks * - The query parameter should already be normalized (lowercase and trimmed) * - Tools with a score of 0 or less are excluded from results * - Scoring is handled by the SearchScorer instance with weighted field matching */ private performFuzzySearch; } export declare const searchCoreService: SearchCoreService; //# sourceMappingURL=search-core.service.d.ts.map