{
  "markdown": "<div align=\"center\">\n  <h1>@cyanheads/treasury-fiscaldata-mcp-server</h1>\n  <p><b>Query US Treasury national debt, interest rates, exchange rates, and fiscal datasets via MCP.</b>\n  <div>7 Tools</div>\n  </p>\n</div>\n\n<div align=\"center\">\n\n[![Version](https://img.shields.io/badge/Version-0.1.10-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/treasury-fiscaldata-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.0.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/treasury-fiscaldata-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/treasury-fiscaldata-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.0-blueviolet.svg?style=flat-square)](https://bun.sh/)\n\n</div>\n\n<div align=\"center\">\n\n[![Install in Claude Desktop](https://img.shields.io/badge/Install_in-Claude_Desktop-D97757?style=for-the-badge&logo=anthropic&logoColor=white)](https://github.com/cyanheads/treasury-fiscaldata-mcp-server/releases/latest/download/treasury-fiscaldata-mcp-server.mcpb) [![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=treasury-fiscaldata-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvdHJlYXN1cnktZmlzY2FsZGF0YS1tY3Atc2VydmVyIl19) [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22treasury-fiscaldata-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Ftreasury-fiscaldata-mcp-server%22%5D%7D)\n\n[![Framework](https://img.shields.io/badge/Built%20on-@cyanheads/mcp--ts--core-67E8F9?style=flat-square)](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)\n\n</div>\n\n<div align=\"center\">\n\n**Public Hosted Server:** [https://treasury-fiscaldata.caseyjhand.com/mcp](https://treasury-fiscaldata.caseyjhand.com/mcp)\n\n</div>\n\n---\n\n## Tools\n\nFive tools for querying the US Treasury Fiscal Data API, plus two for SQL analytics over DuckDB-backed DataCanvas dataframes:\n\n| Tool | Description |\n|:-----|:------------|\n| `treasury_list_datasets` | Browse the curated catalog of 17 Treasury Fiscal Data endpoints with field names, descriptions, and update cadence |\n| `treasury_query_dataset` | Query any Treasury Fiscal Data endpoint by path, field list, filters, sort, and page — with optional DataCanvas spill |\n| `treasury_get_debt` | Fetch national debt (Debt to the Penny) — latest record, specific date, or date-range series with optional DataCanvas spill |\n| `treasury_get_interest_rates` | Average interest rates Treasury pays on outstanding securities by type — marketable issues, non-marketable series, and aggregate totals |\n| `treasury_get_exchange_rates` | Official Treasury statutory exchange rates for ~165 countries, published quarterly |\n| `treasury_dataframe_describe` | List DataCanvas dataframes materialized by the treasury_* tools with schema, row count, and TTL |\n| `treasury_dataframe_query` | Run a single-statement SELECT against DataCanvas dataframes using standard DuckDB SQL |\n\n### `treasury_list_datasets`\n\nBrowse the embedded catalog of available Treasury Fiscal Data endpoints. No network calls — serves from a static catalog bundled with the server.\n\n- Filter by category: `debt`, `interest_rates`, `exchange_rates`, `revenue_spending`, `savings_bonds`, `securities`, `other`\n- Keyword search against dataset name and description (case-insensitive substring)\n- Returns endpoint paths, field names, types, and update cadence\n- Use this first to get the exact endpoint path and field names before calling `treasury_query_dataset`\n- Every path and field name is checked against the live API by `bun run verify:catalog`, so a dataset Treasury moves or renames fails a gate rather than reaching a caller\n\n---\n\n### `treasury_query_dataset`\n\nGeneric parameterized query against any Treasury Fiscal Data endpoint.\n\n- Filter syntax: `{ field, operator, value }` where operator is `eq`, `gt`, `gte`, `lt`, `lte`, `in`\n- Multiple filters ANDed together\n- Pagination via `page_size` (1–10000) and `page_number`\n- Sort by any field, descending with `-` prefix (e.g. `-record_date`)\n- All response values are strings per the API contract — including numeric and date fields; `\"null\"` means no value\n- Pass `canvas_id` to stage the page as a DataCanvas table — the server assigns the name and returns it in `canvas_id`; read its schema with `treasury_dataframe_describe`, then SQL it with `treasury_dataframe_query` (requires `CANVAS_PROVIDER_TYPE=duckdb`)\n\n---\n\n### `treasury_get_debt`\n\nConvenience tool for national debt (Debt to the Penny) — total public debt outstanding broken into publicly-held debt and intragovernmental holdings.\n\n- `mode=latest` — most recent business-day record\n- `mode=date` — specific business day (YYYY-MM-DD; API only records debt on market-open days)\n- `mode=series` — date range, sorted newest-first; auto-spills to DataCanvas when the series exceeds 500 rows\n- Records go back to 1993-04-01\n\n---\n\n### `treasury_get_interest_rates`\n\nAverage interest rates the Treasury pays on outstanding securities. Updated monthly (end-of-month records).\n\n- Covers every security type Treasury reports — marketable issues, non-marketable series, and aggregate totals\n- `security_type` takes any `security_desc` value the data carries, matched exactly; which types Treasury publishes changes over the years, so when a filter matches nothing the response names the types the data does hold\n- `mode=latest` — most recent month's rates for all or one security type\n- `mode=series` — time-range history; auto-spills to DataCanvas when results exceed 200 rows\n\n---\n\n### `treasury_get_exchange_rates`\n\nOfficial Treasury statutory reporting exchange rates for ~165 countries, published quarterly (March 31, June 30, Sep 30, Dec 31).\n\n- Rate expressed as foreign currency units per 1 USD (a Japan-Yen rate of 159.41 means 1 USD = 159.41 JPY)\n- These are **not** market exchange rates — required by US federal agencies for foreign-currency-to-USD conversions in official reporting\n- Filter to one or more countries by exact name; omit for every country in a quarter\n- `mode=latest` returns one row per currency — the operative rate, newest `record_date` and then newest `effective_date`, so an amended rate supersedes the one it replaced and a country holding two legal tenders keeps both\n- Treasury amends a published quarter by reissuing a rate under the same `record_date` with a later `effective_date`, so both dates ride every row; `mixed_record_dates` flags a result whose rows are not all from one quarter\n- `mode=series` auto-spills to DataCanvas when results exceed 500 rows (~19,000 rows full history, back to 2001-03-31)\n\n---\n\n### `treasury_dataframe_describe` / `treasury_dataframe_query`\n\nIn-conversation SQL analytics over the dataframes that `treasury_query_dataset`, `treasury_get_debt`, `treasury_get_interest_rates`, and `treasury_get_exchange_rates` materialize on a shared DuckDB-backed DataCanvas. Each data-returning call with `canvas_id` adds a `df_XXXXX_XXXXX` handle; read its columns with `treasury_dataframe_describe`, then pass the handle to `treasury_dataframe_query` for joins, aggregates, window functions, and CTEs — standard DuckDB SQL.\n\n- **Read-only.** Writes, DDL, DROP, COPY, PRAGMA, ATTACH, and external-file table functions are rejected by the SQL gate. System catalogs (`information_schema`, `pg_catalog`, `sqlite_master`, `duckdb_*`) are denied at the bridge layer.\n- **All Treasury columns are VARCHAR.** CAST to `DECIMAL` or `DATE` for arithmetic and date comparisons.\n- **`register_as` chaining.** `treasury_dataframe_query` can persist its result as a new dataframe with a fresh TTL for multi-step analysis.\n- **Per-table TTL.** Dataframes age on their own clock (default 24h, override with `CANVAS_TTL_MS`).\n- Requires `CANVAS_PROVIDER_TYPE=duckdb`.\n\n## Features\n\nBuilt on [`@cyanheads/mcp-ts-core`](https://www.npmjs.com/package/@cyanheads/mcp-ts-core):\n\n- Declarative tool definitions — single file per tool, framework handles registration and validation\n- Structured output schemas with automatic formatting for human-readable display\n- Unified error handling — handlers throw, framework catches, classifies, and formats\n- Pluggable auth: `none`, `jwt`, `oauth`\n- Structured logging with request-scoped context\n- STDIO and Streamable HTTP transports\n\nTreasury-specific:\n\n- Curated catalog of 17 Treasury Fiscal Data endpoints with field metadata — no discovery round-trip required. Pass any endpoint path directly to `treasury_query_dataset` to access datasets not in the catalog.\n- Convenience tools for the three most-queried datasets (national debt, interest rates, exchange rates)\n- Full generic access to any Fiscal Data endpoint via `treasury_query_dataset`\n- DataCanvas integration: large time-series pulls register as `df_<id>` dataframes queryable via DuckDB SQL\n- No API keys required — the US Treasury Fiscal Data API is free and public\n\nAgent-friendly output:\n\n- Filter expression echo (`applied_filters`) so agents can verify what was sent to the API\n- Field-label maps on query results (`field_labels`) map raw field names to human-readable labels\n- Enrichment notices on empty results, partial-country mismatches, staged canvas tables, and truncated series guide the next tool call\n- Canvas provenance: source tool, original query parameters, row count, and column schema surfaced by `treasury_dataframe_describe`\n\n## Getting started\n\n### Public Hosted Instance\n\nA public instance is available at `https://treasury-fiscaldata.caseyjhand.com/mcp` — no installation required. Point any MCP client at it via Streamable HTTP:\n\n```json\n{\n  \"mcpServers\": {\n    \"treasury-fiscaldata-mcp-server\": {\n      \"type\": \"streamable-http\",\n      \"url\": \"https://treasury-fiscaldata.caseyjhand.com/mcp\"\n    }\n  }\n}\n```\n\n### Self-Hosted / Local\n\nAdd the following to your MCP client configuration file.\n\n```json\n{\n  \"mcpServers\": {\n    \"treasury-fiscaldata-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"bunx\",\n      \"args\": [\"@cyanheads/treasury-fiscaldata-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\"\n      }\n    }\n  }\n}\n```\n\nOr with npx (no Bun required):\n\n```json\n{\n  \"mcpServers\": {\n    \"treasury-fiscaldata-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@cyanheads/treasury-fiscaldata-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\"\n      }\n    }\n  }\n}\n```\n\nOr with Docker:\n\n```json\n{\n  \"mcpServers\": {\n    \"treasury-fiscaldata-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"docker\",\n      \"args\": [\n        \"run\", \"-i\", \"--rm\",\n        \"-e\", \"MCP_TRANSPORT_TYPE=stdio\",\n        \"ghcr.io/cyanheads/treasury-fiscaldata-mcp-server:latest\"\n      ]\n    }\n  }\n}\n```\n\nFor Streamable HTTP, set the transport and start the server:\n\n```sh\nMCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 bun run start:http\n# Server listens at http://localhost:3010/mcp\n```\n\n### DataCanvas SQL workflow\n\nFor large time-series pulls or multi-dataset analysis, use the DataCanvas SQL workflow:\n\n1. **Set `CANVAS_PROVIDER_TYPE=duckdb`** in your server environment.\n2. **Call a data tool with a `canvas_id`** — e.g., `treasury_get_debt` with `mode=series` and a `canvas_id` value, or `treasury_query_dataset` with `canvas_id`. The tool registers the results as a `df_XXXXX_XXXXX` dataframe and returns the table name.\n3. **Inspect the schema** with `treasury_dataframe_describe` — lists column names, types (all VARCHAR for Treasury data), row count, and TTL.\n4. **Query with SQL** via `treasury_dataframe_query` — standard DuckDB SELECT with joins, aggregates, window functions, and CTEs. CAST VARCHAR columns to DECIMAL or DATE for arithmetic.\n\n```sql\n-- Example: debt trend over the last year, month-end records only\nSELECT\n  record_date,\n  CAST(tot_pub_debt_out_amt AS DECIMAL) / 1e12 AS total_debt_trillions\nFROM df_xxxxx\nWHERE CAST(record_date AS DATE) >= CURRENT_DATE - INTERVAL 1 YEAR\nORDER BY record_date DESC\n```\n\n### Prerequisites\n\n- [Bun v1.3.0](https://bun.sh/) or higher (or Node.js v24+).\n- No API key required — the US Treasury Fiscal Data API is free and public.\n- For DataCanvas SQL: `CANVAS_PROVIDER_TYPE=duckdb` (DuckDB is bundled as `@duckdb/node-api`).\n\n### Installation\n\n1. **Clone the repository:**\n\n```sh\ngit clone https://github.com/cyanheads/treasury-fiscaldata-mcp-server.git\n```\n\n2. **Navigate into the directory:**\n\n```sh\ncd treasury-fiscaldata-mcp-server\n```\n\n3. **Install dependencies:**\n\n```sh\nbun install\n```\n\n4. **Configure environment:**\n\n```sh\ncp .env.example .env\n# edit .env as needed — no required vars; CANVAS_PROVIDER_TYPE=duckdb to enable SQL\n```\n\n## Configuration\n\n| Variable | Description | Default |\n|:---------|:------------|:--------|\n| `CANVAS_PROVIDER_TYPE` | Canvas engine. Unset resolves to `none`, and the `treasury_dataframe_*` tools then reject every call — set it to `duckdb` to enable DataCanvas SQL. | `none` |\n| `CANVAS_TTL_MS` | Per-table TTL for DataCanvas dataframes in milliseconds. | `86400000` (24h) |\n| `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http`. | `stdio` |\n| `MCP_HTTP_PORT` | Port for HTTP server. | `3010` |\n| `MCP_SESSION_MODE` | HTTP session handling: `auto`, `stateful`, or `stateless`. `.env.example` ships `stateless`. | `auto` (resolves to `stateful`) |\n| `MCP_AUTH_MODE` | Auth mode: `none`, `jwt`, or `oauth`. | `none` |\n| `MCP_LOG_LEVEL` | Log level (`debug`, `info`, `notice`, `warning`, `error`). | `info` |\n| `LOGS_DIR` | Directory for log files (Node.js/Bun only). | `<project-root>/logs` |\n| `OTEL_ENABLED` | Enable [OpenTelemetry](https://github.com/cyanheads/mcp-ts-core/tree/main/docs/telemetry) spans and metrics. | `false` |\n\nSee [`.env.example`](./.env.example) for the full list of optional overrides.\n\n## Running the server\n\n### Local development\n\n- **Build and run:**\n\n  ```sh\n  bun run rebuild\n\n  bun run start:stdio\n  # or\n  bun run start:http\n  ```\n\n- **Run checks and tests:**\n\n  ```sh\n  bun run devcheck         # Lint, format, typecheck, security\n  bun run test             # Vitest test suite\n  bun run lint:mcp         # Validate MCP definitions against spec\n  bun run verify:catalog   # Probe every catalog endpoint and field against the live API\n  ```\n\n  `verify:catalog` is the one check that needs the network, which is why it is separate from `devcheck` and the test suite. Run it after editing `src/services/fiscal-data/datasets.ts` and before a release.\n\n### Docker\n\n```sh\ndocker build -t treasury-fiscaldata-mcp-server .\ndocker run --rm -e CANVAS_PROVIDER_TYPE=duckdb -p 3010:3010 treasury-fiscaldata-mcp-server\n```\n\nThe Dockerfile defaults to HTTP transport, stateless session mode, and logs to `/var/log/treasury-fiscaldata-mcp-server`. DuckDB native modules are pre-built in the build stage and copied to the production stage — no extra build tools required at runtime. OpenTelemetry peer dependencies are installed by default — build with `--build-arg OTEL_ENABLED=false` to omit them.\n\n## Project structure\n\n| Directory | Purpose |\n|:----------|:--------|\n| `src/index.ts` | `createApp()` entry point — registers tools and inits services. |\n| `src/config/` | Server-specific environment variable parsing and validation with Zod. |\n| `src/mcp-server/tools/definitions/` | Tool definitions (`*.tool.ts`) — 5 data tools + 2 DataCanvas tools. |\n| `src/services/fiscal-data/` | Treasury Fiscal Data API client, embedded endpoint catalog, and types. |\n| `src/services/canvas-bridge/` | Adapter over the framework DataCanvas: `df_<id>` minting, per-table TTL, system-catalog SQL deny. |\n| `tests/` | Unit and integration tests mirroring `src/`. |\n\n## Development guide\n\nSee [`CLAUDE.md`](./CLAUDE.md) and [`AGENTS.md`](./AGENTS.md) for development guidelines and architectural rules. The short version:\n\n- Handlers throw, framework catches — no `try/catch` in tool logic\n- Use `ctx.log` for request-scoped logging, `ctx.state` for tenant-scoped storage\n- All Treasury API values are strings — validate and CAST in downstream SQL; never fabricate missing fields\n- Register new tools via the arrays in `src/index.ts`\n\n## Contributing\n\nIssues and pull requests are welcome. Run checks and tests before submitting:\n\n```sh\nbun run devcheck\nbun run test\n```\n\n## License\n\nApache-2.0 — see [LICENSE](LICENSE) for details.\n",
  "bytes": 16946,
  "sha": "d155edf849b2b822244e0b8052eee3a0d1dd48f7e5bc005c013dae5b868b0108",
  "repo_slug": "cyanheads/treasury-fiscaldata-mcp-server",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_cyanheads_treasury_fiscaldata__dd0ed03c/readme"
}