get_search_suggestions
Get autocomplete suggestions for search queries, including recent searches, popular terms, related concepts, and entity suggestions, based on a partial input and optional project context.
Instructions
Get intelligent search suggestions and autocomplete
Input 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)Main handler function for get_search_suggestions. Parses input with Zod schema, then dispatches to sub-functions (getRecentSearches, getPopularSearchTerms, getRelatedConcepts, getEntitySuggestions) based on requested suggestion_types. Returns an object with partial_query, suggestions (grouped by type), and total_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 for validating the tool's input parameters: partial_query (required string), suggestion_types (enum array with default), context_project_id (optional string), max_suggestions (number 1-20, default 10).
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)Tool definition/registration object (getSearchSuggestionsTool) with name 'get_search_suggestions', description, and inputSchema for the MCP protocol. Exported and collected in the intelligentSearchTools and intelligentSearchHandlers maps.
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)Export of intelligentSearchHandlers mapping the tool name 'get_search_suggestions' to the getSearchSuggestions handler function, which gets merged into the server's tool handler registry in src/index.ts.
export const intelligentSearchHandlers = { universal_search: universalSearch, semantic_search: semanticSearch, get_search_suggestions: getSearchSuggestions, get_search_analytics: getSearchAnalytics } - getRecentSearches helper - placeholder returning mock suggestions based on partial query.
async function getRecentSearches(partialQuery: string, projectId?: string): Promise<string[]> { // Placeholder - would query search history return [`${partialQuery} api`, `${partialQuery} documentation`] } - getPopularSearchTerms helper - placeholder filtering a static list of popular terms.
async function getPopularSearchTerms(partialQuery: string, projectId?: string): Promise<string[]> { // Placeholder - would return popular terms return ['authentication', 'database', 'frontend', 'backend'] .filter(term => term.includes(partialQuery.toLowerCase())) - getRelatedConcepts helper - placeholder returning empty array.
async function getRelatedConcepts(partialQuery: string, projectId?: string): Promise<string[]> { // Placeholder - would return semantically related concepts return [] - getEntitySuggestions helper - queries supabaseService.getProjects to find project names matching the partial query.
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 }