get_search_suggestions
Generate intelligent search suggestions and autocomplete results for partial queries, including recent searches, popular terms, and entity suggestions to improve search accuracy.
Instructions
Get intelligent search suggestions and autocomplete
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| partial_query | Yes | Partial search query for autocomplete | |
| suggestion_types | No | Types of suggestions to return | |
| context_project_id | No | Project context for better suggestions | |
| max_suggestions | No | Maximum number of suggestions |
Implementation Reference
- src/tools/intelligent-search.ts:296-335 (handler)The handler function that implements the core logic for the get_search_suggestions tool. It parses arguments with Zod schema, loops over suggestion types calling helper functions, aggregates results, and returns structured suggestions object.export const getSearchSuggestions = requireAuth(async (args: any) => { const { partial_query, suggestion_types, context_project_id, max_suggestions } = GetSearchSuggestionsSchema.parse(args) logger.info('Getting search suggestions', { partial_query, suggestion_types }) const suggestions: any = { partial_query, suggestions: {}, total_suggestions: 0 } for (const suggestionType of suggestion_types) { try { let typeSuggestions: any[] = [] switch (suggestionType) { case 'recent_searches': typeSuggestions = await getRecentSearches(partial_query, context_project_id) break case 'popular_terms': typeSuggestions = await getPopularSearchTerms(partial_query, context_project_id) break case 'related_concepts': typeSuggestions = await getRelatedConcepts(partial_query, context_project_id) break case 'entity_suggestions': typeSuggestions = await getEntitySuggestions(partial_query, context_project_id) break } suggestions.suggestions[suggestionType] = typeSuggestions.slice(0, max_suggestions) suggestions.total_suggestions += typeSuggestions.length } catch (error) { logger.error(`Failed to get suggestions for ${suggestionType}:`, error) suggestions.suggestions[suggestionType] = [] } } return suggestions })
- Zod schema used for input validation and parsing in the getSearchSuggestions handler.const GetSearchSuggestionsSchema = z.object({ partial_query: z.string().min(1), suggestion_types: z.array(z.enum(['recent_searches', 'popular_terms', 'related_concepts', 'entity_suggestions'])).default(['recent_searches', 'popular_terms', 'entity_suggestions']), context_project_id: z.string().optional(), max_suggestions: z.number().min(1).max(20).default(10) })
- src/tools/intelligent-search.ts:254-287 (registration)MCPTool definition registering the get_search_suggestions tool with name, description, and JSON inputSchema for MCP protocol.export const getSearchSuggestionsTool: MCPTool = { name: 'get_search_suggestions', description: 'Get intelligent search suggestions and autocomplete', inputSchema: { type: 'object', properties: { partial_query: { type: 'string', description: 'Partial search query for autocomplete' }, suggestion_types: { type: 'array', items: { type: 'string', enum: ['recent_searches', 'popular_terms', 'related_concepts', 'entity_suggestions'] }, default: ['recent_searches', 'popular_terms', 'entity_suggestions'], description: 'Types of suggestions to return' }, context_project_id: { type: 'string', description: 'Project context for better suggestions' }, max_suggestions: { type: 'number', minimum: 1, maximum: 20, default: 10, description: 'Maximum number of suggestions' } }, required: ['partial_query'] } }
- src/tools/intelligent-search.ts:667-672 (registration)Registers the getSearchSuggestions handler function in the intelligentSearchHandlers export object, likely used for tool dispatching.export const intelligentSearchHandlers = { universal_search: universalSearch, semantic_search: semanticSearch, get_search_suggestions: getSearchSuggestions, get_search_analytics: getSearchAnalytics }
- Helper function for 'entity_suggestions' type that queries projects via Supabase for matching names.async function getEntitySuggestions(partialQuery: string, projectId?: string): Promise<string[]> { // Search for project names, task titles, etc. that match const suggestions = [] try { const projects = await supabaseService.getProjects({ search: partialQuery }, { limit: 5 }) suggestions.push(...projects.map(p => p.name)) } catch (error) { logger.error('Error getting entity suggestions:', error) } return suggestions }