ontario-data-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ontario-data-mcp find datasets about traffic accidents in Toronto"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ontario-data-mcp
Beta: This project is under active development. The data structure and tool interfaces may change.
LLM-generated analysis may contain errors. Always verify critical findings against the returned source data.
This is an MCP server for discovering, downloading, querying, and analyzing datasets from Ontario's Open Data portals. It allows asking questions of the data in English (or Spanish, Chinese, French, etc).
It currently supports the Ontario, Toronto, Ottawa, Waterloo, Kitchener, and Region of Waterloo portals, and utilizes a shared DuckDB cache for fast SQL queries, statistical analysis, and geospatial operations.
Contributing
Contributions welcome! To get started, see Installation below.
Found a bug? Have an idea? Discovered something interesting? Open an issue here: https://github.com/sprine/ontario-data-mcp/issues
Related MCP server: DuckDB MCP Server
Features
find- search across supported Ontario open data portalsdownload- retrieve and cache datasetsquery- run SQL, statistical, and geospatial analysis via DuckDBvalidate— verify that data claims are supported by query resultsA shared DuckDB cache for high-performance analytics
Architecture
flowchart TD
Client["AI Client<br/>(Claude Code · VS Code · etc.)"]
subgraph Server["ontario-data-mcp (FastMCP)"]
direction TB
subgraph Tools["MCP Tools"]
direction LR
T1["Discovery"]
T2["Metadata"]
T3["Retrieval"]
T4["Querying"]
T5["Geospatial"]
T6["Quality & Validation"]
end
PC["Portal Clients<br/>CKANClient · ArcGISHubClient"]
Cache[("DuckDB Cache<br/>~/.cache/ontario-data/")]
Tools -->|"fan out to all portals"| PC
T3 & T5 -->|"download → store"| Cache
T4 & T6 -->|"SQL queries"| Cache
end
subgraph Portals["Open Data Portals"]
direction LR
CKAN["Ontario · Toronto<br/>CKAN API"]
ArcGIS["Ottawa · Waterloo · Kitchener<br/>Region of Waterloo<br/>ArcGIS Hub"]
end
Client <-->|"MCP Protocol"| Tools
PC -->|"CKAN 2.8"| CKAN
PC -->|"OGC Records / Hub v3"| ArcGISData flow: Discovery and metadata tools fan out to all portals in parallel. Retrieval tools download data and store it in a local DuckDB cache. Querying and quality tools run fast SQL locally against the cache — no repeated API calls.
Installation
With Claude Code
claude mcp add ontario-data -- uvx ontario-data-mcpTo auto-approve all tool calls (no confirmation prompts), add to your Claude Code settings:
{
"permissions": {
"allow": ["mcp:ontario-data:*"]
}
}Tools are annotated as read-only or destructive per the MCP spec. Download tools populate the local cache but are read-only (no remote mutations). Destructive tools (cache_manage, refresh_cache) only modify local cached data.
Add to .vscode/mcp.json:
{
"mcpServers": {
"ontario-data": {
"command": "uvx",
"args": ["ontario-data-mcp"]
}
}
}git clone https://github.com/sprine/ontario-data-mcp
cd ontario-data-mcp
uv sync
uv run ontario-data-mcpTo connect from source to Claude Code:
Note: MCP subprocesses don't inherit your shell's PATH, so you must use the absolute path to
uv(find it withwhich uv).
claude mcp add ontario-data -- /absolute/path/to/uv run --directory /path/to/ontario-data-mcp ontario-data-mcpSupported Portals
All searches fan out to every portal by default — no need to select a portal. Dataset and resource IDs are prefixed with their portal (e.g. toronto:abc123).
Portal | Platform | Datasets |
| CKAN | ~5,700 |
| CKAN | ~533 |
| ArcGIS Hub | ~665 |
| ArcGIS Hub | ~129 |
| ArcGIS Hub | ~219 |
| ArcGIS Hub | ~125 |
List of tools available to the AI agent
Tool | Description |
| Search for datasets across all portals (or narrow with |
| List all available portals with platform type |
| List government ministries with dataset counts |
| List all tags/topics in the catalogue |
| Find datasets related by tags and organization |
Tool | Description |
| Get full metadata for a dataset (use prefixed ID like |
| List all files in a dataset with formats and sizes |
| Get column schema and sample values for a datastore resource |
| Compare metadata side-by-side for multiple datasets (cross-portal) |
Tool | Description |
| Download a resource and cache it in DuckDB (use prefixed ID like |
| Cache statistics + list all cached datasets with staleness |
| Remove a single cached resource or clear the entire cache |
| Re-download cached resources with latest data |
Tool | Description |
| Query a resource via CKAN Datastore API (remote) |
| Run SQL against the CKAN Datastore (remote) |
| Run SQL against locally cached data in DuckDB |
| Quick preview of first N rows of a resource |
Tool | Description |
| Check if a dataset is current vs. its update schedule |
| Statistical profile using DuckDB SUMMARIZE |
| Validate that a data claim is supported by query results |
Tool | Description |
| Cache a geospatial resource (SHP, KML, GeoJSON) into DuckDB |
| Run spatial queries against cached geospatial data |
| Find datasets containing geospatial resources |
MCP Resources
Resources the agent can read for context without calling a tool:
URI | Description |
| List of all locally cached datasets with freshness info |
| Full metadata for a specific dataset (supports prefixed IDs) |
| Overview statistics across all data portals |
| Column schema, types, sample values, and type warnings for a cached table |
| DuckDB SQL reference for Ontario open data analysis |
Prompts
Context-aware guided workflow prompts:
explore_topic— Guided exploration of a topic (fetches live catalogue context)data_investigation— Deep dive into a specific dataset: schema, quality, statisticscompare_data— Side-by-side analysis of multiple datasets
Environment Variables
Variable | Default | Purpose |
|
| DuckDB storage + log file location |
|
| HTTP timeout in seconds |
|
| Max CKAN requests per second |
Development
uv sync
uv run python -m pytest tests/ -vLicense
MIT — see LICENSE for the software.
Data accessed through this tool is provided under the following open government licences:
Contains information licensed under the Open Government Licence – Ontario.
Contains information licensed under the Open Government Licence – Toronto.
Contains information licensed under the Open Government Licence – City of Ottawa.
Contains information licensed under the City of Waterloo Open Data Licence.
Contains information licensed under the Open Government Licence - The Corporation of the City of Kitchener.
Contains information licensed under the Region of Waterloo Open Data Licence v.2.0.
Available Tools
23 toolscache_infoARead-only
Get cache statistics and list all cached datasets.
Returns size, table count, and details for every cached resource.
Inputs: no named parameters. Returns: result
cache_manageADestructive
Manage the local DuckDB cache: remove or clear cached data.
Args: action: One of "remove" (single resource) or "clear" (all) resource_id: Required for "remove" action. Prefixed or bare ID accepted.
Inputs: action (required), resource_id. Returns: result
check_freshnessARead-only
Check if a dataset is current by comparing its update frequency to its last modification date.
Args: dataset_id: Prefixed dataset ID (e.g. "toronto:ttc-ridership") or bare ID
Inputs: dataset_id (required). Returns: result
compare_datasetsARead-only
Compare metadata side-by-side for multiple datasets (can be cross-portal).
Args: dataset_ids: List of prefixed dataset IDs (e.g. ["toronto:abc", "ontario:def"]) to compare (2-5)
Inputs: dataset_ids (required). Returns: result
download_resourceARead-only
Download a dataset resource and cache it locally in DuckDB for fast querying.
Supports CSV, XLSX, JSON, and datastore-active resources. If already cached, returns staleness info so you can decide whether to refresh. Numeric columns stored as text are automatically cast to DOUBLE.
Workflow: search_datasets → get_dataset_info → download_resource → query_cached.
Args: resource_id: Prefixed resource ID (e.g. "toronto:abc123") or bare ID
Inputs: resource_id (required). Returns: result
get_dataset_infoARead-only
Get full metadata for a dataset including all resources.
Args: dataset_id: Prefixed dataset ID (e.g. "toronto:ttc-ridership") or bare ID
Inputs: dataset_id (required). Returns: result
get_resource_schemaARead-only
Get the column schema and sample values for a datastore resource.
Args: resource_id: Prefixed resource ID (e.g. "toronto:abc123") or bare ID sample_size: Number of sample rows to include
Inputs: resource_id (required), sample_size. Returns: resource_id, total_records, num_columns, fields, +2 more
list_geo_datasetsARead-only
Find all datasets that contain geospatial resources (SHP, KML, GeoJSON).
Args: format_filter: Filter to specific format: "SHP", "KML", "GEOJSON", or None for all limit: Max results per portal portal: Narrow to one portal. Default: all portals.
Inputs: format_filter, limit, portal. Returns: result
list_organizationsARead-only
List government ministries and organizations with dataset counts across all portals.
Args: include_counts: Include dataset counts per organization portal: Narrow to one portal. Default: all portals.
Inputs: include_counts, portal. Returns: result
list_portalsARead-only
List all available data portals with their platform type and descriptions.
Inputs: no named parameters. Returns: result
list_resourcesARead-only
List all resources (files) in a dataset with their formats and sizes.
Args: dataset_id: Prefixed dataset ID (e.g. "toronto:ttc-ridership") or bare ID
Inputs: dataset_id (required). Returns: result
list_topicsARead-only
List top tags/topics used across data portals, ranked by dataset count.
Args: query: Optional filter to match tag names portal: Narrow to one portal. Default: all portals. limit: Max tags to return (default 100). Use a higher value to see more.
Inputs: query, portal, limit. Returns: result
load_geodataARead-only
Download and cache a geospatial resource (SHP, KML, GeoJSON) into DuckDB with spatial support.
Args: resource_id: Prefixed resource ID (e.g. "toronto:abc123") or bare ID force_refresh: Re-download even if cached
Inputs: resource_id (required), force_refresh. Returns: result
preview_dataARead-only
Quick preview of the first N rows of a resource (fetched remotely).
Args: resource_id: Prefixed resource ID (e.g. "toronto:abc123") or bare ID rows: Number of rows to preview (1-100)
Inputs: resource_id (required), rows. Returns: result
profile_dataARead-only
Statistical profile and quality check of a cached dataset.
Uses DuckDB SUMMARIZE for column-level statistics (min, max, avg, std, nulls, unique counts). Also checks for duplicate rows.
Args: resource_id: Resource ID (must be cached)
Inputs: resource_id (required). Returns: result
query_cachedARead-only
Run a SQL query against locally cached data in DuckDB.
Use table names from download_resource or cache_info. Supports full DuckDB SQL: aggregations, window functions, CTEs, JOINs across tables.
Use SUM(quantity_col) not COUNT() when rows contain per-row counts (e.g. a "count" or "number_of" column). COUNT() counts rows, not quantities. Column names vary across resources in the same dataset — always DESCRIBE first. Use SELECT * RENAME ("old col" AS new_col) to normalize column names when joining across datasets. Values containing semicolons should be matched with LIKE patterns, not = equality. Quote table names with double quotes in SQL.
Args: sql: SQL query (e.g. SELECT * FROM "ds_my_table_abc12345" LIMIT 10)
Inputs: sql (required). Returns: sql, rows, columns, total_rows, +2 more
query_resourceARead-only
Query a resource via the CKAN Datastore API (remote, no download needed).
Only works for resources with datastore_active=True.
Args: resource_id: Prefixed resource ID (e.g. "toronto:abc123") or bare ID filters: Column filters as {column: value} pairs fields: List of columns to return (default: all) sort: Sort string (e.g. "date desc", "name asc") limit: Max rows (1-1000) offset: Row offset for pagination
Inputs: resource_id (required), filters, fields, sort, +2 more. Returns: result
refresh_cacheADestructive
Re-download cached resources to get the latest data.
Args: resource_id: Specific resource to refresh (prefixed or bare ID), or omit to refresh all
Inputs: resource_id. Returns: result
search_datasetsARead-only
Search for datasets across all open data portals (Ontario, Toronto, Ottawa).
Results include portal-prefixed IDs (e.g. toronto:abc123). Use these IDs with get_dataset_info to view full metadata, then download_resource to cache locally. Use get_resource_schema to check column types before writing queries.
Searches fan out to all portals by default. Narrow to one portal with the portal param.
Args: query: Search terms (e.g. "covid cases", "housing prices", "school enrollment") organization: Filter by ministry/org (e.g. "health", "education") resource_format: Filter by file format (e.g. "CSV", "JSON", "SHP") update_frequency: Filter by frequency (e.g. "yearly", "monthly", "daily") sort_by: Sort order (default: relevance) limit: Max results per portal (1-50) portal: Narrow to one portal (e.g. "ontario", "toronto"). Default: all portals.
Inputs: query (required), organization, resource_format, update_frequency, +3 more. Returns: result
spatial_queryARead-only
Run spatial queries against cached geospatial data.
Args: resource_id: Resource ID (must be cached via load_geodata) operation: "contains_point", "within_bbox", or "within_radius" latitude: Latitude for point queries (-90 to 90) longitude: Longitude for point queries (-180 to 180) radius_km: Radius in kilometers (for within_radius, must be > 0) bbox: Bounding box as [min_lng, min_lat, max_lng, max_lat] (for within_bbox) limit: Max results
Inputs: resource_id (required), operation (required), latitude, longitude, +3 more. Returns: result
sql_queryARead-only
Run a SQL query against the CKAN Datastore (remote).
NOTE: Prefer download_resource + query_cached for repeated queries — the remote API has rate limits (429 errors). Use this tool only for quick one-off queries on datastore-active resources.
Use resource IDs as table names in double quotes. Example: SELECT "Column Name" FROM "resource-id-here" WHERE "Year" > 2020 LIMIT 10
Args: sql: SQL query string (read-only, SELECT only) portal: Portal to query (default: "ontario"). Required because SQL embeds resource IDs directly.
Inputs: sql (required), portal. Returns: result
validate_resultARead-only
Validate that a claim is supported by query results.
Call this after making a data claim to verify it against the source. Re-executes the SQL, extracts numbers and terms from the claim, and checks them against the actual data.
Args: sql: The SQL query that produced the data backing the claim claim: The natural-language claim to verify (e.g. "Toronto had 12,345 building permits in 2023")
Inputs: sql (required), claim (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 23 tools
Most tools have distinct purposes, though some remote query tools (query_resource, sql_query, preview_data) could cause minor confusion. Descriptions help differentiate their use cases.
Tools follow a consistent verb_noun pattern with snake_case, but 'validate_result' breaks the pattern (verb_noun without underscore). Overall, naming is predictable.
23 tools is on the higher end but justified given the comprehensive coverage of data portal operations: discovery, metadata, download, caching, geospatial, and querying.
Covers all major workflows from search to analysis. Minor gaps like lack of bulk operations or dataset update tools, but these align with the read-heavy nature of open data portals.
Maintenance
Related MCP Connectors
Query, join, profile, clean and convert CSV/JSON/Parquet with server-side DuckDB over MCP.
This MCP server provides seamless access to Malaysia's government open data, including datasets, w…
One MCP server for all web data. Scrape, search, crawl, and AI research in one install.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server that provides tools for intelligently querying, analyzing, and retrieving datasets from Toronto's CKAN-powered open data portal. It enables AI assistants to perform natural language searches, inspect data structures, and track dataset update frequencies across the city's open data catalog.12-
- AlicenseNot gradedqualityDmaintenanceA local MCP server enabling AI assistants to query and analyze data via DuckDB SQL engine, supporting local files, memory, S3, and MotherDuck.14 npmApache 2.0
- AlicenseNot gradedqualityBmaintenanceEnables querying open data platforms like CKAN via natural language. Provides a configurable MCP server with plugins for different data sources.MIT
- AlicenseAqualityDmaintenanceAn MCP server that gives LLM agents typed, cached access to civic open-data portals via Socrata (SODA 2.1 + Discovery API), enabling search, query, profiling, sampling, and CSV export of datasets.6MIT