Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

compare_products

Compare nutritional information, ingredients, environmental impact, or processing details between multiple food products using barcodes to make informed purchasing decisions.

Instructions

Compare nutritional information between multiple products

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
barcodesYesArray of product barcodes to compare (max 10)
focusNoFocus comparison on specific aspect

Implementation Reference

  • Main handler function that fetches products by barcodes, validates at least 2 products, and generates comparison using helper.
    async handleCompareProducts(barcodes: string[], focus: string = 'nutrition') {
      const responses = await this.client.getProductsByBarcodes(barcodes);
      const validProducts = responses.filter(r => r.status !== 0 && r.product);
      
      if (validProducts.length < 2) {
        return {
          content: [
            {
              type: "text" as const,
              text: "Need at least 2 valid products to compare.",
            },
          ],
        };
      }
    
      const comparison = this.compareProductsByFocus(validProducts.map(r => r.product!), focus);
    
      return {
        content: [
          {
            type: "text" as const,
            text: comparison,
          },
        ],
      };
    }
  • Input schema definition for the compare_products tool, specifying barcodes array (min 2, max 10) and optional focus enum.
    {
      name: "compare_products",
      description: "Compare nutritional information between multiple products",
      inputSchema: {
        type: "object",
        properties: {
          barcodes: {
            type: "array",
            items: {
              type: "string",
            },
            description: "Array of product barcodes to compare (max 10)",
            maxItems: 10,
            minItems: 2,
          },
          focus: {
            type: "string",
            description: "Focus comparison on specific aspect",
            enum: ["nutrition", "ingredients", "environmental", "processing"],
          },
        },
        required: ["barcodes"],
      },
  • src/index.ts:54-55 (registration)
    Tool dispatch registration in the switch statement for CallToolRequestHandler.
    case 'compare_products':
      return await handlers.handleCompareProducts(args.barcodes, args.focus);
  • Private helper method that generates the comparison string based on focus (nutrition, ingredients, etc.) for the products.
    private compareProductsByFocus(products: Product[], focus: string): string {
      const comparison = [`**Product Comparison (${focus})**\n`];
      
      products.forEach((product, index) => {
        comparison.push(`**${index + 1}. ${product.product_name || 'Unknown'}**`);
        
        switch (focus) {
          case 'nutrition':
            if (product.nutriscore_grade) {
              comparison.push(`Nutri-Score: ${product.nutriscore_grade.toUpperCase()}`);
            }
            if (product.nutriments) {
              const keyNutrients = this.extractKeyNutrients(product.nutriments);
              if (keyNutrients) comparison.push(`Nutrients:\n${keyNutrients}`);
            }
            break;
            
          case 'environmental':
            if (product.ecoscore_grade) {
              comparison.push(`Eco-Score: ${product.ecoscore_grade.toUpperCase()}`);
            }
            if (product.packaging) {
              comparison.push(`Packaging: ${product.packaging}`);
            }
            break;
            
          case 'processing':
            if (product.nova_group) {
              comparison.push(`NOVA Group: ${product.nova_group} (${this.getNovaDescription(String(product.nova_group))})`);
            }
            break;
            
          case 'ingredients':
            if (product.ingredients_text) {
              comparison.push(`Ingredients: ${product.ingredients_text.substring(0, 200)}${product.ingredients_text.length > 200 ? '...' : ''}`);
            }
            break;
        }
        comparison.push('');
      });
      
      return comparison.join('\n');
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool compares nutritional information, implying a read-only operation, but doesn't clarify aspects like data sources, rate limits, authentication needs, or what happens if barcodes are invalid. For a tool with zero annotation coverage, this leaves significant gaps in understanding its 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: 'Compare nutritional information between multiple products.' It is front-loaded with the core purpose, has no redundant words, and every part earns its place by clearly stating the tool's function. This is an excellent example of conciseness.

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 comparing multiple products and the lack of annotations and output schema, the description is incomplete. It doesn't explain the return format, error handling, or how the comparison is presented (e.g., side-by-side table, summary). For a tool with no structured output documentation, more context is needed to guide the agent effectively.

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 schema description coverage is 100%, with clear descriptions for both parameters (e.g., 'Array of product barcodes to compare (max 10)' and 'Focus comparison on specific aspect'). The description adds no additional parameter semantics beyond what the schema provides, such as explaining the 'focus' enum values in context. This meets the baseline for high schema coverage.

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 tool's purpose: 'Compare nutritional information between multiple products.' It specifies the verb ('compare') and resource ('nutritional information between multiple products'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'analyze_product' or 'get_product,' which might also involve product data retrieval, so it doesn't reach the highest 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. It doesn't mention sibling tools like 'analyze_product' or 'search_products,' nor does it specify prerequisites or exclusions. The agent must infer usage from the name and schema alone, which is insufficient for optimal tool selection.

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