Skip to main content
Glama
domdomegg

openfoodfacts-mcp

select_image

Crop, rotate, and assign product images to specific categories on Open Food Facts after uploading. This tool helps organize visual product data in the food database.

Instructions

Select, crop, and rotate a previously uploaded product image on Open Food Facts. Requires OFF_USER_ID and OFF_PASSWORD.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
barcodeYesProduct barcode
imgidYesImage ID (from upload_image response or product data)
imagefieldYesImage type to assign this image to
lcNoLanguage code (default: en)en
angleNoRotation angle in degrees
x1NoCrop: left coordinate
y1NoCrop: top coordinate
x2NoCrop: right coordinate
y2NoCrop: bottom coordinate

Implementation Reference

  • The implementation of the 'select_image' tool handler, which processes input parameters, calls the Open Food Facts API via 'offPost', and returns the result.
    async (args) => {
    	const body: Record<string, string> = {
    		code: args.barcode,
    		imgid: String(args.imgid),
    		id: `${args.imagefield}_${args.lc}`,
    	};
    
    	if (args.angle) {
    		body.angle = args.angle;
    	}
    
    	if (args.x1 !== undefined) {
    		body.x1 = String(args.x1);
    	}
    
    	if (args.y1 !== undefined) {
    		body.y1 = String(args.y1);
    	}
    
    	if (args.x2 !== undefined) {
    		body.x2 = String(args.x2);
    	}
    
    	if (args.y2 !== undefined) {
    		body.y2 = String(args.y2);
    	}
    
    	const data = await offPost(config, '/cgi/product_image_crop.pl', body);
    
    	return jsonResult(data as Record<string, unknown>);
    },
  • The input schema definition for the 'select_image' tool, including validation and field descriptions.
    const inputSchema = strictSchemaWithAliases(
    	{
    		barcode: z.string().describe('Product barcode'),
    		imgid: z.number().int().describe('Image ID (from upload_image response or product data)'),
    		imagefield: z.enum([
    			'front',
    			'ingredients',
    			'nutrition',
    			'packaging',
    			'other',
    		]).describe('Image type to assign this image to'),
    		lc: z.string().default('en').describe('Language code (default: en)'),
    		angle: z.enum([
    			'0',
    			'90',
    			'180',
    			'270',
    		]).optional().describe('Rotation angle in degrees'),
    		x1: z.number().optional().describe('Crop: left coordinate'),
    		y1: z.number().optional().describe('Crop: top coordinate'),
    		x2: z.number().optional().describe('Crop: right coordinate'),
    		y2: z.number().optional().describe('Crop: bottom coordinate'),
    	},
    	{
    		code: 'barcode',
    		id: 'imagefield',
    	},
    );
  • The registration function for the 'select_image' tool.
    export function registerSelectImage(server: McpServer, config: Config): void {
    	server.registerTool(
    		'select_image',
    		{
    			title: 'Select/crop product image',
    			description: 'Select, crop, and rotate a previously uploaded product image on Open Food Facts. Requires OFF_USER_ID and OFF_PASSWORD.',
    			inputSchema,
    			annotations: {
    				readOnlyHint: false,
    			},
    		},
    		async (args) => {
    			const body: Record<string, string> = {
    				code: args.barcode,
    				imgid: String(args.imgid),
    				id: `${args.imagefield}_${args.lc}`,
    			};
    
    			if (args.angle) {
    				body.angle = args.angle;
    			}
    
    			if (args.x1 !== undefined) {
    				body.x1 = String(args.x1);
    			}
    
    			if (args.y1 !== undefined) {
    				body.y1 = String(args.y1);
    			}
    
    			if (args.x2 !== undefined) {
    				body.x2 = String(args.x2);
    			}
    
    			if (args.y2 !== undefined) {
    				body.y2 = String(args.y2);
    			}
    
    			const data = await offPost(config, '/cgi/product_image_crop.pl', body);
    
    			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