Skip to main content
Glama

cdmx-mcp

模型上下文协议 (Model Context Protocol),用于墨西哥城开放数据。 让 Claude 直接访问犯罪、911、空气质量、ECOBICI 和 DENUE 数据 — 无需编写一行摄取代码。

CI Python 3.10+ License: MIT MCP

"¿Cuáles son las 10 colonias con más delitos en Cuauhtémoc en 2025?"
  ↓  Claude llama crime_hotspots(year=2025, alcaldia="CUAUHTEMOC", top_n=10)
  ↓  cdmx-mcp traduce a SQL contra CKAN
  ↓  Claude te contesta con la tabla + análisis, en segundos

📋 前置要求

你需要 Python 3.10+uv(现代 Python 包管理器 — 用单个二进制文件替代 pip + venv + pyenv)。

安装 uv

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

或者使用 Homebrew (macOS):

brew install uv

PowerShell 中:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

或者使用 winget

winget install --id=astral-sh.uv -e

或者使用 Scoop

scoop install uv

验证安装是否成功:

uv --version   # → uv 0.5.x o similar

安装 Python(如果你还没有安装)

uv 可以为你下载并安装 Python — 无需手动安装

uv python install 3.12

当然,如果你更喜欢手动安装:

  • macOS: brew install python@3.12 或从 https://www.python.org/downloads/ 下载

  • Windows: winget install Python.Python.3.12 或从 Microsoft Store 下载

  • Linux (Ubuntu/Debian): sudo apt install python3.12 python3.12-venv

  • Linux (Arch): sudo pacman -S python

验证:

python3 --version   # → Python 3.10.x o superior

💡 使用 uv,你无需激活虚拟环境或处理版本冲突 — uv sync 会读取 pyproject.toml + uv.lock 并自动完成所有配置。


Related MCP server: MobusMCP

⚡ 快速入门 — 30 秒

git clone https://github.com/devcsar/cdmx-mcp.git
cd cdmx-mcp
uv sync                                   # instala Python + dependencias
uv run python tests/smoke_test.py         # verifica: debe decir "smoke: OK"

安装完成后,将其连接到你喜欢的客户端:

Claude Code

claude mcp add cdmx -- uv --directory "$(pwd)" run cdmx-mcp
claude                                    # dentro de la sesión: /mcp

或者直接用 claude 打开此目录,它会自动检测 .mcp.json

Claude Desktop

编辑 claude_desktop_config.json (Settings → Developer → Edit Config) 并粘贴:

{
  "mcpServers": {
    "cdmx": {
      "command": "uv",
      "args": ["--directory", "/ruta/absoluta/a/cdmx-mcp", "run", "cdmx-mcp"]
    }
  }
}

重启 Claude Desktop。各操作系统的详细说明请参考 QUICKSTART.md

Cowork

将相同的 JSON 粘贴到 Cowork 的 MCP 编辑器中,或指向仓库中的 .mcp.json


🎯 第一个测试提示词

复制并粘贴到 Claude:

列出 2025 年 Cuauhtémoc 区最常见的 10 种犯罪类型。然后制作一个带有条形表情符号的 Markdown 表格。

Claude 会自动选择 crime_hotspots 并用真实数据回答你。更多提示词请参考 PROMPTS.md


📊 覆盖范围

数据源

覆盖方式

更新频率

FGJ — 调查档案(犯罪)

datos.cdmx.gob.mx (CKAN API)

每月

911 / LOCATEL — 紧急呼叫

datos.cdmx.gob.mx (CKAN API)

每月

SIMAT — 空气质量

datos.cdmx.gob.mx (CKAN API)

每小时

ECOBICI — 实时自行车/站点

GBFS (标准 feed)

🟢 实时

DENUE (INEGI) — 经济单位

INEGI 公共 API

每季度

迁移后说明:2026 年 4 月,CDMX 门户网站从 OpenDataSoft 迁移到了 CKAN 2.10。查询现在通过 /api/3/action/datastore_search_sql(真正的 PostgreSQL)进行。数据集的 slug 已保留。


🛠 公开工具 (共 9 个)

通用工具 — 适用于门户网站的任何数据集:

工具

功能

list_datasets(search?, limit)

在完整目录中搜索

describe_dataset(dataset_id)

获取真实 Schema(列、类型、总行数)

query_records(dataset_id, where?, select?, order_by?, limit, offset)

通过 datastore_search_sql 进行 SQL 查询

aggregate(dataset_id, group_by, metric?, where?, limit)

服务端 GROUP BY

配方工具 — 前 5 名的快捷方式:

工具

功能

crime_hotspots(year, alcaldia?, category?, top_n)

按犯罪率排名的社区/区

ecobici_status(station_id? · near_lat+near_lng+radius_m)

实时空闲自行车/站点

air_quality_now(zone?, limit)

最新的 SIMAT 指数

denue_near(lat, lng, radius_m, keyword)

附近的企业

此外还有 cache_stats() 和 2 个资源 (cdmx://guide/fgj, cdmx://guide/top5)。

支持的 dataset_id 快捷方式:fgj · 911 · ids · aire


🧪 验证功能

# Test offline (no golpea el portal)
uv run python tests/smoke_test.py
# → smoke: OK

# Test live (opcional — consulta real a datos.cdmx.gob.mx)
CDMX_MCP_LIVE=1 uv run python tests/live_test.py
# → live: OK

CI 在每次推送时都会在 Python 3.10、3.11 和 3.12 上运行冒烟测试。


🔐 DENUE 可选令牌

denue_near 需要一个免费的 INEGI 令牌:

  1. https://www.inegi.org.mx/servicios/api_denue.html 注册(只需 2 分钟)

  2. 在启动 Claude Desktop/Code 之前导出它:

export INEGI_TOKEN=tu_token

或者将其添加到你的 JSON 配置的 env 中 — 请参阅 config/claude_desktop_config.example.json


🏗 架构

Claude (Desktop / Cowork / Code)
          │  stdio · JSON-RPC
          ▼
   cdmx_mcp.server (FastMCP)
          │
   ┌──────┴──────┬───────────┬──────────┐
   ▼             ▼           ▼          ▼
   ckan        gbfs        denue      cache
(datos.cdmx) (ECOBICI)   (INEGI)   (TTL + LRU)
  • CKAN 通过相同的 API (/api/3/action/*) 覆盖了 5 个数据源中的 4 个(FGJ、911、空气、IDS)。

  • describe_dataset 使用 package_show + datastore_search 来公开真实 Schema。

  • query_recordsaggregate 委托给 datastore_search_sql(真正的 PostgreSQL:标识符使用 ",字面量使用 ')。

  • ECOBICI 通过 GBFS(标准 feed;也可通过 ECOBICI_GBFS_URL 覆盖)消费。

  • 缓存:内存中按工具设置 TTL:实时数据 15 秒,查询 10 分钟,目录 1 小时。

  • 无需令牌(DENUE 除外,可选)。


📚 了解更多


🤝 贡献

该服务器旨在轻松扩展。

添加新数据源:

  1. 创建 src/cdmx_mcp/adapters/<fuente>.py,函数返回格式为 {"results": [...], "total_count": N} 的字典。

  2. 使用适当的 TTL 用 cache.cached(...) 包装它们。

  3. server.py 中使用 @mcp.tool() 和清晰的文档字符串(Claude 会读取它)公开它们。

  4. 将名称添加到 tests/smoke_test.py 中的 expected 集合中。

运行本地 CI:

uv run python tests/smoke_test.py
CDMX_MCP_LIVE=1 uv run python tests/live_test.py   # requiere internet

欢迎提交 Issue 和 PR。.github/workflows/ci.yml 工作流会验证所有内容是否在 Python 3.10 / 3.11 / 3.12 上编译通过。


📄 许可证

MIT · 由 rohan.mxcsar.devImpact Lab CDMX 01 (2026 年 4 月) 构建。

扩展

添加新数据源:

  1. 创建 src/cdmx_mcp/adapters/<fuente>.py,函数返回字典。

  2. 使用 cache.cached(...) 包装以设置 TTL。

  3. server.py 中使用 @mcp.tool() 公开。

许可证

MIT。

Install Server
A
license - permissive license
B
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    Enables Claude to connect to and interact with SQLite, SQL Server, PostgreSQL, and MySQL databases through natural language. Supports executing queries, managing tables, exporting data, and storing business insights with authentication options including AWS IAM.
    853
    MIT
  • A
    license
    -
    quality
    B
    maintenance
    Search, preview, and analyze datasets from 20+ platforms and millions of datasets via a single MCP connector. Works with Claude instantly
    2
    27
    MIT
  • F
    license
    -
    quality
    D
    maintenance
    An MCP server that gives Claude deep access to US public data -- demographics, economics, crime, employment, weather, housing, transit, schools, budgets, and more across 30+ cities for government intelligence workflows.

View all related MCP servers

Related MCP Connectors

  • INEGI DENUE MCP — Mexico's directory of economic units (~6M businesses).

  • Official Mexican data for AI agents: CURP, RFC, CFDI, postal codes, phone, SPEI/CEP, DOF, geocoding.

  • MCP server giving Claude AI access to 22+ NYC public-record databases for real estate due diligence

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/devcsar/cdmx-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server