多伦多开放数据MCP服务器
一种MCP(模型上下文协议)服务器,通过CKAN API提供对多伦多开放数据的直接访问。该服务器允许LLM代理高效地发现、探索和查询多伦多的500多个公共数据集。
特性
- 🔍 智能数据集发现:通过智能建议搜索500多个多伦多数据集
- 🧠 智能数据助手:自动处理API和CSV数据源
- 📊 灵活查询:支持对API数据集进行筛选、排序和字段选择
- 📁 CSV支持:自动获取和预览可下载的CSV数据集
- 🤝 LLM友好:设计用于在需要额外上下文时与网络搜索协同使用
- ✅ 稳健的错误处理:清晰的错误信息和可操作的建议
安装
选项1:使用uvx(建议用于MCP)
将此服务器与任何MCP客户端一起使用的最简单方法:
brew install uv# No installation needed! uvx will handle everything
# Just use in your MCP client configuration:
uvx toronto-open-data-mcp-server选项2:开发安装
- 克隆存储库:
git clone https://github.com/yourusername/toronto-open-data-mcp-server.git
cd toronto-open-data-mcp-server- 安装依赖项:
# Install main dependencies
pip install -e .
# Install test dependencies (optional)
pip install -e ".[test]"- 运行服务器:
python main.pyMCP客户端配置
使用uvx(最简单的方法)
将此添加到MCP客户端配置中:
{
"mcpServers": {
"Toronto Open Data Server": {
"command": "uvx",
"args": ["toronto-open-data-mcp-server"]
}
}
}配置文件位置
- 克劳德桌面:
~/Library/Application Support/Claude/claude_desktop_config.json - 光标:检查Cursor的MCP文档以了解配置位置
- 其他MCP客户端:请参阅客户的文件
用法
快速开始
服务器提供了几个专为LLM代理设计的工具:
toronto_start_here()-解释工作流程的基本第一通电话toronto_search_datasets(query)-按关键字查找相关数据集toronto_smart_data_helper(dataset_id, user_question)-智能数据检索toronto_popular_datasets()-快速访问常用数据集
工作流示例
# 1. Start with guidance
toronto_start_here()
# 2. Search for relevant data
toronto_search_datasets("restaurant inspection")
# 3. Get data intelligently
toronto_smart_data_helper("dinesafe", "recent restaurant inspection failures")
# 4. Advanced filtering (if needed)
toronto_query_dataset_data("dinesafe",
filters={"establishment_status": "Conditional Pass"},
sort="inspection_date desc",
limit=10)热门数据集
dinesafe-餐厅检查和健康评分traffic-signals-交通灯位置和时间parks-facilities-公园、游泳池和娱乐设施business-licences-多伦多的特许经营企业building-permits-建筑和装修许可证
测试
该项目包括全面的测试,包括单元测试、集成测试和工作流测试。
先决条件
安装测试依赖项:
pip install -e ".[test]"运行测试
快速测试命令
# Run unit tests only (recommended for development)
python run_tests.py
# Run with verbose output
python run_tests.py --verbose
# Run with coverage report
python run_tests.py --coverage
# Run integration tests (hits real Toronto API)
python run_tests.py --integration
# Run all tests (unit + integration)
python run_tests.py --allapi参考
核心工具
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开放数据门户直接集成
- 协同设计:与网络搜索一起工作,而不是取代它
- 错误恢复:具有可操作建议的智能错误处理
贡献
- 分叉存储库
- 创建要素分支
- 添加新功能的测试
- 运行测试套件:
python run_tests.py --all - 提交拉取请求
