返回市场
多伦多开放数据MCP服务器

多伦多开放数据MCP服务器

作者:vduquette2 星标更新:2025-06-08

项目介绍

多伦多开放数据MCP服务器

这是一个通过CKAN API提供对多伦多开放数据直接访问的MCP(模型上下文协议)服务器。该服务器允许LLM代理高效地发现、探索和查询多伦多的500多个公共数据集。

特性

  • 🔍 智能数据集发现:通过500多个多伦多数据集进行搜索,并提供智能建议
  • 🧠 智能数据助手:自动处理API和CSV数据源
  • 📊 灵活查询:支持对API数据集的过滤、排序和字段选择
  • 📁 CSV支持:自动获取并预览可下载的CSV数据集
  • 🤝 适合LLM:设计用于与网络搜索协作使用,当需要额外上下文时
  • 强大的错误处理:提供清晰的错误消息及操作建议

安装

方案1:使用uvx(推荐用于MCP)

这是使用任何MCP客户端最简单的方法:

brew install uv
# 不需要安装!uvx会处理一切
# 只需在您的MCP客户端配置中使用:
uvx toronto-open-data-mcp-server

方案2:开发安装

  1. 克隆仓库

    git clone https://github.com/yourusername/toronto-open-data-mcp-server.git
    cd toronto-open-data-mcp-server
    
  2. 安装依赖项

    # 安装主要依赖项
    pip install -e .
    
    # 安装测试依赖项(可选)
    pip install -e ".[test]"
    
  3. 运行服务器

    python main.py
    

MCP客户端配置

使用uvx(最简单方法)

在您的MCP客户端配置中添加以下内容:

{
  "mcpServers": {
    "Toronto Open Data Server": {
      "command": "uvx",
      "args": ["toronto-open-data-mcp-server"]
    }
  }
}

配置文件位置

  • Claude Desktop~/Library/Application Support/Claude/claude_desktop_config.json
  • Cursor:查看Cursor的MCP文档以获取配置位置
  • 其他MCP客户端:参考您客户端的文档

使用

快速开始

该服务器提供了几个专为LLM代理设计的工具:

  1. toronto_start_here() - 首次调用,解释工作流程
  2. toronto_search_datasets(query) - 通过关键词查找相关数据集
  3. toronto_smart_data_helper(dataset_id, user_question) - 智能数据检索
  4. toronto_popular_datasets() - 快速访问常用数据集

示例工作流

# 1. 从指导开始
toronto_start_here()

# 2. 查找相关数据
toronto_search_datasets("餐厅检查")

# 3. 智能获取数据
toronto_smart_data_helper("dinesafe", "最近的餐厅检查失败")

# 4. 高级过滤(如有需要)
toronto_query_dataset_data("dinesafe", 
                           filters={"establishment_status": "有条件通过"},
                           sort="inspection_date desc",
                           limit=1

常用数据集

  • dinesafe - 餐厅检查和健康评分
  • traffic-signals - 交通信号灯的位置和时间
  • parks-facilities - 公园、游泳池和娱乐设施
  • business-licences - 多伦多的持照企业
  • building-permits - 建筑和翻新许可

测试

该项目包括全面的测试,涵盖单元测试、集成测试和工作流测试。

先决条件

安装测试依赖项:

pip install -e ".[test]"

运行测试

快速测试命令

# 仅运行单元测试(开发推荐)
python run_tests.py

# 带有详细输出
python run_tests.py --verbose

# 带有覆盖率报告
python run_tests.py --coverage

# 运行集成测试(访问真实的多伦多API)
python run_tests.py --integration

# 运行所有测试(单元 + 集成)
python run_tests.py --all

API参考

核心工具

toronto_start_here() -> str

首次调用,提供工作流程指导和服务器功能。

toronto_search_datasets(query: str, limit: int = 10) -> str

按关键词搜索多伦多的数据集。

toronto_smart_data_helper(dataset_id: str, user_question: str, limit: int = 10) -> str

智能助手,自动处理API和CSV数据源。

toronto_query_dataset_data(dataset_id: str, filters: Dict = None, fields: List = None, limit: int = 10, sort: str = None) -> str

高级查询,对API数据集进行过滤和排序。

实用工具

toronto_popular_datasets() -> str

快速访问常用数据集。

toronto_get_dataset_schema(dataset_id: str) -> str

获取API数据集的字段名称和类型。

toronto_fetch_csv_data(csv_url: str, max_lines: int = 50) -> str

获取并预览CSV文件内容。

架构

  • FastMCP框架:基于FastMCP框架构建,便于工具定义
  • CKAN API:直接集成到多伦多基于CKAN的开放数据门户
  • 协作设计:与网络搜索协同工作,而不是取代它
  • 错误恢复:智能错误处理,带有操作建议

贡献

  1. 分叉仓库
  2. 创建功能分支
  3. 为新功能添加测试
  4. 运行测试套件:python run_tests.py --all
  5. 提交拉取请求