Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

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
NameRequiredDescriptionDefault
barcodeYesThe barcode/ID of the product (e.g., '3017620422003')

Implementation Reference

  • 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, }, ], }; }
  • 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);
  • 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; } }

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/caleb-conner/open-food-facts-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server