Skip to main content
Glama
domdomegg

openfoodfacts-mcp

Get product

get_product
Read-only

Retrieve current product information from Open Food Facts using a barcode. Access up-to-date nutritional data, ingredients, and food details directly from the primary database.

Instructions

Get product information from Open Food Facts by barcode. Reads the primary database directly (no sync lag), so this is always current even when search_products returns stale results. Prefer this over search whenever you have a barcode. If this returns "product not found", the product genuinely isn't in the database — you can add it with add_or_edit_product.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
barcodeYesProduct barcode (EAN-13, UPC-A, etc.)
fieldsNoFields to return. Defaults to: product_name, brands, categories, nutriscore_grade, nova_group, ingredients_text, nutriments, serving_size, image_url, quantity, code
languageNoLanguage code for language-dependent fields (product_name, generic_name, ingredients_text). Defaults to "en". When a product has a different primary language, the unsuffixed field names return that language's data — this param ensures you get the language you want.en

Implementation Reference

  • The tool handler function for 'get_product' that fetches data from the Open Food Facts API and processes the response.
    async (args) => {
    	const fields = args.fields ?? DEFAULT_FIELDS;
    	const lang = args.language as string;
    
    	// For language-dependent fields, also request the lang-suffixed version
    	// so we can prefer the requested language regardless of the product's
    	// primary language.
    	const langFields: string[] = [];
    	for (const field of fields) {
    		if (LANGUAGE_DEPENDENT_FIELDS.includes(field)) {
    			langFields.push(`${field}_${lang}`);
    		}
    	}
    
    	const allFields = [...fields, ...langFields];
    	const params: Record<string, string> = {
    		fields: allFields.join(','),
    	};
    
    	const data = await offGet(config, `/api/v2/product/${args.barcode}.json`, params) as Record<string, unknown>;
    
    	// Prefer lang-suffixed values over unsuffixed (which map to the product's
    	// primary language and may not be what was requested).
    	const product = data.product as Record<string, unknown> | undefined;
    	if (product) {
    		for (const field of LANGUAGE_DEPENDENT_FIELDS) {
    			const langKey = `${field}_${lang}`;
    			if (product[langKey] !== undefined && product[langKey] !== null && product[langKey] !== '') {
    				product[field] = product[langKey];
    			}
    
    			// Remove the lang-suffixed field from output to keep response clean,
    			// unless the caller explicitly requested it.
    			if (!fields.includes(langKey)) {
    				// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
    				delete product[langKey];
    			}
    		}
    	}
    
    	// Restructure the flat nutriments blob into a readable nested format
    	if (product?.nutriments) {
    		product.nutriments = restructureNutriments(product.nutriments as Record<string, unknown>);
    	}
    
    	return jsonResult(data);
    },
  • The input schema validation and alias configuration for 'get_product'.
    const inputSchema = strictSchemaWithAliases(
    	{
    		barcode: z.string().describe('Product barcode (EAN-13, UPC-A, etc.)'),
    		fields: z.array(z.string()).optional().describe(`Fields to return. Defaults to: ${DEFAULT_FIELDS.join(', ')}`),
    		language: z.string().default('en').describe('Language code for language-dependent fields (product_name, generic_name, ingredients_text). Defaults to "en". When a product has a different primary language, the unsuffixed field names return that language\'s data — this param ensures you get the language you want.'),
    	},
    	{
    		code: 'barcode',
    		ean: 'barcode',
    	},
    );
  • Registration of the 'get_product' tool with the MCP server.
    export function registerGetProduct(server: McpServer, config: Config): void {
    	server.registerTool(
    		'get_product',
    		{
    			title: 'Get product',
    			description: 'Get product information from Open Food Facts by barcode. Reads the primary database directly (no sync lag), so this is always current even when search_products returns stale results. Prefer this over search whenever you have a barcode. If this returns "product not found", the product genuinely isn\'t in the database — you can add it with add_or_edit_product.',
    			inputSchema,
    			annotations: {
    				readOnlyHint: true,
    			},
    		},
Behavior4/5

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

While annotations declare readOnlyHint=true, the description adds crucial behavioral context: 'Reads the primary database directly (no sync lag)' explains data freshness, and explicitly documents the 'product not found' response case. It does not mention rate limits or authentication requirements, preventing a perfect score.

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?

Four sentences, each earning its place: (1) purpose definition, (2) behavioral differentiation from siblings, (3) explicit usage preference, (4) error handling and next-step routing. No redundant words or tautology. Information density is optimal.

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

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the 100% schema coverage and readOnlyHint annotation, the description successfully covers the critical gaps: sibling differentiation, data freshness guarantees, and the 'not found' response case. However, it omits description of successful response structure or pagination, which would be helpful despite the lack of output schema.

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?

With 100% schema description coverage, the schema fully documents all three parameters (barcode, fields, language). The description mentions 'by barcode' reinforcing the required parameter, but adds no additional semantic detail for 'fields' or 'language' beyond what the schema provides. Baseline 3 is appropriate given the schema carries the full burden.

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 uses specific verb 'Get', resource 'product information', and method 'by barcode'. It explicitly distinguishes from siblings by contrasting with 'search_products' (stale results vs current) and referencing 'add_or_edit_product' for missing items, leaving no ambiguity about its specific role in the tool set.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit when-to-use guidance: 'Prefer this over search whenever you have a barcode'. It also includes error handling guidance ('If this returns "product not found"... you can add it with add_or_edit_product') and explains data freshness tradeoffs, creating complete decision criteria for the agent.

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/domdomegg/openfoodfacts-mcp'

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