这是一个通过CKAN API提供对多伦多开放数据直接访问的MCP(模型上下文协议)服务器。该服务器允许LLM代理高效地发现、探索和查询多伦多的500多个公共数据集。
这是使用任何MCP客户端最简单的方法:
brew install uv
# 不需要安装!uvx会处理一切
# 只需在您的MCP客户端配置中使用:
uvx toronto-open-data-mcp-server
克隆仓库:
git clone https://github.com/yourusername/toronto-open-data-mcp-server.git
cd toronto-open-data-mcp-server
安装依赖项:
# 安装主要依赖项
pip install -e .
# 安装测试依赖项(可选)
pip install -e ".[test]"
运行服务器:
python main.py
在您的MCP客户端配置中添加以下内容:
{
"mcpServers": {
"Toronto Open Data Server": {
"command": "uvx",
"args": ["toronto-open-data-mcp-server"]
}
}
}
~/Library/Application Support/Claude/claude_desktop_config.json该服务器提供了几个专为LLM代理设计的工具:
toronto_start_here() - 首次调用,解释工作流程toronto_search_datasets(query) - 通过关键词查找相关数据集toronto_smart_data_helper(dataset_id, user_question) - 智能数据检索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
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文件内容。
python run_tests.py --all