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 || ''
        };
    }
Behavior2/5

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

No annotations provided, so description must carry full burden. Only states 'find all products' but omits pagination behavior, read-only nature, or any side effects. Minimal disclosure.

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?

Single sentence with 8 words, no redundancy. Efficient but slightly under-informative for the tool's purpose.

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?

No output schema. Lacks details on result format, pagination limits, matching behavior (exact vs partial), or sorting. Incomplete for a search tool with 3 parameters.

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% (only 'brand' has description). Description does not add meaning beyond 'brand name' or clarify 'page'/'pageSize' usage. Fails to compensate for uncovered parameters.

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?

Description clearly states verb+resource: 'Find all products from a specific brand'. It is specific but does not differentiate from sibling tools like searchProducts or searchByCategory, which also find products.

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?

No guidance on when to use this tool versus alternatives. Lacks when-not-to-use or context about prerequisites or preferred scenarios.

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