census-trade-mcp-server
This server provides access to the U.S. Census Bureau's International Trade Data API, enabling retrieval and analysis of monthly U.S. export and import statistics from January 2010 to present across multiple commodity classifications and geographies.
Capabilities:
List datasets (
census_trade_list_datasets): Describe the 9 available datasets (HS, NAICS, End-Use, SITC, USDA, Advanced Tech, state-level HS/NAICS, and port-level HS) and their supported detail levels.Get dataset variables (
census_trade_get_dataset_variables): Fetch valid Census API field names for a given dataset and direction to avoid "unknown variable" errors.Query export data (
census_trade_query_exports): Retrieve U.S. export statistics with filters by country, commodity, district, state, port, and time range; supports custom columns, wildcard commodity codes, and aggregation levels.Query import data (
census_trade_query_imports): Retrieve U.S. import statistics similarly, including general and consumption import values.Compute trade balance (
census_trade_get_trade_balance): Calculate exports minus imports for one or more countries or groups over a period, optionally restricted to a specific HS code.Rank top partners (
census_trade_get_top_partners): Rank countries by export or import value for a period, with optional commodity filters, returning sorted results and percentages.Look up country codes (
census_trade_lookup_country_code): Translate country/region/bloc names into Census numeric CTY_CODEs (works offline).Output formats: All query tools can return results as markdown tables or JSON.
Flexible time periods: Specify exact months or ranges, or use year/month arrays.
Best practices: Guidance on handling descriptive fields, avoiding timeouts, and interpreting quantity flags and zero-row responses.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@census-trade-mcp-serverWhat were the top US export partners in 2023?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
uscensus-intl-trade-api-mcp
An MCP (Model Context Protocol) server for the U.S. Census Bureau's International Trade Data API — monthly U.S. export and import statistics, January 2010–present, by Harmonized System (HS), NAICS, End-Use, SITC, USDA (Ag/Non-Ag), and Advanced Technology classifications, plus state- and port-level detail.
Setup
Get a free Census API key: https://api.census.gov/data/key_signup.html (you'll get an email with an activation link — click it before using the key).
Install dependencies and build:
npm install npm run buildSet your API key:
cp .env.example .env # edit .env and set CENSUS_API_KEYAdd to your MCP client (e.g. Claude Desktop / Claude Code config):
{ "mcpServers": { "census-trade": { "command": "node", "args": ["/absolute/path/to/uscensus-intl-trade-api-mcp/dist/index.js"], "env": { "CENSUS_API_KEY": "your_40_character_key_here" } } } }
By default the server runs over stdio. Set TRANSPORT=http (and optionally PORT) to run it as a local streamable-HTTP server instead (binds to 127.0.0.1 only).
Related MCP server: Census MCP Server
Tools
Tool | Purpose |
| Describes the 9 available datasets (hs, naics, enduse, sitc, usda, hitech, statehs, statenaics, porths) and what geography/detail each supports. |
| Fetches the valid field names for a given dataset + direction straight from Census's own metadata, to avoid "unknown variable" errors. |
| General-purpose query tool for U.S. export data — any dataset, country/commodity/district/state/port filters, time range. |
| Same, for U.S. import data. |
| Workflow tool: computes exports − imports for one or more countries/groupings over a period in a single call. |
| Workflow tool: ranks countries by export/import value for a period — the Census API itself doesn't sort results, so this does it for you. |
| Looks up the numeric CTY_CODE (Schedule C) needed to filter by country, region, or trade bloc (e.g. NAFTA, EU, OPEC). Works offline, no API key needed. |
Testing
node scripts/smoke-test.mjs— starts the server, lists tools, and exercises the two tools that don't require a live Census API call. No real API key needed.CENSUS_API_KEY=<real key> node scripts/live-test.mjs— exercises real Census API calls end-to-end (needs a real key and outbound network access toapi.census.gov).
Evaluations
evaluation/questions.xml has 10 verified Q&A pairs for testing how well an LLM can use this server, built on the mcp-builder evaluation harness (evaluation/evaluation.py). All questions use January/June 2013 data — final, long-settled figures chosen so the answers never change.
pip install -r evaluation/requirements.txt
export ANTHROPIC_API_KEY=your_api_key
python evaluation/evaluation.py \
-t stdio -c node -a dist/index.js \
-e CENSUS_API_KEY=<your census key> \
-o evaluation/report.md \
evaluation/questions.xmlNotes on the underlying API
Filtering by country uses a numeric
CTY_CODE(Schedule C), not the country name — usecensus_trade_lookup_country_codeto translate.Descriptive text fields (
CTY_NAME,DIST_NAME,*_LDESC, etc.) require their matching code field also be requested, or the API errors.Don't mix commodity-classification parameters across datasets (e.g. don't filter by
NAICSon thehsdataset).Large, unfiltered queries (e.g. all countries × all 10-digit HS codes) commonly time out — narrow with filters or split wildcard queries (
E_COMMODITY=1*, then2*, etc.) and combine client-side.A response with zero rows isn't necessarily an error — it can just mean no trade occurred for that filter combination.
Quantity fields (
QTY_1_MO,QTY_2_MO,GEN_QY1_MO,GEN_QY2_MO,CON_QY1_MO,CON_QY2_MO, and their*_YRvariants) report"0"for both true zeros and missing/unavailable data — always request the matching*_FLAGfield (e.g.QTY_1_MO_FLAG) alongside a quantity field;"M"means missing, blank means a true zero.Requesting
CTY_CODEwithoutsummary_level="DET"returns individual countries and regional/bloc groupings (e.g.4XXXEurope,0001OPEC) mixed in the same response — summing across all rows double-counts. Setsummary_level="DET"before aggregating across countries yourself.
Full reference: Census International Trade Data API User Guide (PDF).
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseDqualityCmaintenanceServidor MCP para a API do ComexStat, ferramenta de acesso às estatísticas de comércio exterior do Brasil.2092MIT
- AlicenseAqualityCmaintenanceNode.js MCP server enabling AI agents to access comprehensive U.S. Census Bureau demographic and economic data, including ACS, decennial census, and business patterns.1722MIT
- AlicenseNot gradedqualityCmaintenanceProvides access to UN Comtrade international bilateral trade data via an MCP server, enabling AI agents to query trade statistics through natural language.16MIT
- AlicenseNot gradedqualityAmaintenanceMCP server to query U.S. Census Bureau data, variables, and geography through 7 tools supporting dataset discovery, variable search, geography resolution, and data queries with suppression code decoding.3242Apache 2.0
Related MCP Connectors
Census Trade MCP — US Census Bureau International Trade data
Comtrade MCP — UN Comtrade API for international bilateral trade data
This MCP server provides seamless access to Malaysia's government open data, including datasets, w…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jslagle9/uscensus-intl-trade-api-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server