
gov.br APIs MCP
io.github.thalisantunes由 GitHub 帳號 thalisantunes 發布v0.2.0更新於 Oct 26, 2026
A catalog-driven gateway over Brazilian government APIs, loading OpenAPI specs on demand.
概覽
以目錄驅動的閘道,讓助理透過一個本機伺服器搜尋、描述並呼叫巴西政府 API(IBGE、央行、眾議院、Serpro 等)。
- 可以做什麼
- 依關鍵字、類別或狀態搜尋並列出內建的 116 個巴西政府 API 目錄項目
- 描述某個 API 項目,並在有 OpenAPI 規格時列出其操作及參數、請求與回應結構
- 呼叫目錄中的任一端點,可指定方法、查詢參數、請求主體與標頭,基底網址與驗證由目錄解析
- 查詢每個 API 需要哪些環境變數,以及目前是否可呼叫
- 以本機 YAML 檔案和額外允許的主機擴充或覆寫目錄
- 適用情境
- 適合需要處理巴西公共資料或服務的情境,讓助理不必為每個端點各自設定工具就能檢索與查詢。適用於透明度、立法、統計或金融資料研究,以及在具備相應憑證或合約後使用 Serpro 或半價票(meia-entrada)流程。
- 執行需求
- 以 stdio 在本機執行,通常透過 PyPI 的 uvx 或容器啟動。多數公共層 API 不需金鑰;其他需要環境變數,如 TRANSPARENCIA_API_KEY、DATAJUD_API_KEY、DADOSGOV_API_KEY、MEIAENTRADA_CODIGO_ACESSO 或 SERPRO_* 的 OAuth2 用戶端 ID 與密鑰組。變數須寫入 MCP 用戶端的 env 區塊,因為不會讀取 .env 檔案。需要連線到允許清單內的 gov.br、leg.br 與 jus.br 主機。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 gov.br APIs MCP,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
govbr-apis-mcp
MCP server that turns Brazilian government APIs into Claude-callable tools through a catalog-driven gateway: instead of one tool per endpoint (hundreds — would blow up client context), five generic tools operate over a local YAML catalog of 116 APIs.
Only the entries that declare an openapi_url have a spec to load: today the Câmara dos
Deputados and the Portal da Transparência, 2 of the 116. For those, describe_api loads
the OpenAPI spec on demand. Every other callable entry (see the "Callable today?" column
below) is reached through call_api alone, using the endpoints in its description and
docs_url.
Catalog tiers
The Conecta tier exists so the catalog reflects the whole landscape now, and becomes
callable later by filling in base_url + credentials — the OAuth2 client-credentials
flow is already implemented (Serpro uses the same one).
Tools
search_catalog(query, category?)— accent-insensitive keyword search; reports total matches and whether the list was truncated.list_apis(category?, status?, limit?)— enumerate entries, callable ones first (by the catalog's status, not by whether your credentials are set; filter it: ~95 Conecta stubs otherwise dominate the output).describe_api(api_id, path?, method?)— catalog metadata + OpenAPI operation list; withpath, parameter/request/response schemas ($refs inlined, depth-limited). Reads OpenAPI 3 and Swagger 2.0, as JSON or YAML.call_api(api_id, path, method?, query?, body?, headers?)— invoke an endpoint; base URL and auth resolved from the catalog entry.methodis GET, HEAD, POST, PUT, PATCH, DELETE or OPTIONS; anything else returns an error withallowed_methods. Abodyis accepted only with POST, PUT and PATCH.pathis relative to thebase_url..and..segments (after up to three rounds of percent-decoding, with\read as/and;parameters removed) and any path that leaves thebase_urlprefix are rejected. So is a#(a fragment is never sent; write a literal one as%23) or a control character.- A query string embedded in
pathis merged withquery; a key inqueryreplaces the embedded one, and a list value repeats the key. - Caller headers are matched case-insensitively, with
_equal to-.Authorization,Proxy-Authorization,Host,CookieandAccept-Encoding, plus connection, proxy, forwarding and method-override headers, are dropped and reported inignored_headers(the full list is inserver.py). The managed credential is applied last and always wins. A header with an invalid name or value is not ignored: it fails the call with anerror. - Method, body, headers and path are validated before any OAuth2 token is requested, and
invalid input comes back as
{"error": ...}. - A
3xxis not followed: the response carries itslocation(redacted, resolved against the requested URL). Response bodies are cut at 60,000 characters.
credentials_status(api_id?)— which env vars each API needs and whether they're set, pluscallable: whethercall_apiwould accept the entry right now (availableandunstableentries;requires_contractones only once their env vars are set).
POC: meia-entrada de estudante
Fluxo funcional ponta a ponta (código da CIE → decisão de elegibilidade), incluindo
modo demo sem credencial: poc/README.md.
Install
Register in Claude Code (.mcp.json or claude mcp add):
From PyPI: uvx govbr-apis-mcp (set "command": "uvx" and "args": ["govbr-apis-mcp"]
in the entry above; no checkout needed). Each release is published to PyPI and to the MCP
Registry automatically (publish.yml).
Or run it in a container. The server speaks stdio, so keep -i:
Credentials
All secrets come from env vars declared per entry in the catalog (auth_config).
Nothing is stored in the repo. .env.example lists the variables. Entries with a free key
carry a signup_url; Serpro credentials come with the contract, at loja.serpro.gov.br.
credentials_status reports readiness.
The server does not read .env files, and MCP clients start it with a minimal environment,
so an export in your shell may never reach it. Put the variables in the client's env
block (the example above, or claude mcp add -e KEY=value). For a container, copy
.env.example to a git-ignored file such as .env.local, fill in the copy and pass it
with docker run --env-file .env.local. Never put real values in .env.example: it is
versioned.
API keys (the value together with any prefix) are stripped of surrounding whitespace and
must be printable ASCII; otherwise the call fails with credential in <VAR> contains invalid characters, without echoing the value. OAuth2 client ids and secrets are only
stripped: they travel base64-encoded, so any text works. The access token the endpoint
returns must be printable ASCII too. When the token endpoint fails, the call returns an
error and the token_url, with neither the response body nor any secret.
Auth profiles: none, api_key (static header, optional value prefix — e.g.
DataJud's APIKey <key>), oauth2_client_credentials (token endpoint + id/secret,
in-memory token cache; used by Serpro today, by Conecta after adhesion).
Extending the catalog
Add an entry to a YAML file in src/govbr_apis_mcp/catalog_data/. The directory is package
data, so the wheel, uvx and the Docker image all carry the catalog. Minimum fields:
id, name, provider, category, status, auth. Add openapi_url when the API
publishes a spec — describe_api then works with zero code. Regenerate the Conecta
tier with .venv/bin/python scripts/scrape_conecta.py. It leaves the file alone when the
page yields no APIs, an id the catalog would reject, or fewer than half the current
entries (--force overrides only the last check).
Entries are validated on load: ids must be filename-safe, URLs must be https on an
allowlisted host (*.gov.br, *.leg.br, *.jus.br plus a few named hosts), and a hostname
may only contain [a-z0-9.-] (write internationalized names in punycode). This is a
security boundary, not style — the catalog decides where your credentials are sent. Add a
host with GOVBR_EXTRA_ALLOWED_HOSTS only if you trust it with them; the same hostname
rule applies to it.
To override entries without forking (e.g. filling in Conecta base URLs after adhesion),
point GOVBR_EXTRA_CATALOG_DIR at a directory of .yaml or .yml files whose same-id
entries win. A directory that does not exist or holds no entries is an error, and so is an
id repeated inside it; an empty value counts as unset. GOVBR_CATALOG_DIR replaces the
base catalog entirely and should be treated as trusted input.
Development
CI runs ruff on Python 3.12 and the test suite on 3.11–3.14, then builds the wheel and loads the catalog from a clean install.
Security notes
- Responses are never written to disk. Only OpenAPI specs are cached, in
$XDG_CACHE_HOME/govbr-apis-mcp/(or~/.cache/govbr-apis-mcp/) for 24 hours, under a file name derived fromsha256(api_id + "\n" + openapi_url): never the id itself, and a changedopenapi_urlnever serves the old spec. OAuth2 tokens live in memory only. call_apidoes not follow redirects — credentialed requests cannot be steered to another host by a3xx; the response carries the (redacted)locationinstead. It always sendsAccept-Encoding: identity, so a server has no reason to compress. The 60,000-character cut counts decoded text, though: a server that compresses anyway can still inflate a small chunk before the cut (an accepted risk; see the roadmap).- Cookies an API sets are never stored or sent back, so one API cannot plant a cookie that another would receive.
- Spec fetches follow redirects only by hand: at most 5 hops, and every URL (the first
and each
Location) must behttpson an allowlisted host before it is requested. The body is capped at 5 MiB, JSON and YAML are accepted (YAML with aliases, including merge keys that rely on them, is refused), and the document must carryopenapiorswagger. A compressed response is refused and the whole download has a 60-second deadline; both come back asspec_error. - The
httpxandhttpcoreloggers stay at WARNING, so httpx logs no request URL (query string included). - Entries flagged
pii: truereturn personal data (CPF, name, photo) into the client transcript. Today:meiaentrada-cie-validador,fesn-cie-validador(callable without any credential: whoever holds a use code gets the holder's data) and the three Serpro entries.
Roadmap
- Conecta adhesion as a public-sector entity → fill gateway base URLs + credentials
- Per-API OpenAPI URLs for Conecta entries (linked from each detail page)
- Serpro trial-mode toggle (call
-trialbase URLs with the published demo token) - Per-call cost guard for paid Serpro APIs
- Bounded decompression for compressed upstream responses
- Pleito à SNJ para a API
conecta-id-jovem(admite instituição privada) - Fallback documental para CIE fora da base DNE (DCEs e entidades estaduais)
License
MIT - see LICENSE.
來源:README.md,提交 c4957f2
工具
0版本歷史
1- v0.2.0最新Oct 19, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分