Skip to main content
Glama
JagjeevanAK

OpenFoodFacts-mcp

by JagjeevanAK

searchByBrand

Retrieve all products from a specific brand. Provide the brand name and optionally set page and page size for paginated results.

Instructions

Find all products from a specific brand

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
brandYesBrand name to search for
pageNo
pageSizeNo

Implementation Reference

  • The core handler function `searchByBrand` that executes the logic: takes a brand name, constructs a URL using Open Food Facts facets API (`/brand/{slug}/{page}.json`), fetches results, maps them via `mapToSearchProduct`, and returns a `SearchResult`.
    export async function searchByBrand(brand: string, page: number, pageSize: number): Promise<SearchResult> {
        const brandSlug = brand.toLowerCase().replace(/\s+/g, '-');
        const url = `${BASE_URL}/brand/${brandSlug}/${page}.json`;
    
        const response = await fetch(url);
        if (!response.ok) {
            throw new Error(`Failed to search by brand: ${response.status}`);
        }
    
        const data = await response.json();
    
        return {
            products: (data.products || []).map(mapToSearchProduct),
            count: data.count || 0,
            page,
            pageSize,
            pageCount: Math.ceil((data.count || 0) / pageSize)
        };
    }
  • Registration of the `searchByBrand` tool on the MCP server via `server.registerTool('searchByBrand', ...)`. Defines the description and input schema (`brandSchema`), and the async handler that delegates to the `searchByBrand` helper function. This is where the tool is registered with the MCP server.
    server.registerTool('searchByBrand', {
        description: 'Find all products from a specific brand',
        inputSchema: brandSchema
    }, async ({ brand, page, pageSize }) => {
        try {
            const results = await searchByBrand(brand, page ?? 1, pageSize ?? 10);
            return { content: [{ type: 'text' as const, text: JSON.stringify(results, null, 2) }] };
        } catch (error: any) {
            return { content: [{ type: 'text' as const, text: `Error: ${error.message}` }], isError: true };
        }
    });
  • The `brandSchema` Zod schema defines the input validation for `searchByBrand`: a required `brand` string, optional `page` number (default 1), and optional `pageSize` number (default 10).
    const brandSchema = {
        brand: z.string().describe('Brand name to search for'),
        page: z.number().default(1),
        pageSize: z.number().default(10)
    };
  • The `registerCategoryTools(server)` call in the main `registerTools` function that causes `searchByBrand` (along with other category tools) to be registered on the server.
      registerCategoryTools(server);
    
      registerNutritionTools(server);
    
      registerInsightsTools(server);
    
      registerPriceTools(server);
    
      logger.info("All OpenFoodFacts MCP tools registered successfully");
    }
  • The `mapToSearchProduct` helper function used by `searchByBrand` to map raw API product data into the structured `SearchProductResult` interface.
    export function mapToSearchProduct(p: any): SearchProductResult {
        return {
            id: p._id || p.code,
            name: p.product_name || 'Unknown',
            brand: p.brands || 'Unknown',
            barcode: p.code || '',
            imageUrl: p.image_url || '',
            nutriScore: p.nutriscore_grade || '',
            ecoScore: p.ecoscore_grade || '',
            novaGroup: p.nova_group || 0,
            categories: p.categories || ''
        };
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.1.0

TDQS

C2.7/5.0
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It states 'all products' but the pagination parameters (page, pageSize) suggest results are paged, not all at once. No mention of whether the operation is read-only, idempotent, or has side effects. This lack of transparency is misleading.

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, concise sentence with no filler words. It is front-loaded with key information (action and scope).

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

Completeness1/5

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

Given the complexity (3 parameters, no output schema, no annotations), the description is severely lacking. It does not explain return format, pagination behavior, or any constraints. The agent would be unable to correctly invoke or interpret results from this description alone.

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 coverage is only 33% (brand parameter has a description in schema). The tool description adds no additional meaning to parameters; it merely restates 'from a specific brand'. The page and pageSize parameters are completely undescribed in both schema and description, failing to inform the agent about their purpose or defaults.

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 'Find all products from a specific brand' clearly states the action (find) and resource (products filtered by brand). It implicitly distinguishes from sibling tools like searchByCategory or searchProducts by narrowing to brand. However, it does not explicitly differentiate from tools like advancedSearch.

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 (e.g., searchProducts, advancedSearch). No context about optimal scenarios or when to avoid this tool is given.

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