Skip to main content

MCP Server for interacting with Statistics Canada Web Data Services API

Project description

Statistics Canada MCP Server

Statistics Canada MCP Server

Python 3.10+ License: MIT MCP GitHub

MCP server for Statistics Canada's Web Data Service (WDS) and SDMX REST API. Gives any MCP client — Claude, ChatGPT, Gemini,Cursor, VS Code Copilot, and more — structured access to Canadian statistical data.

Currently Hosting on Render see quick start!

‼️‼️ LLM's may fabricate information, Always double check outputs, see known issues

‼️‼️ Be critical of conclusions and results of analysis done by LLM's, see known issues

Two setup modes:

Mode Tools available DB/Storage? Best for
HTTP (self-hosted) WDS + SDMX (~15 tools) No Most users — data access without local storage
stdio (full) All tools incl. SQLite Yes Power users — multi-series analysis, SQL queries

💻 So it can also be Self-host locally (with SQL query features and additional SQLite database support), see Features & Tools!

Table of Contents


Examples

Chat examples

Dataset Query Demo Source
Canada's Greenhouse Gas Emissions (2018-2022) "Create a simple visualization for greenhouse emissions for Canada as a whole over the last 4 years" Chat Table 38-10-0097-01
Canada's International Trade in Services "Create a quick analysis for international trade in services for the last 6 months with a visualization" Chat Table 12-10-0144-01
Ontario Building Construction Price Index "Generate a visualization for Ontario's Building Price index from Q4 2023 to Q4 2024" Chat Table 18-10-0289-01

Dashboard examples

Title Link Source
Canadian Unemployement Dashboard Dashboard
Canada's Critical Minerals Economy Dashboard
  • Economic contribution of critical mineral production, by Natural Resources Canada prioritized group, Canada.
  • Economic contribution of critical mineral production based on the Natural Resources Satellite Account, by commodity, Canada (x 1,000,000)
Price of Everything: CPI Dashboard 2015 - 2026 Dashboard
Canada's Biomedical & Biotech Industries Dashboard

Quick Start

🚀 Use the currently hosted version (easiest if available)

Last Hosting Update: Feb 28/2026

No installation required, connect to the public server if you the link below works

Claude Desktop

  1. Go to Settings (⌘,) → Connectors → Add Custom Connector
  2. Add mcp-statcan to name
  3. Add https://mcp-statcan.onrender.com/mcp to Remote MCP Server URL
  4. Restart Claude Desktop

Requires uv:

# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

HTTP mode — WDS + SDMX, no DB (recommended)

Start the server in a terminal and leave it running:

uvx statcan-mcp-server --transport http
# Server running at http://localhost:8000  |  /health  |  /mcp

Then configure your client to connect to http://localhost:8000/mcp — see Setup by Client below.

Full mode — add SQLite DB tools

Run via stdio — no separate server process needed:

uvx statcan-mcp-server

Configure your client with the stdio snippets in Setup by Client.


Setup by Client

Mode DB tools? Tools available
HTTP (self-hosted, start server first) No WDS + SDMX (~15 tools)
stdio (full) Yes All tools incl. SQLite

HTTP mode — WDS + SDMX (no DB)

Before configuring your client: start the server in a separate terminal:

uvx statcan-mcp-server --transport http

Keep it running while using your client. Verify at http://localhost:8000/health.

Most clients use mcp-proxy to bridge stdio ↔ HTTP. Claude Code connects natively.

Claude Desktop

Navigate to: Claude Desktop → Settings (⌘,) → Developer → Edit Config

{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["mcp-proxy", "--transport", "streamablehttp", "http://localhost:8000/mcp"]
    }
  }
}

Restart Claude Desktop after saving.

Claude Code

claude mcp add statcan --transport http http://localhost:8000/mcp --scope global

Cursor

In .cursor/mcp.json (project) or ~/.cursor/mcp.json (global):

{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["mcp-proxy", "--transport", "streamablehttp", "http://localhost:8000/mcp"]
    }
  }
}

VS Code (GitHub Copilot)

In .vscode/mcp.json:

{
  "servers": {
    "statcan": {
      "type": "stdio",
      "command": "uvx",
      "args": ["mcp-proxy", "--transport", "streamablehttp", "http://localhost:8000/mcp"]
    }
  }
}

Google Antigravity

Open the config via the UI: three dots (⋮) → MCP Servers → Manage MCP Servers → View raw config, or edit directly:

  • macOS / Linux: ~/.gemini/antigravity/mcp_config.json
  • Windows: C:\Users\<you>\.gemini\antigravity\mcp_config.json
{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["mcp-proxy", "--transport", "streamablehttp", "http://localhost:8000/mcp"]
    }
  }
}

Full mode — WDS + SDMX + SQLite DB tools

No separate server process. uvx downloads and runs statcan-mcp-server from PyPI automatically.

Claude Desktop

Navigate to: Claude Desktop → Settings (⌘,) → Developer → Edit Config

{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["statcan-mcp-server", "--db-path", "/Users/<you>/.statcan-mcp/statcan_data.db"]
    }
  }
}

Note: Pass --db-path with an absolute path. Claude Desktop overrides the subprocess HOME env var, which breaks the default ~/.statcan-mcp/ path resolution.

Restart Claude Desktop after saving.

Claude Code

claude mcp add statcan --scope global -- uvx statcan-mcp-server

Cursor

In .cursor/mcp.json (project) or ~/.cursor/mcp.json (global):

{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["statcan-mcp-server"]
    }
  }
}

VS Code (GitHub Copilot)

In .vscode/mcp.json:

{
  "servers": {
    "statcan": {
      "type": "stdio",
      "command": "uvx",
      "args": ["statcan-mcp-server"]
    }
  }
}

Google Antigravity

Open the config via the UI: three dots (⋮) → MCP Servers → Manage MCP Servers → View raw config, or edit directly:

  • macOS / Linux: ~/.gemini/antigravity/mcp_config.json
  • Windows: C:\Users\<you>\.gemini\antigravity\mcp_config.json
{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["statcan-mcp-server"]
    }
  }
}

Optional flags (full/stdio mode)

# Custom database path (recommended for Claude Desktop)
uvx statcan-mcp-server --db-path /your/path/statcan_data.db

# Environment variable alternative
STATCAN_DB_FILE=/your/path/statcan_data.db uvx statcan-mcp-server

Features & Tools

SDMX Tools — recommended for data fetching

Server-side filtered observations. Only the requested slice is returned — no downloading full tables.

Tool Description
get_sdmx_structure Fetch dimension codelists + key syntax for a table. Call this before get_sdmx_data.
get_sdmx_data Fetch filtered observations by productId + key. Supports lastNObservations, startPeriod, endPeriod.
get_sdmx_vector_data Fetch observations for a single vectorId via SDMX.

Key syntax (passed to get_sdmx_data):

  • "1.2.1" — Geography=1, Gender=2, Age=1
  • ".2.1" — all geographies (wildcard), Gender=2, Age=1
  • lastNObservations=12 — last 12 periods (e.g. 1 year of monthly data)
  • Limitation: lastNObservations cannot combine with startPeriod/endPeriod (StatCan returns 406)

WDS Discovery & Metadata

Tool Description
search_cubes_by_title Full-text search across all StatCan tables. AND logic on multiple keywords, capped at 25 results.
get_all_cubes_list Paginated table inventory with dimension details (offset/limit, default 100/page).
get_all_cubes_list_lite Same but lighter — no dimension or footnote info.
get_cube_metadata Dimension info, member lists, date ranges. summary=True (default) caps members at 10 per dimension.
get_code_sets Decode StatCan numeric codes (frequency, UOM, scalar factor, status).

WDS Series Resolution

Tool Description
get_series_info Resolve one or more {productId, coordinate} pairs to vectorId + metadata in a single call. Replaces the old single + bulk coord tools.
get_series_info_from_vector Resolve a vectorId to productId, coordinate, titles, frequency.

WDS Change Detection

Tool Description
get_changed_cube_list Tables updated on a specific date (YYYY-MM-DD).
get_changed_series_list Series updated on a specific date.
get_changed_series_data_from_cube_pid_coord Data points that changed for a coordinate.
get_changed_series_data_from_vector Data points that changed for a vectorId.

WDS Data Fetch

Tool Description
get_bulk_vector_data_by_range Fetch multiple vectors filtered by release date range (YYYY-MM-DDTHH:MM). Use when you want "data released between date A and date B", not a reference period range.

Composite Tools (local/stdio mode only)

Tool Description
fetch_vectors_to_database Fetch multiple vectors by reference period range and store to SQLite in one call. Preferred workflow for multi-series analysis.
store_cube_metadata Fetch full cube metadata and store into _statcan_dimensions + _statcan_members tables. Use SQL to browse all members and look up vectorIds without loading them into context.

Database Tools (local/stdio mode only)

Persistent SQLite at ~/.statcan-mcp/statcan_data.db.

Tool Description
create_table_from_data Create a table and insert rows in one step.
insert_data Append rows to an existing table.
query_database Read-only SQL (PRAGMA query_only = ON).
list_tables List all tables.
get_table_schema Schema for a table.
drop_table Drop a table.

Typical workflow (local mode)

1. search_cubes_by_title("unemployment rate")
   → find productId, e.g. 14100287

2. get_sdmx_structure(productId=14100287)
   → see dimensions + codes for key construction

3. get_sdmx_data(productId=14100287, key=".2.1", lastNObservations=24)
   → last 24 months, all geographies, seasonally adjusted

4. (optional) get_series_info(items=[{productId:14100287, coordinate:"1.2.1"}])
   → get vectorId for a specific series

5. (optional) fetch_vectors_to_database(vectorIds=[...], table_name="unemployment")
   → store for SQL analysis

Warning: LLMs may occasionally fabricate data when unable to retrieve actual information. Always verify important figures against official Statistics Canada sources.


Project Structure

src/
├── api/
│   ├── cube_tools.py        # WDS cube + search tools
│   ├── vector_tools.py      # WDS vector tools
│   ├── sdmx_tools.py        # SDMX REST tools
│   ├── composite_tools.py   # fetch_vectors_to_database, store_cube_metadata
│   └── metadata_tools.py    # get_code_sets
├── db/                      # SQLite connection, schema, queries
├── models/                  # Pydantic input models
├── util/
│   ├── registry.py          # ToolRegistry — @decorator → MCP Tool schema
│   ├── truncation.py        # Response truncation + pagination guidance
│   ├── sdmx_json.py         # SDMX-JSON → tabular rows
│   ├── cache.py             # 1-hour TTL cache for cube list
│   └── coordinate.py        # Pad WDS coordinate to 10 dimensions
├── config.py                # BASE_URL, SDMX_BASE_URL, DB_FILE, TRANSPORT, PORT
└── server.py                # create_server(), transport wiring, CLI entrypoint

Known Issues

  • "Unable to open database file" on Claude Desktop: Pass --db-path /Users/<you>/.statcan-mcp/statcan_data.db in your config (see Setup). Claude Desktop overrides the subprocess HOME env var.
  • SSL verification disabled: VERIFY_SSL = False in all StatCan API calls. This is a known limitation — StatCan's certificate chain causes verification failures in some environments.
  • SDMX OR-key geography labels: Using + syntax for multiple geographies (e.g. "1+2.2.1") produces incorrect Geography labels for series 2+. Use wildcard (omit the dimension: ".2.1") instead — this is a StatCan API bug.
  • lastNObservations + date range: StatCan SDMX returns 406 when combining lastNObservations with startPeriod/endPeriod. Use one or the other.
  • Context overflow may cause data fabrication: When tool results are large, the LLM's context window fills up and it may fabricate or hallucinate data values instead of fetching them. Always verify important figures against official Statistics Canada sources. Use precise SDMX queries (lastNObservations, specific keys) to keep responses small.
  • Rate limits: StatCan's API may throttle during high-demand periods.

Made with ❤️❤️❤️ for Statistics Canada

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statcan_mcp_server-0.5.0.tar.gz (156.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statcan_mcp_server-0.5.0-py3-none-any.whl (57.5 kB view details)

Uploaded Python 3

File details

Details for the file statcan_mcp_server-0.5.0.tar.gz.

File metadata

  • Download URL: statcan_mcp_server-0.5.0.tar.gz
  • Upload date:
  • Size: 156.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for statcan_mcp_server-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7b068452620c80d6970bf7e66ac308df4cacdca3a37689934e234bd13809f067
MD5 c59c9d614e673dbe618d8761deda59fc
BLAKE2b-256 6bec4e9f51397ca79f6c38abb312c092e1e57043d98cfb686f7abac539ac33c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for statcan_mcp_server-0.5.0.tar.gz:

Publisher: publish-mcp-registry.yml on Aryan-Jhaveri/mcp-statcan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file statcan_mcp_server-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for statcan_mcp_server-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ea18c5ced7fd1593fc7fcc55437fb985994871404826b622396f7aa50568d18
MD5 fcd9fced495a736a8e313602c3f7abb1
BLAKE2b-256 1d640627b4e8f7b6e2a14e1b10e32f9eeecfeac784ff246e862be13beaea580d

See more details on using hashes here.

Provenance

The following attestation bundles were made for statcan_mcp_server-0.5.0-py3-none-any.whl:

Publisher: publish-mcp-registry.yml on Aryan-Jhaveri/mcp-statcan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page