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.

Example tool call

This call uses example arguments supplied in the tool’s input schema.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "year": "2024",
      "partner_code": "156",
      "reporter_code": "842"
    },
    "name": "comtrade_trade_data"
  }
}

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. Changed8 schema fields changed
    • changedInput schema / properties / cmd_code / description
      Previous value: -"Alias for hs_code — HS commodity code. Use this OR hs_code, not both."New value: +"Alias for hs_code, HS commodity code. Use this OR hs_code, not both."
    • changedInput schema / properties / commodity / description
      Previous value: -"Alias for hs_code — HS commodity code. Use this OR hs_code, not both."New value: +"Alias for hs_code, HS commodity code. Use this OR hs_code, not both."
    • changedInput schema / properties / commodity_code / description
      Previous value: -"Alias for hs_code — HS commodity code (e.g. \"2603\" for copper ores). Use this OR hs_code, not both."New value: +"Alias for hs_code, HS commodity code (e.g. \"2603\" for copper ores). Use this OR hs_code, not both."
    • changedInput schema / properties / flow / description
      Previous value: -"Trade flow: \"M\" for imports, \"X\" for exports. Optional — defaults to both \"M,X\"."New value: +"Trade flow: \"M\" for imports, \"X\" for exports. Optional, defaults to both \"M,X\"."
    • changedInput schema / properties / frequency / description
      Previous value: -"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."New value: +"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."
    • changedInput schema / properties / hs / description
      Previous value: -"Alias for hs_code — HS commodity code. Use this OR hs_code, not both."New value: +"Alias for hs_code, HS commodity code. Use this OR hs_code, not both."
    • changedInput schema / properties / hs_code / description
      Previous 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)."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)."
    • changedInput schema / properties / partner_code / description
      Previous value: -"Partner country name (e.g. \"China\") or UN code (156=China, 0=World). Optional — defaults to World (0). Names resolved automatically."New value: +"Partner country name (e.g. \"China\") or UN code (156=China, 0=World). Optional, defaults to World (0). Names resolved automatically."
  2. 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)."
  3. 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."
  4. 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"
      -]
  5. 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."
  6. 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"
      +  }
      +]
  7. 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"
  8. 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"
      +}
  9. 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"
      +  }
      +]
  10. First observed

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already cover safety (readOnly, idempotent, non-destructive, open-world), and the description goes well beyond them with data-quality behavior an agent cannot get elsewhere: annual data lags ~3 months, monthly lags more with thinner coverage, some reporters never file monthly, and a missing month is absent rather than a zero. It also states that every response self-reports its frequency, which prevents a monthly figure being misread as annual.

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 the core statement and the concrete code gotcha (842 vs 840) before the caveats, and every sentence carries information. It is on the long side and the monthly/coverage caveat is effectively stated twice, but nothing is filler.

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?

A complex, high-parameter-count tool with an output schema and full annotations, and the description covers the remaining risk areas: country code format, frequency semantics, default flow behavior, and data-availability caveats. Nothing an agent needs to invoke it correctly 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 schema already documents all ten parameters including the alias set, the flow enum values M/X, and the YYYYMM convention for monthly. The description still adds real-world meaning the schema does not: the explicit warning that Comtrade uses 842 for the US rather than ISO 840, and the consequence of choosing monthly versus annual (lag and coverage).

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?

Names a specific verb+resource: bilateral trade data between two countries from UN Comtrade, with concrete detail on what comes back (USD trade values, quantities, HS commodity detail, imports and exports for reporter/partner). It also flags itself as authoritative/official statistics and points to comtrade_country_codes for the code lookup, so the agent knows this is the actual data-retrieval tool rather than a discovery helper.

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 explicit triggering contexts ("how much X did US import from China in 2024", "Germany exports to Brazil", "Saudi-Egypt trade move this year") and a concrete branch condition: pass frequency="monthly" instead of relying on the annual default. The only gap is that it does not state when to prefer the sibling tools comtrade_top_partners or comtrade_top_commodities over this one, so the agent must infer the boundary.

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.