Skip to main content
Glama
README.md
# inegi-mcp

Zero-token-first hybrid **Model Context Protocol (MCP)** server for **INEGI** (Instituto Nacional de Estadística y Geografía de México).

Instead of wrapping a single rate-limited REST endpoint, `inegi-mcp` combines:

- **Semantic Resolution**: Accent-insensitive search for states, municipalities, and localities (`wscatgeo/v2`), SCIAN economic activity codes, and Banco de Indicadores metrics.
- **Descarga Masiva Crawler**: Queries INEGI's internal JSON catalog (`/app/api/descarga/descarga/descargamasiva/lista/...`) to discover open-data and microdata archives across DENUE, Microdatos, Tabulados, and Indicadores.
- **Local DuckDB Lakehouse**: Streams `.zip` archives on demand into `~/.local/share/inegi-mcp/`, parses `.csv` (UTF-8 & CP1252) and `.dbf` tables, indexes `diccionario_de_datos`, and executes safe read-only SQL with `norm_txt()` and `haversine_m()`.
- **Progressive Live API Fusion**: Works immediately with **zero tokens**, and automatically unlocks live **Banco de Indicadores v2.0**, **DENUE REST v1**, and **SAKBÉ v3.1** routing/tolls when tokens are configured.

## Quickstart

```bash
cd /home/stinkyyy/dev/inegi-mcp
uv sync
uv run inegi-mcp
```

### Streamable HTTP mode

```bash
uv run inegi-mcp --transport streamable-http --host 127.0.0.1 --port 8000
```

## Optional Environment Variables

| Variable | Purpose | Default |
| :--- | :--- | :--- |
| `INEGI_TOKEN` | Shared token for Indicadores v2 & DENUE REST v1 | Unset (zero-token bulk/geo mode) |
| `INEGI_INDICADORES_TOKEN` | Override token for Banco de Indicadores v2 | `INEGI_TOKEN` |
| `INEGI_DENUE_TOKEN` | Override token for DENUE REST v1 | `INEGI_TOKEN` |
| `INEGI_SAKBE_TOKEN` | Token for SAKBÉ v3.1 road routing & tolls | Unset (Haversine distance estimate) |
| `INEGI_DATA_DIR` | Local cache & DuckDB database directory | `~/.local/share/inegi-mcp` |
| `INEGI_MAX_DOWNLOAD_MB` | Safety cap per downloaded archive (MB) | `500` |
| `INEGI_SQL_MAX_ROWS` | Default max rows returned by `inegi_sql_query` | `200` |

## MCP Client Configuration

```json
{
  "mcpServers": {
    "inegi-mcp": {
      "command": "/home/stinkyyy/dev/inegi-mcp/.venv/bin/inegi-mcp",
      "args": []
    }
  }
}
```

## Bundled Agent Skills (`skills/`)

This repository ships 4 cross-host agent skills designed specifically to pair with `inegi-mcp`:

| Skill | Purpose |
| :--- | :--- |
| `mx-site-selection` | Score Mexican municipalities & micro-radii using Censo 2020 ITER purchasing-power proxies, DENUE competitor saturation, and SAKBÉ corridors |
| `mx-microdata-economist` | Enforce expansion weights (`factor`, `fac_tri`, `fac_hog`/`fac_ele`/`fac_del`) & universe filters for ENIGH, ENOE, ENVIPE, and Censos Económicos |
| `mx-osint-footprint` | Two-hop `nom_estab` → `raz_social` corporate network mapping, industrial park rosters, and headcount bracket estimation in `denue_bulk` |
| `mx-geo-viz` | Export DuckDB geospatial queries to RFC 7946 GeoJSON and zero-key standalone dark-mode MapLibre HTML maps |

Install all 4 skills locally across `~/.agents/skills/`, `~/.claude/skills/`, and `~/.gemini/config/skills/`:

```bash
./scripts/install-skills.sh
```

Or install from GitHub via the skills CLI:

```bash
npx skills add stinkyyyyy/inegi-mcp
```