Skip to main content
Glama
domdomegg

openfoodfacts-mcp

Call API

call_api

Make direct API calls to Open Food Facts endpoints to retrieve food data or update product information using structured JSON or form-encoded parameters.

Instructions

Make a direct call to any Open Food Facts API endpoint. Use get_api_docs to see available endpoints. Auth credentials are included automatically for write operations if configured.

Two body modes for writes:

  • params: form-encoded (for /cgi/.pl and /api/v2/ legacy endpoints)

  • json_body: raw JSON (for /api/v3/* endpoints — required for structured fields like packagings)

Example v3 packagings write: method: PATCH endpoint: /api/v3/product/0123456789012 json_body: {"fields":"packagings","product":{"packagings":[{"number_of_units":1,"shape":{"id":"en:bag"},"material":{"id":"en:plastic"},"recycling":{"id":"en:recycle"}}]}}

WARNING: Do NOT use old-style prepared nutrition params like nutriment_fat_prepared — they have a known server bug that stores data incorrectly. Use new-style params instead: nutrition_input_sets_prepared_100g_nutrients_fat_value_string=0.5

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodNoHTTP method (default: GET)GET
endpointYesAPI endpoint path (e.g. "/api/v2/product/3017620422003.json")
paramsNoQuery parameters (for GET) or form-encoded body fields (for POST/PUT/PATCH to v1/v2 endpoints like /cgi/product_jqm2.pl). Auth fields are added automatically.
json_bodyNoRaw JSON body for v3 endpoints (e.g. PATCH /api/v3/product/{code}). When set, params is ignored and Content-Type is application/json. Auth fields are injected at the top level. Use this for structured writes like packagings.

Implementation Reference

  • The handler logic for the 'call_api' tool, which uses 'offRequest' to execute the API call and returns a JSON result.
    	async (args) => {
    		const data = await offRequest(config, args.method, args.endpoint, args.params, args.json_body);
    
    		return jsonResult(data as Record<string, unknown>);
    	},
    );
  • The Zod input schema defining the parameters for the 'call_api' tool.
    const inputSchema = strictSchemaWithAliases(
    	{
    		method: z.enum([
    			'GET',
    			'POST',
    			'PUT',
    			'PATCH',
    			'DELETE',
    		]).default('GET').describe('HTTP method (default: GET)'),
    		endpoint: z.string().describe('API endpoint path (e.g. "/api/v2/product/3017620422003.json")'),
    		params: z.record(z.string()).optional().describe('Query parameters (for GET) or form-encoded body fields (for POST/PUT/PATCH to v1/v2 endpoints like /cgi/product_jqm2.pl). Auth fields are added automatically.'),
    		json_body: z.record(z.unknown()).optional().describe('Raw JSON body for v3 endpoints (e.g. PATCH /api/v3/product/{code}). When set, params is ignored and Content-Type is application/json. Auth fields are injected at the top level. Use this for structured writes like packagings.'),
    	},
    	{
    		path: 'endpoint',
    		url: 'endpoint',
    		body: 'json_body',
    	},
    );
  • The function that registers the 'call_api' tool with the MCP server.
    export function registerCallApi(server: McpServer, config: Config): void {
    	server.registerTool(
    		'call_api',
    		{
    			title: 'Call API',
    			description: `Make a direct call to any Open Food Facts API endpoint. Use get_api_docs to see available endpoints. Auth credentials are included automatically for write operations if configured.
    
    Two body modes for writes:
    - params: form-encoded (for /cgi/*.pl and /api/v2/* legacy endpoints)
    - json_body: raw JSON (for /api/v3/* endpoints — required for structured fields like packagings)
    
    Example v3 packagings write:
      method: PATCH
      endpoint: /api/v3/product/0123456789012
      json_body: {"fields":"packagings","product":{"packagings":[{"number_of_units":1,"shape":{"id":"en:bag"},"material":{"id":"en:plastic"},"recycling":{"id":"en:recycle"}}]}}
    
    WARNING: Do NOT use old-style prepared nutrition params like nutriment_fat_prepared — they have a known server bug that stores data incorrectly. Use new-style params instead: nutrition_input_sets_prepared_100g_nutrients_fat_value_string=0.5`,
    			inputSchema,
    			annotations: {
    				readOnlyHint: false,
    			},
    		},
    		async (args) => {
    			const data = await offRequest(config, args.method, args.endpoint, args.params, args.json_body);
    
    			return jsonResult(data as Record<string, unknown>);
    		},
    	);
    }
Behavior4/5

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

While annotations declare readOnlyHint=false (indicating write capability), the description adds critical behavioral details: automatic auth injection for writes, Content-Type handling logic, that params is ignored when json_body is set, and a specific server bug warning that prevents data corruption.

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?

Front-loaded with purpose, clearly sectioned with headers ('Two body modes', 'Example', 'WARNING'), and every sentence serves a necessary function for a generic API tool. The length is justified by the complexity and risk of the generic abstraction.

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

Completeness4/5

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

Given the high complexity (generic passthrough to any API endpoint) and lack of output schema, the description is remarkably complete, covering authentication behavior, versioning differences, endpoint compatibility, and specific pitfalls. Only minor gap is explicit mention of variable return formats.

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

Parameters4/5

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

Although schema coverage is 100%, the description adds essential semantic context absent from the schema: the conceptual 'two body modes' framework, a concrete working example tying parameters together, and critical domain-specific syntax rules (the old-style vs new-style parameter naming bug).

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 opens with a specific verb and resource ('Make a direct call to any Open Food Facts API endpoint') and distinguishes this generic tool from its siblings by referencing get_api_docs for endpoint discovery, implying this is the low-level execution tool versus higher-level wrappers like add_or_edit_product.

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

Usage Guidelines5/5

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

Provides explicit prerequisites ('Use get_api_docs'), clear conditional logic for body modes (params for legacy endpoints vs json_body for v3), and precise when-not guidance with alternatives ('Do NOT use old-style prepared nutrition params... Use new-style params instead').

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/domdomegg/openfoodfacts-mcp'

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