Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

get_product_suggestions

Find food product suggestions tailored to dietary preferences like vegan, gluten-free, or organic. Filter by category, Nutri-Score, and max results to make informed food choices.

Instructions

Get product suggestions based on dietary preferences or restrictions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesProduct category to search within
dietary_preferencesNoDietary preferences or restrictions
max_resultsNoMaximum number of suggestions (default: 10)
min_nutriscoreNoMinimum Nutri-Score grade (a, b, c, d, e)

Implementation Reference

  • The main handler function that implements the get_product_suggestions tool logic. It searches for products in a given category, applies filters for dietary preferences and minimum Nutri-Score, and returns formatted product suggestions.
    async handleGetProductSuggestions(params: any) { const { category, dietary_preferences = [], max_results = 10, min_nutriscore } = params; const searchParams: any = { categories: category, page_size: Math.min(max_results * 2, 100), // Get extra to filter sort_by: 'popularity', }; if (min_nutriscore) { const validGrades = ['a', 'b', 'c', 'd', 'e']; const minIndex = validGrades.indexOf(min_nutriscore); const allowedGrades = validGrades.slice(0, minIndex + 1); searchParams.nutrition_grades = allowedGrades.join(','); } const response = await this.client.searchProducts(searchParams); let filteredProducts = response.products; // Filter by dietary preferences if (dietary_preferences.length > 0) { filteredProducts = this.filterByDietaryPreferences(filteredProducts, dietary_preferences); } const suggestions = filteredProducts .slice(0, max_results) .map((product, index) => `${index + 1}. ${this.formatProductSuggestion(product)}`) .join('\n\n'); return { content: [ { type: "text" as const, text: `Product suggestions in ${category}:\n\n${suggestions}`, }, ], }; }
  • Tool schema definition for get_product_suggestions, including name, description, and detailed input schema with parameters like category, dietary_preferences, max_results, and min_nutriscore.
    { name: "get_product_suggestions", description: "Get product suggestions based on dietary preferences or restrictions", inputSchema: { type: "object", properties: { category: { type: "string", description: "Product category to search within", }, dietary_preferences: { type: "array", items: { type: "string", enum: ["vegan", "vegetarian", "gluten-free", "organic", "low-fat", "low-sugar", "high-protein"], }, description: "Dietary preferences or restrictions", }, max_results: { type: "number", description: "Maximum number of suggestions (default: 10)", minimum: 1, maximum: 50, }, min_nutriscore: { type: "string", description: "Minimum Nutri-Score grade (a, b, c, d, e)", enum: ["a", "b", "c", "d", "e"], }, }, required: ["category"], }, },
  • src/index.ts:57-58 (registration)
    Registration of the get_product_suggestions tool in the MCP server. It handles CallToolRequest by routing to the corresponding handler method.
    case 'get_product_suggestions': return await handlers.handleGetProductSuggestions(args);

Other Tools

Related Tools

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