Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

analyze_product

Retrieve detailed nutritional analysis and scores for any food product by inputting its barcode using Open Food Facts database to support informed food choices.

Instructions

Get nutritional analysis and scores for a product by barcode

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
barcodeYesThe barcode/ID of the product to analyze

Implementation Reference

  • The core handler function for the 'analyze_product' tool. Fetches product data via OpenFoodFactsClient and generates nutritional analysis.
    async handleAnalyzeProduct(barcode: string) { const response = await this.client.getProduct(barcode); if (response.status === 0 || !response.product) { return { content: [ { type: "text" as const, text: `Product not found for barcode: ${barcode}`, }, ], }; } const analysis = this.analyzeNutrition(response.product); return { content: [ { type: "text" as const, text: analysis, }, ], }; }
  • Tool schema definition with name, description, and input schema requiring a barcode.
    { name: "analyze_product", description: "Get nutritional analysis and scores for a product by barcode", inputSchema: { type: "object", properties: { barcode: { type: "string", description: "The barcode/ID of the product to analyze", }, }, required: ["barcode"], }, },
  • src/index.ts:51-52 (registration)
    Dispatch case in the MCP server CallToolRequestHandler that routes 'analyze_product' calls to the handler.
    case 'analyze_product': return await handlers.handleAnalyzeProduct(args.barcode);
  • Key helper method that generates the nutritional analysis text including scores and nutrient breakdown.
    private analyzeNutrition(product: Product): string { const sections = [`**Nutritional Analysis: ${product.product_name || 'Unknown Product'}**\n`]; // Scores interpretation const scoreAnalysis = []; if (product.nutriscore_grade) { const grade = product.nutriscore_grade.toUpperCase(); const gradeDesc = this.getNutriscoreDescription(grade); scoreAnalysis.push(`• Nutri-Score ${grade}: ${gradeDesc}`); } if (product.nova_group) { const group = String(product.nova_group); const groupDesc = this.getNovaDescription(group); scoreAnalysis.push(`• NOVA Group ${group}: ${groupDesc}`); } if (product.ecoscore_grade) { const grade = product.ecoscore_grade.toUpperCase(); const gradeDesc = this.getEcoscoreDescription(grade); scoreAnalysis.push(`• Eco-Score ${grade}: ${gradeDesc}`); } if (scoreAnalysis.length > 0) { sections.push(`**Scores:**\n${scoreAnalysis.join('\n')}\n`); } // Detailed nutrition if (product.nutriments) { const nutrition = this.analyzeNutriments(product.nutriments); if (nutrition) { sections.push(`**Nutritional Breakdown:**\n${nutrition}\n`); } } return sections.join('\n'); }

Other Tools

Related 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/caleb-conner/open-food-facts-mcp'

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