Skip to main content
Glama

Comtrade Trade Data

comtrade_trade_data
Read-onlyIdempotent

AUTHORITATIVE bilateral trade data between two countries from UN Comtrade — the official international-trade statistics database (every country's customs filings, harmonized). Returns trade values USD, quantities, and HS commodity-level detail for imports and exports between reporter + partner. Use for "how much X did US import from China in 2024", "what does Germany export to Brazil", "Mexico's top trade partners by commodity", or "how did Saudi–Egypt trade move this year" (pass frequency="monthly" for month-by-month, not just last year's annual total). UN Comtrade reporter/partner codes (842=US — Comtrade uses 842, NOT the ISO 840; 156=China, 276=Germany, 0=World — see comtrade_country_codes). Defaults to ANNUAL data (lags ~3 months from reporting period); pass frequency="monthly" for month-level data (lags more and some reporters never file monthly — a missing month is simply absent from the result, never shown as a zero). Every response states its own "frequency" so a monthly figure is never mistaken for an annual one.

Input Schema

NameRequiredDescriptionDefault
hsNoAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
flowNoTrade flow: "M" for imports, "X" for exports. Optional — defaults to both "M,X".
yearYesTrade period. For frequency="annual" (default): a year, e.g. "2024". For frequency="monthly": year+month as YYYYMM, e.g. "202401" for January 2024.
hs_codeNoHS commodity code at 2/4/6 digit level (e.g., "8471" for computers, "2603" for copper ores). Optional — omit for all commodities. Aliases accepted: commodity_code, commodity, hs, cmd_code (pass exactly one of hs_code/commodity_code/commodity/hs/cmd_code — do not need hs_code as well).
cmd_codeNoAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
commodityNoAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
frequencyNoData frequency: "annual" (default) for yearly totals, or "monthly" for month-level data. Monthly coverage is thinner than annual — not every reporter files monthly, and recent months lag by reporter; a country-month with no filing is simply omitted from the results, not returned as zero. When "monthly", pass `year` as YYYYMM.
partner_codeYesPartner country name (e.g. "China") or UN code (156=China, 0=World). Optional — defaults to World (0). Names resolved automatically.
reporter_codeYesCountry name (e.g. "USA", "China", "Germany") or UN numeric code (US=842, China=156). Names are resolved automatically.
commodity_codeNoAlias for hs_code — HS commodity code (e.g. "2603" for copper ores). Use this OR hs_code, not both.

Output Schema

NameRequiredDescriptionDefault
yearNoTrade year queried
countNoNumber of trade records returned
recordsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed5 schema fields changed
    • addedInput schema / properties / cmd_code
      Added value: +{
      +  "description": "Alias for hs_code — HS commodity code. Use this OR hs_code, not both.",
      +  "type": "string"
      +}
    • addedInput schema / properties / commodity
      Added value: +{
      +  "description": "Alias for hs_code — HS commodity code. Use this OR hs_code, not both.",
      +  "type": "string"
      +}
    • addedInput schema / properties / commodity_code
      Added value: +{
      +  "description": "Alias for hs_code — HS commodity code (e.g. \"2603\" for copper ores). Use this OR hs_code, not both.",
      +  "type": "string"
      +}
    • addedInput schema / properties / hs
      Added value: +{
      +  "description": "Alias for hs_code — HS commodity code. Use this OR hs_code, not both.",
      +  "type": "string"
      +}
    • changedInput schema / properties / hs_code / description
      Previous value: -"HS commodity code at 2/4/6 digit level (e.g., \"8471\" for computers). Optional — omit for all commodities."New value: +"HS commodity code at 2/4/6 digit level (e.g., \"8471\" for computers, \"2603\" for copper ores). Optional — omit for all commodities. Aliases accepted: commodity_code, commodity, hs, cmd_code (pass exactly one of hs_code/commodity_code/commodity/hs/cmd_code — do not need hs_code as well)."
  2. Changed3 schema fields changed
    • changedInput schema / examples
      Previous value: -[
      -  {
      -    "partner_code": "156",
      -    "reporter_code": "842",
      -    "year": "2024"
      -  },
      -  {
      -    "flow": "M",
      -    "hs_code": "8471",
      -    "partner_code": "156",
      -    "reporter_code": "842",
      -    "year": "2023"
      -  }
      -]New value: +[
      +  {
      +    "partner_code": "156",
      +    "reporter_code": "842",
      +    "year": "2024"
      +  },
      +  {
      +    "flow": "M",
      +    "hs_code": "8471",
      +    "partner_code": "156",
      +    "reporter_code": "842",
      +    "year": "2023"
      +  },
      +  {
      +    "frequency": "monthly",
      +    "partner_code": "818",
      +    "reporter_code": "682",
      +    "year": "202401"
      +  }
      +]
    • addedInput schema / properties / frequency
      Added value: +{
      +  "description": "Data frequency: \"annual\" (default) for yearly totals, or \"monthly\" for month-level data. Monthly coverage is thinner than annual — not every reporter files monthly, and recent months lag by reporter; a country-month with no filing is simply omitted from the results, not returned as zero. When \"monthly\", pass `year` as YYYYMM.",
      +  "type": "string"
      +}
    • changedInput schema / properties / year / description
      Previous value: -"Trade year (e.g., \"2024\")"New value: +"Trade period. For frequency=\"annual\" (default): a year, e.g. \"2024\". For frequency=\"monthly\": year+month as YYYYMM, e.g. \"202401\" for January 2024."
  3. Changed4 schema fields changed
    • changedOutput schema / properties / records / items / properties / net_weight_kg / type
      Previous value: -"number"New value: +[
      +  "number",
      +  "null"
      +]
    • changedOutput schema / properties / records / items / properties / quantity / type
      Previous value: -"number"New value: +[
      +  "number",
      +  "null"
      +]
    • changedOutput schema / properties / records / items / properties / quantity_unit / type
      Previous value: -"string"New value: +[
      +  "string",
      +  "null"
      +]
    • removedOutput schema / required
      Removed value: -[
      -  "count",
      -  "year",
      -  "records"
      -]
  4. Changed2 schema fields changed
    • changedInput schema / properties / partner_code / description
      Previous value: -"ISO numeric country code for the partner country (e.g., \"156\" for China, \"0\" for World)"New value: +"Partner country name (e.g. \"China\") or UN code (156=China, 0=World). Optional — defaults to World (0). Names resolved automatically."
    • changedInput schema / properties / reporter_code / description
      Previous value: -"ISO numeric country code for the reporting country (e.g., \"842\" for US, \"156\" for China)"New value: +"Country name (e.g. \"USA\", \"China\", \"Germany\") or UN numeric code (US=842, China=156). Names are resolved automatically."
  5. Changed1 schema field changed
    • changedInput schema / examples
      Previous value: -[
      -  {
      -    "partner_code": "156",
      -    "reporter_code": "840",
      -    "year": "2024"
      -  },
      -  {
      -    "flow": "M",
      -    "hs_code": "8471",
      -    "partner_code": "156",
      -    "reporter_code": "840",
      -    "year": "2023"
      -  }
      -]New value: +[
      +  {
      +    "partner_code": "156",
      +    "reporter_code": "842",
      +    "year": "2024"
      +  },
      +  {
      +    "flow": "M",
      +    "hs_code": "8471",
      +    "partner_code": "156",
      +    "reporter_code": "842",
      +    "year": "2023"
      +  }
      +]
  6. Changed3 schema fields changed
    • removedOutput schema / properties / records / description
      Removed value: -"Array of bilateral trade records"
    • changedOutput schema / properties / records / items / properties / commodity / description
      Previous value: -"Commodity description"New value: +"Commodity description or code"
    • changedOutput schema / properties / records / items / properties / quantity / description
      Previous value: -"Quantity traded"New value: +"Trade quantity"
  7. Changed1 schema field changed
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "properties": {
      +    "count": {
      +      "description": "Number of trade records returned",
      +      "type": "number"
      +    },
      +    "records": {
      +      "description": "Array of bilateral trade records",
      +      "items": {
      +        "properties": {
      +          "commodity": {
      +            "description": "Commodity description",
      +            "type": "string"
      +          },
      +          "commodity_code": {
      +            "description": "HS commodity code",
      +            "type": "string"
      +          },
      +          "flow": {
      +            "description": "Trade flow type (Imports, Exports, Re-exports, Re-imports)",
      +            "type": "string"
      +          },
      +          "net_weight_kg": {
      +            "description": "Net weight in kilograms",
      +            "type": "number"
      +          },
      +          "partner": {
      +            "description": "Partner country name",
      +            "type": "string"
      +          },
      +          "quantity": {
      +            "description": "Quantity traded",
      +            "type": "number"
      +          },
      +          "quantity_unit": {
      +            "description": "Unit of quantity measurement",
      +            "type": "string"
      +          },
      +          "reporter": {
      +            "description": "Reporting country name",
      +            "type": "string"
      +          },
      +          "trade_value_usd": {
      +            "description": "Trade value in USD",
      +            "type": "number"
      +          }
      +        },
      +        "type": "object"
      +      },
      +      "type": "array"
      +    },
      +    "year": {
      +      "description": "Trade year queried",
      +      "type": "string"
      +    }
      +  },
      +  "required": [
      +    "count",
      +    "year",
      +    "records"
      +  ],
      +  "type": "object"
      +}
  8. Changed1 schema field changed
    • addedInput schema / examples
      Added value: +[
      +  {
      +    "partner_code": "156",
      +    "reporter_code": "840",
      +    "year": "2024"
      +  },
      +  {
      +    "flow": "M",
      +    "hs_code": "8471",
      +    "partner_code": "156",
      +    "reporter_code": "840",
      +    "year": "2023"
      +  }
      +]
  9. First observed

TDQS

A4.2/5.0
Behavior4/5

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

Annotations already cover the safety profile (readOnly, idempotent, non-destructive, open-world). The description adds genuinely useful behavior beyond that: annual lags ~3 months, monthly lags more and some reporters never file, and a missing month is 'absent, never shown as a zero,' plus the note that responses state their own frequency. Strong, though not exhaustive on pagination/limits.

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-loads purpose and return content before usage examples and caveats; every clause carries information (codes, frequency, lag, missing-data semantics). It is dense and slightly long for one paragraph, but no sentence is wasteful.

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 an output schema exists (return values need not be explained) and annotations carry the safety profile, the description covers the remaining agent needs: where to get codes, annual-vs-monthly selection, year format, data lag, and the absent-vs-zero behavior. Nothing required to call it correctly is missing.

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%, so the schema already documents every parameter, including the alias set and the YYYYMM vs year rule. The description adds value with the Comtrade-specific gotcha (842=US, not ISO 840; 0=World), but that same detail also appears in the schema, so the incremental gain is modest — baseline 3.

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?

States a specific verb+resource+scope: 'AUTHORITATIVE bilateral trade data between two countries from UN Comtrade.' It names exactly what is returned (USD values, quantities, HS commodity detail for imports/exports between reporter + partner), so an agent distinguishes it from the sibling top/aggregate tools.

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?

Gives concrete usage contexts ("how much X did US import from China in 2024") and explicitly routes to comtrade_country_codes for codes, plus when to choose frequency="monthly" vs annual. It does not explicitly contrast with siblings like comtrade_top_commodities/top_partners, so it stops short of full when-vs-alternatives 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.