Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

analyze_product

Analyze food products by barcode to retrieve nutritional data, ingredient information, and environmental impact scores for informed dietary decisions.

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 main handler function that fetches the product data using OpenFoodFactsClient and generates nutritional analysis by calling the private analyzeNutrition method, returning formatted text content.
    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 in the tools array, specifying the name, description, and input schema that requires a 'barcode' string.
    {
      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)
    Registration in the MCP server's CallToolRequestHandler switch statement, dispatching 'analyze_product' tool calls to handlers.handleAnalyzeProduct with the barcode argument.
    case 'analyze_product':
      return await handlers.handleAnalyzeProduct(args.barcode);
  • Core helper method implementing the nutritional analysis logic, interpreting Nutri-Score, NOVA, Eco-Score, and breaking down key nutriments with qualitative assessments.
    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');
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves nutritional analysis and scores, implying a read-only operation, but doesn't cover aspects like authentication needs, rate limits, error handling, or what specific data is returned. This leaves significant gaps in understanding the tool's behavior.

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, efficient sentence that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, making it easy to parse and understand quickly.

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?

Given the complexity of a tool that analyzes nutritional data, the lack of annotations and output schema means the description is incomplete. It doesn't explain what 'nutritional analysis and scores' entail, the format of the response, or any behavioral traits, leaving the agent with insufficient context for effective use.

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?

The input schema has 100% description coverage, with the 'barcode' parameter fully documented in the schema. The description adds no additional meaning beyond implying it's used for product identification, so it meets the baseline score of 3 where the schema does the heavy lifting.

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 states the action ('Get nutritional analysis and scores') and resource ('for a product by barcode'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_product' or 'search_products', which might also retrieve product information, so it falls short of a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives like 'get_product' or 'search_products'. It implies usage by specifying the barcode parameter but offers no context, exclusions, or comparisons to sibling tools, leaving the agent to infer usage scenarios.

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

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