Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK

getEcoScore

Get the Eco-Score environmental rating (A to E) for any food product by entering its name or barcode. Assess a product's environmental impact with data from OpenFoodFacts.

Instructions

Get the Eco-Score (environmental impact rating A-E) for a product

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameOrBarcodeYesProduct name or barcode (EAN/UPC)

Implementation Reference

  • The core handler function that computes the Eco-Score for a product. Extracts ecoscore_grade and ecoscore_score from the product, then returns an EcoScoreResult with grade, score, packaging, origins, and explanation.
    export function getEcoScore(product: any): EcoScoreResult {
        const grade = product.ecoscore_grade || 'unknown';
        const score = product.ecoscore_score ?? null;
    
        return {
            barcode: product.barcode || product.code,
            productName: product.name || product.product_name || 'Unknown',
            brand: product.brands || 'Unknown',
            ecoScoreGrade: grade.toUpperCase(),
            ecoScoreScore: score,
            packaging: product.packaging || 'Not specified',
            origins: product.origins || 'Not specified',
            explanation: ECO_SCORE_EXPLANATIONS[grade.toLowerCase()] || ECO_SCORE_EXPLANATIONS['unknown']
        };
    }
  • The EcoScoreResult interface defining the return type shape: barcode, productName, brand, ecoScoreGrade, ecoScoreScore, packaging, origins, and explanation.
    export interface EcoScoreResult {
        barcode: string;
        productName: string;
        brand: string;
        ecoScoreGrade: string;
        ecoScoreScore: number | null;
        packaging: string;
        origins: string;
        explanation: string;
    }
  • The ECO_SCORE_EXPLANATIONS constant mapping grades A-E (and 'unknown') to human-readable explanation strings.
    export const ECO_SCORE_EXPLANATIONS: Record<string, string> = {
        'a': 'Very low environmental impact - Excellent eco choice!',
        'b': 'Low environmental impact - Good for the planet.',
        'c': 'Moderate environmental impact - Consider the environment.',
        'd': 'High environmental impact - Consider eco-friendlier options.',
        'e': 'Very high environmental impact - Significant environmental footprint.',
        'unknown': 'Eco-Score not available for this product.'
    };
  • The tool registration for 'getEcoScore' on the MCP server, including description, input schema (nameOrBarcode), and the async handler that looks up a product then calls getEcoScore().
    server.registerTool('getEcoScore', {
        description: 'Get the Eco-Score (environmental impact rating A-E) for a product',
        inputSchema: productIdentifierSchema
    }, async ({ nameOrBarcode }) => {
        try {
            const product = await findProduct(nameOrBarcode);
            if (!product) {
                return { content: [{ type: 'text' as const, text: `Product "${nameOrBarcode}" not found.` }], isError: true };
            }
            const result = getEcoScore(product);
            return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }] };
        } catch (error: any) {
            return { content: [{ type: 'text' as const, text: `Error: ${error.message}` }], isError: true };
        }
    });
  • The getEcoScoreGuide() function providing a markdown resource explaining the Eco-Score grading system.
    function getEcoScoreGuide(): string {
      return `# Eco-Score Guide
    
    Eco-Score rates the environmental impact of food from **A** (lowest impact) to **E** (highest impact).
    
    ## The Grades
    
    ### Grade A - Very Low Impact
    Minimal environmental footprint. Examples:
    - Local seasonal produce
    - Tap water
    - Bulk legumes
    
    ### Grade B - Low Impact
    Small environmental footprint. Examples:
    - Locally sourced products
    - Minimal packaging
    - Plant-based proteins
    
    ### Grade C - Moderate Impact
    Average environmental footprint. Examples:
    - Standard packaged foods
    - Mixed origin products
    
    ### Grade D - High Impact
    Significant environmental footprint. Examples:
    - Air-freighted produce
    - Heavily packaged items
    - Some meat products
    
    ### Grade E - Very High Impact
    Major environmental footprint. Examples:
    - Out-of-season air-freighted foods
    - Products with deforestation links
    - Excessive packaging
    
    ## What Affects Eco-Score
    
    - **Production method** - Organic, conventional, intensive
    - **Transportation** - Local vs imported, air vs ship
    - **Packaging** - Recyclable, plastic, glass
    - **Seasonality** - In-season vs greenhouse/imported
    - **Biodiversity** - Palm oil, deforestation risk
    
    ## Tips
    - Buy **local and seasonal** when possible
    - Choose products with **less packaging**
    - Prefer **plant-based** options
    - Look for **organic** and **fair-trade** labels
    `;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.1.0

TDQS

B3.2/5.0
Behavior2/5

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

No annotations are provided, so the description must disclose behavioral traits. It only states the basic function, omitting details like data source, error conditions, or read-only nature.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The single-sentence description is concise and front-loaded, but could be expanded slightly without losing efficiency.

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

Completeness3/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 is minimally adequate but lacks details on edge cases or return format.

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 description coverage is 100% as the only parameter has a description. The tool description adds no extra meaning beyond the schema, so baseline 3 is appropriate.

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 the Eco-Score (environmental impact rating A-E) for a product. The verb 'Get' and specific resource 'Eco-Score' make the purpose unambiguous, and it distinguishes from sibling tools like getNutriScore.

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?

No guidance is provided on when to use this tool versus alternatives (e.g., getNutriScore, advancedSearch). There are no conditions, prerequisites, or exclusions mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.