Skip to main content
Glama
jslagle9

census-trade-mcp-server

by jslagle9

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

  1. 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).

  2. Install dependencies and build:

    npm install
    npm run build
  3. Set your API key:

    cp .env.example .env
    # edit .env and set CENSUS_API_KEY
  4. Add 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

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 to api.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 — use census_trade_lookup_country_code to 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 NAICS on the hs dataset).

  • 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*, then 2*, 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 *_YR variants) report "0" for both true zeros and missing/unavailable data — always request the matching *_FLAG field (e.g. QTY_1_MO_FLAG) alongside a quantity field; "M" means missing, blank means a true zero.

  • Requesting CTY_CODE without summary_level="DET" returns individual countries and regional/bloc groupings (e.g. 4XXX Europe, 0001 OPEC) mixed in the same response — summing across all rows double-counts. Set summary_level="DET" before aggregating across countries yourself.

Full reference: Census International Trade Data API User Guide (PDF).

Available Tools

7 tools
census_trade_get_dataset_variablesGet Valid Variables for a Trade DatasetA
Read-onlyIdempotent

List every valid Census API variable (field) name for a specific dataset + trade direction, straight from the Census API's own metadata.

Use this before calling census_trade_query_exports/imports when you're unsure which variable names are valid to put in the "get" or "filters" parameters - the Census API rejects unknown variable names with a 400 error, and valid variables differ by dataset (e.g. "SITC" is only valid on the sitc dataset, not hs).

Args:

  • direction ('exports' | 'imports'): which trade direction's variable list to fetch

  • dataset (string): dataset code, e.g. 'hs', 'naics', 'statehs' (see census_trade_list_datasets for the full list)

  • response_format ('markdown' | 'json'): output format (default 'markdown')

Returns: For each variable - its name, human-readable label, whether it's required, and its type (string/int/datetime).

Examples:

  • Use when: "What fields can I request from the imports NAICS endpoint?"

  • Use when: You got a "unknown variable" error from census_trade_query_exports and need to find the correct name

  • Don't use when: You just want dataset descriptions, not field-level detail - use census_trade_list_datasets instead

ParametersJSON Schema
NameRequiredDescriptionDefault
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.
directionYesTrade direction: 'exports' or 'imports'.
response_formatNoOutput format: 'markdown' for a human-readable table, or 'json' for machine-readable structured data.markdown

TDQS

A4.5/5.0
Behavior4/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, establishing a safe read operation. The description adds valuable context beyond this: it notes the Census API rejects unknown variable names with a 400 error, and that valid variables vary by dataset (e.g., SITC only on the sitc dataset). This failure-mode information helps the agent anticipate user needs and error conditions without contradicting any annotations.

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

Conciseness5/5

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

The description is well-organized into distinct sections: purpose, usage, args, returns, and examples. Every sentence serves a purpose, the opening is front-loaded with the core verb and resource, and the examples provide concrete use cases. Despite being longer than average, it avoids redundancy and is scannable.

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?

Given that there is no output schema, the description appropriately details the return structure ('For each variable - its name, human-readable label, whether it's required, and its type'). It also covers the full lifecycle: when to use, how to invoke, what to expect, and when not to use. The tool is fully self-contained and contextually complete for an agent navigating a complex API.

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

Parameters3/5

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

Schema description coverage is 100%, with each parameter (direction, dataset, response_format) having a full description and enum values. The description's Args section somewhat duplicates this information, but it adds a small amount of context, such as the note to 'see census_trade_list_datasets for the full list' and the default value for response_format. Since the schema already carries the heavy load, the description adds marginal value, keeping this at the baseline 3.

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 description opens with a specific verb+resource: 'List every valid Census API variable (field) name for a specific dataset + trade direction.' This clearly distinguishes it from sibling tools like census_trade_query_exports/imports and census_trade_list_datasets. The explicit mention of listing fields rather than querying data or listing datasets removes any ambiguity.

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 explicitly instructs when to use the tool ('Use this before calling census_trade_query_exports/imports when you're unsure which variable names are valid'), and provides a clear 'Don't use when' case with a named alternative (use census_trade_list_datasets instead). This exceeds typical guidance by giving both positive and negative usage scenarios.

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

census_trade_get_top_partnersRank Top Trading PartnersA
Read-onlyIdempotent

Return the top N countries ranked by U.S. export or import value for a given period and (optionally) a specific commodity - the Census API itself does not sort results, so this tool fetches the full country breakdown and sorts it for you.

Args:

  • direction ('exports' | 'imports'): rank by export destinations or import sources

  • dataset (string, default 'hs'): which classification dataset to pull from (see census_trade_list_datasets)

  • time (string, optional) or year+months (optional): time period

  • value_field (string, optional): value field to rank by, e.g. 'ALL_VAL_YR' for year-to-date exports. Defaults to ALL_VAL_MO (exports) or GEN_VAL_MO (imports).

  • filters (object, optional): extra filters, e.g. {"E_COMMODITY":"2709*"} to rank partners for crude oil exports only

  • top_n (number, default 10, max 50): how many partners to return

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

Returns: Ranked list with country, value in USD, and percentage share of total trade across all countries in the response, plus the grand total and count of countries with any trade.

Examples:

  • Use when: "Who are our top 5 export markets in 2024?" -> direction="exports", top_n=5, year="2024", months=[...]

  • Use when: "Which countries do we import the most crude oil from?" -> direction="imports", filters={"I_COMMODITY":"2709*"}, time="2024-06"

  • Don't use when: You want a two-way trade balance calculation - use census_trade_get_trade_balance instead.

ParametersJSON Schema
NameRequiredDescriptionDefault
timeNoTime period as 'YYYY-MM' or a range 'from YYYY-MM to YYYY-MM'. Either 'time' or both 'year'+'months' is required.
yearNo4-digit year, used with 'months' instead of 'time'.
top_nNoHow many top trading partners to return.
monthsNo2-digit months, used with 'year' instead of 'time'.
datasetNoWhich 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.hs
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).
directionYes'exports' to rank countries by U.S. export value, 'imports' to rank by import value.
value_fieldNoWhich value field to rank by, e.g. 'ALL_VAL_MO' (exports) or 'GEN_VAL_MO' (imports). Defaults to ALL_VAL_MO for exports and GEN_VAL_MO for imports if omitted. Use a *_YR variant for year-to-date figures.
response_formatNoOutput format: 'markdown' for a human-readable table, or 'json' for machine-readable structured data.markdown

TDQS

A4.2/5.0
Behavior4/5

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

Annotations already declare read-only, idempotent, non-destructive behavior. The description adds context by explaining that the tool fetches the full country breakdown and sorts it because the API doesn't sort, and details the return shape (country, value, percentage share, grand total). This is useful behavioral context beyond what annotations provide and does not contradict them.

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

Conciseness3/5

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

The description is front-loaded with a clear one-sentence purpose, and the Examples/Don't use sections are effective. However, the Args section duplicates the schema's detailed parameter descriptions, making the description longer than necessary without adding proportional value.

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

Completeness4/5

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

Despite lacking an output schema, the description details what is returned: ranked list with country, USD value, percentage share, grand total, and count. It also addresses the sorting workaround and provides multiple examples covering optional filters and time formats. For a read-only tool with rich schema annotations, this is sufficiently complete.

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

Parameters3/5

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

Schema coverage is 100% with detailed descriptions for all 9 parameters, so the baseline is 3. The description's Args section largely repeats schema information but adds concrete examples like filters={"E_COMMODITY":"2709*"} and default value_field selection. This adds minor value but doesn't significantly compensate beyond the schema's existing detail.

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 description clearly states the tool returns the top N countries ranked by U.S. export or import value for a given period and optionally a commodity. It distinguishes itself from sibling tools by explaining that the Census API doesn't sort results, so the tool fetches the full breakdown and sorts. The 'Don't use when' example further separates it from census_trade_get_trade_balance.

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?

Provides explicit 'Use when' examples for ranking export markets and importing crude oil, and an explicit 'Don't use when' for trade balance calculations, naming the alternative census_trade_get_trade_balance. It also points to census_trade_list_datasets for dataset selection, giving clear context on when to use this tool.

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

census_trade_get_trade_balanceCompute U.S. Trade Balance With CountriesA
Read-onlyIdempotent

Compute the U.S. trade balance (exports minus imports) with one or more countries or country groupings, for a given time period, in one call.

This is a workflow tool that combines an exports/hs query and an imports/hs query (which census_trade_query_exports/imports would otherwise require two separate calls to do), sums values across the requested period, and computes the balance per country plus a combined total.

Args:

  • countries (string[]): one or more CTY_CODE values, e.g. ["1220","2010"] for Canada and Mexico (use census_trade_lookup_country_code to find codes)

  • time (string, optional) or year+months (optional): time period, e.g. time="2024" is invalid - use time="from 2024-01 to 2024-12" or year="2024", months=["01",...,"12"]

  • hs_code (string, optional): restrict to a specific HS commodity code/prefix instead of total trade, e.g. "87" for vehicles

  • import_basis ('general' | 'consumption', default 'general'): which import total to use

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

Returns: Per-country exports, imports, and balance in USD, plus a combined total row. Positive balance = U.S. trade surplus with that country; negative = deficit.

Examples:

  • Use when: "What's the U.S. trade balance with China in 2024?" -> countries=["5700"], year="2024", months=["01",...,"12"]

  • Use when: "Compare our vehicle trade balance with Japan, Germany, and South Korea last year" -> countries=["5880","4280","5800"], hs_code="87", year="2023", months=[...]

  • Don't use when: You just need one direction's raw data - use census_trade_query_exports or census_trade_query_imports.

ParametersJSON Schema
NameRequiredDescriptionDefault
timeNoTime period as 'YYYY-MM' or a range 'from YYYY-MM to YYYY-MM'. Either 'time' or both 'year'+'months' is required.
yearNo4-digit year, used with 'months' instead of 'time'.
monthsNo2-digit months, used with 'year' instead of 'time'.
hs_codeNoOptional HS commodity code (or prefix, e.g. '87' for vehicles) to restrict the balance to a specific product instead of total trade. Applied as E_COMMODITY on the export side and I_COMMODITY on the import side.
countriesYesOne or more Census CTY_CODE values to compute a trade balance for (use census_trade_lookup_country_code to find codes), e.g. ['1220','2010'] for Canada and Mexico. A grouping code (e.g. '0003' for European Union) also works.
import_basisNoWhich import total to use: 'general' imports (GEN_VAL_MO, the standard headline figure) or 'consumption' imports (CON_VAL_MO).general
response_formatNoOutput format: 'markdown' for a human-readable table, or 'json' for machine-readable structured data.markdown

TDQS

A4.9/5.0
Behavior5/5

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

Discloses that it sums values across periods, computes per-country plus combined totals, and explains the sign convention for surplus/deficit. Also warns about invalid time format ('2024' must be expressed as 'from 2024-01 to 2024-12'), which is beyond the annotations' read-only/idempotent hints.

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

Conciseness5/5

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

Well-structured with a clear lead sentence, args list, returns section, and examples. Despite length, every section adds necessary context—no filler. Front-loaded purpose and usage guidance.

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?

For a 7-parameter tool with no output schema, the description includes expected return structure, parameter formats, examples for common use cases, and explicit exclusions. Covers the complexity well.

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 covers all parameters with descriptions (100% coverage), so baseline is 3. The description adds value by giving concrete examples (e.g., country codes for Canada/Mexico, hs_code='87') and clarifying the correct time format with an invalid example. However, some parameter descriptions repeat schema text, so not a full 5.

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?

First sentence states the exact operation: compute U.S. trade balance (exports minus imports) for specified countries and time period. Explicitly differentiates from sibling tools by noting it combines two queries, making it distinct from census_trade_query_exports/imports.

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?

Provides explicit use cases with 'Use when' examples and a 'Don't use when' that directs to sibling tools (census_trade_query_exports/imports). This gives clear guidance on when to select this workflow tool over alternatives.

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

census_trade_list_datasetsList Census International Trade DatasetsA
Read-onlyIdempotent

List the 9 commodity classification / geography datasets available in the Census International Trade Data API, for both exports and imports.

Use this first when you're not sure which dataset to query. Each dataset covers the same underlying monthly trade data (2010-present) but organizes it by a different commodity classification (HS, NAICS, End-Use, SITC, USDA, Advanced Technology) or geography (state, port instead of customs district).

Args: none.

Returns: For each dataset - its short code (used as the "dataset" parameter in census_trade_query_exports/imports), full name, description, level of detail available for exports vs. imports, and which commodity-code parameters it accepts.

Examples:

  • Use when: "What trade datasets are available?" or "Which dataset has state-level export data?"

  • Don't use when: You already know the dataset code you need - go straight to census_trade_query_exports/imports.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4.7/5.0
Behavior4/5

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

Annotations declare readOnly, idempotent, and non-destructive behavior, so the description's burden is lower. It adds valuable context that each dataset covers the same underlying monthly trade data (2010-present) and outlines the return structure (short code, full name, description, level of detail, accepted parameters). This goes beyond the annotations, though it doesn't discuss any side effects or potential pitfalls (none likely for a list operation).

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

Conciseness5/5

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

The description is front-loaded with the purpose, then flows into usage guidance, return format, and examples. Every sentence earns its place; the use/don't-use examples are particularly informative and not redundant. It's appropriately sized for a tool that needs to guide dataset selection.

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?

For a zero-parameter tool with no output schema, the description fully covers what the agent needs to know: what the list contains, the structure of each entry, and how to use the results with sibling tools (e.g., the short code is used as the 'dataset' parameter in census_trade_query_exports/imports). It also gives helpful context about the commodity classifications and geography options.

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?

The tool has zero parameters, and the schema coverage is 100% (no properties). The description explicitly notes 'Args: none,' which is sufficient. Per the calibration, 0 params baseline is 4; there is nothing more to add.

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 description opens with a specific verb ('List'), a concrete resource ('the 9 commodity classification / geography datasets available in the Census International Trade Data API'), and scope ('for both exports and imports'). This clearly distinguishes it from siblings that query specific data, retrieve variables, or compute balances.

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?

Provides explicit when-to-use guidance ('Use this first when you're not sure which dataset to query'), concrete example use cases ('What trade datasets are available?'), and an explicit exclusion ('Don't use when: You already know the dataset code you need - go straight to census_trade_query_exports/imports'). This is exemplary usage guidance.

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

census_trade_lookup_country_codeLook Up Census Trade CTY_CODEA
Read-onlyIdempotent

Look up the Census Bureau Schedule C CTY_CODE (and country groupings like OPEC, NAFTA, European Union, or world regions) needed to filter census_trade_query_exports/imports by country.

The Census API filters trade data by a numeric CTY_CODE, not by country name (CTY_NAME can only be requested as a descriptive field alongside CTY_CODE, not used as a filter by itself). Use this tool to translate a country name into the code you need.

Args:

  • query (string): country/region/bloc name or partial name, e.g. "korea", "vietnam", "european union"

  • limit (number, default 10): max matches to return

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

Returns: Matching entries with their CTY_CODE, name, and ISO alpha-2 code (for individual countries) or just code+name (for groupings). Note South Korea is listed as "South Korea (Republic of Korea)" and North Korea as "North Korea (Democratic People's Republic of Korea)".

Examples:

  • Use when: "What's the country code for Vietnam?" -> query="vietnam" -> returns CTY_CODE 5520

  • Use when: "I want export data for all EU countries as a group" -> query="european union" -> returns CTY_CODE 0003, then pass that as CTY_CODE in census_trade_query_exports filters

  • Don't use when: You already have the CTY_CODE - go straight to census_trade_query_exports/imports.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of matches to return.
queryYesCountry, region, or trade-bloc name (or partial name) to search for, e.g. 'korea', 'european union', 'canada'. Case-insensitive substring match.
response_formatNoOutput format: 'markdown' for a human-readable table, or 'json' for machine-readable structured data.markdown

TDQS

A4.4/5.0
Behavior4/5

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

Annotations already establish read-only, idempotent, non-destructive behavior, and the description adds context beyond that: the API filters by numeric CTY_CODE rather than country name, CTY_NAME cannot be used as a filter, and return values include code, name, and ISO alpha-2 details. It also flags special naming for North/South Korea. This is valuable behavioral transparency, though it doesn't mention rate limits or match-failure behavior.

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 well-structured with intro, Args, Returns, and Examples sections, and it front-loads the core purpose and sibling relationship. It is somewhat longer than strictly necessary because the Args section repeats schema properties, but every other part contributes useful context such as API filtering behavior and usage examples.

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?

For a simple lookup tool with no output schema, the description is complete: it explains what the tool returns, the special case of country groupings, naming caveats, and how to chain the result into sibling tools. It covers when to use, when not to use, and gives concrete examples, so an agent can select and invoke it correctly without additional information.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already fully documents all three parameters with defaults, enums, and constraints. The description's Args section largely restates this information, though the examples ('korea', 'vietnam', 'european union') and the note about partial name matching add modest practical meaning beyond the schema.

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 description clearly states the tool 'looks up' Census Bureau Schedule C CTY_CODE, including country groupings, and explicitly links this to filtering census_trade_query_exports/imports by country. This specific verb+resource framing and the mention of sibling tools distinguishes it from the query/list/dataset siblings.

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 use guidance: 'Use this tool to translate a country name into the code you need', plus concrete 'Use when' examples for Vietnam and European Union. It also gives an exclusion: 'Don't use when: You already have the CTY_CODE - go straight to census_trade_query_exports/imports', naming the alternative tool.

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

census_trade_query_exportsQuery U.S. Export Trade DataA
Read-onlyIdempotent

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

This is the general-purpose tool for pulling export 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.

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","ALL_VAL_MO"]

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

  • year (string, optional) + months (string[], optional): alternative to 'time', e.g. year="2024", months=["01","02","03"]

  • filters (object, optional): e.g. {"CTY_CODE":"1220"} for Canada, {"E_COMMODITY":"0805*"} for HS codes starting with 0805 (citrus fruit)

  • 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. export to Germany in HS code 8703 (cars) in 2024?" -> dataset="hs", get=["E_COMMODITY","E_COMMODITY_LDESC","ALL_VAL_MO"], time="2024-01", filters={"CTY_CODE":"4280","E_COMMODITY":"8703*"}

  • Use when: "Show monthly export value trend for all countries, Jan-Jun 2023" -> get=["ALL_VAL_MO"], time="from 2023-01 to 2023-06"

  • Don't use when: You need import data - use census_trade_query_imports.

  • 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.

ParametersJSON 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

TDQS

A4.8/5.0
Behavior5/5

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

Annotations already declare readOnlyHint=true, openWorldHint=true, idempotentHint=true, destructiveHint=false. The description adds significant behavioral context beyond these: API timeouts on large requests, descriptive text fields requiring code fields or the API errors, zero-row responses not being errors, and results not sorted by value. No contradiction with annotations.

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 clear headings (overview, Args, Best practices, Examples) and front-loaded purpose. Every section contributes value: usage guidance, behavioral constraints, and practical examples. It is longer than ideal but appropriate for a complex tool with 10 parameters and no output schema, and it avoids redundancy with the schema by providing contextual guidance rather than repeating enum values.

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?

For a tool with 10 parameters and no output schema, the description is exceptionally complete. It explains the return format (markdown/json), what rows contain, time range coverage, filter semantics, aggregation levels, error conditions, and provides multiple concrete examples. It also addresses edge cases (zero rows, large queries) and references sibling tools for complementary functionality. No significant gaps found.

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 the schema alone documents all parameters. The description adds meaning by explaining parameter relationships (e.g., time vs year+months alternatives), showing example values for filters with wildcard behavior, clarifying limit truncation client-side, and providing dataset-specific context (e.g., statehs vs porths). This goes beyond what the schema states, though much of the schema is already detailed, so the incremental value is solid but not exhaustive.

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 description clearly states 'Query monthly U.S. export statistics (January 2010-present) from the Census International Trade Data API' and identifies it as the 'general-purpose tool' for export data. It distinguishes itself from siblings by explicitly listing what it is for (by commodity, geography, measures) and contrasting with import/trade balance/top partner tools, giving a specific verb-resource-scope combination.

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 'Use when' and 'Don't use when' examples that name alternative tools (census_trade_query_imports, census_trade_get_trade_balance, census_trade_get_top_partners). It also includes best practices from the Census API User Guide, such as preferring narrow queries and using get_dataset_variables to check valid parameters, which effectively guides selection between this and sibling tools.

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

census_trade_query_importsQuery U.S. Import Trade DataA
Read-onlyIdempotent

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.

ParametersJSON 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

TDQS

A4.8/5.0
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.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 7 tool updatesv1.0.0
    • First observedcensus_trade_get_dataset_variables
    • First observedcensus_trade_get_top_partners
    • First observedcensus_trade_get_trade_balance
    • First observedcensus_trade_list_datasets
    • First observedcensus_trade_lookup_country_code
    • First observedcensus_trade_query_exports
    • First observedcensus_trade_query_imports

TDQS

A4.6/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose: querying exports vs. imports, listing datasets, inspecting variables, computing trade balance, ranking partners, and looking up country codes. There is no functional overlap that would cause an agent to select the wrong tool.

Naming Consistency5/5

All tool names follow the consistent verb_noun pattern with the census_trade_ prefix (query_exports, query_imports, list_datasets, get_dataset_variables, get_trade_balance, get_top_partners, lookup_country_code). This makes the API surface predictable and easy to navigate.

Tool Count5/5

Seven tools is a well-scoped size for this domain. Each tool serves a distinct and necessary function for working with Census trade data, without being bloated or too minimal.

Completeness5/5

The set covers the full workflow: dataset discovery, variable inspection, raw data queries for exports/imports, derived analytics (trade balance, top partners), and supporting lookups (country codes). There are no obvious dead ends or missing operations for the stated purpose of accessing U.S. Census trade statistics.

Maintenance

ActivityMaintained
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    D
    quality
    C
    maintenance
    Servidor MCP para a API do ComexStat, ferramenta de acesso às estatísticas de comércio exterior do Brasil.
    20
    9
    2
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Provides access to UN Comtrade international bilateral trade data via an MCP server, enabling AI agents to query trade statistics through natural language.
    16
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    MCP 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.
    404
    2
    Apache 2.0

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