Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK

getProductPrices

Find the cheapest price for any product by retrieving crowd-sourced price data with its barcode.

Instructions

Get crowd-sourced price data for a specific product - see where it costs less

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
barcodeYesProduct barcode to get prices for
pageNo
pageSizeNo

Implementation Reference

  • The core handler function that executes the tool logic. It fetches crowd-sourced price data from the Open Food Facts Prices API for a given product barcode, with pagination support.
    async function getProductPrices(barcode: string, page: number, pageSize: number): Promise<PricesSearchResult> {
        const url = new URL(`${PRICES_URL}/prices`);
        url.searchParams.set('product_code', barcode);
        url.searchParams.set('page', page.toString());
        url.searchParams.set('size', pageSize.toString());
        url.searchParams.set('order_by', '-date');
    
        const response = await fetch(url.toString());
        if (!response.ok) {
            throw new Error(`Failed to get prices: ${response.status}`);
        }
    
        const data = await response.json();
    
        const prices = (data.items || []).map((p: any): PriceResult => ({
            productCode: p.product_code,
            price: p.price,
            currency: p.currency,
            locationName: p.location?.osm_display_name || 'Unknown location',
            locationId: p.location_id,
            date: p.date,
            proofId: p.proof_id
        }));
    
        return {
            prices,
            count: data.total || prices.length,
            page,
            pageSize
        };
    }
  • The registration of the 'getProductPrices' tool on the MCP server, including description, input schema, and the async handler callback that calls getProductPrices() and formats the response.
    export function registerPriceTools(server: McpServer): void {
        server.registerTool('getProductPrices', {
            description: 'Get crowd-sourced price data for a specific product - see where it costs less',
            inputSchema: productPricesSchema
        }, async ({ barcode, page, pageSize }) => {
            try {
                const result = await getProductPrices(barcode, page ?? 1, pageSize ?? 20);
    
                if (result.prices.length === 0) {
                    return {
                        content: [{
                            type: 'text' as const,
                            text: `No price data available for product ${barcode}. Price data is crowd-sourced and may not be available for all products.`
                        }]
                    };
                }
    
                let message = `Found ${result.count} price records for product ${barcode}:\n\n`;
                result.prices.forEach((p, i) => {
                    message += `${i + 1}. ${p.price} ${p.currency} at ${p.locationName}\n`;
                    message += `   Date: ${p.date}\n\n`;
                });
    
                return {
                    content: [{
                        type: 'text' as const,
                        text: message + `\n\nRaw data:\n${JSON.stringify(result, null, 2)}`
                    }]
                };
            } catch (error: any) {
                return { content: [{ type: 'text' as const, text: `Error: ${error.message}` }], isError: true };
            }
        });
  • The input schema for getProductPrices using Zod validation: barcode (string), page (number with default 1), pageSize (number with default 20).
    const productPricesSchema = {
        barcode: z.string().describe('Product barcode to get prices for'),
        page: z.number().default(1),
        pageSize: z.number().default(20)
    };
  • Type definitions used by getProductPrices: PriceResult interface (productCode, price, currency, locationName, locationId, date, proofId) and PricesSearchResult interface (prices array, count, page, pageSize).
    // Price types
    export interface PriceResult {
        productCode: string;
        price: number;
        currency: string;
        locationName: string;
        locationId: number;
        date: string;
        proofId: number;
    }
    
    export interface PricesSearchResult {
        prices: PriceResult[];
        count: number;
        page: number;
        pageSize: number;
    }
  • The PRICES_URL constant ('https://prices.openfoodfacts.org/api/v1') used by getProductPrices to construct the API endpoint.
    // Constants
    export const BASE_URL = 'https://world.openfoodfacts.org';
    export const SEARCH_API_URL = 'https://search.openfoodfacts.org';
    export const ROBOTOFF_URL = 'https://robotoff.openfoodfacts.org/api/v1';
    export const PRICES_URL = 'https://prices.openfoodfacts.org/api/v1';
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 implies 'get' is read-only but does not confirm safety, authentication needs, rate limits, or response behavior. The description lacks sufficient transparency for a tool with no annotations.

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 description is a single, efficient sentence that front-loads the purpose. However, it could include more detail without becoming overly long, balancing conciseness with completeness.

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 3 parameters, no output schema, and no annotations, the description is incomplete. It does not describe the output structure, pagination behavior, or data sources, leaving critical gaps for an agent working with multiple similar tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With only 33% schema description coverage (only 'barcode' is described), the description should compensate by explaining parameters. It does not mention 'page' or 'pageSize', nor does it clarify the barcode format. The brief description adds minimal semantic value beyond the schema.

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 it retrieves crowd-sourced price data for a specific product, with the intent to find lower prices. It distinguishes itself from sibling tools like getRecentPrices or searchPrices by explicitly referencing crowd-sourced data and focusing on a single product.

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 does not mention prerequisites, exclusions, or compare with sibling tools like searchPrices or getRecentPrices, leaving the agent without contextual direction.

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