get_product
Retrieve detailed food product information by scanning or entering a barcode to access nutritional data, ingredients, and environmental scores from the Open Food Facts database.
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)Main handler function for the 'get_product' tool. Fetches product data from the client and returns formatted text response or not found message.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)Input schema and metadata definition for the 'get_product' tool.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:36-38 (registration)Registers the list tools handler which returns the tools array including 'get_product'.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
- src/index.ts:45-46 (registration)Dispatches 'get_product' tool calls to the handleGetProduct method.case 'get_product': return await handlers.handleGetProduct(args.barcode);
- src/client.ts:42-54 (helper)Helper method in OpenFoodFactsClient that performs the actual API call to retrieve product data by barcode.async getProduct(barcode: string): Promise<ProductResponse> { await this.checkRateLimit('products'); try { const response = await this.client.get(`/api/v2/product/${barcode}`); return ProductResponseSchema.parse(response.data); } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Failed to fetch product ${barcode}: ${error.response?.status} ${error.message}`); } throw error; } }