get_search_suggestions
Generate intelligent search suggestions and autocomplete for partial queries using 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 main handler function that executes the get_search_suggestions tool logic. It parses input arguments using the schema, logs the request, generates suggestions by calling type-specific helper functions (recent_searches, popular_terms, etc.), handles errors, and returns aggregated suggestions.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 definition for input validation of the get_search_suggestions tool, defining parameters like partial_query, suggestion_types, context_project_id, and max_suggestions.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 registration object for get_search_suggestions, defining the tool name, description, and input schema for the 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:660-672 (registration)Module-level exports registering the getSearchSuggestionsTool in intelligentSearchTools and the getSearchSuggestions handler in intelligentSearchHandlers for use in the MCP system.export const intelligentSearchTools = { universalSearchTool, semanticSearchTool, getSearchSuggestionsTool, getSearchAnalyticsTool } export const intelligentSearchHandlers = { universal_search: universalSearch, semantic_search: semanticSearch, get_search_suggestions: getSearchSuggestions, get_search_analytics: getSearchAnalytics }