Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK

getProductAIQuestions

Retrieve AI-generated questions about a food product that require human verification, such as whether it is organic or contains gluten. Provide the product barcode to receive these questions for confirmation.

Instructions

Get AI-generated questions about a product that need human verification (e.g., "Is this product organic?", "Does this contain gluten?")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
barcodeYesProduct barcode (EAN/UPC)

Implementation Reference

  • The actual handler/helper function that fetches AI questions for a product from the Robotoff API. It takes a barcode and optional language, calls the Robotoff /questions/{barcode} endpoint, and returns a QuestionsResult with mapped RobotoffQuestion objects.
    export async function getProductQuestions(barcode: string, lang: string = 'en'): Promise<QuestionsResult> {
        const barcodeNum = parseInt(barcode.replace(/\D/g, ''), 10);
        if (isNaN(barcodeNum)) {
            throw new Error('Invalid barcode format');
        }
    
        const url = `${ROBOTOFF_URL}/questions/${barcodeNum}?lang=${lang}&count=25`;
    
        const response = await fetch(url);
        if (!response.ok) {
            throw new Error(`Failed to get product questions: ${response.status}`);
        }
    
        const data = await response.json();
    
        const questions = (data.questions || []).map((q: any): RobotoffQuestion => ({
            barcode: q.barcode,
            type: q.type,
            value: q.value,
            question: q.question,
            insightId: q.insight_id,
            insightType: q.insight_type,
            imageUrl: q.source_image_url || ''
        }));
    
        return {
            status: data.status || (questions.length > 0 ? 'found' : 'no_questions'),
            questions,
            count: questions.length
        };
    }
  • The tool handler registered as 'getProductAIQuestions'. It defines the input schema (barcode), calls getProductQuestions() from helpers, and formats the response with questions, suggested answers, and insight types.
    server.registerTool('getProductAIQuestions', {
        description: 'Get AI-generated questions about a product that need human verification (e.g., "Is this product organic?", "Does this contain gluten?")',
        inputSchema: barcodeSchema
    }, async ({ barcode }) => {
        try {
            const result = await getProductQuestions(barcode);
    
            if (result.count === 0) {
                return {
                    content: [{
                        type: 'text' as const,
                        text: `No AI questions pending for product ${barcode}. The product data may be complete or not yet analyzed.`
                    }]
                };
            }
    
            let message = `Found ${result.count} AI-generated questions for product ${barcode}:\n\n`;
            result.questions.forEach((q, i) => {
                message += `${i + 1}. ${q.question}\n`;
                message += `   Suggested answer: ${q.value}\n`;
                message += `   Type: ${q.insightType}\n\n`;
            });
    
            return {
                content: [{
                    type: 'text' as const,
                    text: message + `\n\nRaw data:\n${JSON.stringify(result, null, 2)}`
                }]
            };
        } catch (error: any) {
            return { content: [{ type: 'text' as const, text: `Error: ${error.message}` }], isError: true };
        }
    });
  • Input schema for getProductAIQuestions: accepts a single 'barcode' string (EAN/UPC).
    const barcodeSchema = {
        barcode: z.string().describe('Product barcode (EAN/UPC)')
    };
  • Type definitions for the Robotoff question system: RobotoffQuestion interface (barcode, type, value, question, insightId, insightType, imageUrl) and QuestionsResult interface (status, questions, count).
    // Robotoff/Insights types
    export interface RobotoffQuestion {
        barcode: string;
        type: string;
        value: string;
        question: string;
        insightId: string;
        insightType: string;
        imageUrl: string;
    }
    
    export interface RobotoffInsight {
        id: string;
        barcode: string;
        type: string;
        value: string;
        valueTag: string;
        confidence: number;
        latestEvent: string;
        predictor: string;
    }
    
    export interface QuestionsResult {
        status: string;
        questions: RobotoffQuestion[];
        count: number;
    }
  • Registration point: registerInsightsTools(server) is called from the main registerTools function, which registers all tools including getProductAIQuestions.
      registerInsightsTools(server);
    
      registerPriceTools(server);
    
      logger.info("All OpenFoodFacts MCP tools registered successfully");
    }
Behavior3/5

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

No annotations are provided, so the description carries the burden. It states the tool returns AI-generated questions but does not discuss edge cases (e.g., missing barcode), read-only nature, or any side effects. The description is basic but not misleading.

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 concise sentence (20 words) with an illustrative parenthetical example. No redundant information, efficiently conveys the tool's purpose.

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

Completeness4/5

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

For a simple tool with one parameter and no output schema, the description adequately explains what the tool returns (questions needing verification) and gives examples. However, it does not specify the output structure (e.g., list of strings), which would add completeness.

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 coverage is 100% with a single 'barcode' parameter already described as 'Product barcode (EAN/UPC)'. The tool description adds no additional semantics, format details, or examples beyond what the schema provides.

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?

The description clearly states the tool retrieves AI-generated questions about a product needing human verification, with specific examples. It distinguishes from sibling 'getRandomAIQuestions' by focusing on a specific product via barcode.

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?

The description implies usage for obtaining verification questions but provides no explicit guidance on when to use this tool over alternatives like 'getRandomAIQuestions', nor any prerequisites or exclusions.

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