Skip to main content
Glama
PHIAI-IO
by PHIAI-IO

mcp-comex-brasil

MCP server for Brazilian foreign-trade data — with the dataset's traps corrected in the response.

Four tools that don't lie, instead of forty that don't know.


The problem this server solves

An MCP server that merely exposes a dataset hands the agent a clean API to a wrong number. The plumbing doesn't know the field lies.

Comex Stat — the official Brazilian foreign-trade database, published by the Foreign Trade Secretariat / Federal Revenue Service — has a defect that no documentation warns about:

Filtering the transport-mode field by AÉREA returns 139.6 million kg of Chinese imports in 2026 (Jan–Jul). Cross-referencing these same records with the clearance point, only 34.0 million (24%) passed through an airport. The other 89.7 million cleared at seaports and are ammonium sulfate and phosphatic fertilizers — cargo that does not fly, at US$0.29/kg freight.

Uncorrected: air weight overstated 4.1× and freight per kg understated by 70%. The error is silent — nothing in the query flags it.

This server applies the correction, and returns the evidence for why it is needed.

Related MCP server: mcp-comtrade

The two guarantees

  1. Every response carries the known defects that apply to that query, with measured evidence and verification provenance.

  2. The critical correction is applied to the result, not merely warned about. The air channel already means "air mode cleared at an airport". The contaminated block remains queryable as air_declared_at_port, deliberately — for anyone who wants to inspect it.

What the dataset has that published summaries discard

The import files carry VL_FRETE and VL_SEGURO — freight and insurance as declared to customs. It is the best systematic measure of realized cost available publicly, and almost nobody uses it.

China → Brazil, Jan–Jul 2026, already corrected:

Channel

Weight (kg)

Freight US$/kg

Freight % of FOB

Value density

Air (airport)

33,993,130

10.81

9.37%

US$115.36/kg

Sea

16,074,641,185

0.142

5.68%

US$2.51/kg

Air costs 76× more per kilogram and only 1.65× more per dollar of goods. This corridor's modal split is not a freight decision — it is a value-density decision.

Install

Requires Node ≥ 22.5 (uses the built-in SQLite — zero native dependencies, no node-gyp).

git clone <repo> && cd mcp-comex-brasil
npm install && npm run build
npm run db:build -- --years 2025,2026        # baixa da fonte oficial e monta o SQLite

db:build fetches the files straight from balanca.economia.gov.br. No data is redistributed by this package — the database is built on your machine, always fresh from the source.

Useful options:

npm run db:build -- --years 2026 --countries 160        # só China, base pequena e rápida
npm run db:build -- --years 2024,2025,2026 --flows import,export

Configuring the MCP client

{
  "mcpServers": {
    "comex": {
      "command": "node",
      "args": ["--experimental-sqlite", "/caminho/para/mcp-comex-brasil/dist/index.js"],
      "env": { "COMEX_LANG": "pt" }
    }
  }
}

COMEX_LANG accepts pt (default) or en. COMEX_DB overrides the database path.

The four tools

Tool

What it does

comex_trade_flow

Value, weight and value density by year, month, country, HS code and channel. The air channel is already corrected.

comex_freight_cost

Declared freight and insurance per channel: US$/kg and % of FOB. Imports only.

comex_data_caveats

The dataset's known defects, with evidence, correction rule and pre-publication checklist.

comex_resolve_code

Resolves country, HS code, transport mode and clearance unit (with airport/seaport/other classification).

The caveats that accompany the responses

id

Severity

Corrected?

via_contamination

critical

✅ automatic (cross-reference with the clearance point)

simplified_regime_absent

critical

❌ impossible — the data does not exist in the source

declared_not_audited

info

monthly_volatility

warning

❌ requires year-over-year comparison

About simplified_regime_absent: there are transport-mode codes for POSTAL and COURIER, but they are empty (13 records and 72 kg for China in all of 2026, versus ~180 million international parcels reported). Low-value shipments go through the simplified regime and do not enter trade statistics. Formal statistics and parcel volume are disjoint universes — do not add, do not compare arithmetically.

Verification

The aggregates were validated by cross-implementation: the same slice processed by a single awk pass over the raw CSV and by this server's SQL view produces identical figures to the last digit (349,250 records, 7 channels, freight and weight values).

npm test     # 12 testes da lógica de classificação e do registro de caveats

License and source

MIT. Data: Comex Stat, Foreign Trade Secretariat / Federal Revenue Service of Brazil (balanca.economia.gov.br) — public source, consulted at database build time.

Author: Luis Delfin



English

MCP server for Brazilian foreign-trade data — with the dataset's traps corrected in the response.

Four tools that don't lie, instead of forty that don't know.

The problem

An MCP server that merely exposes a dataset hands the agent a clean API to a wrong number. The plumbing doesn't know the field lies.

Brazil's official trade dataset (Comex Stat, published by the Foreign Trade Secretariat / Federal Revenue Service) has a defect no documentation warns about:

Filtering the transport-mode field by AIR returns 139.6 million kg of Chinese imports for Jan–Jul 2026. Cross-referencing those same records against their clearance point, only 34.0 million (24%) passed through an airport. The other 89.7 million cleared at seaports and consist of ammonium sulphate and phosphatic fertilisers — cargo that does not fly, at US$0.29/kg freight.

Uncorrected: air weight overstated 4.1× and freight per kg understated by 70%. The error is silent — nothing in the query flags it.

This server applies the correction, and returns the evidence for why it is needed.

Two guarantees

  1. Every response carries the known defects that apply to that query, with measured evidence and verification provenance.

  2. The critical correction is applied, not merely warned about. The air channel already means "air mode cleared at an airport". The contaminated block stays queryable as air_declared_at_port, deliberately — for anyone who wants to inspect it.

What the dataset has that published summaries discard

The import files carry VL_FRETE and VL_SEGURO — freight and insurance as declared to customs. It is the best systematic measure of realised cost available publicly, and almost nobody uses it.

China → Brazil, Jan–Jul 2026, corrected:

Channel

Weight (kg)

Freight US$/kg

Freight % of FOB

Value density

Air (airport-cleared)

33,993,130

10.81

9.37%

US$115.36/kg

Sea

16,074,641,185

0.142

5.68%

US$2.51/kg

Air costs 76× more per kilogram and only 1.65× more per dollar of goods. This corridor's modal split is not a freight decision — it is a value-density decision.

Install

Requires Node ≥ 22.5 (uses built-in SQLite — zero native dependencies, no node-gyp).

npm install && npm run build
npm run db:build -- --years 2025,2026        # fetches from the official source, builds SQLite

db:build pulls the files straight from balanca.economia.gov.br. No data is redistributed by this package — the database is built on your machine, always fresh from the source.

The four tools

Tool

What it does

comex_trade_flow

Value, weight and value density by year, month, country, HS code and channel. air is pre-corrected.

comex_freight_cost

Declared freight and insurance per channel: US$/kg and % of FOB. Imports only.

comex_data_caveats

The dataset's known defects, with evidence, correction rule and a pre-publication checklist.

comex_resolve_code

Resolves country, HS code, transport mode and clearance unit (with airport/seaport classification).

Verification

Aggregates were validated by cross-implementation: the same slice processed by a single awk pass over the raw CSV and by this server's SQL view produces identical figures to the last digit (349,250 records, 7 channels, freight and weight values).

npm test     # 12 tests covering the classification logic and the caveat registry

MIT. Data: Comex Stat, Brazilian Foreign Trade Secretariat / Federal Revenue Service. Author: Luis Delfin

F
license - not found
A
quality
B
maintenance

Maintenance

UpdatingMaintainers
UpdatingResponse time
Release cycle
1Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

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

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
    C
    maintenance
    Enables access to USDA Foreign Agricultural Service trade and global production data through MCP, supporting natural language queries and tool-based data retrieval.
    19
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Access UN Comtrade international merchandise and services trade statistics via MCP tools for country lookups, HS commodity search, bilateral trade flows, balances, rankings, and data availability.
    107
    3
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • Comtrade MCP — UN Comtrade API for international bilateral trade data

  • Census Trade MCP — US Census Bureau International Trade data

  • Brazilian legal stack in one MCP: lawsuits, court publications, case law, tenders, certificates.

View all MCP Connectors

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/PHIAI-IO/mcp-comex-brasil'

If you have feedback or need assistance with the MCP directory API, please join our Discord server