Skip to main content
Glama

un-comtrade-mcp-server

Get Top Trading Partners

comtrade_get_top_partners
Read-only

Rank trading partners for a reporter by trade value for a given commodity and flow direction. Returns the top N partners sorted by descending value — answers "who does country X mainly export product Y to?" or "where does country X mainly import product Z from?" for a single period. Fetches a disaggregated breakdown across all partners then sorts locally. Takes an HS or SITC code in the selected classification; omit cmd_code to rank partners for total trade.

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_code": "<reporter_code>",
      "flow_code": "<flow_code>",
      "period": "<period>"
    },
    "name": "comtrade_get_top_partners"
  }
}

Input Schema

NameRequiredDescriptionDefault
limitNoNumber of top partners to return; totalPartners counts every partner retrieved.
periodYesSingle period: annual YYYY or monthly YYYYMM, month 01–12; frequency is inferred.
cmd_codeNoSingle goods code in the selected classification: HS (e.g. "84", "8471") or SITC (e.g. "071"). Omit or pass "TOTAL" to rank partners for total merchandise trade.
flow_codeYesTrade flow: M=imports, X=exports.
reporter_codeYesM49 numeric code of the reporting country (0–999).
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.
noticeNoRecovery hint when no data is returned.
periodNoPeriod queried.
cmdCodeNoCommodity code queried (TOTAL when omitted).
flowCodeNoFlow direction queried.
partnersNoTop partners sorted by descending trade value.
truncatedNoTrue when API returned 500 records and results may be incomplete.
reporterCodeNoM49 reporter code.
reporterDescNoReporter country name.
totalPartnersNoPartners retrieved before the limit, excluding the World (0) aggregate.
totalValueUsdNoSum of primary values across all returned partners (before limit truncation).
classificationNoGoods classification the commodity code was read in.
referenceNoticeNoReference descriptions unavailable; codes and values retained.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changed
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `keyless_hs_edition_unsupported`: An explicit HS edition H0–H6 requires authenticated 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. `rate_limited`: UN Comtrade rate-limited the ranking request through its retries. `deadline_exceeded`: The ranking request did not complete within the call's time budget. Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `keyless_hs_edition_unsupported`: An explicit HS edition H0–H6 requires authenticated 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. `rate_limited`: UN Comtrade rate-limited the ranking request through its retries. `upstream_unavailable`: The ranking request hit a UN Comtrade server error or network failure through its retries. `deadline_exceeded`: The ranking request did not complete within the call's time budget. Other values are possible when a failure originates below the handler."
    • changedOutput schema / properties / error / properties / data / properties / reason / examples
      Previous value: -[
      -  "keyless_hs_edition_unsupported",
      -  "invalid_reporter_filter",
      -  "upstream_validation",
      -  "invalid_upstream_response",
      -  "rate_limited",
      -  "deadline_exceeded"
      -]New value: +[
      +  "keyless_hs_edition_unsupported",
      +  "invalid_reporter_filter",
      +  "upstream_validation",
      +  "invalid_upstream_response",
      +  "rate_limited",
      +  "upstream_unavailable",
      +  "deadline_exceeded"
      +]
  2. Changed9 schema fields changed
    • addedInput schema / properties / classification
      Added value: +{
      +  "default": "HS",
      +  "description": "Goods classification: HS as reported, H0–H6 with authenticated access, or SITC S1–S4/SS.",
      +  "type": "string"
      +}
    • changedInput schema / properties / cmd_code / description
      Previous value: -"Single HS commodity code (e.g. \"84\", \"8471\"). Omit or pass \"TOTAL\" to rank partners for total merchandise trade."New value: +"Single goods code in the selected classification: HS (e.g. \"84\", \"8471\") or SITC (e.g. \"071\"). Omit or pass \"TOTAL\" to rank partners for total merchandise trade."
    • changedInput schema / properties / limit / description
      Previous value: -"Maximum number of top partners to return; above 50 returns all retrieved partners."New value: +"Number of top partners to return; totalPartners counts every partner retrieved."
    • changedOutput schema / anyOf
      Previous value: -[
      -  {
      -    "not": {
      -      "required": [
      -        "error"
      -      ]
      -    },
      -    "required": [
      -      "partners",
      -      "reporterCode",
      -      "reporterDesc",
      -      "period",
      -      "flowCode",
      -      "cmdCode",
      -      "totalPartners",
      -      "truncated"
      -    ]
      -  },
      -  {
      -    "required": [
      -      "error"
      -    ]
      -  }
      -]New value: +[
      +  {
      +    "not": {
      +      "required": [
      +        "error"
      +      ]
      +    },
      +    "required": [
      +      "partners",
      +      "reporterCode",
      +      "reporterDesc",
      +      "period",
      +      "flowCode",
      +      "cmdCode",
      +      "classification",
      +      "totalPartners",
      +      "truncated"
      +    ]
      +  },
      +  {
      +    "required": [
      +      "error"
      +    ]
      +  }
      +]
    • addedOutput schema / properties / classification
      Added value: +{
      +  "description": "Goods classification the commodity code was read in.",
      +  "type": "string"
      +}
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `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."New value: +"Machine-readable failure mode. Declared by this tool: `keyless_hs_edition_unsupported`: An explicit HS edition H0–H6 requires authenticated 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. `rate_limited`: UN Comtrade rate-limited the ranking request through its retries. `deadline_exceeded`: The ranking request did not complete within the call's time budget. Other values are possible when a failure originates below the handler."
    • changedOutput schema / properties / error / properties / data / properties / reason / examples
      Previous value: -[
      -  "invalid_reporter_filter",
      -  "upstream_validation",
      -  "invalid_upstream_response"
      -]New value: +[
      +  "keyless_hs_edition_unsupported",
      +  "invalid_reporter_filter",
      +  "upstream_validation",
      +  "invalid_upstream_response",
      +  "rate_limited",
      +  "deadline_exceeded"
      +]
    • changedOutput schema / properties / partners / items / properties / sharePercent / description
      Previous value: -"Share of total trade value among returned partners, as a percentage."New value: +"Share of totalValueUsd across every retrieved partner, as a percentage."
    • changedOutput schema / properties / totalPartners / description
      Previous value: -"Total partners with non-zero trade value returned by API."New value: +"Partners retrieved before the limit, excluding the World (0) aggregate."
  3. Changed11 schema fields changed
    • addedInput schema / properties / cmd_code / pattern
      Added value: +"^(?:[A-Z0-9]+(?:\\.[A-Z0-9]+)*)?$"
    • removedInput schema / properties / flow_code / enum
      Removed value: -[
      -  "M",
      -  "X"
      -]
    • changedInput schema / properties / period / description
      Previous value: -"Single period: annual (YYYY) or monthly (YYYYMM)."New value: +"Single period: annual YYYY or monthly YYYYMM, month 01–12; frequency is inferred."
    • removedInput schema / properties / period / minLength
      Removed value: -4
    • addedInput schema / properties / period / pattern
      Added value: +"^[0-9]{4}(?:0[1-9]|1[0-2])?$"
    • changedInput schema / properties / reporter_code / description
      Previous value: -"M49 numeric code of the reporting country."New value: +"M49 numeric code of the reporting country (0–999)."
    • changedInput schema / properties / reporter_code / maximum
      Previous value: -9007199254740991New value: +999
    • changedInput schema / properties / reporter_code / minimum
      Previous value: --9007199254740991New value: +0
    • 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: `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: +[
      +  "invalid_reporter_filter",
      +  "upstream_validation",
      +  "invalid_upstream_response"
      +]
    • addedOutput schema / properties / referenceNotice
      Added value: +{
      +  "description": "Reference descriptions unavailable; codes and values retained.",
      +  "type": "string"
      +}
  4. First observed

TDQS

A4.1/5.0
Behavior4/5

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

Annotations already cover the safety profile (readOnlyHint, openWorldHint), but the description adds a genuinely useful implementation trait: 'Fetches a disaggregated breakdown across all partners then sorts locally,' which signals that cost/volume is driven by the full partner set rather than by limit. It also discloses the sort order (descending value) and that the result is scoped to a single period. It doesn't discuss rate limits or authentication needs for the broader classification tiers.

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 action, followed by return semantics, example questions, and one behavioral caveat — no filler. The paired export/import example questions are near-mirror images and could be compressed to one, a minor redundancy rather than a flaw.

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?

With an output schema present and 100% parameter coverage, the description only needs to convey purpose, scoping, and the sort/fetch behavior — all of which it does. The remaining minor gap is that it doesn't clarify the relationship between limit and totalPartners in prose, though the schema covers it.

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 coverage is 100%, so every parameter (limit, period, cmd_code, flow_code, reporter_code, classification) is already documented in the schema, including the omit/TOTAL rule and the 'totalPartners' note. The description restates the cmd_code omission and 'single period' constraint but adds no format, default, or interaction detail beyond the schema. Baseline 3 is appropriate when the schema carries the weight.

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?

The description opens with a specific verb+resource+scope: 'Rank trading partners for a reporter by trade value for a given commodity and flow direction.' The two example questions ('who does country X mainly export product Y to?') make the output shape concrete, and the partner-ranking framing is cleanly distinguishable from the sibling comtrade_get_top_commodities, which inverts the dimension.

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?

Usage context is clear: single period only, ranking per commodity+flow, and an explicit rule for the no-commodity case ('omit cmd_code to rank partners for total trade'). It does not name an alternative tool or state when-not to use this one (e.g., when the caller actually wants commodity rankings or multi-period series), so it stops short of full routing 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.