mcp-brasil
README.md
# mcp-brasil
[](https://github.com/vinicius-carv/mcp-brasil/actions/workflows/ci.yml)
*Servidor MCP para dados públicos brasileiros: CNPJ, CEP, IBGE e busca no Diário Oficial da União.*
An [MCP](https://modelcontextprotocol.io) server that gives AI assistants access to Brazilian public data, with no API keys.
Other Brazilian-data MCP servers cover CNPJ, CEP and IBGE. None of them search the **Diário Oficial da União** (DOU), the federal official gazette where laws, procurement notices, appointments and public contracts are published. This one does. CNPJ, CEP and IBGE are here too, built to keep working when a provider is down.
## Tools
| Tool | What it does | Source |
|------|--------------|--------|
| `cnpj_lookup` | Company registration data for a CNPJ (numeric or alphanumeric, check digits verified locally) | BrasilAPI, fallback OpenCNPJ |
| `cep_lookup` | Address for a postal code | BrasilAPI v2, fallback ViaCEP |
| `ibge_municipios` | Municipalities of a state (name + IBGE code) | IBGE localities API |
| `dou_search` | Search DOU acts. `section`: `do1`, `do2`, `do3`, `doe`, `todos`; `period`: `dia`, `semana`, `mes`, `ano` | in.gov.br |
| `dou_article` | Full text of one DOU act, by the `slug` from a search result | in.gov.br |
Every tool returns compact JSON with the same shape whichever provider answered, plus a `source` field. Missing fields are `null`; keys are always present. An unknown CNPJ or CEP returns `{"found": false, "query": "..."}`, not an error.
### Examples
Real output, trimmed. Call: `cnpj_lookup {"cnpj": "33000167000101"}`
```json
{
"found": true,
"cnpj": "33000167000101",
"razao_social": "PETROLEO BRASILEIRO S A PETROBRAS",
"situacao": "ATIVA",
"data_abertura": "1966-09-28",
"cnae_principal": { "codigo": "0600001", "descricao": "Extração de petróleo e gás natural" },
"natureza_juridica": "Sociedade de Economia Mista",
"endereco": { "logradouro": "REPUBLICA DO CHILE", "numero": "65", "municipio": "RIO DE JANEIRO", "uf": "RJ", "cep": "20031170" },
"socios": [{ "nome": "...", "qualificacao": "..." }],
"source": "brasilapi"
}
```
`cep_lookup {"cep": "01310-100"}`
```json
{ "found": true, "cep": "01310100", "logradouro": "Avenida Paulista", "bairro": "Bela Vista",
"cidade": "São Paulo", "uf": "SP", "ibge": "3550308", "source": "brasilapi" }
```
`ibge_municipios {"uf": "RJ"}`
```json
{ "uf": "RJ", "total": 92, "municipios": [ { "codigo": "3300100", "nome": "Angra dos Reis" }, { "codigo": "3300159", "nome": "Aperibé" } ] }
```
`dou_search {"query": "licitação", "period": "semana"}` (first of 20 results)
```json
{
"query": "licitação", "section": "todos", "period": "semana", "total": 3527,
"results": [{
"title": "PORTARIA MRE Nº 707, DE 18 DE NOVEMBRO DE 2026",
"date": "19/11/2026", "section": "DO1_EXTRA_C", "edition": "218-C", "page": "39", "type": "Portaria",
"organ": "Ministério das Relações Exteriores/Gabinete do Ministro",
"excerpt": "... A possibilidade de prorrogação deve estar prevista no ato convocatório de licitação ...",
"slug": "portaria-mre-n-707-de-18-de-novembro-de-2026-745538851",
"url": "https://www.in.gov.br/web/dou/-/portaria-mre-n-707-de-18-de-novembro-de-2026-745538851"
}]
}
```
`dou_article {"slug": "portaria-mre-n-707-de-18-de-novembro-de-2026-745538851"}`
```json
{
"slug": "portaria-mre-n-707-de-18-de-novembro-de-2026-745538851",
"url": "https://www.in.gov.br/web/dou/-/portaria-mre-n-707-de-18-de-novembro-de-2026-745538851",
"title": "PORTARIA MRE Nº 707, DE 18 DE NOVEMBRO DE 2026",
"text": "PORTARIA MRE Nº 707, DE 18 DE NOVEMBRO DE 2026 Aprova o novo Regulamento Consular Brasileiro (RCB) ...",
"truncated": true
}
```
`text` is capped at 20,000 characters; `truncated` says when that happened.
## Install
Requires Node.js 22 or newer.
Claude Code:
```sh
claude mcp add mcp-brasil -- npx -y @vinicius-carv/mcp-brasil
```
Claude Desktop (`claude_desktop_config.json`):
```json
{
"mcpServers": {
"mcp-brasil": {
"command": "npx",
"args": ["-y", "@vinicius-carv/mcp-brasil"]
}
}
}
```
From source:
```sh
git clone https://github.com/vinicius-carv/mcp-brasil && cd mcp-brasil
npm ci && npm run build
node dist/index.js # stdio server; point your MCP client at this command
```
## Robustness
- **Fallback only when it makes sense.** A provider is skipped on network error, timeout, HTTP 429, HTTP 5xx or invalid JSON. A 404 (or ViaCEP's `erro`) means "does not exist" and returns `found: false` without trying the next provider.
- **Errors say what happened.** A failed call lists every provider tried and why each failed, as a one-line tool error.
- **Retries:** up to 2, with 500 ms x 2^n backoff; `Retry-After` is honored up to 5 s.
- **Throttling:** requests to the same host are serialized, with a minimum interval of 250 ms (1 s for in.gov.br). No parallel fan-out.
- **Timeouts:** 10 s (20 s for in.gov.br).
- **In-memory cache** (max 500 entries, oldest dropped first). Errors are never cached.
| Data | Cache TTL |
|------|-----------|
| CNPJ | 24 h |
| CEP | 7 days |
| IBGE municipalities | 7 days |
| DOU search | 10 min |
| DOU article | 24 h |
| Not found (404) | 1 h |
| ViaCEP `{"erro":true}` (unknown CEP) | 7 days (normal CEP TTL) |
Inputs are validated before any network call (CNPJ check digits, 8-digit CEP, the 27 UF codes, DOU enums).
## DOU caveats
- **in.gov.br refuses connections from outside Brazil.** `dou_search` and `dou_article` need a Brazilian IP; from elsewhere they fail with an error that says so. The other tools work anywhere.
- **First page only:** a search returns the first 20 results (`total` shows the full count). Narrow with `period` and `section` instead of paging.
- **It is scraping.** in.gov.br has no public search API, so the parser reads the search page's embedded JSON and the article HTML. If the site changes, the tool fails with "DOU page format changed". Run `npm run test:live` and open an issue.
## Development
```sh
npm ci
npm test # build + offline tests (recorded fixtures, no network)
npm run test:live # one real call per tool; DOU needs a Brazilian IP
```
CI runs the offline suite on Node 22 and 24, Linux and Windows. It never runs the live tests.
## Data sources and terms
Data comes from public services; check their terms before heavy use. This project sends a `User-Agent` identifying itself and keeps request volume low.
- [BrasilAPI](https://brasilapi.com.br) (CNPJ, CEP)
- [OpenCNPJ](https://opencnpj.org) (CNPJ fallback)
- [ViaCEP](https://viacep.com.br) (CEP fallback)
- [IBGE localities API](https://servicodados.ibge.gov.br/api/docs/localidades)
- [Imprensa Nacional, in.gov.br](https://www.in.gov.br) (Diário Oficial da União)
Not affiliated with any of these services or with the Brazilian government.
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues