getAdditivesInfo
List additives in a food product with E-numbers and NOVA processing level by entering a product name or barcode.
Instructions
List all additives in a product with their E-numbers and NOVA processing level
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nameOrBarcode | Yes | Product name or barcode (EAN/UPC) |
Implementation Reference
- src/tools/helpers.ts:268-289 (handler)The actual implementation of getAdditivesInfo. It extracts additives_tags (or additives_original_tags) from a product, maps them to E-number names, and returns an AdditivesResult with barcode, product name, additives list, count, novaGroup, and NOVA explanation.
export function getAdditivesInfo(product: any): AdditivesResult { const additivesTags = product.additives_tags || []; const additivesOriginalTags = product.additives_original_tags || []; const novaGroup = product.novaGroup || product.nova_group || 0; const additives = (additivesTags.length > 0 ? additivesTags : additivesOriginalTags).map((tag: string) => { const match = tag.match(/en:(e\d+[a-z]?)/i); return { tag: tag, name: match ? match[1].toUpperCase() : tag.replace('en:', '').toUpperCase() }; }); return { barcode: product.barcode || product.code, productName: product.name || product.product_name || 'Unknown', additives, count: additives.length, novaGroup, novaExplanation: NOVA_EXPLANATIONS[novaGroup] || 'NOVA group not available' }; } - src/tools/types.ts:43-53 (schema)The AdditivesResult interface defining the return type shape: barcode, productName, additives (array of tag/name), count, novaGroup, and novaExplanation.
export interface AdditivesResult { barcode: string; productName: string; additives: Array<{ tag: string; name: string; }>; count: number; novaGroup: number; novaExplanation: string; } - src/tools/nutrition-tools.ts:61-75 (registration)Registration of the 'getAdditivesInfo' tool on the MCP server. Defines description, input schema (nameOrBarcode), and the callback handler that calls findProduct then getAdditivesInfo.
server.registerTool('getAdditivesInfo', { description: 'List all additives in a product with their E-numbers and NOVA processing level', inputSchema: productIdentifierSchema }, async ({ nameOrBarcode }) => { try { const product = await findProduct(nameOrBarcode); if (!product) { return { content: [{ type: 'text' as const, text: `Product "${nameOrBarcode}" not found.` }], isError: true }; } const result = getAdditivesInfo(product); return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }] }; } catch (error: any) { return { content: [{ type: 'text' as const, text: `Error: ${error.message}` }], isError: true }; } }); - src/tools/types.ts:155-160 (helper)NOVA_EXPLANATIONS constant mapping NOVA groups 1-4 to descriptions, used by getAdditivesInfo to populate novaExplanation.
export const NOVA_EXPLANATIONS: Record<number, string> = { 1: 'Unprocessed or minimally processed foods', 2: 'Processed culinary ingredients', 3: 'Processed foods', 4: 'Ultra-processed foods - contains industrial additives' }; - Documentation/reference mentioning the getAdditivesInfo tool in the list of available nutrition tools.
| Check for allergens | \`getAllergenCheck\` - gluten, milk, nuts, etc. | | Check multiple allergens | \`checkMultipleAllergens\` - check several at once | | See additives | \`getAdditivesInfo\` - E-numbers and processing level |