Comtrade

v0.2.1
io.github.pipeworx-io/comtrade Checked 2 days ago Published 1 month ago

Comtrade MCP — UN Comtrade API for international bilateral trade data

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

comtrade_trade_data

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…

ParameterTypeDescription
partner_code *stringPartner country name (e.g. "China") or UN code (156=China, 0=World). Optional — defaults to World (0). Names resolved automatically.
reporter_code *stringCountry name (e.g. "USA", "China", "Germany") or UN numeric code (US=842, China=156). Names are resolved automatically.
year *stringTrade period. For frequency="annual" (default): a year, e.g. "2024". For frequency="monthly": year+month as YYYYMM, e.g. "202401" for January 2024.
cmd_codestringAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
commoditystringAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
commodity_codestringAlias for hs_code — HS commodity code (e.g. "2603" for copper ores). Use this OR hs_code, not both.
flowstringTrade flow: "M" for imports, "X" for exports. Optional — defaults to both "M,X".
frequencystringData 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…
hsstringAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
hs_codestringHS 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 exac…

comtrade_top_partners

Find a country's top trading partners ranked by trade volume. Returns partner countries and total trade values. Defaults to ANNUAL; pass frequency="monthly" for a single month's ranking instead of the last full year's.

ParameterTypeDescription
flow *stringTrade flow: "M" for imports, "X" for exports
reporter_code *stringCountry name (e.g. "USA", "China") or UN numeric code (842=US). Names resolved automatically.
year *stringTrade period. For frequency="annual" (default): a year, e.g. "2024". For frequency="monthly": year+month as YYYYMM, e.g. "202401".
cmd_codestringAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
commoditystringAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
commodity_codestringAlias for hs_code — HS commodity code (e.g. "2603" for copper ores). Use this OR hs_code, not both.
frequencystringData frequency: "annual" (default) or "monthly". Monthly coverage is thinner — not every reporter files monthly, and recent months lag; a reporter with no filing for the requested month is absent fr…
hsstringAlias for hs_code — HS commodity code. Use this OR hs_code, not both.
hs_codestringOptional HS commodity code to filter by specific product (e.g. "2603" for copper ores) — omit for all commodities (TOTAL). Aliases accepted: commodity_code, commodity, hs, cmd_code (pass exactly one…
limitnumberNumber of top partners to return (default 20)

comtrade_top_commodities

Rank the products two countries actually trade, largest value first — "what does the US import most from China". Returns HS categories with trade value and net weight. Defaults to HS 2-digit chapters (~97 categories, e.g. 85 Electrical machinery); pass hs_level 4 or 6 for finer product detail.

ParameterTypeDescription
flow *stringTrade flow, REQUIRED because it decides what the answer MEANS: "X" for exports (what a country SELLS / ships abroad) or "M" for imports (what it BUYS / receives). Deliberately not defaulted — guessi…
reporter_code *stringCountry name (e.g. "USA", "China") or UN numeric code (842=US). Names resolved automatically.
year *stringTrade period. For frequency="annual" (default): a year, e.g. "2024". For frequency="monthly": year+month as YYYYMM, e.g. "202401".
frequencystringData frequency: "annual" (default) or "monthly". Monthly coverage is thinner — not every reporter files monthly, and recent months lag. When "monthly", pass `year` as YYYYMM.
hs_levelnumberHS aggregation level: 2 for chapters (default, ~97 broad categories), 4 for headings, 6 for subheadings. Higher numbers give finer product detail and many more rows.
limitnumberNumber of top commodities to return (default 20)
partner_codestringPartner country name or UN code (0=World). Optional — defaults to World. Names resolved automatically.

comtrade_country_codes

Look up UN Comtrade reporter/partner codes for trade queries (e.g., "842" = US, "156" = China). Note Comtrade uses 842 for the US, not the ISO 840. Returns code and country name pairs.