tesourodireto-mcp
An MCP server for Brazilian government bonds (Tesouro Direto) — historical prices and yields, current rates, per-maturity statistics and the ANBIMA yield curve — built for LLM agents.
It is the Python/MCP counterpart of the R package
GetTDData: same asset codes, same
parsing rules, same fields. It talks directly to the official Tesouro
Transparente CKAN open data portal, so no R installation is required.
Why this server
- Official data, no R dependency. Downloads
precotaxatesourodireto.csvfrom Tesouro Transparente and reproducesGetTDData::td_get2()semantics. - Robust downloads. Retries, validates the CSV header before replacing the cache, and falls back to a previously valid cache when the portal is down.
- Local cache. One download per day, stored in
~/.cache/tesourodireto-mcp(configurable), with an in-memory parsed cache for fast repeated calls. - Token-efficient output. CSV with a short comment header — not thousands of repetitive JSON records. Long series can be aggregated monthly/yearly.
- The whole curve.
get_yield_curvescrapes ANBIMA's ETTJ and computes maturity dates with the Brazil/ANBIMA business-day calendar. - Agent guidance. Server instructions, a static bond catalog resource and
an
analyze_bondprompt.
Tools
| Tool | What it does |
|---|---|
list_bond_types |
Bond catalog: code, official name, indexer, coupon, description and aliases. |
get_bond_data |
Historical daily prices/yields, filterable by bond family, maturity, dates; optional monthly/yearly means. |
get_current_rates |
Latest snapshot of every bond (one row per maturity). |
get_bond_stats |
Per-maturity summary: last/mean/min/max yield, dates, observation counts. |
get_yield_curve |
ANBIMA real, nominal and implicit-inflation yield curves. |
Resources: tesouro://catalog/bond-types. Prompt: analyze_bond.
Output conventions
yield_bidis a decimal annual rate:0.1183means 11.83% p.a.yield_bid_pctand the*_pctstatistics are already in percent.price_bidis the unit purchase price in BRL (R$).asset_codeis the bond family plus maturity asDDMMYY, e.g.LTN 010123,NTN-B Principal 150835.- Data starts in 2005. Daily series are truncated to the most recent
max_rowsrows; usefrequency="monthly"or a narrower range for long histories.
Install
Requires Python 3.10+.
From PyPI, no clone needed:
uvx tesourodireto-mcp
or with pip:
pip install tesourodireto-mcp
tesourodireto-mcp
From source:
git clone https://github.com/msperlin/tesourodireto-mcp.git
cd tesourodireto-mcp
uv sync
uv run tesourodireto-mcp
Or install the checkout as a standalone tool:
uv tool install .
tesourodireto-mcp
Register with OpenCode
Add to ~/.config/opencode/opencode.json (or a project opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"tesourodireto-mcp": {
"type": "local",
"command": [
"/home/msperlin/GitRepo/mcp-servers/tesourodireto-mcp/.venv/bin/python",
"-m",
"tesourodireto_mcp"
]
}
}
}
}
Or with uv, without hard-coding a virtualenv path:
"command": ["uv", "run", "--directory", "/path/to/tesourodireto-mcp", "tesourodireto-mcp"]
Register with Claude Desktop
{
"mcpServers": {
"tesourodireto-mcp": {
"command": "uvx",
"args": ["tesourodireto-mcp"]
}
}
}
Examples
Ask the agent:
What are the current NTN-B Principal yields and maturities?
How did the LTN 010127 yield evolve in 2024?
Compare the last 10 years of NTN-B Principal yields with the ANBIMA real return curve.
Summarize the inflation implied by today's Brazilian yield curve.
Typical tool calls:
list_bond_types(asset_codes=["NTN-B Principal"])
get_bond_data(asset_codes=["LTN"], first_year=2024, last_year=2024, asset_code="010127")
get_bond_data(asset_codes=["NTN-B Principal"], first_year=2015, frequency="monthly")
get_current_rates(asset_codes=["LFT", "LTN"])
get_bond_stats(asset_codes=["NTN-B Principal"], first_year=2015, max_assets=10)
get_yield_curve()
A live call returns:
# Tesouro Direto — source: Tesouro Transparente (CKAN)
# Retrieved: 2026-11-01T12:00:00+00:00 | data file date: 2026-11-01 | latest ref date: 2026-10-30 | stale cache: no
# yield_bid is a decimal annual rate (0.1183 = 11.83% p.a.); ...
ref_date,yield_bid,yield_bid_pct,price_bid,asset_code,matur_date
2026-10-30,0.118300,11.8300,912.34,LTN 010127,2027-01-01
Configuration
| Variable | Default | Purpose |
|---|---|---|
TESOURO_DIRETO_CACHE_DIR |
~/.cache/tesourodireto-mcp |
Where the raw CSV is cached. |
TESOURO_DIRETO_CSV_URL |
Official CKAN resource URL | Override with a direct CSV URL or a local file path (useful offline/tests). |
MCP_TRANSPORT |
stdio |
stdio, streamable-http or sse. |
MCP_HOST / MCP_PORT |
127.0.0.1 / 8000 |
Bind address for HTTP transports. |
Development
uv sync
uv run pytest # offline unit + end-to-end MCP stdio tests
uv run python scripts/smoke_test.py # live test against Tesouro/ANBIMA
The test suite uses a small CSV fixture, so it does not need network access. The smoke test downloads the real dataset and the current ANBIMA curve.
The ANBIMA business-day calendar (src/tesourodireto_mcp/anbima_holidays.txt)
was exported from the bizdays Brazil/ANBIMA calendar used by GetTDData, so
curve maturity dates match the R package.
Data sources and disclaimer
- Bond data: Tesouro Transparente, the official open data portal of the Brazilian National Treasury.
- Yield curve: ANBIMA.
This project is not affiliated with Tesouro Nacional, ANBIMA or the R package authors. Data is provided as-is; verify before making financial decisions.
License
MIT © Marcelo S. Perlin
Metadata
Release files for tesourodireto-mcp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tesourodireto_mcp-0.1.0.tar.gz | 103.0 kB | With provenance | Details for tesourodireto_mcp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tesourodireto_mcp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tesourodireto_mcp-0.1.0-py3-none-any.whl |
Total release size: 127.9 kB
Release files / tesourodireto_mcp-0.1.0.tar.gz
| Download URL | tesourodireto_mcp-0.1.0.tar.gz |
|---|---|
| Size | 103.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21f9c56987b53603cbf368c91f0b09fcd29ae58c4b1544a25c20e8d4f05ba58f
|
|
BLAKE2b-256 checksum How to use checksums |
2c793e339b4422e262a8d1e47f197dd8ccdcf32e950f0ef9984126bc62e73993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logRelease files / tesourodireto_mcp-0.1.0-py3-none-any.whl
| Download URL | tesourodireto_mcp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69c71abb43a45b26680653492adfe49c54fca8b9f037e9e078a93316991cf69f
|
|
BLAKE2b-256 checksum How to use checksums |
59dd7b17644c255b458897329ecff22b8a1224fecc04f4e01715614be94678df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logSecurity for tesourodireto-mcp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tesourodireto_mcp-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.