Aryan-Jhaveri/mcp-statcan
If you are the rightful owner of mcp-statcan and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Statistics Canada API MCP Server provides tools for interacting with StatCan data APIs, allowing LLMs or other MCP clients to access Canadian statistical data.
๐ Statistics Canada API MCP Server
๐ Description
This project implements a Model Context Protocol (MCP) server that provides tools for interacting with Statistics Canada (StatCan) data APIs.
It allows LLMs or other MCP clients to access and retrieve Canadian statistical data in a structured way.
๐ Table of Contents
- ๐ Description
- ๐ฌ Claude Chat Examples
- โจ Features
- ๐๏ธ Project Structure
- ๐ฅ Installation
- ๐ง Setup
- โ ๏ธ Known Issues
- ๐ Usage Examples
๐ฌ Claude Chat Examples
| Dataset | Query Example | Demo | Data Source |
|---|---|---|---|
| Canada's Greenhouse Gas Emissions (2018-2022) | "Hey Claude! Can you please create a simple visualization for greenhouse emissions for Canada as a whole over the last 4 years?" | View Demo | StatCan Table |
| Canada's International Trade in Services | "Hey Claude, can you create a quick analysis for international trade in services for the last 6 months. Create a visualization with key figures please!" | View Demo | StatCan Table |
| Ontario Building Construction Price Index | "Hey Claude! Can you please generate a visualization for Ontario's Building Price index from Q4 2023 to Q4 2024. Thanks!" | View Demo | StatCan Table |
๐ Claude Dashboard Example
| Dataset | Link | Data Source |
|---|---|---|
| Labour force characteristics by province, territory and economic region, annual | Dashbord Link | Data Source |
Effective Querying Tips
To get the most accurate results from Claude when using this Statistics Canada MCP server:
- Be Specific: Use precise, well-formed requests with exact details about the data you need
- Provide Context: Clearly specify tables, vectors, time periods, and geographical areas
- Avoid Typos: Double-check spelling of statistical terms and place names
- Structured Questions: Break complex queries into clear, logical steps
- Verify Results: Always cross-check important data against official Statistics Canada sources
โ ๏ธ Warning: LLMs like Claude may occasionally create mock visualizations or fabricate data when unable to retrieve actual information. They might also generate responses with data not available in Statistics Canada to satisfy queries. Always verify results against official sources.
โจ Features
This server exposes StatCan API functionalities as MCP tools, including:
API Functionality
Cube Operations:
- Listing all available data cubes/tables โ paginated, default 100 per page (
offset/limit) - Searching cubes by title โ capped at
max_results(default 25) with count message when more exist - Retrieving cube metadata โ
summary=True(default) caps dimension member lists at 5 entries; usesummary=Falsefor all vectorIds - Getting data for the latest N periods based on ProductId and Coordinate
- Getting series info based on ProductId and Coordinate
- Batch-fetching series info for multiple
{productId, coordinate}pairs in a single call โ paginated, with guidance for code-set fields - Getting changed series data based on ProductId and Coordinate
- Listing cubes changed on a specific date
- Providing download links for full cubes (CSV/SDMX) (Discouraged)
Vector Operations:
- Retrieving series metadata by Vector ID
- Getting data for the latest N periods by Vector ID
- Getting data for multiple vectors by reference period range โ paginated with guidance
- Getting bulk data for multiple vectors by release date range โ paginated with guidance
- Getting changed series data by Vector ID
- Listing series changed on a specific date
Composite Operations:
fetch_vectors_to_databaseโ fetches multiple vectors and stores them in SQLite in a single call (preferred workflow for multi-series analysis)store_cube_metadataโ fetches full cube metadata and stores it into_statcan_dimensionsand_statcan_membersSQLite tables; returns only a compact summary so the full member list never enters the context window. Use SQL to browse dimensions and look up vectorIds.
Database Functionality
The server uses a persistent SQLite database at ~/.statcan-mcp/statcan_data.db (configurable via --db-path flag or STATCAN_DB_FILE env var) for:
- Creating tables from API data and inserting rows in one step (
create_table_from_data) - Appending additional rows to existing tables (
insert_data_into_table) - Querying the database with SQL
- Viewing table schemas and listing available tables
- Dropping tables to free space (
drop_table)
This allows for persistent storage of retrieved data and more complex data manipulation through SQL.
(Refer to the specific tool functions within src/api/ for detailed parameters and return types.)
๐๏ธ Project Structure
src/: Contains the main source code for the MCP server.api/: Defines the MCP tools wrapping the StatCan API calls (cube_tools.py,vector_tools.py,composite_tools.py,metadata_tools.py).db/: Handles database interactions, including connection, schema, and queries.models/: Contains Pydantic models for API request/response validation and database representation.util/: Utility functions (e.g., coordinate padding).config.py: Configuration loading (e.g., database credentials, API base URL).server.py: MCP server definition and tool registration.__init__.py: Package initialization forsrc.pyproject.toml: Project dependency and build configuration.server.json: MCP Registry metadata.
๐ฅ Installation
The only requirement is 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"
uvx is bundled with uv and will automatically download and run statcan-mcp-server from PyPI on first use.
๐ง Setting Up Claude Desktop Configuration
Navigate to: Claude Desktop App โ Settings (โ + ,) โ Developer โ Edit Config
{
"mcpServers": {
"statcan": {
"command": "uvx",
"args": ["statcan-mcp-server", "--db-path", "/your/path/to/.statcan-mcp/statcan_data.db"]
}
}
}
โ ๏ธ Important: Pass
--db-pathwith an absolute path. Claude Desktop alters the subprocessHOMEenvironment variable, which can cause the default database path (~/.statcan-mcp/) to resolve incorrectly.
Restart the Claude Desktop app after saving.
Claude Code
WARNING: Untested yet
claude mcp add statcan --scope global -- uvx statcan-mcp-server
โ ๏ธ Known Issues and Limitations
- "Unable to open database file" on Claude Desktop: Pass
--db-path /Users/<you>/.statcan-mcp/statcan_data.dbin your config args (see Setup). Claude Desktop alters the subprocessHOMEenv var, breaking default path resolution. - SSL Verification: Currently disabled for development. Should be enabled for production use.
- Data Validation: Always cross-check your data with official Statistics Canada sources.
- Security Concerns: Query validation is basic; avoid using with untrusted input.
- Performance: Some endpoints may timeout with large data requests.
- API Rate Limits: The StatCan API may impose rate limits that affect usage during high-demand periods.
Made with โค๏ธโค๏ธโค๏ธ for Statistics Canada
GitHub โข Report Bug โข Statistics Canada