Skip to main content
Glama
jslagle9

census-trade-mcp-server

by jslagle9

Query U.S. Import Trade Data

census_trade_query_imports
Read-onlyIdempotent

Query monthly U.S. import statistics by commodity, country, state, or port from Census trade data. Use filters and time ranges to get detailed import figures.

Instructions

Query monthly U.S. import statistics (January 2010-present) from the Census International Trade Data API.

This is the general-purpose tool for pulling import data by commodity (HS/NAICS/End-Use/SITC/USDA/Hi-Tech), country, customs district, state, or port, for any combination of value/quantity/weight measures. Import value fields typically start with GEN_ (general imports) or CON_ (imports for consumption) rather than ALL_ (which is export-only).

Args:

  • dataset (string): which classification/geography dataset, e.g. 'hs' for Harmonized System (see census_trade_list_datasets)

  • get (string[]): variable names to return as columns, e.g. ["CTY_CODE","CTY_NAME","GEN_VAL_MO"]

  • time (string, optional): 'YYYY-MM' or 'from YYYY-MM to YYYY-MM'

  • year (string, optional) + months (string[], optional): alternative to 'time'

  • filters (object, optional): e.g. {"CTY_CODE":"5700"} for China, {"I_COMMODITY":"8471*"} for HS codes starting with 8471 (computers)

  • comm_level (string, optional): e.g. "HS2" to get 2-digit HS totals instead of full detail

  • summary_level (string, optional): "DET" for individual countries only, "CGP" for country groupings only

  • limit (number, default 100): max rows returned

  • response_format ('markdown' | 'json', default 'markdown')

Best practices (per the Census API User Guide):

  • Prefer narrow queries: the Census API times out on very large requests (e.g. all countries x all HS10 codes). Add country/commodity/district filters, or split wildcard commodity queries (e.g. query "1*" then "2*" separately) and combine results yourself.

  • Descriptive text fields (CTY_NAME, DIST_NAME, E_COMMODITY_LDESC/I_COMMODITY_LDESC, NAICS_LDESC, SITC_LDESC, etc.) require their matching code field (CTY_CODE, DISTRICT, E_COMMODITY/I_COMMODITY, NAICS, SITC) to also be in "get", or the API errors.

  • Only use commodity-classification parameters that match the chosen dataset (e.g. don't filter by NAICS on the "hs" dataset) - use census_trade_get_dataset_variables to check.

  • Results are NOT sorted by value; if you need a ranked list (e.g. top trading partners), use census_trade_get_top_partners instead, or sort the returned rows yourself.

  • A request that returns zero rows is not necessarily an error - it may just mean there was no trade for that combination of filters and time period.

Returns: Rows as either a markdown table or JSON, each row containing the fields requested in "get" plus "time".

Examples:

  • Use when: "What did the U.S. import from China in HS 8471 (computers) in March 2024?" -> dataset="hs", get=["I_COMMODITY","I_COMMODITY_LDESC","GEN_VAL_MO"], time="2024-03", filters={"CTY_CODE":"5700","I_COMMODITY":"8471*"}

  • Use when: "Total general imports by state, Q1 2023" -> dataset="statehs", get=["STATE","GEN_VAL_MO"], time="from 2023-01 to 2023-03"

  • Don't use when: You need export data - use census_trade_query_exports.

  • Don't use when: You want a country trade balance or a sorted list of top partners - use census_trade_get_trade_balance or census_trade_get_top_partners.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
getYesCensus API variable names to return as columns, e.g. ['CTY_CODE','CTY_NAME','ALL_VAL_MO']. Must be valid for the chosen dataset/direction - use get_dataset_variables to look them up. Descriptive text fields (e.g. CTY_NAME, DIST_NAME, E_COMMODITY_LDESC) require their matching code field (CTY_CODE, DISTRICT, E_COMMODITY) to also be included, or the API will error.
timeNoTime period as 'YYYY-MM' (e.g. '2024-03') or a range 'from YYYY-MM to YYYY-MM'. Either 'time' or both 'year' and 'months' is required.
yearNo4-digit year, used with 'months' instead of 'time'.
limitNoMaximum number of rows to return (the tool fetches all matching rows from Census, then truncates to this limit client-side).
monthsNo2-digit months (e.g. ['01','02']), used with 'year' instead of 'time'.
datasetYesWhich commodity classification / geography dataset to query: 'hs' (Harmonized System, most detailed commodity codes, by country+district), 'naics' (industry classification, by country+district), 'enduse' (broad economic-use categories, by country+district), 'sitc' (Standard International Trade Classification, by country+district), 'usda' (agricultural vs. non-agricultural, by country+district), 'hitech' (Advanced Technology Products, by country+district), 'statehs' (HS codes by U.S. state instead of district, 2/4/6-digit only), 'statenaics' (NAICS by U.S. state instead of district, 2/3/4-digit only), 'porths' (HS codes by U.S. port instead of district, 2/4/6-digit only). Use list_trade_datasets for full descriptions.
filtersNoAdditional filter predicates as {VARIABLE_NAME: value}, e.g. {"CTY_CODE": "1220"} to filter to Canada, or {"CTY_CODE": ["1220","2010"]} for Canada OR Mexico. Commodity code filters accept a trailing '*' wildcard, e.g. {"E_COMMODITY": "01*"} for all HS codes starting with 01. Only use variable names valid for the chosen dataset/direction (check with get_dataset_variables). Do not mix commodity-classification parameters from different datasets in one call (e.g. do not filter by NAICS on the 'hs' dataset).
comm_levelNoCommodity aggregation level, used with E_COMMODITY/I_COMMODITY, NAICS, or E_ENDUSE/I_ENDUSE fields. One of: HS2, HS4, HS6, HS10 (Harmonized System digit levels), NA2-NA6 (NAICS digit levels), MAN (total manufactured commodities, naics only), EU1, EU5 (End-Use digit levels).
summary_levelNo'DET' restricts results to individual trading partners; 'CGP' restricts results to country groupings (regions, trade blocs) instead of individual countries. Omit to receive both mixed together.
response_formatNoOutput format: 'markdown' for a human-readable table, or 'json' for machine-readable structured data.markdown
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond annotations (readOnlyHint=true, idempotentHint=true), the description discloses important behaviors: the API times out on large requests, descriptive text fields require code fields or the API errors, results are NOT sorted by value, and zero rows may simply mean no trade. These are non-obvious traits not captured in annotations, adding significant transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but well-structured with paragraphs, bullet points, and examples. It front-loads the core purpose and uses sections for best practices and use cases. Some repetition exists with schema descriptions (e.g., limit behavior, descriptive field requirement), which could be trimmed, but overall each section earns its place for a complex 10-parameter tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description covers return format (markdown or JSON, rows containing requested fields plus time), common pitfalls, and dataset options comprehensively. For a complex tool with 10 parameters, the description covers query construction, filtering, aggregation levels, and error interpretation, making it complete enough for an agent to invoke correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so baseline is 3. The description adds extra semantic value by explaining that import value fields start with GEN_/CON_ rather than ALL_ (export-only), and by clarifying dataset-specific behavior (e.g., statehs/statenaics/porths digit restrictions). However, many parameter details are already in the schema, so the added value is supplementary rather than essential.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence states a specific verb+resource: 'Query monthly U.S. import statistics (January 2010-present) from the Census International Trade Data API.' It clearly differentiates from sibling tools by focusing on imports and explicitly noting 'Don't use when: You need export data - use census_trade_query_exports.' The scope is unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage guidance with 'Use when' examples and 'Don't use when' alternatives, naming sibling tools (census_trade_query_exports, census_trade_get_trade_balance, census_trade_get_top_partners). It also includes best practices for narrowing queries to avoid API timeouts, which is actionable when/then guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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