Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK

suggestRecipes

Input a food product name or barcode to receive AI-generated recipe suggestions using OpenFoodFacts data.

Instructions

Get AI recipe suggestions using a product

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameOrBarcodeYes

Implementation Reference

  • The actual tool handler for 'suggestRecipes' - accepts nameOrBarcode, looks up the product, and calls createRecipeSuggestionRequest + requestSampling to generate AI recipes.
    server.registerTool('suggestRecipes', {
      description: 'Get AI recipe suggestions using a product',
      inputSchema: productSchema
    }, async ({ nameOrBarcode }) => {
      if (!nameOrBarcode?.trim()) {
        return { content: [{ type: 'text' as const, text: 'Provide a product.' }], isError: true };
      }
    
      const productData = await findProduct(nameOrBarcode);
      if (!productData?.product) {
        return { content: [{ type: 'text' as const, text: `"${nameOrBarcode}" not found.` }], isError: true };
      }
    
      try {
        const res = await requestSampling(server, createRecipeSuggestionRequest(productData.product));
        return { content: [{ type: 'text' as const, text: `# Recipes using ${productData.product.product_name}\n\n${getResponseText(res)}` }] };
      } catch (e: any) {
        return { content: [{ type: 'text' as const, text: `Recipe generation failed: ${e.message}` }], isError: true };
      }
    });
  • Input schema for suggestRecipes: { nameOrBarcode: z.string() }
    const productSchema = { nameOrBarcode: z.string() };
  • Registration of 'suggestRecipes' tool via server.registerTool with description and inputSchema.
    server.registerTool('suggestRecipes', {
      description: 'Get AI recipe suggestions using a product',
      inputSchema: productSchema
    }, async ({ nameOrBarcode }) => {
      if (!nameOrBarcode?.trim()) {
        return { content: [{ type: 'text' as const, text: 'Provide a product.' }], isError: true };
      }
    
      const productData = await findProduct(nameOrBarcode);
      if (!productData?.product) {
        return { content: [{ type: 'text' as const, text: `"${nameOrBarcode}" not found.` }], isError: true };
      }
    
      try {
        const res = await requestSampling(server, createRecipeSuggestionRequest(productData.product));
        return { content: [{ type: 'text' as const, text: `# Recipes using ${productData.product.product_name}\n\n${getResponseText(res)}` }] };
      } catch (e: any) {
        return { content: [{ type: 'text' as const, text: `Recipe generation failed: ${e.message}` }], isError: true };
      }
    });
  • createRecipeSuggestionRequest builds a SamplingRequest with system prompt for generating 4 recipe types (low-calorie, protein-rich, quick & easy, family-friendly) using product data.
    export function createRecipeSuggestionRequest(productData: any): SamplingRequest {
      const productName = productData.product_name || "this product";
      const category = productData.categories || "food item";
      const ingredients = productData.ingredients_text || "";
      const nutriments = productData.nutriments || {};
      const allergens = productData.allergens || "";
      const brands = productData.brands || "";
    
      return {
        messages: [
          {
            role: "user",
            content: {
              type: "text",
              text: `Generate recipe suggestions for ${productName} (${brands}). ` +
                `Nutritional profile: Energy ${nutriments.energy_100g || "unknown"} kcal, ` +
                `Fat ${nutriments.fat_100g || "unknown"}g, ` +
                `Proteins ${nutriments.proteins_100g || "unknown"}g, ` +
                `Carbs ${nutriments.carbohydrates_100g || "unknown"}g.\n\n` +
                `Category: ${category}\nIngredients: ${ingredients}\nAllergens: ${allergens}`
            }
          }
        ],
        modelPreferences: {
          hints: [{ name: "claude-3" }, { name: "gpt-4o" }],
          intelligencePriority: 0.8,
          speedPriority: 0.5
        },
        systemPrompt: `You are a creative culinary nutritionist. Generate 4 recipe suggestions:
    1. LOW-CALORIE: Light meal focusing on weight management
    2. PROTEIN-RICH: Recipe for fitness enthusiasts  
    3. QUICK & EASY: Minimal prep and cooking time
    4. FAMILY-FRIENDLY: Balanced meal for all ages
    
    For each recipe, provide:
    - Recipe name
    - Ingredient list with measurements
    - Brief preparation steps
    - Approximate nutrition per serving
    - Health benefit highlight`,
        includeContext: "thisServer",
        temperature: 0.7,
        maxTokens: 3500
      };
    }
  • requestSampling sends the sampling/createMessage request to the LLM client via MCP protocol, used by the suggestRecipes handler.
    export async function requestSampling(
      mcpServer: McpServer,
      request: SamplingRequest
    ): Promise<CreateMessageResult> {
      try {
        const response = await mcpServer.server.request({
          method: "sampling/createMessage",
          params: {
            messages: request.messages,
            modelPreferences: request.modelPreferences,
            systemPrompt: request.systemPrompt,
            includeContext: request.includeContext,
            temperature: request.temperature,
            maxTokens: request.maxTokens,
            stopSequences: request.stopSequences,
            metadata: request.metadata
          }
        }, CreateMessageResultSchema);
    
        return response as CreateMessageResult;
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new Error(`Sampling request failed: ${errorMessage}`);
      }
    }
Behavior2/5

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

No annotations are provided, so the description alone must disclose behavioral traits. It only mentions 'AI' but fails to convey limitations, output format, or whether the parameter expects a name or barcode.

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

Conciseness4/5

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

The description is a single efficient sentence, front-loaded with the action verb. However, it sacrifices completeness for brevity.

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?

For a tool with no output schema and no annotations, the description omits return values, error conditions, and parameter details, making it insufficient for reliable invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It only vaguely says 'using a product' without clarifying the parameter format or constraints beyond its name.

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

Purpose5/5

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

The description clearly states 'Get AI recipe suggestions using a product,' specifying a verb and resource, and distinguishes this tool from siblings like searchByBrand or getProductByBarcode which are product-centric.

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

Usage Guidelines4/5

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

The description implies usage when recipe suggestions are needed for a product, but lacks explicit when-not-to-use or alternative recommendations. Siblings are all product data tools, making this unique.

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/JagjeevanAK/OpenFoodFacts-MCP'

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