census-trade-mcp-server
An MCP server for the U.S. Census Bureau's International Trade Data API, enabling queries of monthly export and import statistics by HS, NAICS, end-use, and other classifications, with tools for trade balance, top partners, and country code lookup.
README
census-trade-mcp-server
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 build - Set your API key:
cp .env.example .env # edit .env and set CENSUS_API_KEY - Add to your MCP client (e.g. Claude Desktop / Claude Code config):
{ "mcpServers": { "census-trade": { "command": "node", "args": ["/absolute/path/to/census-trade-mcp-server/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).
Tools
| Tool | Purpose |
|---|---|
census_trade_list_datasets |
Describes the 9 available datasets (hs, naics, enduse, sitc, usda, hitech, statehs, statenaics, porths) and what geography/detail each supports. |
census_trade_get_dataset_variables |
Fetches the valid field names for a given dataset + direction straight from Census's own metadata, to avoid "unknown variable" errors. |
census_trade_query_exports |
General-purpose query tool for U.S. export data — any dataset, country/commodity/district/state/port filters, time range. |
census_trade_query_imports |
Same, for U.S. import data. |
census_trade_get_trade_balance |
Workflow tool: computes exports − imports for one or more countries/groupings over a period in a single call. |
census_trade_get_top_partners |
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. |
census_trade_lookup_country_code |
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.xml
Notes 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.
Full reference: Census International Trade Data API User Guide (PDF).
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。