Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK

checkMultipleAllergens

Check if a product contains any of multiple specified allergens by providing its name or barcode. Instantly identify potential allergens like gluten, milk, eggs in food products.

Instructions

Check if a product contains any of multiple allergens at once

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameOrBarcodeYesProduct name or barcode
allergensYesList of allergens to check (e.g., ["gluten", "milk", "eggs"])

Implementation Reference

  • Core handler function `checkMultipleAllergens` that checks a product against multiple allergens. It inspects product allergens_tags, allergens_hierarchy, and traces_tags to determine if each allergen is found, in traces, or absent. Returns a MultiAllergenResult with per-allergen check results and a safeToConsume flag.
    export function checkMultipleAllergens(product: any, allergens: string[]): MultiAllergenResult {
        const allergensTags = product.allergens_tags || [];
        const allergensHierarchy = product.allergens_hierarchy || [];
        const tracesTags = product.traces_tags || [];
    
        const allAllergenTags = [...new Set([...allergensTags, ...allergensHierarchy])];
    
        const checkResults = allergens.map(allergen => {
            const allergenLower = allergen.toLowerCase();
            const found = allAllergenTags.some(tag => tag.toLowerCase().includes(allergenLower));
            const inTraces = tracesTags.some((tag: string) => tag.toLowerCase().includes(allergenLower));
    
            return { allergen, found, inTraces };
        });
    
        const allAllergens = allAllergenTags.map((tag: string) =>
            tag.replace('en:', '').replace(/-/g, ' ')
        );
    
        const traces = tracesTags.map((tag: string) =>
            tag.replace('en:', '').replace(/-/g, ' ')
        );
    
        const safeToConsume = !checkResults.some(r => r.found || r.inTraces);
    
        return {
            barcode: product.barcode || product.code,
            productName: product.name || product.product_name || 'Unknown',
            checkResults,
            safeToConsume,
            allAllergens,
            traces
        };
    }
  • The `MultiAllergenResult` type interface defining the shape of the output from checkMultipleAllergens, including barcode, productName, checkResults array (with allergen, found, inTraces), safeToConsume boolean, allAllergens, and traces.
    export interface MultiAllergenResult {
        barcode: string;
        productName: string;
        checkResults: Array<{
            allergen: string;
            found: boolean;
            inTraces: boolean;
        }>;
        safeToConsume: boolean;
        allAllergens: string[];
        traces: string[];
    }
  • Input schema definition for the checkMultipleAllergens tool using Zod validation: requires nameOrBarcode (string) and allergens (array of strings).
    const multiAllergenSchema = {
        nameOrBarcode: z.string().describe('Product name or barcode'),
        allergens: z.array(z.string()).describe('List of allergens to check (e.g., ["gluten", "milk", "eggs"])')
    };
  • Registration of the 'checkMultipleAllergens' tool on the MCP server, including description, input schema, and the async handler that looks up the product, calls the handler function, and formats the response message.
    server.registerTool('checkMultipleAllergens', {
        description: 'Check if a product contains any of multiple allergens at once',
        inputSchema: multiAllergenSchema
    }, async ({ nameOrBarcode, allergens }) => {
        try {
            const product = await findProduct(nameOrBarcode);
            if (!product) {
                return { content: [{ type: 'text' as const, text: `Product "${nameOrBarcode}" not found.` }], isError: true };
            }
            const result = checkMultipleAllergens(product, allergens);
    
            let message = result.safeToConsume
                ? `Product appears safe - none of the checked allergens were found.`
                : `WARNING: Some allergens were detected!`;
    
            result.checkResults.forEach(r => {
                const status = r.found ? 'FOUND' : (r.inTraces ? 'TRACES' : 'NOT FOUND');
                message += `\n  • ${r.allergen}: ${status}`;
            });
    
            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 };
        }
    });
  • Import of the checkMultipleAllergens function from helpers.js into the nutrition tools module.
        checkMultipleAllergens
    } from './helpers.js';
    import { logger } from '../transport/transports.js';
Behavior2/5

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

No annotations are present, and the description fails to disclose behavioral traits such as whether the tool is read-only, requires authentication, or has side effects. This leaves the agent with insufficient information about the operation's safety.

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

Conciseness5/5

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

The description is a single, very short sentence that conveys the core purpose without any extraneous information. It is front-loaded and efficient.

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?

Given the tool's simplicity (two parameters, no output schema), the description is minimally adequate but lacks explanation of the return type or behavior. It does not clarify if the result is a boolean or a list, or how the check handles unknown allergens.

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 description coverage is 100%, so both parameters are already documented. The description does not add new semantics beyond rephrasing the parameter types; it merely reinforces the array nature of allergens without providing additional context or constraints.

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

Purpose4/5

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

The description clearly specifies the verb (check) and resource (product for multiple allergens) and distinguishes from the sibling getAllergenCheck by indicating 'multiple allergens at once'. However, it does not explicitly state the output format (e.g., boolean or list).

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like getAllergenCheck for a single allergen. The absence of such context may lead to inappropriate tool selection.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JagjeevanAK/OpenFoodFacts-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server