autocomplete
Find matching entries from food taxonomies: categories, brands, labels, ingredients, allergens, or additives based on a partial query.
Instructions
Get autocomplete suggestions for categories, brands, labels, ingredients, allergens, or additives
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Autocomplete query | |
| taxonomyType | Yes | Type of taxonomy to search | |
| lang | No | Language code | en |
| limit | No | Maximum number of suggestions |
Implementation Reference
- src/tools/helpers.ts:212-225 (handler)The actual implementation of autocomplete logic: calls the Search-a-licious API with query, taxonomyType, lang, and limit parameters and returns the JSON response.
export async function getAutocomplete(query: string, taxonomyType: string, lang: string, limit: number) { const url = new URL(`${SEARCH_API_URL}/autocomplete`); url.searchParams.set('q', query); url.searchParams.set('taxonomy_names', taxonomyType); url.searchParams.set('lang', lang); url.searchParams.set('size', limit.toString()); const response = await fetch(url.toString()); if (!response.ok) { throw new Error(`Autocomplete failed: ${response.status}`); } return await response.json(); } - src/tools/category-tools.ts:38-44 (schema)The Zod schema defining input validation for the autocomplete tool: query (string), taxonomyType (enum), lang (string, default 'en'), limit (number, default 10).
const autocompleteSchema = { query: z.string().describe('Autocomplete query'), taxonomyType: z.enum(['categories', 'brands', 'labels', 'countries', 'ingredients', 'allergens', 'additives']) .describe('Type of taxonomy to search'), lang: z.string().default('en').describe('Language code'), limit: z.number().default(10).describe('Maximum number of suggestions') }; - src/tools/category-tools.ts:96-106 (registration)Registration of the 'autocomplete' tool via server.registerTool, with its description and the async handler that calls getAutocomplete helper.
server.registerTool('autocomplete', { description: 'Get autocomplete suggestions for categories, brands, labels, ingredients, allergens, or additives', inputSchema: autocompleteSchema }, async ({ query, taxonomyType, lang, limit }) => { try { const suggestions = await getAutocomplete(query, taxonomyType, lang ?? 'en', limit ?? 10); return { content: [{ type: 'text' as const, text: JSON.stringify(suggestions, null, 2) }] }; } catch (error: any) { return { content: [{ type: 'text' as const, text: `Error: ${error.message}` }], isError: true }; } }); - src/tools/index.ts:174-183 (registration)The main tools index calls registerCategoryTools(server) which registers the autocomplete tool among others.
registerCategoryTools(server); registerNutritionTools(server); registerInsightsTools(server); registerPriceTools(server); logger.info("All OpenFoodFacts MCP tools registered successfully"); }