get_product
Retrieve detailed food product information, including nutritional data and environmental scores, by entering the product barcode using the Open Food Facts MCP Server.
Instructions
Retrieve detailed information about a food product by its barcode
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| barcode | Yes | The barcode/ID of the product (e.g., '3017620422003') |
Implementation Reference
- src/handlers.ts:7-32 (handler)The main handler function for the 'get_product' tool. Fetches product data using the client, handles not found cases, formats the product information, and returns it as formatted text content.async handleGetProduct(barcode: string) { const response = await this.client.getProduct(barcode); if (response.status === 0 || !response.product) { return { content: [ { type: "text" as const, text: `Product not found for barcode: ${barcode}`, }, ], }; } const product = response.product; const formattedProduct = this.formatProduct(product); return { content: [ { type: "text" as const, text: formattedProduct, }, ], }; }
- src/tools.ts:5-17 (schema)The tool schema definition including name, description, and input schema requiring a 'barcode' string.name: "get_product", description: "Retrieve detailed information about a food product by its barcode", inputSchema: { type: "object", properties: { barcode: { type: "string", description: "The barcode/ID of the product (e.g., '3017620422003')", }, }, required: ["barcode"], }, },
- src/index.ts:45-46 (registration)Registration of the 'get_product' tool in the main switch statement that dispatches tool calls to the appropriate handler.case 'get_product': return await handlers.handleGetProduct(args.barcode);