Metadata-Version: 2.5
Name: maplestats-mcp
Version: 0.7.0
Summary: One MCP server for Canadian open data: Statistics Canada (tables, Census, PUMF microdata), the Bank of Canada, CMHC, federal agencies and provincial and municipal open-data portals, in English and French.
Project-URL: Homepage, https://github.com/dsanchezp18/maplestats-mcp
Project-URL: Repository, https://github.com/dsanchezp18/maplestats-mcp
Project-URL: Issues, https://github.com/dsanchezp18/maplestats-mcp/issues
Project-URL: Changelog, https://github.com/dsanchezp18/maplestats-mcp/releases
Author: Daniel Sánchez Pazmiño
License-Expression: MIT
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
Keywords: ai,bilingual,canada,census,donnees-ouvertes,francophone,gouvernement,government,llm,mcp,microdata,open-data,quebec,statcan,statistics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: English
Classifier: Natural Language :: French
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.12
Requires-Dist: access-parser==0.0.6
Requires-Dist: beautifulsoup4>=4.15.0
Requires-Dist: cachetools>=5.3.0
Requires-Dist: defusedxml>=0.7.1
Requires-Dist: duckdb>=2.0.0
Requires-Dist: fastmcp<4.3,>=4.0.3
Requires-Dist: gtfs-realtime-bindings>=3.0.0
Requires-Dist: h2>=4.1.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: openpyxl>=3.1.5
Requires-Dist: pydantic>=2.12
Requires-Dist: pypdf>=7.0.1
Requires-Dist: pyreadstat>=1.3.7
Requires-Dist: pyyaml>=6.0.3
Requires-Dist: tenacity>=8.0.0
Requires-Dist: tzdata>=2024.1
Requires-Dist: uvicorn>=0.30.0
Requires-Dist: xlrd>=2.0.1
Provides-Extra: ocr
Requires-Dist: pypdfium2<6,>=5; extra == 'ocr'
Provides-Extra: semantic
Requires-Dist: numpy>=1.26.0; extra == 'semantic'
Requires-Dist: onnxruntime>=1.20.0; extra == 'semantic'
Requires-Dist: sentencepiece>=0.2.0; extra == 'semantic'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/dsanchezp18/maplestats-mcp/main/site/assets/logo.svg" width="160" height="160" alt="MapleStats MCP logo: a white pixel maple leaf over the name maplestats-mcp on a red square">
</p>
<p align="center">
  <h1 align="center">MapleStats MCP</h1>
  <p align="center">
    <strong>One MCP server for Canadian open data.</strong>
  </p>
  <p align="center">
    <a href="https://pypi.org/project/maplestats-mcp/"><img src="https://img.shields.io/pypi/v/maplestats-mcp" alt="PyPI version"></a>
    <a href="https://pypi.org/project/maplestats-mcp/"><img src="https://img.shields.io/pypi/pyversions/maplestats-mcp" alt="Supported Python versions"></a>
    <a href="https://github.com/dsanchezp18/maplestats-mcp/blob/main/LICENSE"><img src="https://img.shields.io/github/license/dsanchezp18/maplestats-mcp" alt="License: MIT"></a>
    <a href="https://pypistats.org/packages/maplestats-mcp"><img src="https://img.shields.io/pypi/dm/maplestats-mcp" alt="PyPI downloads per month"></a>
    <a href="https://github.com/dsanchezp18/maplestats-mcp/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/dsanchezp18/maplestats-mcp/ci.yml?branch=main&label=CI" alt="CI status"></a>
    <a href="https://maplestats.danielstats.io/"><img src="https://img.shields.io/github/actions/workflow/status/dsanchezp18/maplestats-mcp/pages.yml?branch=main&label=website" alt="Website build status"></a>
    <a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a>
    <a href="https://github.com/dsanchezp18/maplestats-mcp/actions/workflows/uptime.yml"><img src="https://img.shields.io/github/actions/workflow/status/dsanchezp18/maplestats-mcp/uptime.yml?branch=main&label=uptime" alt="Hosted server uptime check"></a>
    <a href="https://github.com/microsoft/pyright"><img src="https://img.shields.io/badge/types-Pyright-1674b1" alt="Type-checked with Pyright"></a>
    <a href="https://m8ven.ai/mcp/dsanchezp18/maplestats-mcp"><img src="https://m8ven.ai/badge/mcp/dsanchezp18/maplestats-mcp" alt="M8ven Score"></a>
    <a href="https://mcplookup.com/server/io.github.dsanchezp18/maplestats-mcp"><img src="https://mcplookup.com/badge/io.github.dsanchezp18/maplestats-mcp" alt="MCPLookup Trust Index"></a>
    <a href="https://glama.ai/mcp/servers/dsanchezp18/maplestats-mcp"><img src="https://glama.ai/mcp/servers/dsanchezp18/maplestats-mcp/badges/score.svg" alt="MapleStats MCP server quality and maintenance score on Glama"></a>
    <a href="https://mcprush.com/to/maplestats-mcp?ref=badge"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fmcprush.com%2Fbadge%2Fmaplestats-mcp%2Fshields.json&amp;query=%24.message&amp;label=mcprush&amp;color=BEF264&amp;labelColor=1A1A1A" alt="MapleStats MCP grade on Mcprush"></a>
    <a href="https://lobehub.com/mcp/dsanchezp18-maplestats-mcp"><img src="https://lobehub.com/badge/mcp/dsanchezp18-maplestats-mcp" alt="MapleStats MCP on LobeHub"></a>
    <a href="https://www.piwheels.org/project/maplestats-mcp/"><img src="https://img.shields.io/badge/piwheels-Raspberry%20Pi-C51A4A" alt="Wheels for Raspberry Pi on piwheels"></a>
    <a href="https://registry.modelcontextprotocol.io/?q=io.github.dsanchezp18/maplestats-mcp"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fregistry.modelcontextprotocol.io%2Fv0%2Fservers%2Fio.github.dsanchezp18%252Fmaplestats-mcp%2Fversions%2Flatest&query=%24.server.version&label=MCP%20Registry&prefix=v&color=blue" alt="MCP Registry version"></a>
  </p>
</p>

<!-- mcp-name: io.github.dsanchezp18/maplestats-mcp -->

MapleStats MCP gives AI agents (Claude, Cursor and any MCP client) typed
access to Canadian open data through one server: Statistics Canada
(tables, Census, public use microdata), the Bank of Canada, CMHC, federal
agencies, and federal, provincial, territorial and municipal open-data
portals, in English and French. Every figure comes back with its citation,
its quality flags and its licence, so an answer built on it can be traced to
the publisher and checked.

*MapleStats MCP donne aux agents IA un accès structuré aux données
ouvertes canadiennes par un seul serveur, en français et en anglais. Chaque
chiffre revient avec sa citation, ses indicateurs de qualité et sa licence.*

## Provenance and accountability

- **Every figure comes with its citation.** A Statistics Canada value carries
  its table and vector, reference period, release date, unit and scale,
  geography and a link to the table's page; a Bank of Canada value, its series
  id and the Valet URL. Every result's `provenance` block names the source,
  the exact URL and the time of the query. Results are brief by default (the
  values, citation, flags, caveats and limits, long row lists as CSV text);
  `detail="full"` on `call_tool` returns the complete `provenance` block and
  every field.
- **Quality flags are kept.** StatCan's "use with caution" and "too
  unreliable to be published", preliminary and revised stay on each value;
  public microdata tabulations give a CV and a quality grade per cell where
  the survey's user guide sets one; staff forecasts are marked as forecasts.
- **Gaps are named, not filled.** When a figure is not published or a period
  is not released yet, the server says so and points to the closest published
  figure. A date range that stops before the newest data gets a note that
  newer data exist.
- **Answers can be checked.** `check_answer` re-reads the StatCan and Bank of
  Canada figures an answer cites and reports only the problems.
  `reproduce_code` writes the R, Python, Stata or Julia script (or Excel Power
  Query) that pulls the same data straight from the publisher, and
  `reproduce_workbook` gives the rows.
- **Licences travel with the data.** Each result carries the publisher's
  licence, where it has one, and whether it allows commercial use
  (`provenance.commercial_use`; the AESO's market data, for one, are
  `not_allowed`).
- **StatCan's data and its documentation.** Besides tables and vectors, the
  server reaches definitions, methods and analysis (`statcan_reference_*`),
  the survey directory and IMDB metadata (`statcan_surveys_*`), PUMF codebooks
  and user guides (`statcan_pumf_*`), The Daily's articles and release tables
  (`statcan_daily_*`) and classifications (`rdaas_*`).
- **Measured.** On the 53 questions of the
  [Maple Test](https://maplestats.danielstats.io/benchmarks.html), MapleStats
  answered 91.8% correctly over three runs (November 3, 2026), with no false
  claims and no invented StatCan table or vector ids. Fifty-three questions are
  few, part of them were chosen from what MapleStats covers, and later
  MapleStats runs are in-sample ([details](https://github.com/dsanchezp18/maplestats-mcp/blob/main/tests/maple_test/README.md)).

## Why MapleStats

Built by a statistician, for anyone who works with the numbers: economists,
demographers, policy analysts, researchers, journalists, students, anyone who
needs a Canadian figure they can trust and cite. MapleStats is designed around
the mistakes people actually make with official data, and we test it against
other tools on public benchmarks: [see how it does](https://maplestats.danielstats.io/benchmarks.html).

- **It knows the traps.** Constant vs current dollars, family vs individual
  income, annual average vs December over December, survey rent vs listing
  rent: it warns in plain language, and each fitness-for-use caution rests on
  the publisher's own documentation.
- **It says when data do not exist.** A series that is not published, a period
  not released yet or a date with no data gets a plain no, and the nearest
  figure that does exist.
- **The answer can be checked.** Before replying, the assistant can send the
  StatCan and Bank of Canada figures it cites to `check_answer`, which re-reads
  them from the source.
- **Your work stays reproducible.** It writes the R, Python, Stata or Julia
  script, or the Excel query, that pulls the same data from the source.
- **Quality flags and revisions, shown:** "use with caution", "too unreliable
  to be published", preliminary and revised are spelled out on every StatCan
  value.
- **It only reads, in English and French.** The server only reads from public
  sources. The scripts it writes run only if you run them (the full-table ones
  then save the download under `data/raw/`), and saving a workbook to disk is
  opt-in (`MAPLE_EXPORT_DIR`, on a local server).

Project vision: [`docs/PROJECT_GUIDE.md`](https://github.com/dsanchezp18/maplestats-mcp/blob/main/docs/PROJECT_GUIDE.md).
Source coverage: [`docs/ROADMAP.md`](https://github.com/dsanchezp18/maplestats-mcp/blob/main/docs/ROADMAP.md).
Website: <https://maplestats.danielstats.io/>.

## The easiest way: ask your agent

1. Copy this prompt.
2. Paste it into Claude Code, Codex, Cursor or any agent that can run
   commands on your computer.
3. Restart the agent when it says so, then ask for data.

> Connect the MapleStats MCP server to this agent. Follow the setup steps in https://github.com/dsanchezp18/maplestats-mcp

### Instructions for the agent doing the setup

The default is the hosted server: nothing to install, no account, no key.

1. Register this remote (HTTP) MCP server under the name `maplestats`:
   - **Claude Code:** `claude mcp add --transport http --scope user maplestats https://mcp.maplestats.danielstats.io/mcp`
   - **Codex CLI:** `codex mcp add maplestats --url https://mcp.maplestats.danielstats.io/mcp`
   - **Cursor, Claude Desktop and other `mcpServers` clients:** add the entry
     below to the client's config file (Cursor: `~/.cursor/mcp.json`; Claude
     Desktop: `~/Library/Application Support/Claude/claude_desktop_config.json`
     on macOS, `%APPDATA%\Claude\claude_desktop_config.json` on Windows),
     keeping any servers already there.
   - **claude.ai and the Claude phone app:** on the web, open Settings →
     Connectors → Add custom connector, name it `MapleStats`, and enter
     `https://mcp.maplestats.danielstats.io/mcp`. Then switch it on from the tools
     menu in a chat, on the web or in the phone app. Claude asks for approval
     before each call by default; every tool is read-only, so set them to
     always allow in the connector's tool permissions.
   - **ChatGPT (web):** turn on Settings → Security and login → Developer mode,
     then create a developer-mode app for a remote MCP server with the same
     address and No Authentication. Every tool is read-only, so ChatGPT
     should not ask to confirm calls. OpenAI documents this feature for the web.
   - **A whole organization:** on Claude Team or Enterprise, an Owner adds it once
     under Organization settings → Connectors → Add custom connector, and each
     member then connects it. On ChatGPT Business, Enterprise or Edu, an admin
     turns on Developer mode (Workspace Settings → Permissions & Roles →
     Connected Data), creates the app, and publishes it (Workspace settings →
     Apps → Drafts → Publish). The hosted server is shared and limits each
     client to 60 requests a minute, so a large organization should run its own
     copy.
   - **VS Code:** the same entry under a `servers` key, with `"type": "http"`,
     in `.vscode/mcp.json`.

   ```json
   {
     "mcpServers": {
       "maplestats": {
         "url": "https://mcp.maplestats.danielstats.io/mcp"
       }
     }
   }
   ```
2. Tell the user to restart or reload the client, then check that the
   `search_tools` tool is listed.
3. Only if the client cannot use remote servers, or the user wants
   everything kept on their own machine, run it locally instead: `claude mcp add --scope user maplestats -- uvx maplestats-mcp`
   (needs [uv](https://docs.astral.sh/uv/)), or the equivalent `uvx
   maplestats-mcp` entry for other clients (see [Install](#install)).

Each client gets 60 requests a minute. Your agent's tool calls (a search phrase, a table number)
reach the server and its host, Microsoft Azure (Canada Central). The code keeps
no log of them, but its in-memory cache can hold a search phrase or filter in a
key or a response until the entry expires or the server restarts. Check
Microsoft's [terms](https://azure.microsoft.com/support/legal/) and [privacy statement](https://privacy.microsoft.com/privacystatement); for full privacy, run it locally. What it logs:
[FAQ](https://maplestats.danielstats.io/faq.html#hosted). Other
clients: the [Connect](https://maplestats.danielstats.io/connect.html)
page.

### Teach your agent to use it well

[`skills/maplestats/SKILL.md`](skills/maplestats/SKILL.md) is a portable
instruction file (Agent Skills format) for Claude Code, Codex, Cursor and
similar agents: start with `plan_query`, ask for the latest periods, read
the caveats, cite table, vector and release date, and run `check_answer`
before answering. Copy it into your agent's skills folder or project
instructions. It works with the hosted server and with a local one.

### Clients for R, Python and Julia

To call the hosted server from a script, with no agent in between, use the
small clients in [`clients/r`](clients/r/README.md),
[`clients/python`](clients/python/README.md) and
[`clients/julia`](clients/julia/README.md). Each returns a data frame with
its citation. They are not on CRAN, PyPI or the Julia registry yet; each
README gives the command to install from GitHub.
[`docs/clients.md`](docs/clients.md) explains the design.

## Install locally (optional)

Prefer to run it on your machine? It works over stdio with no account or key.

```bash
uvx maplestats-mcp                 # run without installing
uv tool install maplestats-mcp     # or install the command once (pip works too)
uv tool upgrade maplestats-mcp     # update
```

For the development version: `uv tool install git+https://github.com/dsanchezp18/maplestats-mcp.git`.
If you installed the command, use `"command": "maplestats-mcp"` with no
`args` in the JSON above. On Windows, make sure the directory where `uv`
installs tools is on `PATH`, and restart the client afterwards.

## Using it

Tools are found through search rather than listed flat: call
`search_tools` with a plain-language query (English or French), then
`call_tool` with the name it returns.

```json
{"name": "search_tools", "arguments": {"query": "consumer price index"}}
{"name": "call_tool", "arguments": {"name": "wds_search_cubes", "arguments": {"query": "consumer price index"}}}
```

`plan_query` turns a question into an ordered, multi-source plan, and
`reproduce_code` writes the R, Python, Stata or Julia script (or an Excel
Power Query) that fetches the same data straight from the source;
`reproduce_workbook` returns the rows as a formatted Excel workbook.
Before replying with figures, the assistant can call `check_answer` with the
StatCan and Bank of Canada figures it cites: it re-reads them from the source
and returns only the problems (a different value, a missed scale factor, a
newer period, another geography, an unadjusted series), each with a fix.
The `calc_` tools do the arithmetic across series that assistants get wrong,
from StatCan and Bank of Canada series, and return the formula and every
input's citation with the result: `calc_ratio` (one series over another,
aligned by period, scale factors applied), `calc_rank` (places ranked for one
period, ties shared), `calc_cagr` (compound annual growth between two periods)
and `calc_count_changes` (how many times a series moved, such as policy rate
decisions). Mismatched frequencies or units are refused, not guessed.
Every tool accepts `lang: "en"|"fr"`;
some sources only publish English content (for example Yukon's CKAN portal,
the World Bank's indicator definitions and the PMPRB), so there `lang`
changes the labels MapleStats adds, not the source's own text. Every response
has a `provenance` block: source, URL, query time, freshness and limits.
Through `call_tool` results are brief by default: values, periods, unit and
scale, the citation, status flags, caveats, limits, licence and URL, with a
list of six or more rows sent as one CSV text block (`{"format": "csv",
"csv": ...}`) and the boilerplate (query time, cache flag, schema name,
freshness, the reproduce hint) left out. Pass `detail="full"` for every field
and the whole `provenance` block, rows as JSON objects. `reproduce_code` and
`reproduce_workbook` always read the full result.
`docs://catalogue` describes every module in both languages. The guided
prompts take `lang` too, and each `docs://<module>/...` resource has a French
twin at `docs://<module>/fr/...` (for example `docs://statcan/fr/pieges`).

To call the sources from Python without MCP, see [`docs/library.md`](https://github.com/dsanchezp18/maplestats-mcp/blob/main/docs/library.md).

## What to watch for

MapleStats retrieves data directly from the original sources and returns
values as published. When a result is trimmed, scaled, cleaned or computed,
it says so in its `provenance` block or its notes; series values come
unscaled, with the scale factor beside them. When a source is down or blocks
the request, the tool returns an error, not a silent gap or a substitute
value.

The risk is in the use. An AI assistant can pick the wrong table, geography
or reference period, and the answers, summaries and analysis it writes are
AI-generated and can contain errors. For anything you would publish,
spot-check a few figures against the source's own site and use
`reproduce_code` to fetch them again outside the assistant. Publishers revise
their figures, so a value retrieved today can differ from an earlier one.

Each dataset keeps its own licence and attribution terms, shown in the
result's `provenance`; credit the publisher, not MapleStats. MapleStats is an
independent project, not affiliated with or endorsed by Statistics Canada,
the Bank of Canada, CMHC or any other data provider. It is provided as is,
depends on upstream services that can change or go offline, and is not
professional, legal or financial advice. Parts of the code and tests were
written with AI assistance; the discovery benchmark's questions were
written by one AI session and reviewed by a second, independent one, not yet
by a person
([`tests/discovery_benchmark/REVIEW.md`](tests/discovery_benchmark/REVIEW.md)).

## What it covers

488 tools in 93 modules. Read `docs://catalogue` (or `docs_read_resource` through `call_tool`) for the full, bilingual list.

| Area | Tool prefixes | Covers |
|---|---|---|
| Statistics Canada | `wds_`, `sdmx_`, `sdmx_space_`, `rdaas_`, `cimt_`, `statcan_*` | Tables and series, the extra SDMX spaces (energy information, shared data), classifications, Census Profiles 2001–2021, public use microdata (codebooks, weighted tables, standard errors where the survey's guide gives a method, the LFS included; SAS, SPSS and Stata files read), merchandise trade by commodity (CIMT), open databases (LODE), The Daily and the tables inside each release as first published, delta files, indicators, surveys, census geography |
| Bank of Canada | `boc_` | Valet series, groups, observations |
| CMHC | `cmhc_`, `cmhc_dt_` | Housing Market Information Portal and Excel data tables |
| Federal agencies | `eccc_`, `eccc_coverages_`, `eccc_datamart_`, `ised_*`, `gazette_`, `tc_recalls_`, `recalls_`, `cdc_`, `cfia_`, `fcac_`, `finance_`, `cihi_`, `cihi_workforce_`, `phac_infobase_`, `hc_*`, `pmra_`, `pmprb_`, `gc_infobase_`, `disclosure_`, `cer_`, `nrcan_*`, `dfo_iwls_`, `dfo_landings_`, `cgc_`, `nfd_`, `ircc_*`, `cbsa_`, `cbsa_tariff_`, `pbo_`, `competition_bureau_`, `elections_results_`, `elections_financial_returns_`, `cra_digital_economy_registry_`, `cra_charities_`, `jobbank_`, `telecom_`, `earthquakes_`, `borealis_`, `isc_` | Weather, climate and gridded climate projections, pollutant releases and emissions (NPRI, GHGRP, NAPS), corporations and IP, regulations, recalls, dairy, animal disease, consumer banking, federal and provincial fiscal tables, health, health workforce (CIHI: physicians, nurses, pharmacists, therapists), drugs, natural health products, medical devices, adverse reactions, pesticides, spending, federal contracts, grants and travel and hospitality disclosures, energy, energy use by sector (NRCan, to 2023), mineral production, oceans, commercial fisheries landings, grain, forestry, immigration and application processing times, Job Bank wages and outlooks by occupation, registered charities, mobile and Internet plan prices, border wait times, customs tariff rates, budgets, mergers, elections, earthquakes, university-library data tables, First Nation profiles, registered population and drinking water advisories |
| Wildland fire | `cwfis_`, `nrcan_nbac_`, `ab_wildfire_` | NRCan's Canadian Wildland Fire Information System (satellite hotspots, fire danger, weather stations), burned areas, and Alberta Wildfire's live fire status |
| Electricity | `electricity_ontario_`, `electricity_quebec_`, `electricity_alberta_`, `oeb_` | IESO (Ontario) demand, generation and prices; Hydro-Québec demand, generation and trade (CC BY-NC 4.0: credit Hydro-Québec, non-commercial use only); AESO (Alberta) hourly, daily and monthly pool prices, load and current generation by fuel (AESO terms: non-commercial use only); Ontario Energy Board datasets |
| Parliament and elected officials | `ourcommons_`, `senate_`, `represent_` | MPs and their roles, party standings, Cabinet, Senate votes; elected officials and districts for a postal code via Open North's Represent (unofficial) |
| Provincial agencies | `aer_`, `bcer_`, `bcgw_`, `bc_stats_`, `bc_env_`, `bc_lobbyists_`, `drivebc_`, `ab_economic_`, `ab_opendata_`, `isq_`, `nl_stats_`, `yukon_stats_`, `nwt_stats_`, `elections_provincial_`, `on_fir_` | Alberta Energy Regulator (well licences, production, ST98 energy outlook), BC Energy Regulator bulk well files (well index, monthly production by well zone, drilling, hydraulic fracture and directional survey records, facilities; BCER states no licence for them, so use them for personal or internal analysis and check with BCER before redistributing), BC Geographic Warehouse, BC Stats Excel tables, BC environmental monitoring (air quality, snow, groundwater, streamflow), BC lobbyists registry, DriveBC road events, Alberta Economic Dashboard, Open Alberta files, Institut de la statistique du Québec, the Newfoundland and Labrador, Yukon and Northwest Territories statistics bureaus, provincial general election results (Quebec, Alberta, British Columbia, Saskatchewan, Manitoba), Ontario's municipal Financial Information Return (every schedule of every municipality, 2000 on) |
| Housing (links only) | `crea_` | Links, release timing and terms for CREA's MLS® Home Price Index; no values, because CREA's terms allow private, non-commercial analysis only |
| International | `worldbank_`, `imf_`, `bis_`, `oecd_`, `eurostat_`, `ilo_`, `abs_`, `ons_`, `fed_`, `ecb_`, `fred_` (needs `FRED_API_KEY`) | World Bank World Development Indicators for Canada and peer countries (CC BY 4.0); International Monetary Fund datasets for Canada and peers: consumer prices, exchange rates, balance of payments, labour statistics, national accounts, World Economic Outlook, commodity prices, each result labelled as the IMF's own figures, not Statistics Canada's (copying allowed with the IMF credited; commercial reuse needs the IMF's permission, so each result is flagged `not_allowed`); Bank for International Settlements statistics: policy rates, debt service ratios, credit, house prices, banking and payment statistics (free reuse with citation); OECD Data Explorer for Canada and its peers: Economic Outlook projections, productivity, unit labour costs, PPPs, tax revenue, house prices, leading indicators (any use with credit, third-party data excepted); Eurostat for the EU, the euro area and member states (CC BY 4.0, not commercially for non-EU countries' data); ILOSTAT, the International Labour Organization's internationally comparable labour statistics for Canada and its peers: unemployment, participation, hours, earnings, minimum wages and ILO modelled estimates (CC BY 4.0); the Australian Bureau of Statistics' headline inflation, labour force, GDP, wage and population series, each with the Canadian table to pair with, and any ABS dataset by SDMX key (CC BY 4.0); the UK Office for National Statistics' headline inflation, GDP and labour market series, each with the Canadian table to pair with (Open Government Licence v3.0); US Federal Reserve Board releases: the federal funds rate, Treasury yields, the Canadian dollar per US dollar, industrial production and capacity utilization, money and credit (public domain, Board cited); European Central Bank Data Portal: key interest rates, €STR, euro reference rates (EUR/CAD), euro area HICP, money and credit (free reuse with 'Source: ECB statistics', third-party data excepted); optionally `fred_` (3 tools), the St. Louis Fed's FRED, which exists only on a server whose operator sets `FRED_API_KEY` (a free key they create at FRED; MapleStats never ships or asks for one) and is hidden everywhere else: FRED's notice is on every result, and series it marks Copyright are described without their values |
| Open-data portals | `ckan_`, `arcgis_hub_`, `socrata_` + `portal` | Federal, provincial, territorial and municipal catalogues (`*_list_portals` names each one) |
| Other municipal | `opendatasoft_vancouver_`, `nl_opendata_`, `eps_`, `ets_`, `epcor_`, `bc_transit_`, `toronto_` | Vancouver, Newfoundland and Labrador, Edmonton police, transit and water quality, BC Transit real-time vehicle positions, arrival predictions and service alerts, City of Toronto neighbourhood profiles, RentSafeTO building scores, short-term rental registrations and DineSafe inspections |
| Transit schedules | `transit_` + `agency` | Static GTFS timetables of the STM (buses), OC Transpo, Calgary Transit, VIA Rail, GO Transit, UP Express, the BC Transit systems and the Quebec networks listed on Données Québec (exo, RTC, STL, STS and others), plus further agencies from Statistics Canada's 2025 Canadian Public Transit Network Database: stops, routes, scheduled departures, frequency by hour |

Other federal series (CRA, OSFI, ISED insolvency) are ordinary
open.canada.ca datasets, reachable with
`ckan_search_datasets(portal="federal", fq="organization:<org>")`.

Statistics Canada's bot check (November 2026): StatCan now answers some
automated requests with a check only a person in a web browser can pass. It
blocks the SDMX service, trade by HS commodity (CIMT), The Daily's RSS feeds,
the catalogue and publication pages, the census site (www12) and, on some
networks, the full-table files. MapleStats does not try to get past it. The Web
Data Service still answers scripts, so the SDMX tools read the same series from
it, `wds_get_full_table_download` returns a Python script that rebuilds a table
through it, and a result whose refresh is blocked comes back from the last good
copy, labelled with its date. `statcan_check_access` says which services answer
now; details in [docs/findings/statcan-captcha-2026-11.md](docs/findings/statcan-captcha-2026-11.md).
`plan_query` and `search_tools` use what the server saw: a tool with no other
route on a path that answered with the check in the last 15 minutes (the CIMT
tools, and the StatCan reference and PUMF catalogue tools) is marked
`blocked: true`, listed after the ones that work, and `plan_query` puts the
working route first (the same data through WDS, labelled). They send no request
and probe nothing: the paths are noted from real calls and from
`statcan_check_access`, and forgotten after 15 minutes or when the path answers.
Nothing is marked while no path has been seen blocked.

Not covered: CAPP's Statistics Handbook, Petrinex and Payments Canada were
not built, because their terms or download hosts do not permit automated
access. CanadaBuys, OpenParliament.ca and the Toronto Transit Commission's
own schedule download were removed for the same reason (the TTC schedule is
still served from Statistics Canada's national transit database). The City
of Whitehorse's open data files are not built: its terms bar commercial
reproduction without the City's written consent. The City of Toronto's
files (as opposed to its DataStore tables) are not read: its portal's robots.txt
disallows automated file downloads. The
City of Hamilton's portal is left out because it answers automated requests
with a Cloudflare challenge (Niagara Open Data did too until 2026-11-08, and is
now covered). The 2006-2016 census data tables and the 2016 Census Profile service were removed because Statistics Canada's www12 host answers automated clients with a bot challenge, 503 errors or timeouts (the 2021 profile and the WDS tables remain, and `statcan_census_profile_archive_*` still lists the links to the 2001-2016 Census Profile bulk files without opening them; the 1996-2021 Census GeoSuite geography tables are read from MountainMath's checked re-host, `statcan_geosuite_*`). Justice Laws (federal statutes and
regulations) is out of scope, because legislation text is not data this
server carries, and the Saskatchewan Bureau of Statistics' Provincial
Economic Accounts were not built: they are under Crown copyright, for
non-commercial reuse only, and the site's terms bar automated access. The
BC Energy Regulator's bulk well, production and drilling files (`bcer_`) are built, but their terms are unresolved:
BCER states no licence for them and its website terms ask for written permission before the material is
reproduced or redistributed, so each result says to use it for personal or internal analysis, carries
`commercial_use: unknown` and asks you to check with BCER before redistributing. The
[roadmap](https://github.com/dsanchezp18/maplestats-mcp/blob/main/docs/ROADMAP.md)
records each decision.

## Development

```bash
uv sync                          # install
uv run ruff check src tests scripts  # lint
uv run ruff format src tests scripts  # format
uv run pyright                   # type check
uv run pytest                    # unit tests (mocked, no network)
```

`.\scripts\verify.ps1` runs that gate plus every `scripts/smoke_test*.py`
against the live APIs. The website is generated from the tool registry:
`uv run python scripts/build_site.py` writes `build/site/`. See
[`AGENTS.md`](https://github.com/dsanchezp18/maplestats-mcp/blob/main/AGENTS.md)
for the contributor guide and how to add a source module.

## Hosting

`MAPLE_TRANSPORT=http MAPLE_HOST=0.0.0.0 MAPLE_PORT=8000 uv run maplestats-mcp`
serves HTTP instead of stdio. Docker Compose does the same in Docker, but the
image and `docker-compose.yml` set `MAPLE_REQUIRE_AUTH=1`, so the server refuses to
start until `MAPLE_AUTH_TOKEN` is set:
`MAPLE_AUTH_TOKEN=<a long random string> docker compose up --build`. Clients
then send that token as a bearer token. Docker is optional and unnecessary on
a personal computer. If the server is exposed beyond your machine, set
`MAPLE_AUTH_TOKEN` and keep `MAPLE_REQUIRE_AUTH=1`. `GET /health` reports uptime and version. `GET /stats`
is public, needs no token and reports calls per tool name and day, each tool's
p50 and p95 duration, and each upstream host's error counts and circuit-breaker
state (see `MAPLE_USAGE_STATS` and `MAPLE_BREAKER` below). After repeated
failures (timeouts, connection errors, 5xx answers) a host is paused for a
cooldown: its tools fail at once with an "unavailable" error that says when to
retry, instead of waiting for another timeout. The `docs://status` resource
lists the paused hosts.

A Cloudflare challenge is counted in `/stats` but never pauses a host, and it is
reported as a block, not an outage: a retry in a minute does not clear it.
Statistics Canada's `www150.statcan.gc.ca` host answers some paths (SDMX, CIMT)
with one while its Web Data Service answers scripts, so pausing the host would
cut off what works (`statcan_check_access` shows what answers now). The error
says the host is challenging automated clients, not to retry, and what still
works (the 2021 census profile and the CCEI and shared SDMX spaces on
`api.statcan.gc.ca`, `geo.statcan.gc.ca`, the Bank of Canada, CMHC, the
provincial modules and the OECD). MapleStats does not try to get past a
challenge (no disguised User-Agent, headless browser, proxy or cookies); it
recognises the challenge, by its `Cf-Mitigated: challenge` header or, without
it, by the page title ("Just a moment", "Security Check", "Vérification de
sécurité"), and reports it.

| Env var | Default | Purpose |
|---|---|---|
| `MAPLE_TRANSPORT` | `stdio` | `stdio` for local clients, `http` for hosting |
| `MAPLE_HOST` / `MAPLE_PORT` | `127.0.0.1` / `8000` | HTTP bind address |
| `MAPLE_AUTH_TOKEN`, `MAPLE_REQUIRE_AUTH` | unset, `0` | Bearer token required on `/mcp`; refuse to start without one if `1`. The Docker image and `docker-compose.yml` default `MAPLE_REQUIRE_AUTH` to `1` |
| `MAPLE_RATE_LIMIT_REQUESTS` / `MAPLE_RATE_LIMIT_WINDOW_SECONDS` | `120` / `60` | Per-client rate limit |
| `MAPLE_MAX_CONCURRENT_REQUESTS` | `8` | In-flight request cap; the excess waits 5 s, then gets 503 |
| `MAPLE_MAX_REQUESTS_PER_CLIENT` | `0` (off) | In-flight requests one client (IPv6: one /64) may hold; past it, 429. Leave off where many people share an address |
| `MAPLE_SSL_CERTFILE` / `MAPLE_SSL_KEYFILE` | unset | TLS in-process |
| `MAPLE_TRUST_PROXY_HEADERS` | `0` | Rate-limit on `X-Forwarded-For`; only behind a proxy that sets it |
| `MAPLE_TRUSTED_PROXY_HOPS` | `1` | Proxies that append to `X-Forwarded-For`; the client address is read that many entries from the right |
| `MAPLE_ALLOWED_ORIGINS` | project website, localhost | Browser origins allowed on `/mcp` (comma-separated, `*.` and `:*` wildcards); others get 403, clients without an Origin are allowed |
| `MAPLE_CACHE_MAX_ENTRIES` | `2000` | Response cache size per TTL bucket |
| `MAPLE_CACHE_MAX_MB` | `128` | Estimated memory cap for the response cache, all buckets together |
| `MAPLE_LAST_GOOD_MB` | `32` | Memory for the last good copy of each result, served (with its date) when a refresh meets a bot check; 0 turns it off |
| `MAPLE_PARSE_WORKERS` / `MAPLE_PARSE_TIMEOUT_SECONDS` | `4` / `60` | Threads for parsing Excel and CSV files, and the time one parse may take |
| `MAPLE_TOOL_TIMEOUT_SECONDS` | `120` | Longest a tool call may run |
| `MAPLE_OCR`, `MAPLE_OCR_MEMORY_MB` | `0`, `1024` | `1` lets `statcan_reference_get_section_text` read the pages of a scanned PDF (no text layer) by OCR: the `[ocr]` extra (`pip install "maplestats-mcp[ocr]"`, pypdfium2) and the system's `tesseract` program with its English and French data (the Docker image has both) must be installed; otherwise those pages come back empty with a note. One page is read at a time, 10 pages at most per call (5 by default), within the 40 s PDF budget, at up to 12 megapixels a page. The memory value caps the tesseract child's address space (enforced on Linux only; `0` turns it off) |
| `MAPLE_BREAKER` | `1` | Pause requests to an upstream host after repeated failures; `0` sends every request |
| `MAPLE_BREAKER_FAILURES` / `MAPLE_BREAKER_WINDOW_SECONDS` / `MAPLE_BREAKER_COOLDOWN_SECONDS` | `5` / `300` / `60` | Failures in a row, within the window, that pause a host, and how long before one probe request is sent |
| `MAPLE_STATCAN_FALLBACK` | `1` | When Statistics Canada's Web Data Service answers a `wds_get_data_from_vectors`, `wds_get_data_from_cube_coord` or `wds_get_series_info` call with the Cloudflare challenge (and no last good copy is held), answer from another official source instead, labelled in `provenance` (source, url, `substituted_for`, caveats): StatCan's CCEI and shared SDMX spaces on api.statcan.gc.ca, the Bank of Canada's Valet API for the CPI vectors it carries, or the Alberta Economic Dashboard's copy of a table. StatCan is always asked first; `0` turns the substitutes off |
| `MAPLE_PUMF_TABULATE` | `1` | `0` hides `statcan_pumf_tabulate` (it downloads whole PUMF ZIPs); search, listings and codebooks stay |
| `MAPLE_QUERY_SERIES` | `1` locally, `0` over HTTP | `0` hides `wds_query_series` (server-side SQL): off by default when serving HTTP, since one query could use more memory than a small instance has |
| `MAPLE_GIS` | `1` | `0` runs a statistics-only profile from the same install: the 14 pure geospatial tools (`bcgw_*`, `eccc_coverages_*`, `nrcan_geo_*`, `nrcan_nbac_query_fires`, the three census boundary tools of `statcan_geo_*` and the two fire-perimeter tools) leave `search_tools`, `plan_query`, the server instructions and `docs://catalogue`, and a call by name reads as an unknown tool. Tools that serve rows or figures from a map service (ArcGIS Hub, ECCC observations, fire points) stay. Nothing is hidden by default |
| `MAPLE_PRELOAD` | `0` locally, `1` over HTTP | `1` imports every module and builds the search index at startup, before the port opens, so the first calls after a start are not slow; off locally so desktop clients start fast |
| `MAPLE_PUMF_CACHE_DIR`, `MAPLE_PUMF_CACHE_MAX_GB` | system temp, `5` | Downloaded microdata cache; use a persistent volume when hosted |
| `MAPLE_CLIENT_IP_HEADER` | unset | Header the outermost proxy sets to the caller's own address (Cloudflare's `CF-Connecting-IP`), used for the per-client rate limit when `MAPLE_TRUST_PROXY_HEADERS` is on; set it only when every request passes through that proxy |
| `MAPLE_DUCKDB_MEMORY_LIMIT` | unset | Memory limit for DuckDB queries over downloaded files (patents, open databases, microdata), such as `256MB`; beyond it DuckDB spills to the temporary folder. Set it on a small hosted instance |
| `MAPLE_DUCKDB_TEMP_DIR`, `MAPLE_DUCKDB_TEMP_MAX_GB` | system temp (`maplestats-duckdb`), `1` | Where DuckDB spills past its memory limit (each query in its own subfolder, removed when it ends), and the most one query may spill |
| `MAPLE_QUERY_MEMORY_MB`, `MAPLE_QUERY_MAX_CONCURRENT` | `256`, `2` | `wds_query_series` runs each SQL query in its own process: the memory it may use beyond its start (enforced on Linux), and how many run at once |
| `MAPLE_LODE_CACHE_DIR`, `MAPLE_LODE_CACHE_MAX_GB` | system temp, `3` | Where StatCan open-database (LODE) archives are unpacked, and the size cap (least recently used files go first); use a persistent volume when hosted |
| `MAPLE_LODE_MAX_DOWNLOAD_MB` | `300` | Largest open-database archive one call may download; `0` turns downloads off |
| `MAPLE_IP_HORIZONS_CACHE_DIR`, `MAPLE_IP_HORIZONS_CACHE_MAX_GB` | system temp, `3` | CIPO patent table cache |
| `MAPLE_CBSA_TARIFF_CACHE_DIR` | system temp | Customs Tariff editions as Parquet (under 1 MB each, newest 12 kept) |
| `MAPLE_CENSUS_CACHE_DIR` | system temp | Census profile values kept between restarts: one file of at most 8 MB, each value 14 days (a census request takes 33 to 47 s); `off` keeps them in memory only; use a persistent volume when hosted |
| `MAPLE_ON_FIR_CACHE_DIR`, `MAPLE_ON_FIR_CACHE_MAX_MB` | system temp, `500` | Ontario FIR years kept as Parquet (about 3 MB each); use a persistent volume when hosted |
| `MAPLE_EXPORT_DIR` | unset (no files saved) | Folder where `reproduce_workbook` saves Excel workbooks on a local server. Unset, the workbook comes back as base64 and every tool is read-only |
| `MAPLE_SEARCH`, `MAPLE_SEMANTIC_DIR` | `bm25`, unset | `hybrid` fuses BM25 with a local multilingual-e5-small index (needs the `[semantic]` extra and `python -m maplestats_mcp.shared.semantic build`); off by default, see `tests/discovery_benchmark/phase2.md` |
| `MAPLE_RESPONSE_MAX_BYTES` | `200000` | Byte budget for one tool result (minimum 10,000); a larger result has its biggest lists trimmed, and `provenance.limits` says what was kept and how to get the rest |
| `MAPLE_GOATCOUNTER_URL`, `MAPLE_GOATCOUNTER_TOKEN` | unset | With both set (an https GoatCounter site and an API token allowed to record pageviews), each counted tool call is also sent there as the event `mcp/<instance>/<tool>` (`/error` appended on failure), in batches each minute, so counts outlive restarts and several hosts add up; no arguments or addresses, `no_sessions` on |
| `MAPLE_INSTANCE_NAME` | `server` | The `<instance>` label in those events (`azure`, `render`) |
| `MAPLE_OPENAI_APPS_CHALLENGE` | unset | Token served as plain text at `GET /.well-known/openai-apps-challenge` (no auth), which OpenAI's plugin portal fetches to verify the domain; unset, that path answers 404 |
| `MAPLE_USAGE_STATS` | `1` | Counts calls and durations per tool name and UTC day, each failure's error code (`not_found`, `invalid_input`, ...: a fixed list, never the message), and upstream errors per host (never arguments or client addresses), in memory, and serves them at the public `/stats` route; `0` turns both off |
| `MAPLE_INTERNAL_TOKEN` | unset | A secret that marks your own calls in the `/stats` counts: a client that sends it in an `X-Maple-Internal` header is counted under the client label `internal` (`/stats` also gives `calls_excluding_internal`), so your use and benchmark runs do not mix with other people's. Every other call is labelled by the kind of client (`claude-code`, `cursor`, `python-fastmcp`, ... or `other`), matched from the name the client announces when it connects, or from a `?client=` value on the endpoint URL (the chat demo adds `?client=maplestats-chat`), against a fixed list; neither the name nor the token is stored. Unset labels nothing internal |
| `MAPLE_USAGE_STATS_FILE` | unset | A JSON file the `/stats` call counts and error codes (per tool and per UTC day, kept 400 days) are read from at startup and saved to every minute and on exit, so a restart or deploy does not reset them; point it at a persistent volume. Several processes saving to one file add up rather than overwrite each other. Latencies stay in memory |
| `MAPLE_DELTA_MAX_SCAN_MB` / `MAPLE_DELTA_MAX_SCAN_SECONDS` | `400` / `75` | How much of a Delta File one `statcan_delta_read_table` call streams (seconds kept 30 under the tool timeout) |
| `MAPLE_DELTA_INDEX_DIR` | system temp | Saved Delta File resume points (a few MB per day); `off` keeps them in memory only |

## License

MIT. Third-party notices are in [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md).

## Security and conduct

Report a vulnerability privately through GitHub's
[private vulnerability reporting](https://github.com/dsanchezp18/maplestats-mcp/security/advisories/new);
see [`SECURITY.md`](SECURITY.md). Changes are recorded in
[`CHANGELOG.md`](CHANGELOG.md), and community expectations in
[`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).

## Acknowledgments

MapleStats owes its architecture to
[EcuDataMCP](https://github.com/DweskZ/EcuDataMCP), the MCP server for
Ecuador's open data that I help maintain with
[DweskZ](https://github.com/DweskZ) and its other contributors. Its
approach to Canadian data owes much to the R developers who got there
first: Jens von Bergmann ([mountainMath](https://github.com/mountainMath))
and his co-authors, including Dmitry Shkolnik
([dshkol](https://github.com/dshkol)), Thierry Warin ([statcanR](https://github.com/warint/statcanR)), Valentin
Lucet ([rgovcan](https://github.com/VLucet/rgovcan)), and others. Thanks
to them, and to everyone who publishes Canadian data in the open.

For other ways to get Canadian data, see the
[alternatives](https://maplestats.danielstats.io/about.html#alternatives).
