Skip to main content
Glama
caleb-conner

Open Food Facts MCP Server

by caleb-conner

get_product

Retrieve detailed food product information by scanning or entering a barcode to access nutritional data, ingredients, and environmental scores from the Open Food Facts database.

Instructions

Retrieve detailed information about a food product by its barcode

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
barcodeYesThe barcode/ID of the product (e.g., '3017620422003')

Implementation Reference

  • Main handler function for the 'get_product' tool. Fetches product data from the client and returns formatted text response or not found message.
    async handleGetProduct(barcode: string) {
      const response = await this.client.getProduct(barcode);
      
      if (response.status === 0 || !response.product) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Product not found for barcode: ${barcode}`,
            },
          ],
        };
      }
    
      const product = response.product;
      const formattedProduct = this.formatProduct(product);
    
      return {
        content: [
          {
            type: "text" as const,
            text: formattedProduct,
          },
        ],
      };
    }
  • Input schema and metadata definition for the 'get_product' tool.
      name: "get_product",
      description: "Retrieve detailed information about a food product by its barcode",
      inputSchema: {
        type: "object",
        properties: {
          barcode: {
            type: "string",
            description: "The barcode/ID of the product (e.g., '3017620422003')",
          },
        },
        required: ["barcode"],
      },
    },
  • src/index.ts:36-38 (registration)
    Registers the list tools handler which returns the tools array including 'get_product'.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools };
    });
  • src/index.ts:45-46 (registration)
    Dispatches 'get_product' tool calls to the handleGetProduct method.
    case 'get_product':
      return await handlers.handleGetProduct(args.barcode);
  • Helper method in OpenFoodFactsClient that performs the actual API call to retrieve product data by barcode.
    async getProduct(barcode: string): Promise<ProductResponse> {
      await this.checkRateLimit('products');
      
      try {
        const response = await this.client.get(`/api/v2/product/${barcode}`);
        return ProductResponseSchema.parse(response.data);
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`Failed to fetch product ${barcode}: ${error.response?.status} ${error.message}`);
        }
        throw error;
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Retrieve' implies a read operation, it doesn't specify whether this requires authentication, rate limits, error conditions (e.g., invalid barcode), or what 'detailed information' includes (e.g., nutritional data, pricing). For a tool with zero annotation coverage, this leaves significant behavioral gaps.

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 with zero waste. It front-loads the core purpose ('Retrieve detailed information') and specifies the key constraint ('by its barcode') without unnecessary elaboration. Every word earns its place.

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

Completeness3/5

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

For a simple read operation with one well-documented parameter and no output schema, the description is minimally adequate. However, it lacks context about the nature of 'detailed information' returned, which could be critical for an agent. Without annotations or output schema, the description should ideally hint at the response structure or data scope to be fully complete.

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%, with the single parameter 'barcode' fully documented in the schema. The description adds no additional parameter semantics beyond implying the barcode identifies a food product, which is already clear from the schema's example. Baseline 3 is appropriate when the schema does the heavy lifting.

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 the specific action ('Retrieve detailed information') and target resource ('about a food product by its barcode'), distinguishing it from siblings like 'search_products' (which likely returns multiple results) or 'analyze_product' (which might perform analysis rather than basic retrieval). The verb+resource combination is precise and unambiguous.

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_suggestions'. It doesn't mention prerequisites (e.g., needing a barcode), exclusions, or comparative use cases. The agent must infer usage from the description alone without explicit direction.

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