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")')
    };
Behavior2/5

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

No annotations provided; description implies read-only but doesn't confirm no side effects or data mutation.

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?

Single sentence, no wasted words, front-loads the core action.

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

Completeness2/5

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

No output schema; description omits what 'check' returns (boolean, string?), lacking completeness for a simple tool.

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?

Input schema provides 100% coverage for both parameters; description adds example allergens but little additional meaning.

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?

Description clearly states the tool checks for a specific allergen with examples, but does not differentiate from sibling 'checkMultipleAllergens'.

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 on when to use this tool versus alternatives like 'checkMultipleAllergens' or any prerequisites.

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