World Trade MCP
README.md
# World Trade MCP
A provider-agnostic MCP server for querying official international trade, tariff, and macroeconomic datasets from one interface.
The project starts with four official data providers:
| Provider | Coverage | Access |
|---|---|---|
| UN Comtrade | Global merchandise and services trade by reporter, partner, product, and period | Anonymous preview (up to 500 rows); registered free API key unlocks the standard data API |
| WTO Timeseries | Merchandise trade, services, tariffs, market-access and related indicators | Free API key |
| World Bank Indicators | Trade, GDP, development and macro indicators | No API key |
| Eurostat | EU trade and other European statistics | No API key |
ITC Trade Map is tracked as a future integration. ITC says its secure API is made available only in specific circumstances; this project will not scrape the Trade Map website or bypass its access controls. A user's Trade Map account does not automatically provide a general-purpose developer API.
## What this server exposes
- `list_data_sources` — provider coverage, credential status, and access notes.
- `get_un_comtrade_trade_data` — annual or monthly trade records. Uses the public preview automatically when no key is configured.
- `get_un_comtrade_releases` — latest Comtrade release information.
- `get_wto_timeseries` — WTO indicator time series.
- `get_world_bank_indicator` — World Bank country/indicator time series.
- `get_eurostat_dataset` — query a public Eurostat dataset using its dataset code and dimension filters.
Provider responses retain their source fields and include provenance metadata. Values from different providers are not silently merged because definitions, reporting bases, currencies, and revisions can differ.
## Quick start
Requirements: Python 3.11+
```bash
git clone https://github.com/trehsan1-creator/world-trade-mcp.git
cd world-trade-mcp
python -m venv .venv
# Windows PowerShell
.venv\Scripts\Activate.ps1
# macOS / Linux
source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env
```
Add API keys to `.env` only if you have them. The World Bank and Eurostat tools work without credentials; Comtrade starts in public-preview mode.
Run the MCP server over stdio:
```bash
python -m world_trade_mcp.server
```
For local MCP clients, configure the server command as `python` with argument `-m world_trade_mcp.server`, using the project directory as the working directory.
## Environment variables
| Variable | Required | Purpose |
|---|---:|---|
| `UN_COMTRADE_API_KEY` | No | Enables the registered Comtrade data API instead of anonymous preview |
| `WTO_API_KEY` | No | Enables WTO Timeseries queries |
| `HTTP_TIMEOUT_SECONDS` | No | HTTP timeout (default: 30) |
| `MCP_LOG_LEVEL` | No | Logging level (default: INFO) |
Never commit `.env`, API keys, cookies, or personal account credentials.
## Example tool calls
UN Comtrade exports from China to the world, HS total, 2024:
- `reporter_code=156`
- `partner_code=0` (world)
- `period=2024`
- `flow_code=X`
- `cmd_code=TOTAL`
UN Comtrade imports into the United States from China for HS code 0901 in 2023:
- `reporter_code=842`
- `partner_code=156`
- `period=2023`
- `flow_code=M`
- `cmd_code=0901`
World Bank example indicator: `NE.EXP.GNFS.CD` (exports of goods and services, current US$).
## Data quality and interpretation
- Always retain provider, dataset/indicator, reporter, partner, product classification, period, unit, and source notes with a result.
- Do not interpret mirror statistics as reporter-submitted statistics.
- Do not compare values from different sources until units, coverage, valuation basis, and definitions have been checked.
- Product codes are classification- and year-dependent (for example HS revisions); this server does not silently translate between HS editions.
- A successful API response is not a guarantee that a country/product/period has reported data.
## Development
```bash
pytest
ruff check .
```
## Official documentation
- [UN Comtrade API documentation](https://comtrade.un.org/en/api-docs)
- [UN Comtrade subscription plans](https://comtrade.un.org/en/subscriptions)
- [WTO API Developer Portal](https://apiportal.wto.org/)
- [World Bank Indicators API](https://datahelpdesk.worldbank.org/knowledgebase/articles/889392)
- [Eurostat API access](https://ec.europa.eu/eurostat/web/user-guides/data-browser/api-data-access)
## Roadmap
1. Add WITS / UNCTAD TRAINS adapter after endpoint and access behavior are validated.
2. Add national statistical APIs (starting with US Census and selected major trading economies).
3. Add HS nomenclature and country-code metadata helpers.
4. Add normalized cross-provider comparison with explicit unit and methodology checks.
5. Add optional REST/OpenAPI gateway and hosted deployment after the stdio MCP interface is tested.
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessOutdated data