{
  "markdown": "# UN Comtrade — Bilateral Trade Statistics\n\nThe United Nations Statistics Division's Commodity Trade Database. Bilateral trade flows between every reporting country and every partner country, broken down by commodity (HS codes), going back decades. The standard source for \"who exports what to whom\" at country level.\n\nPart of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1476+ live data sources.\n\n## Why this matters for AI agents\n\nIf an agent is answering anything about international trade — bilateral relationships, commodity flows, tariffs in context, supply-chain concentration — Comtrade is the source. The data is structured (HS codes) and harmonized across countries, making cross-country comparison reliable.\n\nCommon flows:\n\n- **Bilateral analysis.** \"US-China trade flows in 2024.\" → `comtrade_trade_data({reporter_code: \"842\", partner_code: \"156\", year: \"2024\"})` → imports + exports + balance.\n- **Top commodities.** \"What does the US import most from China?\" → `comtrade_top_commodities({reporter_code, partner_code, flow: \"M\"})`.\n- **Top partners.** \"Who are the top buyers of US semiconductors?\" → `comtrade_top_partners({reporter_code, hs_code: \"8542\", flow: \"X\"})`.\n- **Country code lookup.** ISO 3-digit numeric codes — `comtrade_country_codes` returns the full mapping.\n\nUsed by the `trade_bilateral_analysis` and `trade_country_profile` compounds.\n\n## Auth\n\nComtrade has free and premium tiers. The free tier is heavily rate-limited (a few requests per minute). For higher volumes, register at https://comtradeplus.un.org and pass an API key via `_apiKey`.\n\n## Country and commodity codes\n\n| Type | Format | Example |\n|---|---|---|\n| Country | ISO 3166-1 numeric | `842` (US), `156` (China), `484` (Mexico) |\n| Commodity | HS chapter / heading / subheading | `85` (electrical), `8517` (telephones), `851712` (smartphones) |\n| Flow | M / X / re-import / re-export | `M` = imports, `X` = exports |\n\n`comtrade_country_codes` returns the full mapping. Most agents pass the 3-digit numeric to avoid name-disambiguation problems.\n\n## Update cadence\n\nComtrade releases data with a substantial lag — typically 6–12 months after the calendar year. The most recent year you can query is usually last calendar year. Pipeworx caches with 30-day TTL since this data is essentially static once published.\n\n## Common pitfalls\n\n- **Reporter vs. partner mirror data.** Both sides of a trade report it (the US reports imports from China; China reports exports to the US). Numbers don't perfectly match — different valuation methods (CIF vs FOB), shipping treatment, classification differences. Reporter-side is the convention; if you need both, request both.\n- **HS revision changes.** The HS classification updates every 5 years (HS17, HS22, etc.). Long time-series straddle revisions; codes for the same commodity can shift. Comtrade harmonizes for you in standard queries.\n- **Service trade NOT included.** Comtrade is goods only. Service trade lives separately (BEA / WTO data). Don't conflate.\n- **Re-exports.** Hong Kong's \"exports to the US\" include massive re-exports of Chinese-origin goods. The `flow` parameter distinguishes; use it explicitly.\n- **Currency.** Default values are USD — but check the `unit` field. Some series report quantity (kg, units) only without value.\n- **Unreported pairs.** Not every country reports to Comtrade every year. Cuba, Iran, North Korea have major gaps. Mirror data from partners can fill the holes — query the partner's reports of trade with that country.\n\n## Quick Start\n\nAdd to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):\n\n```json\n{\n  \"mcpServers\": {\n    \"comtrade\": {\n      \"url\": \"https://gateway.pipeworx.io/comtrade/mcp\"\n    }\n  }\n}\n```\n\n### What this endpoint actually serves\n\n`tools/list` at `https://gateway.pipeworx.io/comtrade/mcp` returns the tools in the table\nabove **plus the shared Pipeworx meta-tools** — `ask_pipeworx`,\n`discover_tools`, `search_within`, `remember`/`recall` and the rest of the\ngateway-wide set. So the tool count you see is larger than this table: a\nsingle-pack endpoint currently lists roughly 30 shared tools alongside the\npack's own. The connection's `initialize` response states its exact scope, and\nis the authoritative answer for a given day.\n\nThis is deliberate, not multiplexing by accident. The meta-tools are what let a\nscoped connection answer a question this pack does not cover — via\n`ask_pipeworx`, which routes across the whole catalog — without you adding a\nsecond MCP server. There is currently no way to mount a pack endpoint without\nthem; if the extra schemas cost you more context than the routing is worth,\nconnect to the full gateway once rather than to several pack endpoints.\n\nOr connect to the full Pipeworx gateway to get every pack's tools listed\ndirectly, instead of just this one's:\n\n```json\n{\n  \"mcpServers\": {\n    \"pipeworx\": {\n      \"url\": \"https://gateway.pipeworx.io/mcp\"\n    }\n  }\n}\n```\n\nBoth URLs reach the same gateway and the same 1476+ data sources. The\nonly difference is which pack's tools are listed **directly**; `ask_pipeworx`\nreaches all of them from either one.\n\n## Using with ask_pipeworx\n\nInstead of calling tools directly, you can ask questions in plain English —\nthis works on the pack endpoint above as well as on the full gateway:\n\n```\nask_pipeworx({ question: \"your question about Comtrade data\" })\n```\n\nThe gateway picks the right tool and fills the arguments automatically.\n\n## More\n\n- [Docs and guides](https://pipeworx.io/docs)\n- [pipeworx.io](https://pipeworx.io)\n\n## License\n\nMIT\n",
  "bytes": 5567,
  "sha": "ea472d4afc454250bf7cf25021154eb5156a82a7b52a1dc752a9ecf829cb7709",
  "repo_slug": "pipeworx-io/mcp-comtrade",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_pipeworx_io_comtrade_7bdbd277/readme"
}