brazil-legislation-mcp-server
by cyanheads
README.md
<div align="center">
<h1>@cyanheads/brazil-legislation-mcp-server</h1>
<p><b>Search Brazilian federal legislation, read legal texts, and trace amendments via MCP. STDIO or Streamable HTTP.</b></p>
<div>6 Tools</div>
</div>
<div align="center">
[](./CHANGELOG.md) [](./LICENSE) [](https://github.com/users/cyanheads/packages/container/package/brazil-legislation-mcp-server) [](https://modelcontextprotocol.io/) [](https://www.npmjs.com/package/@cyanheads/brazil-legislation-mcp-server) [](https://www.typescriptlang.org/) [](https://bun.sh/)
</div>
<div align="center">
[](https://github.com/cyanheads/brazil-legislation-mcp-server/releases/latest/download/brazil-legislation-mcp-server.mcpb) [](https://cursor.com/en/install-mcp?name=brazil-legislation-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvYnJhemlsLWxlZ2lzbGF0aW9uLW1jcC1zZXJ2ZXIiXX0=) [](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22brazil-legislation-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Fbrazil-legislation-mcp-server%22%5D%7D)
[](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)
</div>
---
## Overview
Search the Senado Federal catalog for Brazilian federal norms and selected STF constitutional-review decisions. Resolve a citation such as `Lei 13.709/2018` (LGPD), read a specific publication or provision, and trace the acts that changed it. Exact state and municipal LexML URNs can return bibliographic metadata. The sources are public and require no API key.
### Tools
| Tool | Purpose |
|:---|:---|
| [`brlaw_search_norms`](#brlaw_search_norms) | Search Portuguese summaries and nicknames or browse a signature year. |
| [`brlaw_lookup_citation`](#brlaw_lookup_citation) | Resolve citations, nicknames and LexML URNs in a batch. |
| [`brlaw_get_norm`](#brlaw_get_norm) | Get norm metadata, publication IDs and change counts. |
| [`brlaw_get_text`](#brlaw_get_text) | Read an edition, available translation, article or section. |
| [`brlaw_get_changes`](#brlaw_get_changes) | Trace later and earlier acts by act or provision. |
| [`brlaw_list_reference`](#brlaw_list_reference) | Inspect citation syntax, source coverage, mirror state and Senado vocabularies. |
## Capability reference
For search, changes and vocabulary pages, `limit` defaults to 25 and clamps to 200. Continue with `next_offset` and optionally pass back `page_token` to check continuity. On `page_changed`, restart at offset 0 without the token.
### `brlaw_search_norms` <sub>tool</sub>
- Searches Portuguese ementas and nicknames with accent-insensitive matching. Filter by Senado `types` (including family expansion), `number`, and either signature year or ISO date bounds. The default sort is `relevance` with a query and `newest` without one. `oldest` is also available.
- Send equal year bounds or two dates in one year, with no `query`, to browse live. Other searches require the initialized mirror. The response names the source and gives the live observation time or the mirror's coverage.
### `brlaw_lookup_citation` <sub>tool</sub>
- Resolves the first 25 `citations` in input order, preserving the rest in `unprocessed`. Include a type and year when available. Provision addresses such as `Art. 26, § 1º, II` can follow a citation.
- Outcomes are `found`, `ambiguous`, `not_found`, `outside_base`, and `unavailable`. A found row gives the Senado ID for subsequent calls. `outside_base` covers exact non-federal LexML URNs. Some nickname lookups need the mirror.
### `brlaw_get_norm` <sub>tool</sub>
- Takes `norm` as a Senado ID, LexML URN, typed citation, or nickname. Returns the official summary, subject indexing, publications, text versions, and recorded change counts. Use a returned `publication_id` to select an edition.
- `include_lexml` defaults to false. When enabled, it can add a bill of origin and doctrine references. Doctrine pages default to 10 rows and continue with `lexml.doctrine.next_offset`.
### `brlaw_get_text` <sub>tool</sub>
- Defaults to consolidated Portuguese text. The server tries Senado, Câmara and verified Planalto compilations, then the original. Choose `version: "as_published"` or an exact `publication_id`. Available Senado translations can be requested with `language: "en"` or `"fr"`.
- Choose `articles` or `sections`. Article selection processes up to 10 addresses and returns the rest for a follow-up. Text over 24,000 characters returns an outline. Use its section IDs with the same edition to retrieve complete sections. A repeated section ID returns `same_as_selection`, the one-based position of its first result in `selections`.
- Results distinguish `whole`, `outline`, `selected` and `unavailable`. Read the served source, date and date basis before citing. An unknown compilation date means freshness is unknown. Dated later acts are recorded changes and do not establish legal effect. The Diário Oficial da União is authoritative.
### `brlaw_get_changes` <sub>tool</sub>
- Set `direction` to `changed_by` (default), `changes` or `both`. Use `view: "by_act"` (default) or `"by_article"`. Filter by related-act signature dates, relation kinds, actions or act classes such as `stf_ruling`.
- Includes recorded Portuguese relation labels, notes, and affected provisions where the source supplies them. Each item indicates whether the recorded action changes wording.
### `brlaw_list_reference` <sub>tool</sub>
- `topic: "overview"` (default) gives citation and provision examples, source credits, and index coverage. Choose `types`, `publications`, `relations` or `actions` for vocabulary rows and snapshot provenance.
- Senado uses `ADCon` in type filters for the STF action cited as ADC. `ADC` in those filters stands for Ato Declaratório.
## Features
Built on [`@cyanheads/mcp-ts-core`](https://github.com/cyanheads/mcp-ts-core): stdio and Streamable HTTP transports, pluggable auth (`none` / `jwt` / `oauth`), swappable storage (`in-memory`, `filesystem`, `Supabase`, `Cloudflare KV/R2/D1`), structured logging with optional OpenTelemetry tracing.
- Cross-year search uses a persistent SQLite FTS5 mirror of the Senado catalog. The November 30, 2026 sweep indexed 244,266 unique IDs across signature years 1808–2026. Use `brlaw_list_reference` for current local coverage and readiness.
- Reformatted texts retain source links and publication notices. Source credits go to [Senado Federal](https://legis.senado.leg.br/dadosabertos/), [Câmara dos Deputados](https://www2.camara.leg.br/atividade-legislativa/legislacao), [Presidência da República](https://www.planalto.gov.br/ccivil_03/) and [LexML Brasil](https://www.lexml.gov.br/).
## Getting started
For npm installs, use [Node.js](https://nodejs.org/) 24 or later with built-in SQLite. The portable `.mcpb` is a stdio bundle and declares the same Node floor for the runtime that the host uses to launch it.
```sh
claude mcp add brazil-legislation-mcp-server -- npx -y @cyanheads/brazil-legislation-mcp-server
```
For other clients, add this to the MCP config file:
```json
{
"mcpServers": {
"brazil-legislation-mcp-server": {
"command": "npx",
"args": ["-y", "@cyanheads/brazil-legislation-mcp-server"]
}
}
}
```
For local Streamable HTTP:
```sh
MCP_TRANSPORT_TYPE=http npx -y @cyanheads/brazil-legislation-mcp-server
```
Connect to `http://127.0.0.1:3010/mcp`. For Docker or a source build, see [Running the server](#running-the-server).
## Configuration
| Variable | Description | Default |
|:---|:---|:---|
| `BRLAW_DATA_DIR` | Writable directory for the index and reference snapshot. Use the same directory for the CLI and server. | `brazil-legislation-mcp-server` in the per-user app data directory |
| `MCP_TRANSPORT_TYPE` | `stdio` or `http`. | `stdio` |
| `MCP_HTTP_HOST` | HTTP bind address. | `127.0.0.1` |
| `MCP_HTTP_PORT` | HTTP port. | `3010` |
| `MCP_HTTP_ENDPOINT_PATH` | HTTP MCP path. | `/mcp` |
| `MCP_SESSION_MODE` | HTTP session mode. | `stateless` |
| `MCP_AUTH_MODE` | `none`, `jwt`, or `oauth`. | `none` |
| `MCP_LOG_LEVEL` | Minimum log level. | `info` |
| `OTEL_ENABLED` | Enable [OpenTelemetry](https://github.com/cyanheads/mcp-ts-core/tree/main/docs/telemetry). | `false` |
See [`.env.example`](./.env.example) for common framework overrides.
## Running the server
### Initialize and refresh the index
Exact citations and single-year listings can use live Senado data from first launch. Initialize the mirror once for cross-year and text searches:
```sh
npx -y --package @cyanheads/brazil-legislation-mcp-server brazil-legislation-mirror init
npx -y --package @cyanheads/brazil-legislation-mcp-server brazil-legislation-mirror verify
npx -y --package @cyanheads/brazil-legislation-mcp-server brazil-legislation-mirror refresh
```
`init` resumes interrupted work. `verify` reports integrity and coverage. HTTP schedules a daily refresh for an initialized index. For stdio, run `refresh` to update the index and reference vocabularies. A refresh covers this year and the previous year, or all years when the last complete sweep is at least seven calendar days old. Keep the data directory across restarts.
### Local development
Requires [Bun v1.4.4](https://bun.sh/) or higher for project scripts and Node.js 24 or later for the start scripts.
```sh
git clone https://github.com/cyanheads/brazil-legislation-mcp-server.git
cd brazil-legislation-mcp-server && bun install
cp .env.example .env
bun run rebuild
bun run start:http
# or bun run start:stdio
```
After building, the mirror commands are also available as `node dist/mirror-cli.js init`, `refresh`, and `verify`.
### Docker
Initialize a named volume and use it again when starting the server:
```sh
docker run --rm -v brlaw-data:/usr/src/app/.mirror \
ghcr.io/cyanheads/brazil-legislation-mcp-server:latest bun run dist/mirror-cli.js init
docker run --rm -p 127.0.0.1:3010:3010 -v brlaw-data:/usr/src/app/.mirror \
ghcr.io/cyanheads/brazil-legislation-mcp-server:latest
```
The image defaults to HTTP with stateless sessions. Substitute `refresh` or `verify` in the lifecycle command as needed. For stdio, run with `-i` and `-e MCP_TRANSPORT_TYPE=stdio` in place of the port mapping. To build locally, run `docker build -t brazil-legislation-mcp-server .`.
## Project structure
| Directory | Purpose |
|:---|:---|
| `src/mcp-server/tools` | Six MCP tool contracts and handlers. |
| `src/domain` | Citation resolution, provision addresses, and change relationships. |
| `src/services/senado` | Norm records, publication retrieval and reference vocabularies. |
| `src/services/mirror` | Local SQLite mirror and reference refresh. |
| `src/services/text` | Edition selection, legal HTML parsing and text provenance. |
| `src/services/lexml` | Exact-URN ficha and doctrine metadata. |
| `tests/` | Contract and service tests. |
## Development guide
See [`CLAUDE.md`](./CLAUDE.md) for development guidelines and architectural rules. See [`docs/design.md`](./docs/design.md) for source mappings and mirror behavior.
## Contributing
Issues are welcome. Run checks and tests before submitting:
```sh
bun run devcheck
bun run test
```
## License
This project is licensed under the Apache 2.0 License. See the [LICENSE](./LICENSE) file for details.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues