comtrade_get_top_partners
Returns a reporter's N trade partners ranked by primary value for a chosen commodity, period, and flow from UN Comtrade data.
Instructions
A reporter's n largest partners in one product and period, by primary value.
One data/v1/get call for goods (typeCode C) without partnerCode (every
partner), pinned to the total of every breakdown (partner2Code 0, customsCode
C00, motCode 0, breakdownMode classic), with descriptions (includeDesc).
The rows are sorted by primary_value, largest first, here rather than upstream;
partner 0, World, is dropped because it is the total over all partners, not a
partner; the first n rows are returned and nothing else is changed. Areas that
are not countries, such as 490 "Other Asia, nes", stay in the ranking where the
reporter reported them. Bounded by construction at one row per partner (310 in the
packaged partnerAreas.json), so there is no count call. Arguments are resolved and
checked before the call; an unknown reporter raises UnknownCode, an
InvalidRequestError naming the packaged list and the closest area, another
mistake InvalidRequestError naming the closest valid value. meta.request holds
the get_data arguments that were sent, and n.
Args:
reporter: The reporting area, as UN Comtrade's code or its ISO alpha-3 code:
"757" or "CHE" Switzerland, "842" or "USA", "276" or "DEU"
Germany, "156" or "CHN" China; list_reporters(search=...) finds them.
Codes are UN Comtrade's, not ISO numeric (Switzerland is 757, not 756). An
alpha-3 code that several codes share resolves to the one still in use
("DEU" is 276, not 280 Fed. Rep. of Germany until 1990).
commodity: One product code of cl_code: "TOTAL" all goods, an HS chapter
"27", heading "3004" or subheading "300490".
list_commodities("HS", search="medicament") finds codes.
period: One year "2023" (annual data) or month "202305" (monthly data).
flow: One trade flow: "X" exports, "M" imports, "RX" re-exports,
"RM" re-imports.
n: How many partners, at least 1, e.g. 10; fewer come back when fewer
partners have a row.
cl_code: Product classification, "HS" by default: all HS editions as each
reporter reported them (rows name the edition in classification_code, e.g.
"H6"); an edition "H0" to "H5", SITC "SS" or "S1" to "S4",
BEC "B4", "B5" also work. "H6" is valid but upstream answered HTTP 500
to every try on 2026-10-23, so "HS" stays the default. EBOPS "EB",
"EB02", "EB10", "EB10S" (services), "BE" and "TM" are
accepted but untested with the pinned typeCode C.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"reporter": "<reporter>",
"commodity": "<commodity>",
"period": "<period>",
"flow": "<flow>",
"n": "<n>"
},
"name": "comtrade_get_top_partners"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| n | Yes | ||
| flow | Yes | ||
| period | Yes | ||
| cl_code | No | HS | |
| reporter | Yes | ||
| commodity | Yes |