Skip to main content
Glama
README.md
# mcp-dados-br

[![CI](https://github.com/DanielCamucatto/mcp-dados-br/actions/workflows/ci.yml/badge.svg)](https://github.com/DanielCamucatto/mcp-dados-br/actions/workflows/ci.yml)
![MCP](https://img.shields.io/badge/MCP-server-blue)
![License: MIT](https://img.shields.io/badge/license-MIT-green)

An **MCP (Model Context Protocol) server** that gives Claude and other AI assistants access to **Brazilian public data**: official exchange rates, interest rates, inflation, unemployment, postal codes, company registry and holidays.

No API keys. Data comes straight from **Banco Central do Brasil** and **BrasilAPI**.

> *"How much is US$ 5,000 in reais today?"* → `converter_moeda` → **R$ 27,843.00** (PTAX 5.5686, Dec 1 2026)

## Tools

| Tool | What it does | Source |
|---|---|---|
| `cotacao_ptax` | Official PTAX rate for any currency and date; on weekends/holidays it returns the previous business day | BCB PTAX |
| `converter_moeda` | Converts between BRL and foreign currencies (or two foreign ones) with the PTAX selling rate | BCB PTAX |
| `serie_bcb` | Selic target, effective Selic, CDI, IPCA (monthly and 12-month), IGP-M, unemployment, or **any** SGS series by code | BCB SGS |
| `consultar_cep` | Address and coordinates for a postal code | BrasilAPI |
| `consultar_cnpj` | Company registry data: legal name, status, CNAE, size, location | Receita Federal via BrasilAPI |
| `feriados_nacionais` | National holidays for a year, including movable ones | BrasilAPI |

Also exposes:
- **Resource** `dados-br://indicadores`: the indicator catalog (SGS code, unit, frequency)
- **Prompt** `panorama_economico`: a short briefing on Selic, inflation, unemployment and the dollar

## Install

### Claude Code

```sh
claude mcp add dados-br -- npx -y github:DanielCamucatto/mcp-dados-br
```

### Claude Desktop / other MCP clients

```json
{
  "mcpServers": {
    "dados-br": {
      "command": "npx",
      "args": ["-y", "github:DanielCamucatto/mcp-dados-br"]
    }
  }
}
```

Requires Node.js 20+.

## Example prompts

- "Qual foi a PTAX do euro no último dia útil de 2025?"
- "Como a Selic e o IPCA 12 meses evoluíram nos últimos 6 meses?"
- "Quais feriados de 2027 caem em dia de semana?"
- "Consulta o CNPJ 00.000.000/0001-91 e me diz a atividade principal."

## Design notes

- **Errors are returned as data** (`isError: true`) with a readable message, so the model can recover (e.g. ask for a valid CEP) instead of the call crashing.
- **Validation before network**: inputs are validated with Zod; CNPJ check digits are verified locally, including the new **alphanumeric CNPJ** (Receita Federal, July 2026).
- **Privacy by default**: `consultar_cnpj` drops partner (QSA) personal data from the response.
- **Business-day aware**: PTAX looks back up to 10 days and prefers the closing bulletin; dates use Brasília time.
- **Future-dated points filtered**: the BCB publishes some series ahead (e.g. the Selic target until the next Copom), so `serie_bcb` only returns values up to today.
- **Read-only tools** annotated with `readOnlyHint`, an in-memory TTL cache to avoid hammering public APIs, and timeouts on every request.
- Each tool returns both a JSON text block and `structuredContent`.

## Development

```sh
npm install
npm test          # Vitest: unit tests + in-memory MCP client/server tests with mocked fetch
npm run build
npm run inspect   # opens the MCP Inspector against the built server
```

```
src/
├── index.ts          # stdio entry point
├── server.ts         # McpServer: tools, resource and prompt
├── tools/bcb.ts      # PTAX, conversion, SGS series
├── tools/brasilapi.ts# CEP, CNPJ, holidays
├── series.ts         # indicator catalog
├── cnpj.ts           # CNPJ normalization + check digits
├── dates.ts          # date formats and Brasília "today"
├── http.ts           # fetch with timeout, errors and TTL cache
└── result.ts         # tool result helpers
```

## License

MIT · Built by [Daniel Camuçatto](https://danielcamucatto.dev.br)