Un MCP Server

UN Comtrade international trade statistics via MCP. Country/HS lookups, flows, balances, rankings.

Local serverstdio

What is the Un MCP server?

Un MCP server exists for a simple reason — assistants are far more useful when they can act on Un directly instead of describing what you should do. UN Comtrade international trade statistics via MCP. Country/HS lookups, flows, balances, rankings.

What you get

  • Declarative tool and resource definitions — single file per primitive, framework handles registration and validation
  • Unified error handling — handlers throw, framework catches, classifies, and formats
  • Pluggable auth: none, jwt, oauth
  • Swappable storage backends: in-memory, filesystem, Supabase, Cloudflare KV/R2/D1
  • Structured logging with optional OpenTelemetry tracing
  • STDIO and Streamable HTTP transports

Setting it up

Setup follows the usual MCP pattern — install or clone the server, register it in your client's configuration file, restart the client. The configuration blocks on this page cover the common clients.

What the assistant can call

Once Un is connected, these are the calls the assistant has available:

  • comtrade_lookup_countries — Resolve country and area names to Comtrade M49 numeric codes. Accepts partial names or ISO alpha-2/alpha-3 codes. Returns matching entries with
  • comtrade_search_commodities — Find HS commodity codes by keyword, partial description, or code prefix. Returns codes at 2-, 4-, or 6-digit aggregation with descriptions, parent
  • comtrade_list_service_categories — List EBOPS 2010 service trade categories — the services-domain equivalent of comtrade_search_commodities. Returns codes, descriptions, and parent
  • comtrade_get_trade_flows — Fetch bilateral trade flow records. Returns primaryValue (USD, FOB for exports / CIF for imports), quantity, net weight, and period/commodity/partner
  • comtrade_get_trade_balance — Compute trade balance (exports minus imports) for a country over one or more periods with optional commodity filter. Fetches export and import totals
  • comtrade_get_top_partners — Rank trading partners for a reporter by trade value for a given commodity and flow direction. Returns top N partners sorted by descending value for a
  • comtrade_get_top_commodities — Rank commodity categories for a reporter by trade value for a given flow direction and period. Returns top N HS chapters (2-digit) or headings
  • comtrade_get_services_trade — Fetch international trade-in-services data (EBOPS 2010). Same bilateral structure as goods trade: returns flow value, period, and
  • comtrade_get_data_availability — Check which reporter/period/classification combinations have published data before constructing expensive queries. Returns record count and
  • Prerequisites — The Prerequisites tool exposed by this server
  • Installation — The Installation tool exposed by this server

Configuration and credentials

You will need 6 environment variables: MCP_TRANSPORT_TYPE, MCP_LOG_LEVEL, COMTRADE_SUBSCRIPTION_KEY, COMTRADE_API_BASE_URL, MCP_HTTP_ENDPOINT_PATH, MCP_PUBLIC_URL. The server will not start without them, which is usually why the tools fail to appear on a first run. Keep credentials in your client's env block or a secrets manager rather than in a file you might commit.

  • Bun v1.3.0 or higher (or Node.js v24+). - Optional: a UN Comtrade subscription key for full API access. Without one, all tools fall back to the public preview endpoint (500 records/call). Reference/lookup tools (comtrade_lookup_countries, comtrade_search_commodities, comtrade_list_service_categories) never require a key — they query

Before you rely on it

  • It runs with your machine's permissions. That is convenient and also the reason to think about what you point it at before you approve a tool call.
  • With 11 tools registered it takes up a noticeable share of the context window; turn it off in projects that never touch Un.
  • Missing credentials fail quietly in some clients — if no tools show up, check the environment block first.
  • MCP clients confirm each tool call by default. Leave that on until you have watched what the un mcp server does with a few real requests.

Choosing this one

Among the developer tooling options, the useful question is rarely "what can it do" but "what does it cost you to run" — permissions, credentials, and how much of your context its toolset consumes. Un's toolset — comtrade_lookup_countries, comtrade_search_commodities, comtrade_list_service_categories and 8 more — is a fair guide to whether it matches your workflow. It is maintained by cyanheads; worth a glance at recent repository activity before you build anything load-bearing on it.

SyncDev reviews every entry in this directory against the project's own documentation before publishing, and revisits them as servers change.

Available tools

ToolWhat it does
comtrade_lookup_countriesResolve country and area names to Comtrade M49 numeric codes. Accepts partial names or ISO alpha-2/alpha-3 codes. Returns matching entries with validAsReporter flag — regional groupings are valid partner codes but not re
comtrade_search_commoditiesFind HS commodity codes by keyword, partial description, or code prefix. Returns codes at 2-, 4-, or 6-digit aggregation with descriptions, parent code, leaf status, and a recommended_query_code field.
comtrade_list_service_categoriesList EBOPS 2010 service trade categories — the services-domain equivalent of comtrade_search_commodities. Returns codes, descriptions, and parent codes. Filter by keyword or browse from a parent code.
comtrade_get_trade_flowsFetch bilateral trade flow records. Returns primaryValue (USD, FOB for exports / CIF for imports), quantity, net weight, and period/commodity/partner metadata per row. Accepts multiple periods and commodity codes in one
comtrade_get_trade_balanceCompute trade balance (exports minus imports) for a country over one or more periods with optional commodity filter. Fetches export and import totals in parallel; returns signed balance, component values, and coverage ra
comtrade_get_top_partnersRank trading partners for a reporter by trade value for a given commodity and flow direction. Returns top N partners sorted by descending value for a single period.
comtrade_get_top_commoditiesRank commodity categories for a reporter by trade value for a given flow direction and period. Returns top N HS chapters (2-digit) or headings (4-digit) sorted by descending value.
comtrade_get_services_tradeFetch international trade-in-services data (EBOPS 2010). Same bilateral structure as goods trade: returns flow value, period, and reporter/partner/category metadata.
comtrade_get_data_availabilityCheck which reporter/period/classification combinations have published data before constructing expensive queries. Returns record count and publication date per dataset.
PrerequisitesThe Prerequisites tool exposed by this server.
InstallationThe Installation tool exposed by this server.

How to install the Un MCP server

{
  "mcpServers": {
    "un-comtrade-mcp-server": {
      "type": "stdio",
      "command": "bunx",
      "args": ["@cyanheads/un-comtrade-mcp-server@latest"],
      "env": {
        "MCP_TRANSPORT_TYPE": "stdio",
        "MCP_LOG_LEVEL": "info",
        "COMTRADE_SUBSCRIPTION_KEY": "your-key-here"
      }
    }
  }
}

Configuration as documented by the project. Restart the client after saving.

Configuration

  • Bun v1.3.0 or higher (or Node.js v24+). - Optional: a UN Comtrade subscription key for full API access. Without one, all tools fall back to the public preview endpoint (500 records/call). Reference/lookup tools (comtrade_lookup_countries, comtrade_search_commodities, comtrade_list_service_categories) never require a key — they query
VariableDescriptionRequired
MCP_TRANSPORT_TYPEConfiguration value read at startup.Optional
MCP_LOG_LEVELConfiguration value read at startup.Optional
COMTRADE_SUBSCRIPTION_KEYCredential the server authenticates with.Yes
COMTRADE_API_BASE_URLEndpoint or connection string the server talks to.Yes
MCP_HTTP_ENDPOINT_PATHFilesystem location the server is allowed to use.Optional
MCP_PUBLIC_URLEndpoint or connection string the server talks to.Yes

Example prompts to try

  • Use Un to comtrade lookup countries.
  • Use Un to comtrade search commodities.
  • Use Un to comtrade list service categories.

Frequently asked questions

It connects Un to MCP-compatible AI assistants such as Claude and Cursor, exposing 11 tools (comtrade_lookup_countries, comtrade_search_commodities, comtrade_list_service_categories, and more) that the assistant can call on your behalf. Instead of copying data back and forth by hand, the assistant works with Un directly.