StatCan ODCAF MCP Server
An MCP server that lets an AI assistant query Statistics Canada's ODCAF open dataset in natural language. I built it end to end in a challenge that lasted 48 hours.
Architecture
A FastAPI service implements the Model Context Protocol. It exposes a small set of typed tools that an LLM can call. Each tool validates its parameters, queries the ODCAF dataset, and returns structured results the model can reason over.
Key decisions
MCP instead of a bespoke plugin
MCP is a portable interface. The same server works with any client that speaks MCP, so the integration is not tied to one product. That portability was worth more than a custom endpoint.
FastAPI to move fast under a deadline
With 48 hours on the clock, I picked FastAPI for typed request validation and almost no boilerplate, so most of the time went into the data tools rather than the plumbing.
The hard part
Keeping an LLM inside safe boundaries
The model drives the queries, so the tools cannot accept arbitrary input. Each tool exposes a narrow, validated surface with fixed parameters, whitelisted fields, and bounded results. The model gets useful freedom without any path to arbitrary or abusive queries.
Security and performance
- Every tool parameter is validated and constrained. The model never composes raw queries against the data source.
- The dataset is public and read only, so there is no sensitive data and no write path to protect.