Skip to main content
Glama
jslagle9

census-trade-mcp-server

by jslagle9

Rank Top Trading Partners

census_trade_get_top_partners
Read-onlyIdempotent

Rank top U.S. trading partners by export or import value for a period or commodity. Returns each country's share and grand total.

Instructions

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.

Input Schema

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

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