Skip to main content
Glama
jslagle9

census-trade-mcp-server

by jslagle9

Compute U.S. Trade Balance With Countries

census_trade_get_trade_balance
Read-onlyIdempotent

Compute the U.S. trade balance (exports minus imports) for one or more countries in a single call, with optional HS commodity filtering. Returns per-country exports, imports, and balance in USD.

Instructions

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.

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

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