Skip to main content
Glama

UN Comtrade Trade Data Query

comtrade.trade.query
Read-onlyIdempotent

Query international merchandise trade statistics from the UN Comtrade database. Returns up to 500 records of imports and/or exports for a specific reporting country, reference period, commodity code, and partner country. Data covers 200+ reporter countries from 1962 (annual) and 2010 (monthly). Values in USD (primary value), CIF for imports, FOB for exports. Commodities classified by Harmonized System (HS) or SITC. Use reporter_code from comtrade.reporters, HS chapter codes (e.g. "84" for machinery, "27" for petroleum, "85" for electronics), and flow_code M=imports, X=exports. Source: UN Comtrade public preview API, no auth, 500 calls/day free.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodYesReference period to query. Annual: 4-digit year (e.g. "2022"). Monthly: YYYYMM (e.g. "202209" for Sep 2022). Comma-separated for multiple periods (e.g. "2020,2021,2022").
cmd_codeNoCommodity code filter. Use HS codes (e.g. "84" for machinery, "27" for petroleum, "TOTAL" for aggregate totals, "AG2" for all 2-digit chapters). Omit to return all commodities (may be large). Default: TOTAL.
flow_codeYesTrade flow direction. M=Imports, X=Exports, MX=Both imports and exports, RM=Re-imports, RX=Re-exports.
freq_codeNoFrequency. A=Annual (default), M=Monthly.
type_codeNoTrade data type. C=Commodities (default), S=Services.
max_recordsNoMaximum number of records to return (1–500). Default 100. The public preview API is capped at 500 records per request.
aggregate_byNoAggregate results by a dimension. Valid values: "cmdCode", "flowCode", "partnerCode", "reporterCode", "period". Omit to return unaggregated records.
customs_codeNoCustoms procedure code filter (e.g. "C00"=all procedures, "C03"=outright export, "C04"=warehousing). Omit for all procedures.
partner_codeNoUN numeric code for the partner country. 0=World aggregate (all partners combined). Omit to return all individual partners.
partner2_codeNoSecondary partner code for extended trade flow tracking (consignment country). 0=World aggregate. Omit to use the default world aggregate.
reporter_codeYesUN numeric code for the reporting country (e.g. 276=Germany, 840=USA, 156=China, 826=UK). Use comtrade.reporters to look up codes.
classificationNoCommodity classification system. HS=Harmonized System (default, most common). B4/B5=BEC, EB=EBOPS services, S1-S4/SS=SITC revisions.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
errorNoPresent only when the call failed. Includes error code, message, request_id, and any provider-specific extras.
resultNoTool response payload. Shape varies per tool — consult the tool description and inputSchema. May be an object, array, string, or number depending on the upstream provider response.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.4/5.0
Behavior5/5

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

Annotations already establish read-only, idempotent, non-destructive behavior. The description adds substantial behavioral context beyond those hints: the 500-record cap, 500 calls/day limit, no authentication requirement, annual and monthly coverage starting years, CIF/FOB valuation conventions, USD primary value, and HS/SITC classification handling. This gives an agent a clear operational picture of what happens when the tool is called.

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 tightly written and front-loaded with the core action and result, then progresses through coverage, valuation, classification, usage hints, and API constraints. Every sentence carries operational value, and none are redundant filler. It is compact despite covering many important details.

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

Completeness5/5

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

Given 12 parameters with 100% schema documentation, an output schema, and read-only/idempotent annotations, the description is complete enough for correct invocation. It covers what the query returns, scope limits, valuation units, classification systems, required registration codes, sibling lookup guidance, authentication needs, and rate limits. No critical operational context is missing.

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?

Schema coverage is 100%, so the baseline is 3. The description adds practical parameter orientation: examples of HS chapter codes for machinery, petroleum, and electronics; flow_code M/X abbreviations; and direction to use comtrade.reporters for reporter codes. Much of this overlaps with schema text, but the examples and the explicit linkage to sibling lookup tools add marginal value beyond the raw schema.

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 names a specific verb and resource: "Query international merchandise trade statistics from the UN Comtrade database," and clearly states what it returns (up to 500 records of imports/exports for reporter, period, commodity, partner). However, it does not explicitly contrast itself with closely related sibling tools like comtrade.trade.availability or comtrade.trade.metadata, so the differentiation comes from the reader's inference rather than direct statement.

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

Usage Guidelines4/5

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

The description provides concrete usage context: how to get reporter codes via comtrade.reporters, example HS chapter codes, flow code meanings, and API constraints such as no auth and 500 calls/day. It does not, however, state when to prefer this tool over trade.availability or trade.metadata, nor does it give explicit exclusions or when-not-to-use guidance.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.