Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

search_products

Find food products using search terms and filters for categories, brands, countries, nutrition grades, or processing levels to make informed choices.

Instructions

Search for food products with various filters and criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
searchNoSearch terms for product names, brands, or ingredients
categoriesNoFilter by categories (e.g., 'beverages', 'dairy')
brandsNoFilter by brand names
countriesNoFilter by countries (e.g., 'france', 'united-states')
nutrition_gradesNoFilter by Nutri-Score grades (a, b, c, d, e)
nova_groupsNoFilter by NOVA processing groups (1, 2, 3, 4)
sort_byNoSort results by: popularity, product_name, created_datetime, last_modified_datetime
pageNoPage number for pagination (default: 1)
page_sizeNoNumber of results per page (default: 20, max: 100)

Implementation Reference

  • Main handler function for search_products tool: calls client.searchProducts, handles empty results, formats summary and product list into text response.
    async handleSearchProducts(params: any) {
      const response = await this.client.searchProducts(params);
      
      if (response.products.length === 0) {
        return {
          content: [
            {
              type: "text" as const,
              text: "No products found matching your search criteria.",
            },
          ],
        };
      }
    
      const summary = `Found ${response.count} products (showing page ${response.page} of ${response.page_count}):\n\n`;
      const productList = response.products
        .map((product, index) => `${index + 1}. ${this.formatProductSummary(product)}`)
        .join('\n\n');
    
      return {
        content: [
          {
            type: "text" as const,
            text: summary + productList,
          },
        ],
      };
    }
  • Tool definition including name, description, and detailed input schema for search_products with optional parameters like search, categories, brands, etc.
    {
      name: "search_products",
      description: "Search for food products with various filters and criteria",
      inputSchema: {
        type: "object",
        properties: {
          search: {
            type: "string",
            description: "Search terms for product names, brands, or ingredients",
          },
          categories: {
            type: "string",
            description: "Filter by categories (e.g., 'beverages', 'dairy')",
          },
          brands: {
            type: "string",
            description: "Filter by brand names",
          },
          countries: {
            type: "string",
            description: "Filter by countries (e.g., 'france', 'united-states')",
          },
          nutrition_grades: {
            type: "string",
            description: "Filter by Nutri-Score grades (a, b, c, d, e)",
          },
          nova_groups: {
            type: "string",
            description: "Filter by NOVA processing groups (1, 2, 3, 4)",
          },
          sort_by: {
            type: "string",
            description: "Sort results by: popularity, product_name, created_datetime, last_modified_datetime",
            enum: ["popularity", "product_name", "created_datetime", "last_modified_datetime"],
          },
          page: {
            type: "number",
            description: "Page number for pagination (default: 1)",
            minimum: 1,
          },
          page_size: {
            type: "number",
            description: "Number of results per page (default: 20, max: 100)",
            minimum: 1,
            maximum: 100,
          },
        },
        required: [],
      },
    },
  • src/index.ts:48-49 (registration)
    Registration in the main server request handler switch statement: dispatches search_products calls to handlers.handleSearchProducts.
    case 'search_products':
      return await handlers.handleSearchProducts(args);
  • Client method that performs the actual HTTP search request to OpenFoodFacts API, builds query params, handles rate limiting, and parses response.
    async searchProducts(params: {
      search?: string;
      categories?: string;
      brands?: string;
      countries?: string;
      page?: number;
      page_size?: number;
      sort_by?: string;
      nutrition_grades?: string;
      nova_groups?: string;
    } = {}): Promise<SearchResponse> {
      await this.checkRateLimit('search');
    
      const searchParams = new URLSearchParams();
      
      if (params.search) searchParams.append('search_terms', params.search);
      if (params.categories) searchParams.append('categories_tags', params.categories);
      if (params.brands) searchParams.append('brands_tags', params.brands);
      if (params.countries) searchParams.append('countries_tags', params.countries);
      if (params.nutrition_grades) searchParams.append('nutrition_grades_tags', params.nutrition_grades);
      if (params.nova_groups) searchParams.append('nova_groups_tags', params.nova_groups);
      if (params.sort_by) searchParams.append('sort_by', params.sort_by);
      
      searchParams.append('page', String(params.page || 1));
      searchParams.append('page_size', String(Math.min(params.page_size || 20, 100)));
      searchParams.append('json', '1');
    
      try {
        const response = await this.client.get(`/cgi/search.pl?${searchParams.toString()}`);
        return SearchResponseSchema.parse(response.data);
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`Search failed: ${error.response?.status} ${error.message}`);
        }
        throw error;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions filtering and sorting capabilities but doesn't address key behavioral aspects like whether this is a read-only operation, expected response format, pagination behavior beyond schema hints, rate limits, or authentication requirements. The description is too minimal for a tool with 9 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 gets straight to the point with no wasted words. It's appropriately sized for a search tool and front-loads the core functionality without unnecessary elaboration.

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 9 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what kind of results to expect, how results are structured, whether there are limitations on search scope, or how to interpret empty results. The agent would need to guess about important behavioral aspects despite the comprehensive parameter schema.

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?

Schema description coverage is 100%, so the schema already documents all 9 parameters thoroughly. The description adds minimal value beyond the schema by mentioning 'various filters and criteria' but doesn't provide additional context about parameter interactions, default behaviors, or usage examples. This meets the baseline for high schema coverage.

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 verb ('search') and resource ('food products'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_product_suggestions' or 'analyze_product' which might also involve searching or retrieving product information, so it doesn't achieve full sibling differentiation.

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 'get_product' (for single product retrieval) or 'get_product_suggestions' (which might offer recommendations). It mentions 'various filters and criteria' but doesn't specify contexts where this comprehensive search is preferred over simpler sibling tools.

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