Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK

getAllergenCheck

Check if a food product contains a specific allergen by entering its name or barcode. Supports common allergens like gluten, milk, eggs, nuts, peanuts, soy, fish, and shellfish.

Instructions

Check if a product contains a specific allergen (gluten, milk, eggs, nuts, peanuts, soy, fish, shellfish, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameOrBarcodeYesProduct name or barcode
allergenYesAllergen to check for (e.g., "gluten", "milk", "eggs", "nuts", "peanuts", "soy", "fish", "shellfish")

Implementation Reference

  • Core handler function that checks if a product contains a specific allergen by scanning allergens_tags, allergens_hierarchy, and traces_tags fields.
    export function checkAllergen(product: any, allergen: string): AllergenResult {
        const allergensTags = product.allergens_tags || [];
        const allergensHierarchy = product.allergens_hierarchy || [];
        const tracesTags = product.traces_tags || [];
    
        const allergenLower = allergen.toLowerCase();
    
        const allAllergenTags = [...new Set([...allergensTags, ...allergensHierarchy])];
        const allergenFound = allAllergenTags.some(tag =>
            tag.toLowerCase().includes(allergenLower)
        );
    
        const inTraces = tracesTags.some((tag: string) =>
            tag.toLowerCase().includes(allergenLower)
        );
    
        const allAllergens = allAllergenTags.map((tag: string) =>
            tag.replace('en:', '').replace(/-/g, ' ')
        );
    
        const traces = tracesTags.map((tag: string) =>
            tag.replace('en:', '').replace(/-/g, ' ')
        );
    
        return {
            barcode: product.barcode || product.code,
            productName: product.name || product.product_name || 'Unknown',
            allergenFound: allergenFound || inTraces,
            allergenChecked: allergen,
            allAllergens,
            allergensTags: allAllergenTags,
            traces
        };
    }
  • Type definition for the allergen check result returned by checkAllergen.
    export interface AllergenResult {
        barcode: string;
        productName: string;
        allergenFound: boolean;
        allergenChecked: string;
        allAllergens: string[];
        allergensTags: string[];
        traces: string[];
    }
  • Registration of the getAllergenCheck tool on the MCP server with its description, input schema, and handler callback that calls checkAllergen.
    server.registerTool('getAllergenCheck', {
        description: 'Check if a product contains a specific allergen (gluten, milk, eggs, nuts, peanuts, soy, fish, shellfish, etc.)',
        inputSchema: allergenCheckSchema
    }, async ({ nameOrBarcode, allergen }) => {
        try {
            const product = await findProduct(nameOrBarcode);
            if (!product) {
                return { content: [{ type: 'text' as const, text: `Product "${nameOrBarcode}" not found.` }], isError: true };
            }
            const result = checkAllergen(product, allergen);
    
            let message = result.allergenFound
                ? `WARNING: ${result.allergenChecked.toUpperCase()} found in this product!`
                : `${result.allergenChecked.toUpperCase()} not detected in this product.`;
    
            if (result.traces.length > 0) {
                message += `\n\nNote: May contain traces of: ${result.traces.join(', ')}`;
            }
    
            return {
                content: [{
                    type: 'text' as const,
                    text: `${message}\n\n${JSON.stringify(result, null, 2)}`
                }]
            };
        } catch (error: any) {
            return { content: [{ type: 'text' as const, text: `Error: ${error.message}` }], isError: true };
        }
    });
  • Zod input schema for the getAllergenCheck tool specifying nameOrBarcode and allergen string parameters.
    const allergenCheckSchema = {
        nameOrBarcode: z.string().describe('Product name or barcode'),
        allergen: z.string().describe('Allergen to check for (e.g., "gluten", "milk", "eggs", "nuts", "peanuts", "soy", "fish", "shellfish")')
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.1.0

TDQS

B3.4/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must disclose behavior. It says 'Check if' but does not indicate the return type (e.g., boolean, detailed info) or behavior on missing data. Minimal disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence listing examples, no fluff. Efficient but could benefit from additional structure (e.g., return type).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with no output schema, the description is adequate but lacks behavioral details (e.g., return value). It covers the basic purpose and parameters.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema covers all parameters with descriptions. The description adds useful examples for the allergen param, but no extra insight beyond schema. Baseline of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description explicitly states the tool checks for a specific allergen in a product, with a clear list of examples. It distinguishes from sibling tools like checkMultipleAllergens and analyzeProduct by focusing on a single allergen check.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit when-to-use or when-not-to-use guidance. The purpose implies it's for single allergen checks, but does not mention alternatives like checkMultipleAllergens for multiple allergens.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.