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
| Name | Required | Description | Default |
|---|---|---|---|
| barcode | Yes | Product barcode (EAN/UPC) |
Implementation Reference
- src/tools/helpers.ts:465-495 (handler)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 }; } - src/tools/insights-tools.ts:38-70 (handler)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 }; } }); - src/tools/insights-tools.ts:12-14 (schema)Input schema for getProductAIQuestions: accepts a single 'barcode' string (EAN/UPC).
const barcodeSchema = { barcode: z.string().describe('Product barcode (EAN/UPC)') }; - src/tools/types.ts:78-104 (schema)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; } - src/tools/index.ts:178-183 (registration)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"); }