Skip to main content
Glama
statistics-canada-mcp

statistics-canada-mcp

statistics-canada-mcp

Statistics Canada Web Data Service (WDS) MCP server. It exposes dedicated, validated read-only tools for the documented public WDS REST API and preserves the source skeleton's multi-user Vault/Postgres, dual transport, A2A, LangGraph worker, and pg-boss scheduling architecture.

Status and provenance

  • Server identity: MCP_SERVER_NAME=statistics-canada-mcp.

  • GitHub destination requested: LesterAJohn/statistics-canada-mcp; publication is intentionally not performed in this workspace.

  • Repository mode: new (standalone, fresh history). This directory is not initialized as a Git repository; the parent will initialize, commit, create/push the remote, and check Actions after review.

  • Skeleton source: https://github.com/LesterAJohn/skeleton-mcp, exact source commit bfbf26a6939a3c3c387a34bd2461f1bb5d0b8eec.

  • License: MIT; see LICENSE. Upstream copyright/license notices are retained.

  • User-provided API-DOCS.md and docs/web-data-service.html are preserved unchanged. The local HTML is the official WDS landing page and lists 15 methods; the linked official WDS User Guide, revision 1.6, documents those methods plus supplemental getCodeSets. No official OpenAPI file was available. The normalized reviewed coverage inventory records this provenance and the guide's one inconsistent query-parameter example.

Related MCP server: Tuyan MCP

API coverage

All 16 documented WDS operations have dedicated wds_* MCP tools. The guide uses GET and POST to retrieve public data/metadata; every operation is read-only regardless of HTTP verb. The adapter rejects undocumented endpoints, other HTTP methods, arbitrary hosts, and credential-bearing headers. It does not forward upstream authorization credentials because WDS is public and the documents specify no upstream authentication.

API operation

MCP tool

getChangedSeriesList

wds_get_changed_series_list

getChangedCubeList

wds_get_changed_cube_list

getCubeMetadata

wds_get_cube_metadata

getSeriesInfoFromCubePidCoord

wds_get_series_info_from_cube_pid_coord

getSeriesInfoFromVector

wds_get_series_info_from_vector

getAllCubesList

wds_get_all_cubes_list

getAllCubesListLite

wds_get_all_cubes_list_lite

getChangedSeriesDataFromCubePidCoord

wds_get_changed_series_data_from_cube_pid_coord

getChangedSeriesDataFromVector

wds_get_changed_series_data_from_vector

getDataFromCubePidCoordAndLatestNPeriods

wds_get_data_from_cube_pid_coord_and_latest_n_periods

getDataFromVectorsAndLatestNPeriods

wds_get_data_from_vectors_and_latest_n_periods

getBulkVectorDataByRange

wds_get_bulk_vector_data_by_range

getDataFromVectorByReferencePeriodRange

wds_get_data_from_vector_by_reference_period_range

getFullTableDownloadCSV

wds_get_full_table_download_csv

getFullTableDownloadSDMX

wds_get_full_table_download_sdmx

Supplemental getCodeSets

wds_get_code_sets

Each tool's Zod input schema is defined in src/services/wdsOperations.js. Endpoint method/path, required inputs, implementation status, test mapping, uncertainty, and coverage totals are in inventory/statistics-canada-wds.json and docs/api-coverage.md.

npm run inventory:generate # deterministic JSON + Markdown output
npm run inventory:check    # fails for stale output, missing/duplicate mappings, invalid names, or uncovered methods

WDS rate limits documented by Statistics Canada are 25 requests/second per IP (50 overall per IP in guide availability notes); the adapter uses a 15-second timeout and bounded retries with Retry-After handling for 429/5xx/network failures. Responses are capped by STATCAN_WDS_MAX_RESPONSE_BYTES (32 MiB default). Large cube-list and table-download URL calls may be expensive in response size; full-table tools return the documented download URL and do not download the archive.

Runtime and identity model

  • Transports: stdio, HTTP, or both (MCP_TRANSPORT_MODE=stdio|http|both). HTTP supports token auth, OAuth2 introspection, or both; request body limits, rate limits, origin/IP controls, token validation, and response redaction are retained.

  • WDS has no tenant- or user-specific upstream data. WDS reads still require MCP HTTP transport authentication where HTTP is used. Agent tasks, credentials, configuration, memory, schedules, grants, and checkpoints are owner-scoped by authenticated tenant and user/account; caller-supplied identity does not authorize access.

  • Default scope is tenant/user default. HTTP scope comes from the authenticated identity. Public WDS data is not a substitute for authorization to MCP configuration or agent state.

  • Secrets remain in Vault; non-secret configuration and durable agent/scheduling state remain in Postgres. Raw inference keys and authorization inputs are not written to Postgres, tasks, memory, checkpoints, schedules, or logs.

  • Changing MCP_SERVER_NAME changes the persistence namespace. Plan and perform an explicit data migration; never change it casually.

Derived names for this server:

  • Postgres prefix/schema: statistics_canada_mcp; config table statistics_canada_mcp_config; agent, tenant, memory, schedule, grant, and run tables use the same prefix.

  • LangGraph checkpoint schema: statistics_canada_mcp_langgraph.

  • pg-boss schema: statistics_canada_mcp_pgboss; task and schedule-trigger queues are derived from the same namespace.

  • Vault token index: statistics-canada-mcp/http/auth/token-index, with tenant/principal token-index paths supported.

  • Agent credential KV path: statistics-canada-mcp/tenants/<tenant>/<users|accounts>/<principal>/agent/credentials/<credentialRef>.

  • APP_NAME is only a legacy migration input. Legacy data is retained when copied; Postgres identifier normalization collision checks remain enabled.

Tool catalog

Statistics Canada tools

  • service_connection_info, service_scope_info, service_health_check, service_list_endpoints, and service_query_suggestion provide connection/scope details, API reachability, endpoint discovery, and schema-valid recommendations.

  • The 16 dedicated wds_* tools in the coverage table perform the documented API operations.

  • service_api_request is a read-only compatibility/discovery tool, restricted by the adapter to documented WDS paths, GET/POST, the configured official WDS origin (or loopback test endpoint), and a safe request-header allowlist. It does not replace dedicated operation tools.

Config, Vault, and access-management tools

  • Postgres non-secret config: config_list, config_get, config_set, config_delete, token_rotation_config.

  • Vault Agent sink: vault_agent_token_read (admin-only; token material is omitted unless explicitly requested).

  • User access tokens: vault_seed_http_token, vault_seed_oauth_token; corresponding CLI helpers are npm run vault:seed-http-token and npm run vault:seed-oauth-token. The token index stores hashes/metadata and maintains default-user fallback.

  • Vault lifecycle: token_lookup_self, token_renew_self, token_create, token_revoke, token_revoke_self; raw Vault tokens remain redacted unless a guarded tool explicitly requests one.

  • Tenant/principal administration: tenancy_tenant_*, tenancy_user_*, tenancy_account_*, and proxy_user_initialize.

Agent, worker, A2A, and scheduling tools

  • Agent discovery/readiness: agent_config_schema reports the supported config contract and registered capabilities; agent_readiness reports Postgres, Vault, pg-boss, principal inference configuration, and worker-process status without claiming a separate worker is live.

  • Agent config: agent_config_get, agent_config_set, agent_config_update, agent_config_delete, agent_config_validate, agent_config_test_connection; separate delegated tools are agent_config_user_get/list/set/update/delete.

  • Vault inference credentials: agent_credential_set, agent_credential_rotate, agent_credential_get, agent_credential_delete. All require admin authorization, derive scope from authenticated identity, return metadata only, and use principal-scoped KV paths.

  • Tasks/compositions/memory: agent_goal, agent_task_status, agent_task_resume, agent_task_cancel, agent_compositions_list, agent_composition_run, agent_memory_search, agent_memory_add.

  • Scheduling: agent_schedule_create, agent_schedule_once, agent_schedule_update, agent_schedule_get, agent_schedule_list, agent_schedule_enable, agent_schedule_disable, agent_schedule_delete, agent_schedule_run_now, agent_schedule_preview, agent_schedule_runs/history, agent_schedule_grant_create/get/revoke.

  • pg-boss administration/inspection is exposed by pgboss_* tools. Agent scheduling uses owner-scoped app tables and revocable grants, not stored bearer tokens. Disabling/deleting a schedule does not cancel already-submitted tasks.

OAuth and authorization contract

HTTP bearer authentication is separate from tool authorization. Set MCP_HTTP_AUTH_MODE=oauth2 (or both) and configure a trusted introspection provider. MCP_HTTP_OAUTH2_<PROVIDER>_SCOPE_MAP is an allowlist from provider scopes to only the canonical scopes below. With no mapping, verified provider scopes pass through. The API itself has no upstream OAuth scopes.

Recommended client registration requests mcp:invoke for MCP invocation. Configure the provider's REQUIRED_SCOPES for its own accepted authorization scope (for example <provider-invoke-scope>); configure the MCP required scopes deliberately. Examples use placeholders for provider values and never include real credentials.

Accepted MCP scope

Purpose and tool/operation classes

Operation class / gate

mcp:invoke

Invoke MCP tools; also permits agent task/A2A execution when the caller has an enabled scoped config.

Read-only WDS calls require valid HTTP authentication, not an extra per-tool mcp:read check; agent execution requires mcp:invoke or mcp:agent.

mcp:read

Descriptive read scope; useful in issued token metadata and HTTP admission policy.

Read-only; no separate per-tool check is added by the WDS adapter.

mcp:write

Non-admin config mutations, pg-boss mutation, and agent capability execution where the registry requires a mutating capability.

Mutating; no WDS operation is mutating.

mcp:admin

Vault lifecycle/credential tools, agent config and connection tests, schedule/grant administration, and privileged operations.

Admin-only; equivalent to authorizationKey only in scope-based authorization mode.

mcp:agent

Agent task/A2A execution alternative to mcp:invoke.

Execution only, still owner/config/capability constrained.

mcp:tenancy:admin

Tenant/user/account administration and scoped access-token provisioning.

Admin-only, bounded to authenticated/delegated tenant unless global mcp:admin.

mcp:proxy:initialize

Initialize a user from a trusted Apify/MCPize proxy identity.

Admin-like bootstrap for that fixed proxy identity only.

mcp:agent-config:admin

Cross-user agent config administration within an authorized tenant.

Admin-only; does not grant Vault server-token administration.

For OAuth clients, protected tool authorization uses the mapped scopes; a raw bearer token or authorizationKey does not bypass tenant/principal ownership checks. In key mode, protected tools require MCP_ADMIN_AUTH_KEY; in scope mode, protected operations use the scopes above. There are no Statistics Canada service-specific upstream OAuth scopes.

Example mapping uses placeholders:

MCP_HTTP_AUTH_MODE=oauth2
MCP_AUTHZ_MODE=auto
MCP_HTTP_OAUTH2_PROVIDERS=provider
MCP_HTTP_OAUTH2_PROVIDER_INTROSPECTION_URL=https://identity.example.invalid/introspect
MCP_HTTP_OAUTH2_PROVIDER_CLIENT_ID=<introspection-client-id>
MCP_HTTP_OAUTH2_PROVIDER_CLIENT_SECRET=<deployment-secret>
MCP_HTTP_OAUTH2_PROVIDER_REQUIRED_SCOPES=<provider-invoke-scope>
MCP_HTTP_OAUTH2_PROVIDER_SCOPE_MAP=<provider-invoke-scope>:mcp:invoke,<provider-write-scope>:mcp:write,<provider-admin-scope>:mcp:admin
MCP_HTTP_OAUTH2_REQUIRED_SCOPES=mcp:invoke

Fresh deployment and agent configuration

No inference provider or credential is needed to start the MCP, HTTP/stdio transports, config tools, A2A card, worker, or scheduler. Readiness reports missing inference config separately; inference-dependent tasks fail with actionable errors until an operator configures it.

  1. Provision Postgres and Vault. Use local Compose, or app-only external Compose with the external VAULT_* and POSTGRES_* settings listed below.

  2. Set MCP_SERVER_NAME=statistics-canada-mcp consistently for server, worker, init, and Postgres/Vault assets. Set MCP_ADMIN_AUTH_KEY through deployment secrets; production protected operations fail closed when no required admin protection is configured.

  3. Configure and verify HTTP auth if HTTP is used. The default local auth token is a placeholder and must be replaced with Vault-indexed or OAuth credentials.

  4. As an authorized operator, call agent_credential_set with credentialRef: "inference/default" and the provider key in the credential argument. The value is written only to Vault under the authenticated principal's scoped path; the response never echoes it.

  5. Call agent_config_validate with a non-secret configuration object. Supported inference contract: protocol: "openai-compatible", HTTPS public endpoint (loopback HTTP only in development), model, credentialRef, temperature/token/time limits, service instructions, permitted MCP capabilities, and memory settings. Secret values in config are rejected.

  6. Call agent_config_test_connection to validate the configured endpoint/credential. It makes a network request to the configured endpoint (/models) and may incur provider charges. Check response/readiness with agent_config_get.

  7. Call agent_config_set with the validated config, enabled: true, expectedRevision: 0, and admin authorization. Then submit a non-destructive agent_goal such as reading wds_get_code_sets, and poll agent_task_status.

  8. For scheduled work, create a revocable grant restricted to minimal read-only WDS tools, create a future one-shot or strict five-field cron schedule, and inspect its run/task history. Configure and test with disposable inference when validating actual worker dispatch.

Credential rotation uses agent_credential_rotate; deletion permanently removes the scoped Vault KV metadata/versions but does not delete configs, tasks, or schedules. Update the agent config or re-provision a credential before execution. Config deletion tombstones the config and disables execution; it does not cancel prior tasks or schedules. Shared credentials are not used across principal scopes.

Setup and deployment

Requires Node.js 22+ and npm. Local Compose requires Docker Compose 2.24+.

npm ci
cp .env.example .env
# Configure deployment secrets locally; do not commit .env.
docker compose up -d
npm run start:stdio             # stdio MCP
npm run start:http              # HTTP MCP, or use Compose's mcp-http
npm run start:agent-worker      # separate process; Compose starts this worker

The local compose stack includes Postgres, Raft-backed Vault, vault-unseal-key-init, HTTP MCP, and an agent worker. Preserve vault-unseal-key-init startup ordering. It resolves the managed unseal key using VAULT_UNSEAL_KEY, then src/config/vault.unseal.key.json, then generates a key if neither exists. This does not initialize, unseal, or auto-unseal Vault. Keep actual Vault initialization output and unseal material out of Git.

For existing Vault/Postgres services:

docker compose -f docker-compose.external.yml up -d

External Services Mode

External deployment requires VAULT_ADDR, VAULT_TOKEN (or the configured Vault Agent auth path), POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER, and POSTGRES_PASSWORD; PGBOSS_CONNECTION_STRING may override the pg-boss connection, but transactional task dispatch requires the same database. Use TLS and least-privilege Vault auth in production. See Vault Raft migration and recovery guidance.

Agent worker settings must be shared between server and worker: MCP_SERVER_NAME=statistics-canada-mcp, MCP_AGENT_WORKER_ENABLED=true, PGBOSS_ENABLED=true, the same Postgres/Vault credentials, and matching auth/admin configuration. MCP server and worker are separate processes. The worker starts with npm run start:agent-worker; enabling a flag alone does not start it. The scheduler reconciles registrations and durable runs; pg-boss state and application state must use the same database.

HTTP TLS behavior

MCP_HTTP_TLS_ENABLED=false is the documented and configured default. Without native TLS, local HTTP examples are loopback-only; for remote production, terminate TLS at a trusted reverse proxy and set proxy trust only when the immediate proxy is controlled. An internal unencrypted hop is acceptable only on a trusted network.

To enable Node native TLS, set MCP_HTTP_TLS_ENABLED=true, provide externally provisioned PEM certificate/key paths through MCP_HTTP_TLS_CERT_PATH and MCP_HTTP_TLS_KEY_PATH, and optionally configure MCP_HTTP_TLS_KEY_PASSPHRASE and MCP_HTTP_TLS_MIN_VERSION (default TLSv1.2). Startup fails if either file is missing/unreadable and never falls back to HTTP. Both Compose app deployments mount ./certs at /app/certs read-only for this purpose; never generate or commit production key material. Renew/rotate files securely and restart the process after replacement.

Use https://<host>:<port>/mcp and https://<host>:<port>/a2a when native TLS is enabled; set MCP_A2A_PUBLIC_URL to the externally reachable HTTPS URL when behind a proxy or using a non-default host/path. Example HTTP client URLs such as http://127.0.0.1:3000/mcp are for loopback development only.

Configuration and environment

Service settings:

Variable

Default / purpose

MCP_SERVER_NAME

statistics-canada-mcp; single namespace source.

STATCAN_WDS_BASE_URL

https://www150.statcan.gc.ca/t1/wds/rest; only the official HTTPS host or loopback test endpoint is accepted.

STATCAN_WDS_TIMEOUT_MS

15000 ms.

STATCAN_WDS_MAX_RESPONSE_BYTES

33554432 (32 MiB).

MCP_TRANSPORT_MODE

stdio; accepts stdio, http, both.

MCP_HTTP_TLS_ENABLED

false.

Transport/auth variables include MCP_HTTP_HOST, MCP_HTTP_PORT, MCP_HTTP_PATH, MCP_HTTP_HEALTH_PATH, MCP_HTTP_AUTH_MODE, MCP_HTTP_TOKEN_SOURCE, MCP_HTTP_AUTH_TOKENS, MCP_HTTP_VAULT_TOKEN_INDEX_PATH, MCP_HTTP_VAULT_TOKEN_REQUIRED_SCOPES, MCP_HTTP_OAUTH2_PROVIDERS, MCP_HTTP_OAUTH2_<PROVIDER>_*, MCP_HTTP_ALLOWED_ORIGINS, MCP_HTTP_ALLOWED_IPS, MCP_HTTP_TRUST_PROXY, MCP_HTTP_MAX_BODY_BYTES, MCP_HTTP_RATE_LIMIT_WINDOW_MS, MCP_HTTP_RATE_LIMIT_MAX_REQUESTS, and the TLS variables above.

Persistence and agent variables include POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, optional POSTGRES_CONNECTION_STRING, VAULT_ADDR, VAULT_TOKEN, VAULT_KV_MOUNT, VAULT_AGENT_ENABLED, VAULT_AGENT_AUTH_MODE, VAULT_AGENT_TOKEN_FILE_PATH, VAULT_AGENT_LISTENER_ENABLED, VAULT_AGENT_LISTENER_ADDR, VAULT_UNSEAL_KEY, PGBOSS_ENABLED, PGBOSS_CONNECTION_STRING, PGBOSS_SUPERVISE, MCP_ADMIN_AUTH_KEY, MCP_AUTHZ_MODE, MCP_CONFIG_DEFAULT_TENANT_ID, MCP_CONFIG_DEFAULT_USER_ID, MCP_AGENT_WORKER_ENABLED, MCP_AGENT_MAX_GOAL_BYTES, MCP_AGENT_MAX_TASK_RUN_TIME_MS, MCP_AGENT_SCHEDULE_RECONCILE_MS, MCP_AGENT_SCHEDULE_RETENTION_DAYS, MCP_A2A_PATH, MCP_A2A_CARD_PATH, and MCP_A2A_PUBLIC_URL. Rotation default and user overrides are MCP_TOKEN_ROTATION_DEFAULT_INTERVAL_MS and the user-scoped token.rotation.intervalMs config key.

See .env.example for the complete variable template, including all OAuth provider options and TLS paths. Production secrets must be injected through a secret manager, not committed. APP_NAME is legacy migration input only, not a second naming knob.

Tests, CI, and local push gate

npm run inventory:check
npm test

npm test covers workspace contracts, all WDS tool mappings and request formats, response limits/retries/allowlists, auth, redaction, stdio/HTTP, TLS enabled/disabled/failure behavior, agent config and credential lifecycle, A2A, scheduling, and Vault Agent listener/both/env fallback. The ordinary local run skips the two opt-in Postgres/pg-boss integration tests and the required Vault/Postgres disposable-services integration test when those services are not configured. Skips are not live service verification.

For required disposable-service checks, set MCP_AGENT_TEST_DATABASE_URL, VAULT_ADDR, and VAULT_TOKEN to throwaway local services and run:

npm run test:required

This forces the Postgres agent/scheduler integration and Vault/Postgres persistence smoke test to run; failures are not skipped. GitHub Actions checks the deterministic inventory and runs tests against disposable Postgres and Vault. No real inference provider, credentials, production API, or paid model is used. A full controlled OpenAI-compatible end-to-end inference + scheduled occurrence run remains an operator/deployment validation item; the local adapter and schedule unit coverage do not constitute that live end-to-end verification.

Install the version-controlled pre-push check after the parent initializes/clones the repository:

npm run setup:hooks

It configures .githooks/pre-push to run inventory checks and npm run test:required, and requires the disposable service URLs/token above. Branch protection and GitHub required checks are not configured locally; repository creation/publishing was explicitly deferred.

Maintainer notes

  • Review agent/playbooks/service-onboarding.md and agent/templates/service-spec.md before extending this adapter.

  • Keep API inventory output reproducible from checked-in operation definitions; do not make CI download mutable documentation.

  • Preserve docker-compose.external.yml for external Vault/Postgres deployments and vault-unseal-key-init dependency ordering for local/production Raft flows.

  • Do not add any Statistics Canada write operation without official documentation, an explicit operation classification, strict authorization, and tests; no such operation is documented in this build's inventory.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables discovery of HEPData records, tables, and data access with read-only operations and export links.
      9
      21 PyPI
      GPL 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables scientific-figure agents to retrieve versioned workflow bundles, public templates, rules, JSON Schemas, and dataset manifests through a single anonymous, read-only, stateless MCP tool.
      1
      Apache 2.0
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables discovery and querying of public OpenBind structure-affinity datasets, experimental binding events, benchmark results, and live Fragalysis targets and observations through read-only REST endpoints without requiring an API key.
      -