GnistAI GnistAI
Log in

UN Comtrade

International trade statistics — imports, exports, and commodity flows between countries.

Overview   |   MCP   |   REST API   |   OpenAPI   |   CLI   |   Tutorial   |   Toolkits   |   Home
status: healthy status status healthy healthy tools: 6 tools tools 6 6 type: api wrapper type type api wrapper api wrapper lifecycle: maintained lifecycle lifecycle maintained maintained Economics

Data source: UN Comtrade

MCP Endpoint (Streamable HTTP) https://context.gnist.ai/mcp/un-comtrade/
Authentication

All requests require a Gnist-API-Key header (or api_key query parameter).

Free tier: 100 calls/day. Get your API key.

Tools (6)

get_trade_flow

Fetch bilateral trade flows between two countries for a commodity.

Data from UN Comtrade — 200+ countries, 6,000+ HS commodity codes, back to 1962.

Args:
reporter: Reporting country name or ISO numeric code (e.g., "Germany", "276").
partner: Partner country name or ISO numeric code (e.g., "China", "156").
Use "World" or "0" for global aggregates.
commodity_code: HS commodity code (e.g., "8471" for computers, "27" for fuels,
"TOTAL" for all commodities). Use search_commodities to find codes.
year_from: Start year (e.g., 2018). If omitted, returns most recent year.
year_to: End year (e.g., 2022). If omitted, same as year_from.
flow: Trade direction — "M" (imports), "X" (exports), "MX" (both, default).

Returns:
List of trade records with reporter, partner, commodity, flow, value (USD), and weight (kg).

ParameterTypeRequiredDescription
reporterstringrequiredReporting country name or ISO numeric code (e.g., "Germany", "276").
partnerstringrequiredPartner country name or ISO numeric code (e.g., "China", "156"). Use "World" or "0" for global aggregates.
commodity_codestringrequiredHS commodity code (e.g., "8471" for computers, "27" for fuels, "TOTAL" for all commodities). Use search_commodities to find codes.
year_fromanyoptionalStart year (e.g., 2018). If omitted, returns most recent year.
year_toanyoptionalEnd year (e.g., 2022). If omitted, same as year_from.
flowstringoptionalTrade direction — "M" (imports), "X" (exports), "MX" (both, default). (default: "MX")
JSON-RPC Request
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": 1,
  "params": {
    "name": "get_trade_flow",
    "arguments": {
      "reporter": "NO",
      "partner": "NO",
      "commodity_code": "example"
    }
  }
}
top_partners

Rank a country's top trading partners for a given commodity.

Args:
reporter: Reporting country name or ISO numeric code (e.g., "Germany", "276").
commodity_code: HS commodity code (e.g., "87" for vehicles). Use "TOTAL" for all trade.
year: Year (e.g., 2022).
flow: "X" for exports (default) or "M" for imports.
limit: Number of top partners to return (1–50, default 10).

Returns:
Ranked list of trading partners by trade value with country name, code, and value (USD).

ParameterTypeRequiredDescription
reporterstringrequiredReporting country name or ISO numeric code (e.g., "Germany", "276").
commodity_codestringrequiredHS commodity code (e.g., "87" for vehicles). Use "TOTAL" for all trade.
yearintegerrequiredYear (e.g., 2022).
flowstringoptional"X" for exports (default) or "M" for imports. (default: "X")
limitintegeroptionalNumber of top partners to return (1–50, default 10). (default: 10)
JSON-RPC Request
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": 1,
  "params": {
    "name": "top_partners",
    "arguments": {
      "reporter": "NO",
      "commodity_code": "example",
      "year": 1
    }
  }
}
top_commodities

Rank the top commodities traded between two countries.

Args:
reporter: Reporting country name or ISO numeric code (e.g., "Germany", "276").
partner: Partner country name or ISO numeric code (e.g., "China", "156").
year: Year (e.g., 2022).
flow: "X" for exports (default) or "M" for imports.
limit: Number of top commodities to return (1–50, default 10).

Returns:
Ranked list of commodities by trade value with HS code, description, and value (USD).

ParameterTypeRequiredDescription
reporterstringrequiredReporting country name or ISO numeric code (e.g., "Germany", "276").
partnerstringrequiredPartner country name or ISO numeric code (e.g., "China", "156").
yearintegerrequiredYear (e.g., 2022).
flowstringoptional"X" for exports (default) or "M" for imports. (default: "X")
limitintegeroptionalNumber of top commodities to return (1–50, default 10). (default: 10)
JSON-RPC Request
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": 1,
  "params": {
    "name": "top_commodities",
    "arguments": {
      "reporter": "NO",
      "partner": "NO",
      "year": 1
    }
  }
}
search_commodities

Search for HS commodity codes by keyword.

Helps find the right HS code to use with get_trade_flow, top_partners, and top_commodities.

Args:
query: Keyword to search (e.g., "steel", "petroleum", "machinery", "vehicles").

Returns:
List of matching HS chapters (2-digit codes) with descriptions.

ParameterTypeRequiredDescription
querystringrequiredKeyword to search (e.g., "steel", "petroleum", "machinery", "vehicles").
JSON-RPC Request
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": 1,
  "params": {
    "name": "search_commodities",
    "arguments": {
      "query": "example"
    }
  }
}
trade_balance

Calculate bilateral trade balance between two countries.

Args:
reporter: Reporting country name or ISO numeric code (e.g., "Germany", "276").
partner: Partner country name or ISO numeric code (e.g., "China", "156").
year: Year (e.g., 2022).

Returns:
Total exports, imports, and trade balance (exports minus imports) in USD.
Positive balance indicates a trade surplus; negative indicates a deficit.

ParameterTypeRequiredDescription
reporterstringrequiredReporting country name or ISO numeric code (e.g., "Germany", "276").
partnerstringrequiredPartner country name or ISO numeric code (e.g., "China", "156").
yearintegerrequiredYear (e.g., 2022).
JSON-RPC Request
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": 1,
  "params": {
    "name": "trade_balance",
    "arguments": {
      "reporter": "NO",
      "partner": "NO",
      "year": 1
    }
  }
}
report_feedback

Report a bug, feature request, or general feedback for this data source.

Use this when something doesn't work as expected, when you'd like
a new feature, or when you have suggestions for improvement.

Args:
feedback: Describe the issue or suggestion.
feedback_type: One of 'bug', 'feature_request', or 'general'.

ParameterTypeRequiredDescription
feedbackstringrequired
feedback_typestringoptional (default: "general")
JSON-RPC Request
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": 1,
  "params": {
    "name": "report_feedback",
    "arguments": {
      "feedback": "example"
    }
  }
}

Quick Start

Shell
curl -X POST "https://context.gnist.ai/mcp/un-comtrade/" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Gnist-API-Key: YOUR_API_KEY" \
  -d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_trade_flow", "arguments": {"reporter": "example", "partner": "example", "commodity_code": "example"}}}'
Python
import httpx

resp = httpx.post(
    "https://context.gnist.ai/mcp/un-comtrade/",
    headers={"Gnist-API-Key": "YOUR_API_KEY", "Content-Type": "application/json"},
    json={
  "jsonrpc": "2.0",
  "method": "tools/call",
  "id": 1,
  "params": {
    "name": "get_trade_flow",
    "arguments": {
      "reporter": "example",
      "partner": "example",
      "commodity_code": "example"
    }
  }
},
)
print(resp.json())

Related Toolkits (Economics)

Resources