UNPKG

mcp-open-food-facts

Version:

MCP server to use Open Food Facts API

20 lines (16 loc) 922 B
import { SearchProductByNameResponse, GetProductByIdResponse, SearchProductByBarcodeResponse } from "../types/mcp.type"; export const searchProduct = async (query: string): Promise<SearchProductByNameResponse> => { const response = await fetch(`https://world.openfoodfacts.org/cgi/search.pl?search_terms=${query}&search_simple=1&action=process&json=1`); const data = await response.json(); return data; } export const getProduct = async (id: string): Promise<GetProductByIdResponse> => { const response = await fetch(`https://world.openfoodfacts.org/api/v0/product/${id}.json`); const data = await response.json(); return data; } export const getProductByBarcode = async (barcode: string): Promise<SearchProductByBarcodeResponse> => { const response = await fetch(`https://world.openfoodfacts.org/api/v0/product/${barcode}.json`); const data = await response.json(); return data; }