Skip to main content
Glama

un-comtrade-mcp-server

Get Top Trade Commodities

comtrade_get_top_commodities
Read-only

Rank HS chapters (2-digit) or headings (4-digit) by trade value for one reporter, flow, and annual or monthly period. Set parent_code and a deeper aggr_level to rank headings or subheadings within one chapter or heading. The tool uses matching TOTAL to identify the HS edition and queries explicit commodity codes in chunks, subdividing capped chunks. Shares use matching TOTAL or the reported parent value for a drill-down. Incomplete coverage returns available categories without ranks or shares and identifies unresolved codes. Defaults to World; optionally select one bilateral partner. Counterpart to comtrade_get_top_partners.

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_commodities"
  }
}

Input Schema

NameRequiredDescriptionDefault
limitNoNumber of top commodity categories to return; totalCommodities counts every category retrieved.
periodYesSingle period: annual (YYYY) or monthly (YYYYMM, month 01–12).
flow_codeYesTrade flow: M=imports, X=exports.
aggr_levelNoHS aggregation level: 2 = chapter, 4 = heading, 6 = subheading. Level 6 requires parent_code.
parent_codeNoTwo-digit HS chapter or four-digit heading. Supply a deeper aggr_level. Blank is treated as omitted.
partner_codeNoM49 partner code (0–999) for a bilateral relationship; omit for World aggregate (0).
reporter_codeYesM49 numeric code of the reporting country (0–999).

Output Schema

NameRequiredDescriptionDefault
errorNoPresent when the call failed. Absent on success.
noticeNoRecovery hint when no data is returned, naming the code to query instead of a partner-only reporter_code (250 → 251, 158 → 490) or of a partner_code with a reporter-valid counterpart (840 → 842, 158 → 490); or what a residual row holds when it is on the returned page.
periodNoPeriod queried.
flowCodeNoFlow direction queried.
aggrLevelNoHS aggregation level used.
truncatedNoTrue when complete commodity-code coverage could not be established.
parentCodeNoHS chapter or heading selected for the drill-down.
commoditiesNoTop commodity categories sorted by descending trade value.
missingCodesNoCodes whose retrieval failed, remained capped, or did not fit the call's time budget; empty when the code universe is unavailable.
reporterCodeNoM49 reporter code.
reporterDescNoReporter country name.
totalValueUsdNoSum of primary values across all returned categories (before limit).
coverageNoticeNoExplanation of coverage and ranking availability.
coverageCompleteNoWhether complete coverage was established for the matching HS edition and requested scope.
totalCommoditiesNoTotal commodity categories returned by API.
classificationCodeNoHS edition identified by matching TOTAL.
denominatorValueUsdNoMatching parent or TOTAL value used as the share denominator, separate from the retrieved-category sum.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed10 schema fields changed
    • changedInput schema / properties / aggr_level / anyOf
      Previous value: -[
      -  {
      -    "const": 2,
      -    "type": "number"
      -  },
      -  {
      -    "const": 4,
      -    "type": "number"
      -  }
      -]New value: +[
      +  {
      +    "const": 2,
      +    "type": "number"
      +  },
      +  {
      +    "const": 4,
      +    "type": "number"
      +  },
      +  {
      +    "const": 6,
      +    "type": "number"
      +  }
      +]
    • changedInput schema / properties / aggr_level / description
      Previous value: -"HS aggregation level: 2 = chapter (broader), 4 = heading (more specific)."New value: +"HS aggregation level: 2 = chapter, 4 = heading, 6 = subheading. Level 6 requires parent_code."
    • addedInput schema / properties / parent_code
      Added value: +{
      +  "description": "Two-digit HS chapter or four-digit heading. Supply a deeper aggr_level. Blank is treated as omitted.",
      +  "pattern": "^(?:[0-9]{2}(?:[0-9]{2})?)?$",
      +  "type": "string"
      +}
    • changedOutput schema / properties / commodities / items / properties / aggrLevel / description
      Previous value: -"HS aggregation level (2 or 4)."New value: +"HS aggregation level (2, 4, or 6)."
    • changedOutput schema / properties / commodities / items / properties / residual / description
      Previous value: -"True on the residual code for commodities not specified according to kind (99 for chapters, 9999 for headings): trade not allocated to a code at this level, ranked and shared like any other row. Absent on every other row."New value: +"True on a catalogued residual code at this level (99, 9999, 999999 or historical 9999AA), ranked and shared like any other row. Absent on every other row."
    • changedOutput schema / properties / commodities / items / properties / sharePercent / description
      Previous value: -"Share of matching TOTAL trade value, only with complete code coverage."New value: +"Share of the matching parent or TOTAL trade value, only with complete code coverage."
    • changedOutput schema / properties / coverageComplete / description
      Previous value: -"Whether every code in the matching HS edition was queried without a capped response."New value: +"Whether complete coverage was established for the matching HS edition and requested scope."
    • changedOutput schema / properties / denominatorValueUsd / description
      Previous value: -"Matching TOTAL value used as the share denominator, separate from the retrieved-category sum."New value: +"Matching parent or TOTAL value used as the share denominator, separate from the retrieved-category sum."
    • changedOutput schema / properties / notice / description
      Previous value: -"Recovery hint when no data is returned, naming the code to query instead of a partner-only reporter_code (250 → 251, 158 → 490) or of a partner_code with a reporter-valid counterpart (840 → 842, 158 → 490); or what the residual row (99 or 9999) holds when it is on the returned page."New value: +"Recovery hint when no data is returned, naming the code to query instead of a partner-only reporter_code (250 → 251, 158 → 490) or of a partner_code with a reporter-valid counterpart (840 → 842, 158 → 490); or what a residual row holds when it is on the returned page."
    • addedOutput schema / properties / parentCode
      Added value: +{
      +  "description": "HS chapter or heading selected for the drill-down.",
      +  "type": "string"
      +}
  2. Changed4 schema fields changed
    • addedOutput schema / properties / commodities / items / properties / residual
      Added value: +{
      +  "description": "True on the residual code for commodities not specified according to kind (99 for chapters, 9999 for headings): trade not allocated to a code at this level, ranked and shared like any other row. Absent on every other row.",
      +  "type": "boolean"
      +}
    • 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 requires authenticated access. `upstream_validation`: UN Comtrade rejects the supplied query dimensions. `invalid_upstream_response`: UN Comtrade returns a malformed response. `invalid_reporter_filter`: The query omits required reporter filtering. `rate_limited`: With TOTAL or the HS reference unavailable, UN Comtrade rate-limited the aggregate fallback through its retries. `deadline_exceeded`: With TOTAL or the HS reference unavailable, the aggregate fallback 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 requires authenticated access. `upstream_validation`: UN Comtrade rejects the supplied query dimensions. `invalid_upstream_response`: UN Comtrade returns a malformed response. `invalid_reporter_filter`: The query omits required reporter filtering. `rate_limited`: With TOTAL or the HS reference unavailable, UN Comtrade rate-limited the aggregate fallback through its retries. `upstream_unavailable`: With TOTAL or the HS reference unavailable, the aggregate fallback hit a UN Comtrade server error or network failure through its retries. `deadline_exceeded`: With TOTAL or the HS reference unavailable, the aggregate fallback 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",
      -  "upstream_validation",
      -  "invalid_upstream_response",
      -  "invalid_reporter_filter",
      -  "rate_limited",
      -  "deadline_exceeded"
      -]New value: +[
      +  "keyless_hs_edition_unsupported",
      +  "upstream_validation",
      +  "invalid_upstream_response",
      +  "invalid_reporter_filter",
      +  "rate_limited",
      +  "upstream_unavailable",
      +  "deadline_exceeded"
      +]
    • changedOutput schema / properties / notice / description
      Previous value: -"Recovery hint when no data is returned."New value: +"Recovery hint when no data is returned, naming the code to query instead of a partner-only reporter_code (250 → 251, 158 → 490) or of a partner_code with a reporter-valid counterpart (840 → 842, 158 → 490); or what the residual row (99 or 9999) holds when it is on the returned page."
  3. Changed10 schema fields changed
    • changedInput schema / properties / limit / description
      Previous value: -"Maximum number of top commodity categories to return; above 50 returns all retrieved categories."New value: +"Number of top commodity categories to return; totalCommodities counts every category retrieved."
    • changedInput schema / properties / partner_code / description
      Previous value: -"M49 partner code for a bilateral relationship; omit for World aggregate (0)."New value: +"M49 partner code (0–999) for a bilateral relationship; omit for World aggregate (0)."
    • changedInput schema / properties / partner_code / maximum
      Previous value: -9007199254740991New value: +999
    • changedInput schema / properties / partner_code / minimum
      Previous value: --9007199254740991New value: +0
    • 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. Declared by this tool: `keyless_hs_edition_unsupported`: An explicit HS edition requires authenticated access. `upstream_validation`: UN Comtrade rejects the supplied query dimensions. `invalid_upstream_response`: UN Comtrade returns a malformed response. `invalid_reporter_filter`: The query omits required reporter filtering. 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 requires authenticated access. `upstream_validation`: UN Comtrade rejects the supplied query dimensions. `invalid_upstream_response`: UN Comtrade returns a malformed response. `invalid_reporter_filter`: The query omits required reporter filtering. `rate_limited`: With TOTAL or the HS reference unavailable, UN Comtrade rate-limited the aggregate fallback through its retries. `deadline_exceeded`: With TOTAL or the HS reference unavailable, the aggregate fallback 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",
      -  "upstream_validation",
      -  "invalid_upstream_response",
      -  "invalid_reporter_filter"
      -]New value: +[
      +  "keyless_hs_edition_unsupported",
      +  "upstream_validation",
      +  "invalid_upstream_response",
      +  "invalid_reporter_filter",
      +  "rate_limited",
      +  "deadline_exceeded"
      +]
    • changedOutput schema / properties / missingCodes / description
      Previous value: -"Codes whose retrieval failed or remained capped; empty when the code universe is unavailable."New value: +"Codes whose retrieval failed, remained capped, or did not fit the call's time budget; empty when the code universe is unavailable."
  4. Changed17 schema fields changed
    • removedInput schema / properties / flow_code / enum
      Removed value: -[
      -  "M",
      -  "X"
      -]
    • changedInput schema / properties / partner_code / description
      Previous value: -"M49 partner code to filter to a specific bilateral relationship. Omit to rank commodities across all partners."New value: +"M49 partner code for a bilateral relationship; omit for World aggregate (0)."
    • 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)."
    • removedInput schema / properties / period / minLength
      Removed value: -4
    • addedInput schema / properties / period / pattern
      Added value: +"^[0-9]{4}(?:0[1-9]|1[0-2])?$"
    • changedOutput schema / anyOf
      Previous value: -[
      -  {
      -    "not": {
      -      "required": [
      -        "error"
      -      ]
      -    },
      -    "required": [
      -      "commodities",
      -      "reporterCode",
      -      "reporterDesc",
      -      "period",
      -      "flowCode",
      -      "aggrLevel",
      -      "totalCommodities",
      -      "truncated"
      -    ]
      -  },
      -  {
      -    "required": [
      -      "error"
      -    ]
      -  }
      -]New value: +[
      +  {
      +    "not": {
      +      "required": [
      +        "error"
      +      ]
      +    },
      +    "required": [
      +      "commodities",
      +      "reporterCode",
      +      "reporterDesc",
      +      "period",
      +      "flowCode",
      +      "aggrLevel",
      +      "totalCommodities",
      +      "truncated",
      +      "coverageComplete",
      +      "coverageNotice",
      +      "missingCodes"
      +    ]
      +  },
      +  {
      +    "required": [
      +      "error"
      +    ]
      +  }
      +]
    • addedOutput schema / properties / classificationCode
      Added value: +{
      +  "description": "HS edition identified by matching TOTAL.",
      +  "type": "string"
      +}
    • changedOutput schema / properties / commodities / items / properties / rank / description
      Previous value: -"Rank (1 = largest trade value)."New value: +"Rank (1 = largest trade value), only with complete code coverage and known values."
    • changedOutput schema / properties / commodities / items / properties / sharePercent / description
      Previous value: -"Share of total trade value among returned commodities, as a percentage."New value: +"Share of matching TOTAL trade value, only with complete code coverage."
    • changedOutput schema / properties / commodities / items / required
      Previous value: -[
      -  "rank",
      -  "cmdCode",
      -  "cmdDesc",
      -  "aggrLevel"
      -]New value: +[
      +  "cmdCode",
      +  "cmdDesc",
      +  "aggrLevel"
      +]
    • addedOutput schema / properties / coverageComplete
      Added value: +{
      +  "description": "Whether every code in the matching HS edition was queried without a capped response.",
      +  "type": "boolean"
      +}
    • addedOutput schema / properties / coverageNotice
      Added value: +{
      +  "description": "Explanation of coverage and ranking availability.",
      +  "type": "string"
      +}
    • addedOutput schema / properties / denominatorValueUsd
      Added value: +{
      +  "description": "Matching TOTAL value used as the share denominator, separate from the retrieved-category sum.",
      +  "type": "number"
      +}
    • 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: `keyless_hs_edition_unsupported`: An explicit HS edition requires authenticated access. `upstream_validation`: UN Comtrade rejects the supplied query dimensions. `invalid_upstream_response`: UN Comtrade returns a malformed response. `invalid_reporter_filter`: The query omits required reporter filtering. Other values are possible when a failure originates below the handler."
    • addedOutput schema / properties / error / properties / data / properties / reason / examples
      Added value: +[
      +  "keyless_hs_edition_unsupported",
      +  "upstream_validation",
      +  "invalid_upstream_response",
      +  "invalid_reporter_filter"
      +]
    • addedOutput schema / properties / missingCodes
      Added value: +{
      +  "description": "Codes whose retrieval failed or remained capped; empty when the code universe is unavailable.",
      +  "items": {
      +    "type": "string"
      +  },
      +  "type": "array"
      +}
    • changedOutput schema / properties / truncated / description
      Previous value: -"True when API returned 500 records and results may be incomplete."New value: +"True when complete commodity-code coverage could not be established."
  5. First observed

TDQS

A4.2/5.0
Behavior4/5

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

Annotations only declare readOnlyHint and openWorldHint, so the description carries most of the burden and does well: it discloses HS-edition detection via matching TOTAL, chunked querying of explicit codes, how shares are computed, and the degraded-but-graceful behavior when coverage is incomplete (no ranks/shares, unresolved codes identified). The only miss is silence on pagination or rate/volume limits despite describing chunking internally.

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 drill-down mechanism, then moves to behavior and defaults with no filler sentences. Some of it is implementation detail ('queries explicit commodity codes in chunks, subdividing capped chunks') that is only marginally actionable for a caller.

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?

An output schema exists, so return-shape explanation is unnecessary, yet the description still tells the agent what to expect on incomplete coverage (categories without ranks/shares plus unresolved codes). For a 7-parameter read-only ranking tool this covers purpose, drill-down mechanics, defaults, and degraded behavior.

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 baseline is 3 and the schema already documents each parameter. The description adds some cross-parameter meaning (parent_code must pair with a deeper aggr_level; partner defaults to World) and clarifies 'Shares use matching TOTAL or the reported parent value for a drill-down', but an agent must still consult the schema to learn the level-6-requires-parent_code constraint.

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?

Opens with a specific verb and resource: 'Rank HS chapters (2-digit) or headings (4-digit) by trade value' for a defined reporter/flow/period, and explicitly frames itself as the 'Counterpart to comtrade_get_top_partners'. An agent can distinguish this commodity-ranking tool from the partner-ranking sibling without opening either schema.

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 conditions: set parent_code plus a deeper aggr_level to rank within a chapter, defaults to World, and optionally select one bilateral partner. It names the counterpart tool but does not spell out explicit when-not-to-use conditions or other alternatives, keeping it just below a 5.

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.