Skip to main content
Glama
domdomegg

openfoodfacts-mcp

Search products (Lucene)

search_products_lucene
Read-only

Search Open Food Facts products using Lucene query syntax for advanced filtering, boolean logic, and negation capabilities.

Instructions

Search Open Food Facts using the Search-a-licious Elasticsearch backend. Powered by Lucene query syntax with full boolean logic and negation support.

Use this instead of search_products_standard when you need:

  • Negation queries: find gluten-free cereals with allergens_tags_without="en:gluten"

  • Filter-only browsing: categories_tags without any text query (standard API times out on this)

  • Combined text + filter with relevance scoring: text matches are ranked by relevance within filter results

  • Boolean logic in raw Lucene: brands:"kellogg*" OR brands:"nestle"

Trade-offs vs search_products_standard:

  • Counts are approximate (capped at 10,000 for large result sets)

  • Brand tag matching may be narrower (less normalization than standard)

  • Data has a short sync delay (hours) from the primary database

  • popularity sort uses scan counts rather than the standard popularity algorithm

Response format matches search_products_standard: { count, page, page_size, page_count, products: [...] }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoFree-text search terms. Combined with any filter params using AND logic. Omit to browse by filters alone (unlike search_products_standard, filter-only queries work here without timeouts).
categories_tagsNoFilter by category tag (e.g. "en:breakfast-cereals"). Added as categories_tags:"value" in the Lucene query.
brands_tagsNoFilter by brand tag (e.g. "nutella"). Added as brands_tags:"value" in the Lucene query.
nutrition_grades_tagsNoFilter by Nutri-Score grade (a, b, c, d, e). Added as nutriscore_grade:"value".
labels_tagsNoFilter by label tag (e.g. "en:organic", "en:fair-trade"). Added as labels_tags:"value".
countries_tagsNoFilter by country tag (e.g. "en:united-kingdom", "en:france"). Added as countries_tags:"value".
allergens_tags_withoutNoEXCLUDE products containing this allergen (e.g. "en:gluten", "en:milk"). This is negation — a capability unique to this tool. Added as -allergens_tags:"value". Use for allergen-free searches.
lucene_queryNoRaw Lucene query string for full control. If provided, all other filter params are ignored. Supports field:value, negation (-field:value), quoted phrases, wildcards. Examples: 'categories_tags:"en:beverages" nutriscore_grade:a -allergens_tags:"en:gluten"', 'brands:"kellogg*"'
sort_byNoSort order. Note: uses different underlying fields than search_products_standard.
sort_descendingNoSort in descending order (default: true). Set false for ascending (e.g. lowest nutriscore_score first).
pageNoPage number (default: 1)
page_sizeNoResults per page (default: 24, max: 100)
fieldsNoFields to return per product. Defaults to: code, product_name, brands, categories, nutriscore_grade, nova_group, image_url, quantity

Implementation Reference

  • The actual handler function for the `search_products_lucene` tool which constructs the Lucene query, fetches from the Search-a-licious API, normalizes the response, and returns the result.
    		async (args) => {
    			const luceneQuery = args.lucene_query ?? buildLuceneQuery(args);
    
    			const url = new URL(`${SEARCH_A_LICIOUS_BASE}/search`);
    			url.searchParams.set('q', luceneQuery);
    			url.searchParams.set('page', String(args.page));
    			url.searchParams.set('page_size', String(args.page_size));
    
    			if (args.sort_by) {
    				const mappedField = SORT_FIELD_MAP[args.sort_by] ?? args.sort_by;
    				const prefix = args.sort_descending ? '-' : '';
    				url.searchParams.set('sort_by', `${prefix}${mappedField}`);
    			}
    
    			const fields = args.fields ?? DEFAULT_FIELDS;
    			url.searchParams.set('fields', fields.join(','));
    
    			const response = await fetch(url.toString(), {
    				headers: {
    					'User-Agent': config.userAgent,
    					Accept: 'application/json',
    				},
    			});
    
    			if (!response.ok) {
    				const errorText = await response.text();
    				throw new Error(`Search-a-licious API error: ${response.status} ${response.statusText} - ${errorText}`);
    			}
    
    			const data = await response.json() as Record<string, unknown>;
    			const normalized = normalizeResponse(data);
    
    			return jsonResult(normalized);
    		},
    	);
    }
  • Zod input schema for the `search_products_lucene` tool.
    const inputSchema = strictSchemaWithAliases(
    	{
    		query: z.string().optional().describe('Free-text search terms. Combined with any filter params using AND logic. Omit to browse by filters alone (unlike search_products_standard, filter-only queries work here without timeouts).'),
    		categories_tags: z.string().optional().describe('Filter by category tag (e.g. "en:breakfast-cereals"). Added as categories_tags:"value" in the Lucene query.'),
    		brands_tags: z.string().optional().describe('Filter by brand tag (e.g. "nutella"). Added as brands_tags:"value" in the Lucene query.'),
    		nutrition_grades_tags: z.string().optional().describe('Filter by Nutri-Score grade (a, b, c, d, e). Added as nutriscore_grade:"value".'),
    		labels_tags: z.string().optional().describe('Filter by label tag (e.g. "en:organic", "en:fair-trade"). Added as labels_tags:"value".'),
    		countries_tags: z.string().optional().describe('Filter by country tag (e.g. "en:united-kingdom", "en:france"). Added as countries_tags:"value".'),
    		allergens_tags_without: z.string().optional().describe('EXCLUDE products containing this allergen (e.g. "en:gluten", "en:milk"). This is negation — a capability unique to this tool. Added as -allergens_tags:"value". Use for allergen-free searches.'),
    		lucene_query: z.string().optional().describe('Raw Lucene query string for full control. If provided, all other filter params are ignored. Supports field:value, negation (-field:value), quoted phrases, wildcards. Examples: \'categories_tags:"en:beverages" nutriscore_grade:a -allergens_tags:"en:gluten"\', \'brands:"kellogg*"\''),
    		sort_by: z.enum([
    			'popularity',
    			'product_name',
    			'created_t',
    			'last_modified_t',
    			'nutriscore_score',
    			'ecoscore_score',
    		]).optional().describe('Sort order. Note: uses different underlying fields than search_products_standard.'),
    		sort_descending: z.boolean().optional().default(true).describe('Sort in descending order (default: true). Set false for ascending (e.g. lowest nutriscore_score first).'),
    		page: z.number().int().min(1).default(1).describe('Page number (default: 1)'),
    		page_size: z.number().int().min(1).max(100).default(24).describe('Results per page (default: 24, max: 100)'),
    		fields: z.array(z.string()).optional().describe(`Fields to return per product. Defaults to: ${DEFAULT_FIELDS.join(', ')}`),
    	},
    	{
    		q: 'query',
    		search: 'query',
    	},
    );
  • Registration function for `search_products_lucene` within the MCP server.
    export function registerSearchProductsLucene(server: McpServer, config: Config): void {
    	server.registerTool(
    		'search_products_lucene',
    		{
    			title: 'Search products (Lucene)',
    			description: `Search Open Food Facts using the Search-a-licious Elasticsearch backend. Powered by Lucene query syntax with full boolean logic and negation support.
    
    Use this instead of search_products_standard when you need:
    - Negation queries: find gluten-free cereals with allergens_tags_without="en:gluten"
    - Filter-only browsing: categories_tags without any text query (standard API times out on this)
    - Combined text + filter with relevance scoring: text matches are ranked by relevance within filter results
    - Boolean logic in raw Lucene: brands:"kellogg*" OR brands:"nestle"
    
    Trade-offs vs search_products_standard:
    - Counts are approximate (capped at 10,000 for large result sets)
    - Brand tag matching may be narrower (less normalization than standard)
    - Data has a short sync delay (hours) from the primary database
    - popularity sort uses scan counts rather than the standard popularity algorithm
    
    Response format matches search_products_standard: { count, page, page_size, page_count, products: [...] }`,
    			inputSchema,
    			annotations: {
    				readOnlyHint: true,
    			},
    		},
    		async (args) => {
    			const luceneQuery = args.lucene_query ?? buildLuceneQuery(args);
    
    			const url = new URL(`${SEARCH_A_LICIOUS_BASE}/search`);
    			url.searchParams.set('q', luceneQuery);
    			url.searchParams.set('page', String(args.page));
    			url.searchParams.set('page_size', String(args.page_size));
    
    			if (args.sort_by) {
    				const mappedField = SORT_FIELD_MAP[args.sort_by] ?? args.sort_by;
    				const prefix = args.sort_descending ? '-' : '';
    				url.searchParams.set('sort_by', `${prefix}${mappedField}`);
    			}
    
    			const fields = args.fields ?? DEFAULT_FIELDS;
    			url.searchParams.set('fields', fields.join(','));
    
    			const response = await fetch(url.toString(), {
    				headers: {
    					'User-Agent': config.userAgent,
    					Accept: 'application/json',
    				},
    			});
    
    			if (!response.ok) {
    				const errorText = await response.text();
    				throw new Error(`Search-a-licious API error: ${response.status} ${response.statusText} - ${errorText}`);
    			}
    
    			const data = await response.json() as Record<string, unknown>;
    			const normalized = normalizeResponse(data);
    
    			return jsonResult(normalized);
    		},
    	);
    }
Behavior4/5

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

While annotations indicate readOnlyHint=true (safe read operation), the description substantially augments this with critical behavioral details: approximate counts capped at 10,000, data sync delays of hours, narrower brand tag normalization, different popularity sorting algorithms, and response format structure. This operational context helps the agent understand result reliability and freshness limitations beyond the basic safety annotation.

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?

Well-structured with clear sections: opening statement of purpose, bullet list of use cases, bullet list of trade-offs, and response format specification. Every sentence provides actionable information; bullet points allow efficient parsing. No redundant or filler text despite the length needed to cover trade-offs.

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

Completeness5/5

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

Given 13 parameters with complex interactions and no output schema, the description achieves completeness by explicitly documenting the response format ({ count, page... }), explaining behavioral limitations that affect result interpretation, and clarifying the relationship to sibling tools. The coverage is sufficient for an agent to confidently construct queries and interpret results.

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

Parameters4/5

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

With 100% schema description coverage, baseline is 3. The description adds value by demonstrating concrete parameter interactions in examples (e.g., combining allergens_tags_without with categories_tags for gluten-free cereals), noting that lucene_query ignores other filters, and explaining that filter-only queries work without timeouts (unlike the sibling tool). This usage guidance exceeds the structural schema definitions.

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 searches Open Food Facts using the Search-a-licious Elasticsearch backend with Lucene syntax. It explicitly distinguishes itself from sibling 'search_products_standard' by name and describes specific capabilities (boolean logic, negation) that differentiate the two search tools.

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?

Exceptional guidance with explicit 'Use this instead of search_products_standard when you need' section listing four specific scenarios (negation, filter-only browsing, relevance scoring, raw Lucene boolean logic). Additionally provides 'Trade-offs vs search_products_standard' section detailing four specific limitations, giving clear when-not-to-use guidance.

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