Token导航 LogoToken导航TokenDH.com
MCP Statcan logo
数据服务stdio官方级别未说明来源级核验

MCP Statcan

MCP Server

提供对加拿大统计局Web数据服务和SDMX REST API的结构化访问,支持MCP客户端和独立CLI工具进行数据查询和下载。

工具数

17

提示词数

0

GitHub Stars

4

资源数

0
数据服务PythonClaudeClaude DesktopClaudeCursorVS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

Aryan-Jhaveri

提供方

Aryan-Jhaveri

最后核验

2026/5/17 20:22

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

uvx statcan-mcp-server --transport http

详细介绍

加拿大统计局MCP服务器

![SafeSkill 93/100](https://safeskill.dev/scan/aryan-jhaveri-mcp-statcan)

加拿大统计局的MCP服务器和CLI Web数据服务(WDS)SDMX REST API.为任何MCP客户端(Claude、Cursor、VS Code Copilot、Gemini)提供对加拿大统计数据的结构化访问。包括一个独立 statcan CLI用于直接下载,无需LLM。

托管在Render上——大多数用户不需要安装。看 快速开始.

⚠️ LLM可能会伪造数据。始终根据以下内容核实重要数字 加拿大官方统计数据来源.

______________________________________________________________________

目录

______________________________________________________________________

快速开始

选择适合你的选项。您不需要为选项1安装任何东西。

选项1——使用托管服务器(推荐)

直接连接到Render上的公共服务器。不 uv,没有终端,没有本地设置。

克劳德桌面/Claude.ai

  1. 打开 设置→ 连接器→ 添加自定义连接器
  2. 姓名: mcp-statcan
  3. 网址: https://mcp-statcan.onrender.com/mcp
  4. 保存并重新启动

克劳德代码

claude mcp add statcan --transport http https://mcp-statcan.onrender.com/mcp --scope global
托管服务器提供所有WDS+SDMX工具。数据库工具(SQLite)需要本地设置(选项3)——它们被有意排除在共享服务器之外。

______________________________________________________________________

选项2——自主机HTTP(WDS+SDMX,无数据库)

使用与托管版本相同的工具运行本地服务器。

步骤1 --安装 uv:

# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

步骤2 --启动服务器:

uvx statcan-mcp-server --transport http
# Listening at http://localhost:8000

步骤3 --将您的客户端连接到 http://localhost:8000/mcp.

______________________________________________________________________

选项3——完全本地设置(WDS+SDMX+SQLite)

选项2中的所有内容,以及用于使用SQL存储和查询数据的数据库工具。通过stdio运行。

步骤1 --安装 uv (与上述相同)。

步骤2 --使用中的stdio代码段配置您的客户端 客户端设置 在......下面

uvx 首次使用时自动下载并运行服务器。

______________________________________________________________________

选项4-- statcan CLI(不需要LLM)

直接从终端下载StatCan数据。看 statcan命令行界面.

uvx statcan-mcp-server        # installs the package
statcan search "labour force"
statcan download 14-10-0287-01 --last 12 --output lfs.csv

______________________________________________________________________

示例

聊天示例

数据集查询演示源代码
加拿大的温室气体排放量“为过去4年加拿大整体温室气体排放创建一个简单的可视化”聊天表38-10-0097-01
加拿大国际服务贸易“通过可视化对过去6个月的国际服务贸易进行快速分析”聊天表12-10-0144-01
安大略省建筑价格指数“生成2023年第四季度至2024年第四财季安大略省建筑物价指数的可视化结果”聊天表18-10-0289-01
加拿大失业仪表板“使用statcan mcp创建加拿大失业仪表盘”聊天表14-10-0287-01

仪表板示例

标题链接来源
加拿大关键矿产经济仪表盘表36-10-0708-01
万物价格:2015-2026年CPI仪表板仪表盘表18-10-0004-01
加拿大生物医学和生物技术产业仪表盘表27-10-0297-01

______________________________________________________________________

客户端设置

托管服务器(选项1)

克劳德桌面 --设置→ 连接器→ 添加自定义连接器

  • 姓名: mcp-statcan
  • 网址: https://mcp-statcan.onrender.com/mcp

克劳德代码

claude mcp add statcan --transport http https://mcp-statcan.onrender.com/mcp --scope global

光标.cursor/mcp.json (项目)或 ~/.cursor/mcp.json (全球):

{
  "mcpServers": {
    "statcan": {
      "url": "https://mcp-statcan.onrender.com/mcp"
    }
  }
}

VS代码(GitHub副本).vscode/mcp.json:

{
  "servers": {
    "statcan": {
      "type": "http",
      "url": "https://mcp-statcan.onrender.com/mcp"
    }
  }
}

______________________________________________________________________

自托管HTTP(选项2)

开始 uvx statcan-mcp-server --transport http 首先,然后配置您的客户端。

大多数客户需要 mcp-proxy 桥接stdio↔ HTTP。Claude Code本机连接。

克劳德桌面 --设置→ 开发者→ 编辑配置:

{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["mcp-proxy", "--transport", "streamablehttp", "http://localhost:8000/mcp"]
    }
  }
}

克劳德代码

claude mcp add statcan --transport http http://localhost:8000/mcp --scope global

光标/VS码/双子座 --同样的 mcp-proxy 包装,指向 http://localhost:8000/mcp.

______________________________________________________________________

完全本地/stdio(选项3)

克劳德桌面 --设置→ 开发者→ 编辑配置:

{
  "mcpServers": {
    "statcan": {
      "command": "uvx",
      "args": ["statcan-mcp-server", "--db-path", "/Users//.statcan-mcp/statcan_data.db"]
    }
  }
}
通过 --db-path 一条绝对的路径。Claude Desktop覆盖子流程 HOME env-var,这可能会破坏默认路径解析。

克劳德代码

claude mcp add statcan --scope global -- uvx statcan-mcp-server

光标/VS码/双子座 --使用 uvx statcan-mcp-server 作为stdio命令。

______________________________________________________________________

Claude.ai如何使用此服务器

Claude.ai(web)没有bash沙盒——它不能运行shell命令。相反,它使用MCP工具进行发现和 Python脚本工具 在不扩大上下文窗口的情况下获取数据。

模式:

1. MCP tools (small payloads — metadata only):
   search_cubes_by_title("labour force")  → productId
   get_sdmx_structure(productId=...)      → dimension layout + codes
   get_sdmx_key_for_dimension(...)        → OR key for large dimensions

2. Python script (data never enters context):
   url = "https://mcp-statcan.onrender.com/files/sdmx/
/?lastNObservations=12"
   → validate URL domain → write to ./statcan_
.csv → print summary only

3. Follow-up script (analysis from local file):
   rows = list(csv.DictReader(open("./statcan_
.csv")))
   → filter / sort / aggregate → print only the result

get_sdmx_data 在托管服务器上始终返回 download_csv URL而不是内联数据——无论响应大小如何,数据都不会出现在上下文窗口中。

克劳德代码(bash沙盒) 使用 statcan 改为CLI:

statcan search "labour force"
statcan download 14-10-0287-01 --last 12 --output ./lfs.csv
awk -F',' 'NR>1 && $1=="Canada"' ./lfs.csv | sort -t',' -rn -k5 | head -10

______________________________________________________________________

MCP提示

服务器提供了五个提示,可以在支持的客户端中作为斜线命令访问。每个都有双指令——Claude Code(bash)和Claude.ai web(Python脚本)。

提示它教什么
/statcan-data-lookup端到端:搜索→ 结构→ 构建密钥→ 获取到本地文件→ 分析
/sdmx-key-builderSDMX键语法:通配符、OR键、时间参数、下载URL格式
/statcan-download下载特定表格:CLI命令+Python脚本替代
/statcan-explore提交前的样本:3周期提取、列布局、大小估计
/statcan-vector-pipeline多系列下载和跨系列比较

克劳德代码中的用法:

/statcan-data-lookup topic="consumer price index" analysis_goal="trend last 5 years"
/statcan-download product_id=18100004 last_n=24

______________________________________________________________________

statcan命令行界面

一个独立的CLI,用于在没有LLM的情况下下载StatCan数据。将管道友好的CSV/JSON输出到stdout;进度和错误将转到stderr。

安装:

pip install statcan-mcp-server   # or: uvx statcan-mcp-server (no install)

命令:

statcan search             Search tables by keyword
statcan metadata 
    Show table structure (dimensions + members)
statcan download 
    Download observations via SDMX
statcan vector ...    Download one or more vector series
statcan codeset                  Show StatCan code definitions (UOM, frequency, etc.)

常用用法:

# Find a table
statcan search "consumer price index"
statcan search "labour force" --max-results 10 --format json

# Inspect structure before downloading
statcan metadata 18-10-0004-01
statcan metadata 18100004 --full        # show all dimension members

# Download data
statcan download 18-10-0004-01 --last 12 --output cpi.csv
statcan download 18-10-0004-01 --key "1.1.1" --start 2020-01 --end 2024-12
statcan download 18-10-0004-01 --last 5 --dry-run   # preview SDMX URL

# Download by vector ID
statcan vector v41690973 --last 24 --output series.csv
statcan vector v41690973 v41690974 --last 12 --output multi.csv

# Decode numeric codes
statcan codeset --type uom
statcan codeset --type frequency --format json

输出格式: csv (默认下载/矢量), table (搜索/元数据/代码集的默认值), json

管道样式:

# Top 10 by value
statcan download 14-10-0287-01 --last 1 --format csv \
  | awk -F',' 'NR>1' | sort -t',' -k5 -rn | head -10

# Extract unique geographies
statcan download 14-10-0287-01 --last 1 --format csv \
  | awk -F',' 'NR>1 {print $1}' | sort -u

# Chain search → download
PID=$(statcan search "CPI" --format json | python3 -c "import sys,json; print(json.load(sys.stdin)[0]['Product ID'])")
statcan download $PID --last 12 --output cpi.csv

有关完整的CLI参考,请参阅 cli.md.

______________________________________________________________________

功能和工具

SDMX工具--服务器端过滤数据提取

只返回您请求的切片。无法下载完整表格。

工具说明
get_sdmx_structure表的维度代码列表+键语法。打电话之前 get_sdmx_data.
get_sdmx_data按以下方式过滤观察结果 productId +钥匙。返回托管服务器上的CSV下载URL——数据脱离上下文。
get_sdmx_vector_data通过SDMX对单个矢量Id的观测。
get_sdmx_key_for_dimension将大维度的所有叶子成员ID作为可粘贴的OR键。当一个维度有>30个代码时使用(例如NOC、CMA)。

关键语法 (传给 get_sdmx_data):

  • "1.2.1" --地理=1,性别=2,年龄=1
  • ".2.1" --所有地区(通配符),性别=2,年龄=1
  • "1+2.2.1" --地理1或2,性别=2,年龄=1
注: 通配符(.)在大于30个代码的维度上,返回稀疏、不可预测的样本。使用 get_sdmx_key_for_dimension 以获得正确的OR键。

WDS发现和元数据

工具说明
search_cubes_by_title在所有StatCan表中进行全文搜索。AND逻辑,最多25个结果。
get_all_cubes_list / _lite分页表库存(offset/limit,默认为100/页)。
get_cube_metadata维度信息、成员列表、日期范围。 summary=True 每个尺寸上有10个盖子。
get_code_sets解码StatCan数字代码(频率、计量单位、标量因子、状态)。

WDS系列分辨率和变化检测

工具说明
get_series_info解决 {productId, coordinate} 配对为vectorId+元数据。
get_series_info_from_vector将vectorId解析为productId、坐标、标题、频率。
get_changed_cube_list在特定日期更新的表格。
get_changed_series_list系列在特定日期更新。
get_changed_series_data_from_cube_pid_coord坐标发生变化的数据点。
get_changed_series_data_from_vector为vectorId更改的数据点
get_bulk_vector_data_by_range按发布日期范围过滤的多个向量。

复合和数据库工具 *(仅限本地/stdio模式)*

这些工具在托管的Render服务器上不可用——SQLite是每个进程的,不会在用户之间共享。

工具说明
fetch_vectors_to_database按参考周期范围获取向量并存储到SQLite。
store_cube_metadata将完整的多维数据集元数据提取到SQLite中——使用SQL浏览所有成员和向量ID。
query_database针对本地SQLite数据库的只读SQL。
create_table_from_data / insert_data创建或附加到表。
list_tables / get_table_schema / drop_table数据库实用程序。

典型工作流程

Claude.ai网站(托管服务器):

1. search_cubes_by_title("unemployment rate")
   → productId e.g. 14100287

2. get_sdmx_structure(productId=14100287)
   → dimension positions + sample codes

3. get_sdmx_key_for_dimension(productId=14100287, dimension_position=3)
   → or_key for large dimensions

4. get_sdmx_data(productId=14100287, key=".2.1", lastNObservations=24)
   → returns download_csv URL

5. Python script: validate URL domain → write to ./statcan_14100287.csv → analyze → print summary

克劳德代码(bash沙盒):

statcan search "unemployment rate"
statcan metadata 14100287
statcan download 14-10-0287-01 --last 24 --output ./lfs.csv
awk -F',' 'NR>1 && $1=="Canada"' ./lfs.csv | sort -t',' -rn -k5 | head -10

______________________________________________________________________

项目结构

src/
├── api/
│   ├── cube/
│   │   ├── discovery.py         # search_cubes_by_title, get_all_cubes_list
│   │   ├── metadata.py          # get_cube_metadata
│   │   └── series.py            # get_series_info, change detection
│   ├── vector/
│   │   └── vector_tools.py      # vector series, bulk range fetch
│   ├── sdmx/
│   │   └── sdmx_tools.py        # get_sdmx_structure, get_sdmx_data, get_sdmx_key_for_dimension
│   ├── composite_tools.py       # fetch_vectors_to_database, store_cube_metadata (stdio only)
│   └── metadata_tools.py        # get_code_sets
├── cli/
│   ├── main.py                  # statcan CLI entry point (Typer app)
│   ├── output.py                # write_output, format helpers
│   └── commands/
│       ├── search.py            # statcan search
│       ├── metadata.py          # statcan metadata
│       ├── download.py          # statcan download
│       ├── vector.py            # statcan vector
│       └── codeset.py           # statcan codeset
├── db/                          # SQLite connection, schema, queries (stdio only)
├── models/                      # Pydantic input models
├── util/
│   ├── registry.py              # ToolRegistry — @decorator → MCP Tool schema
│   ├── truncation.py            # Response truncation + pagination guidance
│   ├── sdmx_json.py             # SDMX-JSON → tabular rows
│   └── cache.py                 # 1-hour TTL cache for cube list
├── config.py                    # BASE_URL, SDMX_BASE_URL, RENDER_BASE_URL, TRANSPORT, PORT
└── server.py                    # create_server(), MCP Prompts, HTTP routes (/files/sdmx/), CLI

______________________________________________________________________

已知问题

问题状态解决方法
“无法打开Claude Desktop上的数据库文件”活动通行证 --db-path /Users//.statcan-mcp/statcan_data.db 在您的配置中
SSL验证已禁用活动VERIFY_SSL = False 在所有API调用中-StatCan证书问题使这成为必要
lastNObservations + startPeriod/endPeriod → 406活动使用其中一个,而不是两个
地理维度的OR语法不可靠活动使用通配符(.)地理学;OR适用于其他尺寸
通配符返回大维度的稀疏数据缓解使用 get_sdmx_key_for_dimension 获取完整的OR密钥(例如NOC、CMA)
上下文溢出可能导致数据伪造缓解托管服务器返回 download_csv URL——通过脚本而非上下文处理的数据

______________________________________________________________________

Made with ❤️❤️❤️ for Statistics Canada

GitHub • Report Bug • Statistics Canada

目录标签

目录标签

数据服务PythonClaude本地部署统计分析加拿大统计局SDMXMCP协议

支持客户端

Claude DesktopClaudeCursorVS Code

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

17

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP