Skip to main content
Glama
domdomegg

openfoodfacts-mcp

autocomplete

Get autocomplete suggestions for food taxonomy entries like brands, categories, and labels from the Open Food Facts database to speed up data entry and ensure accuracy.

Instructions

Get autocomplete suggestions for Open Food Facts taxonomy entries (brands, categories, labels, etc.).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tagtypeYesType of taxonomy to search
queryYesSearch prefix
lcNoLanguage code (default: en)en
limitNoMax results (default: 10, max: 100)

Implementation Reference

  • The handler function that executes the autocomplete tool logic, calling the Open Food Facts API with the provided parameters.
    async (args) => {
    	const params: Record<string, string> = {
    		tagtype: args.tagtype,
    		string: args.query,
    		lc: args.lc,
    		limit: String(args.limit),
    	};
    
    	const data = await offGet(config, '/api/v3/taxonomy_suggestions', params);
    
    	return jsonResult(data as Record<string, unknown>);
    },
  • The input schema definition using Zod for the autocomplete tool, including tagtype, query, language, and limit.
    const inputSchema = strictSchemaWithAliases(
    	{
    		tagtype: z.enum([
    			'brands',
    			'categories',
    			'labels',
    			'countries',
    			'stores',
    			'packaging',
    			'ingredients',
    			'traces',
    			'allergens',
    			'additives',
    			'states',
    		]).describe('Type of taxonomy to search'),
    		query: z.string().describe('Search prefix'),
    		lc: z.string().default('en').describe('Language code (default: en)'),
    		limit: z.number().int().min(1).max(100).default(10).describe('Max results (default: 10, max: 100)'),
    	},
    	{
    		type: 'tagtype',
    		term: 'query',
    		q: 'query',
    	},
    );
  • The registration function that defines the 'autocomplete' tool with the MCP server.
    export function registerAutocomplete(server: McpServer, config: Config): void {
    	server.registerTool(
    		'autocomplete',
    		{
    			title: 'Autocomplete',
    			description: 'Get autocomplete suggestions for Open Food Facts taxonomy entries (brands, categories, labels, etc.).',
    			inputSchema,
    			annotations: {
    				readOnlyHint: true,
    			},
    		},
    		async (args) => {
    			const params: Record<string, string> = {
    				tagtype: args.tagtype,
    				string: args.query,
    				lc: args.lc,
    				limit: String(args.limit),
    			};
    
    			const data = await offGet(config, '/api/v3/taxonomy_suggestions', params);
    
    			return jsonResult(data as Record<string, unknown>);
    		},
    	);
    }

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