What is StatCan Web Data Service MCP Server?
StatCan Web Data Service MCP Server is a Model Context Protocol (MCP) server that provides access to Statistics Canada's Web Data Service, allowing AI assistants to discover, explore, analyze, and cite Canadian statistical data through natural language.
How to use StatCan Web Data Service MCP Server?
To use the server, clone the repository, set up a virtual environment, install dependencies, and start the server. You can then configure it with AI assistants like Claude to query Canadian statistics.
Key features of StatCan Web Data Service MCP Server?
- Dataset discovery by keywords, themes, or geography
- Data retrieval with proper formatting for time series data
- Detailed metadata exploration
- Persistent storage using SQLite
- Advanced statistical analysis and forecasting
- Data visualizations with Vega-Lite integration
- Proper citation generation for datasets
- Robust error handling and API resilience
Use cases of StatCan Web Data Service MCP Server?
- Discovering datasets related to consumer prices in Canada.
- Analyzing trends in GDP over time.
- Generating visualizations for unemployment rate changes.
- Citing Statistics Canada data in academic work.
FAQ from StatCan Web Data Service MCP Server?
- Can I use this server for all Statistics Canada datasets?
Yes, it provides access to a wide range of datasets available through the StatCan Web Data Service.
- Is there a limit to the number of queries I can make?
Yes, high-volume queries may be throttled by the StatCan WDS API due to rate limiting.
- How do I handle API errors?
The server includes robust error handling and fallback mechanisms to ensure data access.
StatCan Web Data Service MCP Server

A MCP (Model Context Protocol) server that provides access to Statistics Canada's Web Data Service, enabling AI assistants to discover, explore, analyze, and cite Canadian statistical data through natural language.
Project Overview
This server addresses several technical challenges in accessing Statistics Canada's Web Data Service (WDS) API:
- API Format Requirements: Identified correct formats for StatCan WDS API endpoints to resolve 406 errors
- Resilient Data Access: Implements multi-tier caching and fallbacks for API limitations
- Enhanced Metadata: Provides rich context for statistical interpretation and proper citation
- Analysis Capabilities: Includes statistical analysis, visualization, and forecasting features
- MCP Integration: Connects with other MCP servers for expanded functionality
Features
- 🔍 Dataset Discovery: Search and browse StatCan datasets by keywords, themes, or geography
- 📊 Data Retrieval: Extract time series data with proper formatting for key vectors
- 📝 Metadata Exploration: Access detailed information about dataset structure and content
- 💾 Persistent Storage: Store datasets for future use with SQLite backend
- 📊 Advanced Analysis: Perform comprehensive statistical analysis, trend detection, seasonality analysis, and forecasting
- 📈 Visualizations: Generate data visualizations with integration to Vega-Lite
- 📑 Citations: Generate properly formatted citations for StatCan data
- 🖼️ Figure References: Track and reference figures created from StatCan data
- 🔄 API Resilience: Robust error handling with fallbacks for API limitations
Current Limitations
The StatCan WDS API has several limitations that this server addresses:
- Data Retrieval Constraints: Some API endpoints remain problematic despite correct formatting
- Format Sensitivity: Vector IDs must be numeric without the 'v' prefix, and payloads must be in array format
- Coordinate Access: Vector-based queries are more reliable than coordinate-based queries
- Performance Issues: Some API calls may timeout for large requests or during peak times
- Rate Limiting: High-volume queries may be throttled by the StatCan WDS API
The current implementation uses these strategies to work around these limitations:
- Multi-tier caching system at metadata, vector, and cube levels
- Local fallbacks for common statistical indicators
- Automatic format adjustment and retries with exponential backoff
- Graceful degradation to cached data when API endpoints fail
See docs/implementation_status.md and docs/api_connection_guide.md for details.
Quick Start
# Clone the repository
git clone https://github.com/yourusername/mcp-statcan.git
cd mcp-statcan
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -e .
# Start the MCP server
python -m src
Dependencies
pip install sqlitedict aiohttp mcp pydantic python-dotenv pandas numpy
Usage with Claude
- Open Claude Desktop App
- Go to Settings > MCP Servers
- Add a new server with the following configuration:
- Name: StatCan Data
- Command:
path/to/venv/bin/python -m src
- Start chatting with Claude and ask about Canadian statistics!
Working Example Queries
Here are queries that work reliably with the current implementation:
Basic Data Discovery
- "Find datasets about consumer prices in Canada"
- "What datasets do you have about employment?"
- "Show me the latest CPI data"
Vector-Based Data Retrieval
- "Get data for CPI vector 41690973"
- "Retrieve GDP data from vector 21581063"
- "Get the latest values for employment vector 111955426"
Analysis and Visualization
- "Generate a line chart for CPI data over the last 5 years"
- "Analyze the trend in GDP for the past 10 quarters"
- "Create a visualization of unemployment rate changes"
Citations
- "Generate a citation for the Consumer Price Index dataset"
- "How should I cite Statistics Canada's GDP data in APA format?"
- "Create a reference for the Labour Force Survey"
Testing
To verify the API client works correctly:
python -m tests.api.api_connection_steps
This runs step-by-step tests for:
- API connectivity
- Metadata retrieval
- Vector data access
- Format requirements
Project Structure
/src
- Core server implementation/docs
- Documentation and guides/tests
- Test suite for API and functionality/docs/references
- API specifications and code sets
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
This project uses data from Statistics Canada, accessed via their Web Data Service API. It is not affiliated with or endorsed by Statistics Canada.
The Statistics Canada logo is used for informational purposes only to indicate the data source.