Skip to main content
Glama

un-comtrade-mcp-server

Get Trade Flow Records

comtrade_get_trade_flows
Read-only

Fetch bilateral trade flow records — the primary data retrieval tool. Returns trade value in USD (primaryValue — FOB for exports, CIF for imports), quantity, net weight, and period/commodity/partner metadata for each row. Accepts multiple periods and commodity codes per call; pass partner_code 0 to get totals aggregated across all partners. Omit cmd_code or pass "TOTAL" to aggregate all commodities. Preview makes one paced request per served period, with a 500-record cap per request. Use comtrade_lookup_countries to resolve reporter/partner codes and comtrade_search_commodities to resolve HS codes. For SITC, supply codes from the selected SITC revision.

Input Schema

NameRequiredDescriptionDefault
freqNoFrequency: A=annual YYYY, M=monthly YYYYMM (01–12).A
periodYesOne or more periods to query. Annual: "YYYY" (e.g. ["2022", "2023"]). Monthly: "YYYYMM" (e.g. ["202201", "202202"]). Serves the first 12 periods and discloses the remainder; input ceiling 120.
cmd_codeNoHS or SITC commodity codes to query. Serves the first 20 codes and discloses the remainder; input ceiling 200. Pass ["TOTAL"] or omit to aggregate all commodities. Use comtrade_search_commodities for codes in the selected HS or SITC edition.
flow_codeYesTrade flow direction: M=imports, X=exports, RX=re-exports, RM=re-imports.
partner_codeNoM49 code of the trade partner. Use 0 to aggregate across all partners (World total). Omit to get a disaggregated breakdown by partner country.
reporter_codeNoM49 reporter code or nonempty array (input ceiling 200). Deduplicates and serves the first 20 reporters, disclosing the remainder. Omit only with an explicit partner_code to query all reporters.
classificationNoGoods classification: HS as reported, H0–H6 with authenticated access, or SITC S1–S4/SS.HS

Output Schema

NameRequiredDescriptionDefault
errorNoPresent when the call failed. Absent on success.
shownNoNumber of records returned in this response.
noticeNoRecovery hint when no records are returned. Absent on successful responses.
recordsNoTrade flow records.
truncatedNoTrue when any preview response reached 500 and may be incomplete.
totalCountNoSum of upstream response counts before local filtering; not a full match count when capped.
truncationHintNoQuery narrowing and authenticated access guidance when possibly incomplete.
referenceNoticeNoNotice when reference descriptions could not be loaded; codes and trade values remain available.
unservedPeriodsNoPeriods beyond the 12-period work cap; query them separately.
unservedCmdCodesNoCommodity codes beyond the 20-code work cap; query them separately.
unservedReportersNoReporter codes beyond the 20-reporter work cap; query them separately.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed28 schema fields changed
    • changedInput schema / properties / classification / description
      Previous value: -"Goods classification: HS/H0–H6 or SITC S1–S4/SS. Defaults to combined HS."New value: +"Goods classification: HS as reported, H0–H6 with authenticated access, or SITC S1–S4/SS."
    • removedInput schema / properties / classification / enum
      Removed value: -[
      -  "HS",
      -  "H0",
      -  "H1",
      -  "H2",
      -  "H3",
      -  "H4",
      -  "H5",
      -  "H6",
      -  "S1",
      -  "S2",
      -  "S3",
      -  "S4",
      -  "SS"
      -]
    • changedInput schema / properties / cmd_code / description
      Previous value: -"HS or SITC commodity codes to query. Serves the first 20 codes and discloses the remainder; input ceiling 200. Pass [\"TOTAL\"] or omit to aggregate all commodities. Use comtrade_search_commodities for HS codes only."New value: +"HS or SITC commodity codes to query. Serves the first 20 codes and discloses the remainder; input ceiling 200. Pass [\"TOTAL\"] or omit to aggregate all commodities. Use comtrade_search_commodities for codes in the selected HS or SITC edition."
    • addedInput schema / properties / cmd_code / items / pattern
      Added value: +"^(?:[A-Z0-9]+(?:\\.[A-Z0-9]+)*)?$"
    • removedInput schema / properties / flow_code / enum
      Removed value: -[
      -  "M",
      -  "X",
      -  "RX",
      -  "RM"
      -]
    • changedInput schema / properties / freq / description
      Previous value: -"Frequency: A=annual, M=monthly."New value: +"Frequency: A=annual YYYY, M=monthly YYYYMM (01–12)."
    • removedInput schema / properties / freq / enum
      Removed value: -[
      -  "A",
      -  "M"
      -]
    • changedInput schema / properties / partner_code / maximum
      Previous value: -9007199254740991New value: +999
    • changedInput schema / properties / partner_code / minimum
      Previous value: --9007199254740991New value: +0
    • removedInput schema / properties / period / items / minLength
      Removed value: -4
    • addedInput schema / properties / period / items / pattern
      Added value: +"^[0-9]{4}(?:0[1-9]|1[0-2])?$"
    • addedInput schema / properties / reporter_code / anyOf
      Added value: +[
      +  {
      +    "description": "One M49 reporter code.",
      +    "maximum": 999,
      +    "minimum": 0,
      +    "type": "integer"
      +  },
      +  {
      +    "description": "Reporter codes to query together.",
      +    "items": {
      +      "maximum": 999,
      +      "minimum": 0,
      +      "type": "integer"
      +    },
      +    "maxItems": 200,
      +    "minItems": 1,
      +    "type": "array"
      +  }
      +]
    • changedInput schema / properties / reporter_code / description
      Previous value: -"M49 numeric code of the reporting country. Use comtrade_lookup_countries to resolve names to codes."New value: +"M49 reporter code or nonempty array (input ceiling 200). Deduplicates and serves the first 20 reporters, disclosing the remainder. Omit only with an explicit partner_code to query all reporters."
    • removedInput schema / properties / reporter_code / maximum
      Removed value: -9007199254740991
    • removedInput schema / properties / reporter_code / minimum
      Removed value: --9007199254740991
    • removedInput schema / properties / reporter_code / type
      Removed value: -"integer"
    • changedInput schema / required
      Previous value: -[
      -  "reporter_code",
      -  "flow_code",
      -  "period"
      -]New value: +[
      +  "flow_code",
      +  "period"
      +]
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode."New value: +"Machine-readable failure mode. Declared by this tool: `keyless_hs_edition_unsupported`: Explicit HS editions require authenticated data access. `invalid_reporter_filter`: Reporter omission lacks an explicit partner. `upstream_validation`: UN Comtrade rejects the query dimensions. `invalid_upstream_response`: UN Comtrade returns malformed trade data. Other values are possible when a failure originates below the handler."
    • addedOutput schema / properties / error / properties / data / properties / reason / examples
      Added value: +[
      +  "keyless_hs_edition_unsupported",
      +  "invalid_reporter_filter",
      +  "upstream_validation",
      +  "invalid_upstream_response"
      +]
    • addedOutput schema / properties / records / items / properties / altQty
      Added value: +{
      +  "description": "Alternate quantity, in its own unit.",
      +  "type": "number"
      +}
    • addedOutput schema / properties / records / items / properties / altQtyUnitAbbr
      Added value: +{
      +  "description": "Alternate quantity unit abbreviation.",
      +  "type": "string"
      +}
    • addedOutput schema / properties / records / items / properties / altQtyUnitCode
      Added value: +{
      +  "description": "Alternate quantity unit code.",
      +  "type": "number"
      +}
    • addedOutput schema / properties / records / items / properties / classificationCode
      Added value: +{
      +  "description": "Actual classification edition supplied by the row.",
      +  "type": "string"
      +}
    • addedOutput schema / properties / records / items / properties / isNetWgtEstimated
      Added value: +{
      +  "description": "Whether net weight is estimated.",
      +  "type": "boolean"
      +}
    • addedOutput schema / properties / records / items / properties / isQtyEstimated
      Added value: +{
      +  "description": "Whether quantity is estimated.",
      +  "type": "boolean"
      +}
    • addedOutput schema / properties / records / items / properties / qtyUnitAbbr
      Added value: +{
      +  "description": "Quantity unit abbreviation supplied or resolved from the unit catalog.",
      +  "type": "string"
      +}
    • addedOutput schema / properties / records / items / properties / qtyUnitCode
      Added value: +{
      +  "description": "Quantity unit code; -1 means unavailable.",
      +  "type": "number"
      +}
    • addedOutput schema / properties / unservedReporters
      Added value: +{
      +  "description": "Reporter codes beyond the 20-reporter work cap; query them separately.",
      +  "items": {
      +    "type": "number"
      +  },
      +  "type": "array"
      +}
  2. First observed

TDQS

A4/5.0
Behavior4/5

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

Annotations already declare readOnlyHint and openWorldHint, yet the description adds substantive behavior: return fields and their valuation basis (FOB for exports, CIF for imports), the paced one-request-per-period pattern in Preview mode, and a 500-record cap per request. The truncation behavior (first 12 periods, first 20 codes, first 20 reporters with the remainder disclosed) is also surfaced rather than left buried in the schema.

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?

The description is front-loaded with purpose and return shape before moving into calling conventions and helper tools, and each sentence carries information. There is minor redundancy, such as restating that multiple periods and commodity codes can be accepted per call, which the array schema already conveys.

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?

For a 7-parameter, open-world retrieval tool with an output schema, this is close to complete: it covers aggregation semantics, code resolution, classification caveats, and request pacing limits. The remaining gap is the unexplained 'Preview' mode and the cap/truncation interplay across parameters, which an agent may still misjudge in combination.

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 a baseline of 3 applies, but the description adds real meaning on top: the FOB/CIF interpretation of primaryValue, the World-total shortcut of partner_code 0, the disaggregated default when partner_code is omitted, and the TOTAL/omit convention for cmd_code. It does not clarify the freq defaults or the 'Preview' notion that has no corresponding schema parameter, which keeps it short of a 5.

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 first sentence names a specific verb and resource (fetch bilateral trade flow records) and frames it as the primary data retrieval tool, which pairs well with the read-only annotations. It does not explicitly contrast itself with the closest siblings that could be confused with it (comtrade_get_services_trade, comtrade_get_top_commodities), so the agent must infer that this tool covers goods flows rather than services or rankings.

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?

It gives concrete operational guidance: pass partner_code 0 to aggregate across all partners, omit cmd_code or pass TOTAL to aggregate commodities, and use comtrade_lookup_countries and comtrade_search_commodities to resolve codes before calling. It also notes the SITC revision dependency. What's missing is an explicit when-not clause or a direct pointer to the services/rankings siblings for those use cases.

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.