Metadata-Version: 2.5
Name: kz-opendata-mcp
Version: 0.2.0
Summary: MCP server for Kazakhstan's open data portal data.egov.kz: let Claude, Cursor and other AI assistants search and query government datasets.
Project-URL: Homepage, https://github.com/almatulymiras688-lgtm/kz-opendata-mcp
Project-URL: Issues, https://github.com/almatulymiras688-lgtm/kz-opendata-mcp/issues
License-Expression: MIT
License-File: LICENSE
Keywords: ai-agents,egov,kazakhstan,llm,mcp,model-context-protocol,open-data
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: mcp<3,>=2.3
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

<!-- mcp-name: io.github.almatulymiras688-lgtm/kz-opendata-mcp -->
<h1 align="center">🇰🇿 kz-opendata-mcp</h1>

<p align="center"><b>Ask AI assistants about Kazakhstan's open government data.</b></p>

<p align="center">
  <a href="https://github.com/almatulymiras688-lgtm/kz-opendata-mcp/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/almatulymiras688-lgtm/kz-opendata-mcp/actions/workflows/ci.yml/badge.svg"></a>
  <a href="https://github.com/almatulymiras688-lgtm/kz-opendata-mcp/releases"><img alt="Release" src="https://img.shields.io/github/v/release/almatulymiras688-lgtm/kz-opendata-mcp?color=00AFCA"></a>
  <a href="https://pypi.org/project/kz-opendata-mcp/"><img alt="PyPI" src="https://img.shields.io/pypi/v/kz-opendata-mcp?color=3775A9&logo=pypi&logoColor=white"></a>
  <img alt="Python" src="https://img.shields.io/badge/python-3.10%2B-3776AB?logo=python&logoColor=white">
  <a href="https://modelcontextprotocol.io"><img alt="MCP" src="https://img.shields.io/badge/MCP-server-6E56CF"></a>
  <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-green"></a>
  <a href="https://data.egov.kz"><img alt="data.egov.kz" src="https://img.shields.io/badge/data-data.egov.kz-FEC50C"></a>
</p>

**English** · [Русский](README.ru.md) · [Қазақша](README.kk.md)

An [MCP](https://modelcontextprotocol.io) server for **[data.egov.kz](https://data.egov.kz)**, Kazakhstan's official open data portal (about 4,000 government datasets: schools, hospitals, pharmacies, budgets, prices, regions and more).

Connect it to Claude Desktop, Claude Code, Cursor or any other MCP client, and ask questions in plain language. The assistant finds the right dataset, reads its fields, and filters or aggregates the data itself.

> "How many schools are there in Arys, and what types are they?"
>
> The assistant calls `search_datasets("школ")`, then `get_dataset_info("mektepter_tizimi")`, then `aggregate_dataset(group_by="name7", filters={"name": "Арыс"})`, and answers: *39 schools. 22 are general secondary schools (ЖОМ), 9 are small-class primary schools (ШЖБМ), 5 are primary schools (БМ)…*, with a link to the source dataset.

**No API key needed.** The server uses the portal's public endpoints.

## Demo

Real answers from the portal, shortened (Claude Desktop with this server, November 2026):

> **You:** Count schools in Turkestan region by type.
>
> **Claude:** *(search_datasets → get_dataset_info → aggregate_dataset)* According to the "List of schools" dataset (1,040 rows, 2016): general secondary (ЖОМ) 729, small-class primary (ШЖБМ) 68, НОМ 64, small-class secondary (ШЖЖОМ) 55, primary (БМ) 40, ОМ 24… Note: about 14 rows are district totals mixed into the data.

> **You:** Which district has the most kindergartens?
>
> **Claude:** The Turkestan dataset on the portal is empty, but Abai region has fresh data (December 2025): 177 kindergartens, most of them in Semey (74), then Ayagoz (12) and Urzhar (5).

```mermaid
flowchart LR
    U["You: a question in plain language"] --> A["AI assistant<br/>Claude · Cursor · …"]
    A -- MCP --> S["kz-opendata-mcp"]
    S -- "search · meta · query" --> P[("data.egov.kz<br/>~4000 datasets")]
    P --> S --> A --> U
```

## Tools

| Tool | What it does |
|---|---|
| `search_datasets` | Searches the catalogue by keywords (in Russian, Kazakh or English). Returns dataset ids, titles, descriptions and tags. |
| `get_dataset_info` | Returns the title, description, owner agency, update date, versions, row count, and **field labels**. Field names on the portal are often opaque (`name1`, `name2`…), and the labels explain what they mean. |
| `query_dataset` | Reads rows with field filters, free-text search, paging, sorting and a field selection. Accepts a raw Elasticsearch query for advanced use, such as geo-distance. |
| `aggregate_dataset` | Computes `count`, `sum`, `avg`, `min` or `max`, optionally grouped by a field. Numbers stored as text (`"1 219"`, `"12,5"`) are parsed. |

## Installation

You need [uv](https://docs.astral.sh/uv/getting-started/installation/) (`brew install uv`, or `pip install uv`).

### Claude Desktop

Open *Settings → Developer → Edit Config* and add the server to `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "kz-opendata": {
      "command": "uvx",
      "args": ["kz-opendata-mcp"]
    }
  }
}
```

Until the package is on PyPI, use `"args": ["--from", "git+https://github.com/almatulymiras688-lgtm/kz-opendata-mcp", "kz-opendata-mcp"]`.

Then restart Claude Desktop. If Claude Desktop can't find `uvx`, replace it with the full path from `which uvx`.

> **macOS:** Claude Desktop can't read files in `~/Documents`, `~/Desktop` or `~/Downloads` (privacy protection), so a server installed there fails with `PermissionError: Operation not permitted`. Keep the source anywhere you like, but install it as a tool with `uv tool install --python 3.12 /path/to/kz-opendata-mcp` and use `~/.local/bin/kz-opendata-mcp` (as a full path) as the `command`.

### Claude Code

```bash
claude mcp add kz-opendata -- uvx kz-opendata-mcp
```

### Cursor

Add the same block as for Claude Desktop to `~/.cursor/mcp.json`.

### Remote server (HTTP)

The same server can run as a web service, so it can be used without installing anything: in claude.ai (Settings → Connectors → Add custom connector), ChatGPT developer mode, or any client that supports remote MCP.

```bash
kz-opendata-mcp --transport http --host 0.0.0.0 --port 8000   # endpoint: http://HOST:8000/mcp
docker build -t kz-opendata-mcp . && docker run -p 8000:8000 kz-opendata-mcp
```

Free hosting: the repository has a `render.yaml`, so on [Render](https://render.com) choose *New → Blueprint*, pick this repository, and you get `https://<name>.onrender.com/mcp` (the free plan sleeps after 15 minutes without requests and takes about a minute to wake up). `GET /health` returns the server status.

### From source

```bash
git clone https://github.com/almatulymiras688-lgtm/kz-opendata-mcp
cd kz-opendata-mcp
uv venv && uv pip install -e ".[dev]"
.venv/bin/kz-opendata-mcp            # stdio server
npx @modelcontextprotocol/inspector .venv/bin/kz-opendata-mcp   # try it in the browser
```

## Example questions

- "Find datasets about pharmacies in Astana and show me 10 of them."
- "Which districts of Turkistan region have the most schools?"
- "What is the average number of pupils per school in Arys?"
- "Find datasets about the state budget. Which agency publishes them, and when were they last updated?"
- "Мектептер туралы деректер жинағын тауып, аудандар бойынша санын көрсет."

## Configuration

| Variable | Default | Meaning |
|---|---|---|
| `EGOV_BASE_URL` | `https://data.egov.kz` | Portal address |
| `EGOV_TIMEOUT` | `30` | HTTP timeout in seconds |
| `MCP_TRANSPORT` | `stdio` | `stdio` or `http` (same as `--transport`) |
| `HOST`, `PORT` | `127.0.0.1`, `8000` | Address for the HTTP mode |

## How it works

The server uses four public parts of the portal:

- `/datasets/search?text=…`: the catalogue search page (HTML)
- `/datasets/view?index=…`: the dataset page, which lists the available versions (HTML)
- `/meta/{dataset}/{version}`: metadata and field labels in Kazakh, Russian and English (JSON)
- `/api/detailed/{dataset}/{version}?source={…}`: rows, using an Elasticsearch 1.x query (JSON)

`/api/v4/…` requires a personal API key, and the server doesn't need it.

Limitations:

- The portal stores most values as text, so the portal itself can't compute sums or averages. `aggregate_dataset` pages through up to 20,000 matching rows and computes the result locally. It reports `truncated: true` if there were more.
- Many datasets haven't been updated for years. The `modified` field in `get_dataset_info` shows when each was last changed.
- Field filters use full-text matching, so `{"name": "Арыс"}` also matches "Арыс қаласы".

## Development

```bash
uv venv && uv pip install -e ".[dev]"
pytest              # offline tests (HTTP is mocked)
pytest -m live      # smoke test against the real portal
ruff check . && ruff format --check .
```

## Ideas for the roadmap

- [x] Publish to PyPI so `uvx kz-opendata-mcp` works
- [x] Remote HTTP mode for claude.ai, ChatGPT and other web clients
- [ ] MCP resources for categories and government agencies
- [ ] Results cache
- [ ] Geo-search helper ("pharmacies within 1 km of a point")
- [ ] Optional `/api/v4` support with an API key
- [ ] Integration with other KZ sources (stat.gov.kz, adilet.zan.kz)

## License

MIT. The data belongs to its publishers on data.egov.kz. This project is not affiliated with the Government of the Republic of Kazakhstan.
