# Statistics Canada MCP Server [Health: Active]

**Category:** 📊 Data Platforms  
**Repository:** https://github.com/Aryan-Jhaveri/mcp-statcan  
**GitHub Stars:** 8  
**Views:** 12  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/statistics-canada-mcp-server

## Description
Access Statistics Canada data via the Web Data Services API

## Tools
Capabilities this server exposes over MCP:

- **search_cubes_by_title** — Find StatCan tables by title keywords. Returns productId, title, dates and
frequency; each includes key_template, the dimension order of the SDMX key.
- **get_sdmx_structure** — A table's dimensions in key order with their codes (id, name, parent).
Use search to find the codes for labels like 'Ontario' instead of guessing.
- **get_sdmx_data** — Observations for productId + key, or one vectorId. Over 100 observations you get a
per-series summary. Pass sql to compute over every row (growth, averages, ranking)
server-side. Cite _sdmx_url.
- **get_series_info** — Series metadata for productId + coordinates, or vectorIds: vectorId, key, title,
frequency, unit of measure and scalar (decoded), decimals.
- **get_changes** — What StatCan released: tables updated on a date (default today), or today's new
data points for one series (vectorId, or productId + coordinate).
- **fetch_vectors_to_database** — PREFERRED tool for multi-series analysis. Fetches data for multiple StatCan
vector IDs in a single API call and immediately stores the results in a SQLite
table — no separate create/insert steps needed.

*** USE THIS TOOL whenever you need data for multiple provinces, age groups,
industries, or any other breakdown. It replaces the slow pattern of calling
get_data_from_cube_pid_coord_and_latest_n_periods once per series. ***

Typical workflow:
  1. search_cubes_by_title("unemployment rate") → find productId
  2. get_series_info(productId=..., ...) → find vectorIds for each series you want
  3. fetch_vectors_to_database(
       vectorIds=["v111","v222","v333"],
       table_name="unemployment_by_province",
       startRefPeriod="2023-01-01",
       endRefPeriod="2024-12-31"
     )  ← single call fetches + stores everything
  4. query_database("SELECT * FROM unemployment_by_province") → analyze

Args:
    input_data.vectorIds: List of vector IDs to fetch (strings, e.g. ["111","222"]).
    input_data.table_name: SQLite table to create and populate.
    input_data.startRefPeriod: Optional start date (YYYY-MM-DD).
    input_data.endRefPeriod: Optional end date (YYYY-MM-DD).

Storage: observations are upserted into the shared store (_statcan_series +
_statcan_observations) and table_name becomes a VIEW with columns: dimension labels
(when the series was also fetched via SDMX), series_key, period, ref_date, value,
VECTOR_ID, UOM, SCALAR_FACTOR, STATUS, SYMBOL, release_time, product_id, fetched_at.
The same series fetched via fetch_sdmx_to_database shares rows with this tool.

Returns:
    Dict with view name, columns, rows_inserted, new/revised/unchanged counts, and a
    small sample so you can verify the data looks right before querying.

IMPORTANT: In your final response cite the vectorIds and reference period used.
- **fetch_sdmx_to_database** — PREFERRED tool for storing SDMX data. Fetches observations for a productId + key
via SDMX and writes ALL rows straight into a SQLite table — the rows never pass
through your context, and the MAX_SDMX_ROWS (500) cap does not apply.

*** Use this instead of get_sdmx_data → create_table_from_data. Do NOT copy rows
from get_sdmx_data into create_table_from_data — that sends every row through
the context window twice. ***

Same key syntax and time parameters as get_sdmx_data (see that tool for wildcard
and OR-key rules). lastNObservations cannot be combined with startPeriod/endPeriod.

Typical workflow:
  1. search_cubes_by_title("consumer price index") → productId
  2. get_sdmx_structure(productId=...) → dimension positions + codes
  3. fetch_sdmx_to_database(productId=18100004, key="2+3+4.2",
                            startPeriod="2020-01", table_name="cpi_by_province")
  4. query_database("SELECT ... FROM cpi_by_province ...") → analyze

Storage: observations are upserted into the shared store (_statcan_series +
_statcan_observations, one row per series and period, with source and fetch time),
and table_name becomes a VIEW over the series and periods this call fetched.
Re-fetching updates values in place; new/revised/unchanged report what changed.
For cross-table analysis, query the store directly, e.g.
  SELECT o.period, o.value FROM _statcan_observations o
  JOIN _statcan_series s USING (series_id) WHERE s.product_id = 18100004

Returns a compact summary: view name, columns, rows_inserted, series_count,
period range, new/revised/unchanged counts, a small sample, and the _sdmx_url.

IMPORTANT: In your final response, cite the _sdmx_url, productId and key used.
- **store_cube_metadata** — Fetches FULL metadata for a cube and stores it into two normalized SQLite
tables (_statcan_dimensions, _statcan_members) without returning the full
data to the context window.

Use this when you need to browse all dimension members or look up vectorIds.
Table structure tools (get_sdmx_structure) list only the first few members per dimension —
call this tool first, then use SQL to drill into specific dimensions.

Typical workflow:
  1. store_cube_metadata(productId=1234567)
     → stores all members + vectorIds, returns compact summary
  2. query_database("SELECT * FROM _statcan_dimensions WHERE pid = 1234567")
     → see all dimension names and member counts
  3. query_database("SELECT member_name_en, vector_id FROM _statcan_members
                     WHERE pid = 1234567 AND dim_index = 2")
     → browse all members for a specific dimension
  4. fetch_vectors_to_database(vectorIds=[...], ...) → fetch the data

Tables are shared across multiple pids — calling this for a new pid adds
rows without affecting data for other pids already stored.

Returns a compact summary: dimension names + member counts + example SQL.

IMPORTANT: Cite the productId and cubeTitleEn in your final response.
- **create_table_from_data** — Creates a new SQLite table from the provided data AND immediately inserts all rows.
Infers column names and types from the first item in the data list.
WARNING: Overwrites the table if it already exists.

Use this as a single step to store fetched API data — no need to call
insert_data_into_table afterwards. Use insert_data_into_table only to
append more rows to an already-existing table.

Args:
    table_input: Object containing table_name and data (list of dicts).

Returns:
    Dict[str, Any]: A summary with table name, columns created, and rows inserted.

IMPORTANT: The database is persistent and does NOT clean itself automatically.
This tool overwrites the table if it exists, giving you a clean slate each call.
- **insert_data_into_table** — Appends rows (list of dicts) into an ALREADY EXISTING SQLite table.
Use this only to add more data to a table that was previously created.

For the common "fetch API data then store" workflow, use create_table_from_data
or fetch_vectors_to_database instead — both create the table AND insert data
in a single call, so you do NOT need to call this tool after them.

This tool is useful when:
- You want to merge data from multiple API calls into one table
- You're appending new time periods to an existing dataset

Args:
    table_input: Object containing table_name and data (list of dicts).

Returns:
    Dict[str, str]: A dictionary indicating success (with row count) or failure.

IMPORTANT: In your final response to the user, you MUST cite the source of the data you are inserting
if it comes from an API call (e.g., "Data from Product ID 123456").
- **list_tables** — Lists all user-created tables and views in the SQLite database, plus the size of
the canonical observation store.

fetch_sdmx_to_database and fetch_vectors_to_database create VIEWS (listed under both
"tables" and "views") over the shared store tables _statcan_series and
_statcan_observations, which you can also query directly for cross-table analysis.

Returns:
    Dict[str, Any]: {"tables": [all table and view names], "views": [view names],
    "store": {"series": n, "observations": n}} or an error message.

IMPORTANT: The database is persistent. Use this to check for old tables that might need cleaning.
- **get_table_schema** — Retrieves the schema (column names and types) for a specific table.

Args:
    table_name_input: Object containing the table_name.

Returns:
    Dict[str, Any]: Dictionary describing the schema or an error message.
- **drop_table** — Permanently deletes (drops) a table or view from the SQLite database.

Use this to free up space or remove tables that are no longer needed.
This action is irreversible — all data in the table will be lost. Dropping a
view created by a fetch tool removes only the view; its observations stay in
the shared store. The store tables themselves (_statcan_series,
_statcan_observations) can't be dropped with this tool.

Args:
    table_name_input: Object containing the table_name to drop.

Returns:
    Dict[str, Any]: A dictionary indicating success or an error message.
- **query_database** — Executes a read-only SQL query (SELECT or PRAGMA) against the database and returns the results.
WARNING: Potential security risk! Avoid using this tool with untrusted input
or queries that modify data (INSERT, UPDATE, DELETE). Prefer more specific tools
like list_tables or get_table_schema when possible. Results may be truncated.

Args:
    query_input: Object containing the sql_query string.

Returns:
    Dict[str, Any]: Dictionary with 'columns', 'rows' (list of dicts), and optionally a 'message', or an error message.

IMPORTANT: In your final response to the user, you MUST cite the source of your data (e.g., "Query results from table 'my_analysis'").

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "statistics-canada-mcp-server": {
    "command": "uvx",
    "args": ["statcan-mcp-server"]
  }
}
```

## Documentation

## What Statistics Canada MCP Server does

Statistics Canada MCP Server exposes Statistics Canada's Web Data Services (WDS) and SDMX REST API through MCP. Agents can search table titles, inspect a cube's dimensions and member codes, retrieve observations, identify series metadata, and check changes released on a date. Results can include source details such as the SDMX URL, product ID, key, vector ID, period, unit, scalar, and status information.

The server also provides a standalone `statcan` command-line interface for searching tables, inspecting metadata, downloading data, and viewing a machine-readable command reference without using an LLM.

## How it works

A typical data-discovery flow starts with `search_cubes_by_title`, followed by `get_sdmx_structure` to learn the dimension order and valid codes. `get_series_info` can then resolve vector IDs and series details for selected coordinates. Agents can retrieve observations directly with `get_sdmx_data`, including server-side SQL calculations for larger result sets, or use `get_changes` to inspect recent updates.

For analysis across multiple provinces, age groups, industries, or other series, `fetch_vectors_to_database` fetches several vector IDs in one API request and exposes the results through a SQLite view. `fetch_sdmx_to_database` performs the same storage-oriented workflow for an SDMX product and key. Both tools write to shared canonical series and observation tables, report new, revised, and unchanged rows, and return compact samples for verification.

## Setup and configuration

The hosted endpoint is available at `https://mcp-statcan.com/mcp` and can be configured as a custom HTTP connector. Claude Desktop, Claude Code, Cursor, and VS Code examples are provided for this endpoint. The hosted deployment includes WDS and SDMX tools; SQLite database tools require local execution.

For a local HTTP deployment, install or run the package with `uvx statcan-mcp-server --transport http`, then connect a client to `http://localhost:8000/mcp`. A full local stdio deployment runs `uvx statcan-mcp-server` and supports the database features. The database location can be set with the `--db-path` argument. Python 3.10 or newer is supported.

The CLI can be run with `uvx statcan-mcp-server`, followed by commands such as `statcan search`, `statcan metadata`, or `statcan download`.

## Tools and capabilities

- Search Statistics Canada cubes by title keywords.
- Inspect SDMX dimensions, member codes, and key order.
- Retrieve observations by product ID and key or by vector ID.
- Compute SQL expressions across returned series on the server.
- Resolve series titles, frequencies, units, scalar factors, and decimal settings.
- Check tables or series for newly released data.
- Store vector-based or SDMX-based observations in SQLite-backed views.
- Store complete cube metadata in normalized dimension and member tables.
- Create, append to, list, inspect, and drop SQLite tables and views.
- Run read-only `SELECT` and `PRAGMA` queries with `query_database`.

## Limitations and notes

The hosted service intentionally excludes SQLite database tools, so persistent storage and SQL analysis require the local setup. `get_sdmx_structure` lists only an initial subset of members; use `store_cube_metadata` when browsing all members or looking up vector IDs. `fetch_sdmx_to_database` is intended for storage and avoids the 500-row context limit described for direct SDMX retrieval.

Database state is persistent. `create_table_from_data` replaces an existing table, while `insert_data_into_table` appends to one that already exists. Dropping a view created by a fetch operation removes the view but leaves its observations in the shared store. Queries should remain read-only, and important figures should be checked against official Statistics Canada sources because language models can produce inaccurate interpretations or values.

_Full upstream README: https://allmcps.com/mcp/statistics-canada-mcp-server/readme_

