Skip to main content
Glama

mcp-brazil-erp

An MCP server that gives an AI assistant the small Brazilian "plumbing" checks that ERP work runs into every day: is this CNPJ/CPF valid, what does this boleto say, which company issued this NF-e, where is this CEP. It is written in TypeScript on the official @modelcontextprotocol/sdk and uses the stdio transport.

Four of the six tools run fully offline and are pure functions. The other two make read-only calls to the public BrasilAPI.

Tools

Tool

Input

Output

Network

validate_cnpj

cnpj

valid, normalized, formatted, reason. Also accepts the new alphanumeric CNPJ (IN RFB 2.229/2024)

no

validate_cpf

cpf

valid, normalized, formatted, reason

no

lookup_cnpj

cnpj

legal name, trade name, status, opening date, main activity (CNAE), size, address. The CNPJ is validated locally first

BrasilAPI /cnpj/v1

parse_boleto

line, optional reference_date

47 digits (bank): bank code, currency, due date, amount, per-field and general check digits. 48 digits starting with 8 (utilities/taxes): segment, effective/reference value, block check digits

no

parse_nfe_key

key (44 positions)

UF, year-month, issuer CNPJ, model (NF-e/NFC-e/CT-e/MDF-e), series, number, emission type, random code, check digit

no

lookup_cep

cep

street, district, city, UF

BrasilAPI /cep/v2

Boleto due dates after the 2025 reset. The due-date factor counts days from 1997-10-07. It reached 9999 on 2025-02-21 and restarted at 1000 on 2025-02-22, so every factor now maps to two dates about 27 years apart. parse_boleto takes the candidate closest to reference_date (default: today). The tests cover both cycles.

Related MCP server: mcp-fiscal-brasil

Install

npm install
npm run build
npm test

Claude Code:

claude mcp add brazil-erp -- node /absolute/path/to/mcp-brazil-erp/dist/src/index.js

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "brazil-erp": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-brazil-erp/dist/src/index.js"]
    }
  }
}

Safety notes

  • Read-only. No tool writes anything. All of them are annotated readOnlyHint: true and destructiveHint: false, and only the two lookups are openWorldHint: true.

  • No credentials. BrasilAPI is public, so there are no keys or tokens to configure or leak.

  • Validated input. Every tool's input is described with zod schemas and length limits. lookup_cnpj rejects an invalid CNPJ before any network call.

  • Bounded network calls. Lookups have a timeout (15 s by default). Failures come back as tool errors with a kind (not_found, invalid_input, rate_limited, timeout, upstream, network) and BrasilAPI's own message, so the model can explain the failure instead of retrying blindly.

  • Mind the data. lookup_cnpj returns public company-registry data. Validating a CPF only checks the arithmetic of the number. It does not look up a person.

  • stdout carries the MCP protocol, so the server logs to stderr only.

Tests

The tests cover check-digit validation (with valid and invalid examples), CNPJ/CPF, NF-e keys, both boleto layouts, both due-date cycles, typo detection, and the MCP server end to end through the SDK's in-memory transport. Network tools are tested against a fake fetch, so the test suite never touches the network.

The test values are either textbook test numbers (CNPJ 11.222.333/0001-81, CPF 111.444.777-35, and Receita's alphanumeric example 12.ABC.345/01DE-35) or synthetic numbers whose check digits are computed in the test. No real person's CPF is used.

Trade-offs

  • Two date candidates instead of one rule. Picking the due date closest to a reference date handles the 2025 factor reset without a hard cutover. It is wrong only for a boleto due more than about 13 years from the reference date, which is not a realistic case.

  • No due date for arrecadação. Utility and tax slips have no standard due-date field (when one exists, it is inside the free field and its layout varies by agreement), so the tool returns null rather than guessing.

  • The alphanumeric CNPJ in NF-e keys is accepted using the same ASCII-48 rule as the CNPJ check digits. Confirm this against the latest technical note before relying on it for a SEFAZ submission.

  • Single upstream provider. BrasilAPI's CEP endpoint aggregates other providers and is sometimes unavailable. A production version would add a fallback provider and a cache.

  • Compact output. lookup_cnpj returns a stable subset of the BrasilAPI payload instead of the full JSON. That keeps the model's context small, but some fields are dropped.

AI-assisted development

This server was written with Claude Code (Anthropic) as a coding assistant. I chose the tools and the safety constraints from what my ERP work needs, and I reviewed and verified the output with the test suite and manual runs.

License

MIT, see LICENSE.

Available Tools

6 tools
lookup_cepLook up CEPB
Read-onlyIdempotent

Address for a Brazilian postal code (CEP) via BrasilAPI.

Inputs: cep (required).

lookup_cnpjLook up CNPJB
Read-onlyIdempotent

Public registry data of a company (legal name, status, main activity, address) via BrasilAPI.

Inputs: cnpj (required).

parse_boletoParse boletoA
Read-onlyIdempotent

Decode a boleto linha digitável: 47 digits (bank) or 48 digits starting with 8 (utilities/taxes). Returns bank, amount, due date (handles the 2025 due-factor reset) and check-digit results.

Inputs: line (required), reference_date.

parse_nfe_keyParse NF-e access keyA
Read-onlyIdempotent

Decode a 44-position NF-e/NFC-e access key: UF, year/month, issuer CNPJ, model, series, number, emission type, check digit.

Inputs: key (required).

validate_cnpjValidate CNPJA
Read-onlyIdempotent

Check a CNPJ's check digits and format it (accepts masked, digits-only and the new alphanumeric format). Offline.

Inputs: cnpj (required).

validate_cpfValidate CPFA
Read-onlyIdempotent

Check a CPF's check digits and format it. Offline; does not query any registry.

Inputs: cpf (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool targets a distinct artifact and action: validate_* performs offline check-digit verification, lookup_* queries a remote registry, and parse_* decodes a fixed-length Brazilian payment/fiscal string. The validate_cnpj vs. lookup_cnpj pair is explicitly separated by the 'Offline'/'via BrasilAPI' language, and parse_boleto vs. parse_nfe_key differ by input format (47/48 vs. 44 digits).

    Naming Consistency5/5

    All six tools follow a strict verb_noun snake_case pattern with a small, reused verb vocabulary (validate_, lookup_, parse_). No casing or style deviations.

    Tool Count5/5

    Six tools is well within the ideal range and each one maps to a concrete Brazilian ERP validation/lookup/parsing need. Nothing looks redundant or filler.

    Completeness4/5

    CNPJ has both validation and registry lookup, CPF is validated, boletos and NF-e keys are decoded, and CEP resolves to an address — covering the common ERP intake paths. Gaps include no offline CEP format validation, no inscrição estadual (state registration) handling, and no boleto/NF-e emission or encoding counterparts, though agents can work around these.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Validates LatAm banking and tax IDs (Mexican CLABE, Brazilian CNPJ/CPF checksums) and performs BrasilAPI company, CEP, and bank lookups, enabling AI agents to verify financial and tax information in Latin America.
      94 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants and business systems to query and validate Brazilian fiscal data and documents, including CNPJ/CPF, Simples Nacional/MEI, NF-e/NFS-e, SPED, eSocial, and supplier compliance, without mandatory API keys. It also supports offline reference tables, tax-regime comparison, due-diligence scoring, and 2026 IBS/CBS reform analysis through composable tools.
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI assistants to query Brazilian public data through BrasilAPI, including company registry details and partners by CNPJ, addresses by CEP, and national holidays. It also performs offline CNPJ/CPF validation before any network request and does not store queried numbers.
      5
      69 npm
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to query Brazilian public data such as CEP, CNPJ, banks, holidays, business days, FIPE vehicle prices, DDD, IBGE municipalities, .br domains, and ISBN, with read-only tools and offline document validation.
      14
      61 npm
      MIT