MCP server for UN Comtrade API access
Project description
UN Comtrade MCP Server
A Model Context Protocol (MCP) server that provides access to the UN Comtrade international trade statistics API. This server enables AI assistants like Claude to query and analyze global trade data directly.
Features
The Comtrade MCP server provides tools for:
- Trade Data Queries: Preview or retrieve detailed trade data (final and tariff line data)
- Data Availability: Check what data is available for specific criteria
- Metadata: Access publication notes and metadata about trade datasets
- Reference Data: Query reference tables (countries, commodities, trade flows, etc.)
- Country Code Conversion: Convert ISO3 country codes to Comtrade codes
- Live Updates: Get notifications about recent data releases
Installation
Using uvx (Recommended)
The easiest way to use this MCP server is with uvx:
uvx comtrade-mcp-server
Using pip
pip install comtradeapicall
cd mcp-server
pip install -e .
Configuration
For Claude Desktop
Add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"comtrade": {
"command": "uvx",
"args": ["comtrade-mcp-server"],
"env": {
"COMTRADE_SUBSCRIPTION_KEY": "your-api-key-here"
}
}
}
}
Environment Variables
COMTRADE_SUBSCRIPTION_KEY(optional): Your UN Comtrade API subscription key- Required for:
get_trade_data,get_live_updates - Not required for:
preview_trade_data,get_data_availability,get_metadata, reference tools - Get a free key at: https://comtradeplus.un.org/
- Required for:
Available Tools
1. preview_trade_data
Preview final trade data (limited to 500 records). No subscription key required.
Example use: "Show me a preview of Australia's imports of commodity code 91 in May 2022"
Parameters:
typeCode: "C" (Goods) or "S" (Services)freqCode: "A" (Annual) or "M" (Monthly)clCode: Classification code (e.g., "HS", "SITC")period: Time period (e.g., "2022" for annual, "202205" for monthly)reporterCode: Country code (useget_referencewith "reporter" to find codes)cmdCode: Commodity code(s), comma-separated (e.g., "91" or "91,90")flowCode: Trade flow ("M" for imports, "X" for exports)partnerCode(optional): Partner country codebreakdownMode(optional): "classic" or "plus"includeDesc(optional): Include descriptions (default: true)
2. get_trade_data
Get full trade data with subscription key (up to 250K records). Requires subscription key.
Example use: "Get detailed trade data for France's exports in 2022"
Parameters: Same as preview_trade_data plus:
maxRecords(optional): Maximum records to return (default: 2500)
3. get_data_availability
Check what trade data is available. Free to use.
Example use: "What trade data is available for 2021?"
Parameters:
typeCode: "C" or "S"freqCode: "A" or "M"clCode: Classification codeperiod: Time periodreporterCode(optional): Country code (omit for all countries)
4. get_metadata
Get metadata and publication notes. Free to use.
Example use: "Get metadata for monthly data in May 2022"
Parameters:
typeCode: "C" or "S"freqCode: "A" or "M"clCode: Classification codeperiod: Time periodreporterCode(optional): Country codeshowHistory(optional): Show historical notes (default: false)
5. list_references
List all available reference tables. Free to use.
Example use: "What reference tables are available?"
Parameters:
category(optional): Filter by category (e.g., "cmd:HS")
6. get_reference
Get contents of a specific reference table. Free to use.
Example use: "Get the list of reporter countries"
Common categories:
reporter: Reporter countriespartner: Partner countriesflow: Trade flow codescustoms: Customs procedure codesmot: Mode of transport codes
Parameters:
category: Reference category name
7. convert_country_iso3_to_code
Convert ISO3 country codes to Comtrade codes. Free to use.
Example use: "Convert USA, FRA, and CHE to Comtrade codes"
Parameters:
iso3_codes: Comma-separated ISO3 codes (e.g., "USA,FRA,CHE")
8. get_live_updates
Get recent data releases. Requires subscription key.
Example use: "What data was recently released?"
Usage Examples
With Claude Desktop
After configuration, you can ask Claude:
- "What countries are available in Comtrade?"
- "Show me Australia's imports of electronics in May 2022"
- "Convert USA, GBR, and JPN to Comtrade country codes"
- "What trade data is available for 2021?"
- "Get metadata for monthly HS classification data in June 2022"
Programmatically
# The MCP server runs as a subprocess and communicates via stdio
# Typically used through MCP clients like Claude Desktop
Data Types and Codes
Type Codes
C: Goods (Commodities)S: Services
Frequency Codes
A: AnnualM: Monthly
Classification Codes
Common classifications include:
HS: Harmonized SystemSITC: Standard International Trade Classification- Use
list_referencesto see all available classifications
Flow Codes
M: ImportsX: ExportsRE: Re-exportsRM: Re-imports
Learn More
- UN Comtrade Documentation
- UN Comtrade Developer Portal
- Model Context Protocol
- comtradeapicall Python Package
License
MIT License - See LICENSE file for details
Support
For issues specific to this MCP server, please open an issue on GitHub.
For UN Comtrade API questions, visit the UN Comtrade Developer Portal.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file comtrade_mcp_server-1.0.0.tar.gz.
File metadata
- Download URL: comtrade_mcp_server-1.0.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
868295b1bebe7110c16f80e1f830579c9875e8f75846e49b88ce9e558a284b30
|
|
| MD5 |
6d4cdbdec4feda4bc78838d45ff9673f
|
|
| BLAKE2b-256 |
41d044a5fce04affa05406c38d82d6267c7a77c74746fac8538769ac7e072874
|
File details
Details for the file comtrade_mcp_server-1.0.0-py3-none-any.whl.
File metadata
- Download URL: comtrade_mcp_server-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e485f92d719d33f4fbe65e8baf60f61ec56207d465e62f0642fad3c9b0b162e
|
|
| MD5 |
afdc2a7bfe36404a388e7b892f72b0fc
|
|
| BLAKE2b-256 |
75ca9e13a5caa63536779e6cc745c4aa2b29e22937f76788c09b4115a4bb9756
|