Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

get_product_suggestions

Find food products matching dietary preferences like vegan, gluten-free, or organic within specific categories using nutritional scoring.

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

  • Main handler function executing the tool: destructures params, builds search query for category and nutriscore, calls client.searchProducts, filters by dietary preferences, formats suggestions, returns formatted text response.
    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 including input schema with parameters: category (required), dietary_preferences, max_results, 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 in the MCP server request handler switch statement, dispatching to the handler function.
    case 'get_product_suggestions':
      return await handlers.handleGetProductSuggestions(args);
  • Helper method to filter products based on dietary preferences by checking labels, categories, and ingredients.
    private filterByDietaryPreferences(products: Product[], preferences: string[]): Product[] {
      return products.filter(product => {
        const labels = (product.labels || '').toLowerCase();
        const categories = (product.categories || '').toLowerCase();
        const ingredients = (product.ingredients_text || '').toLowerCase();
        
        return preferences.every(pref => {
          switch (pref) {
            case 'vegan':
              return labels.includes('vegan') || categories.includes('vegan');
            case 'vegetarian':
              return labels.includes('vegetarian') || categories.includes('vegetarian');
            case 'gluten-free':
              return labels.includes('gluten') && labels.includes('free');
            case 'organic':
              return labels.includes('organic') || labels.includes('bio');
            case 'low-fat':
              return labels.includes('low-fat') || labels.includes('light');
            case 'low-sugar':
              return labels.includes('sugar-free') || labels.includes('no-sugar');
            case 'high-protein':
              return labels.includes('high-protein') || labels.includes('protein');
            default:
              return true;
          }
        });
      });
    }
  • Helper method to format individual product suggestions including summary and scores.
    private formatProductSuggestion(product: Product): string {
      const summary = this.formatProductSummary(product);
      const scores = [];
      if (product.nutriscore_grade) scores.push(`Nutri-Score: ${product.nutriscore_grade.toUpperCase()}`);
      if (product.nova_group) scores.push(`Processing: NOVA ${product.nova_group}`);
      if (product.ecoscore_grade) scores.push(`Eco: ${product.ecoscore_grade.toUpperCase()}`);
      
      return summary + (scores.length > 0 ? `\nScores: ${scores.join(' | ')}` : '');
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states what the tool does ('Get product suggestions') without describing how it behaves—such as whether it's a read-only operation, how results are returned, potential rate limits, or authentication needs. This is inadequate for a tool with 4 parameters and no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral traits, result format, and usage context, which are essential for an agent to effectively invoke this tool without structured support.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'dietary preferences or restrictions', which aligns with one parameter, but adds minimal value beyond the input schema, which has 100% coverage and detailed descriptions for all parameters. Since schema coverage is high, the baseline score is 3, as the description doesn't significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Get product suggestions based on dietary preferences or restrictions', which specifies the verb ('Get'), resource ('product suggestions'), and key input criteria. However, it doesn't explicitly differentiate from sibling tools like 'search_products' or 'get_product', which might have overlapping functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'search_products' or 'get_product'. It mentions the input criteria but doesn't specify use cases, prerequisites, or exclusions, leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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