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
    `;
    }
Behavior2/5

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

With no annotations, the description should disclose behavioral traits. It only mentions the output but does not specify error handling, prerequisites (e.g., product existence), or rate limits.

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, concise sentence with no wasted words. It is appropriately front-loaded.

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?

The description mentions the rating range A-E but does not specify the return format (e.g., string, object). It lacks details on what happens if the product is not found. For a simple tool, it is partially complete.

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 covers the parameter with a description; the description adds no new meaning beyond what is already in the schema. 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 (A-E rating) for a product, with a specific verb and resource. It is distinct from sibling tools like getNutriScore or getProductByBarcode.

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 or searchProducts). There is no explicit context for usage or exclusions.

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/JagjeevanAK/OpenFoodFacts-MCP'

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