Skip to main content
Glama
kesesfigyelo-mcp

kesesfigyelo-mcp

by bozsikarmand
README.md
# kesesfigyelo-mcp

A read-only [Model Context Protocol](https://modelcontextprotocol.io) server that lets an AI assistant answer questions about Budapest public transport reliability, plus an evaluation harness that measures how well different models use it.

The data comes from **Késésfigyelő**, a monitor I built that collects BKK GTFS-Realtime feeds every minute and aggregates delays per line, hour and day. Live site: [kesesfigyelo.armands.dev](https://kesesfigyelo.armands.dev). The server reads only its public JSON API, so it needs no database access and no secrets.

```mermaid
flowchart LR
    BKK[BKK GTFS-Realtime] -->|every minute| W[Késésfigyelő v3<br/>Cloudflare Workers + D1]
    W -->|public JSON API| M[kesesfigyelo-mcp<br/>FastMCP, Python]
    M -->|stdio or HTTP| C[MCP client<br/>Claude Code, Claude Desktop, …]
    M -->|in-process, recorded fixtures| E[evals/run.py<br/>Groq, Ollama]
```

## Tools

| Tool | What it answers |
|---|---|
| `find_routes` | Which line is “6”, “907A” or “M2”? Search by name and vehicle type. |
| `get_network_overview` | Network median delay, most delayed lines right now, hourly trend. |
| `get_line_report` | Daily and hourly delays of one line, the stops where delays accumulate, today’s per-minute medians. |
| `get_alerts` | Service alerts recorded today, optionally for one line. |
| `get_live_vehicles` | Vehicles reporting a position, per line or for one line. |
| `get_data_quality` | Collector uptime, feed fetch results, schedule-resolution rate, upstream health. |

All tools are marked `readOnlyHint`. Conventions in every result: delays in minutes (negative means early), `late` means at least 5 minutes late, times in UTC and Europe/Budapest. When a period has no data, the result says so explicitly, so the model has no reason to guess.

## Running it

Requires Python 3.12+ and [uv](https://docs.astral.sh/uv/).

```bash
uv sync
uv run kesesfigyelo-mcp            # stdio
uv run kesesfigyelo-mcp --http     # streamable HTTP on 127.0.0.1:8000
```

**Claude Code / Claude Desktop** (`.mcp.json` or the Desktop config):

```json
{
  "mcpServers": {
    "kesesfigyelo": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/kesesfigyelo-mcp", "kesesfigyelo-mcp"]
    }
  }
}
```

Optional settings: `KFG_API_BASE`, `KFG_HTTP_TIMEOUT`, `KFG_HTTP_RETRIES`. Responses are cached in memory (30 s to 1 h depending on the endpoint) to keep load on the API low.

## Evaluation

`evals/` measures whether a model, given these tools, picks the right tool, passes the right arguments, reports the right numbers and admits when data is missing.

- **Golden set** (`evals/golden.yaml`): questions in Hungarian and English. Expected values are not hard-coded; each one points into the recorded API responses in `tests/fixtures/`, so re-recording the fixtures keeps the expectations correct.
- **Checks per case**: tool choice, arguments, facts within tolerance, *groundedness* (every decimal number in the answer must appear in a tool output), refusal for no-data questions, “not found” for unknown lines, answer language.
- **Model-agnostic runner** (`evals/run.py`): any OpenAI-compatible endpoint drives the tools in-process against the fixtures. Free options only: Groq’s free tier and a local Ollama. Runs are cached per model, case, fixtures and server code.

```bash
uv sync --group eval
uv run --group eval python evals/run.py --model groq:openai/gpt-oss-120b
uv run --group eval python evals/run.py --model ollama:qwen3:8b
```

Groq needs `GROQ_API_KEY`; the runner reads it from `~/.config/kesesfigyelo-mcp/.env`, never from the repository.

### Results (fixtures recorded 2026-11-30, 10 cases)

| Model | Passed | Notes |
|---|---|---|
| `qwen/qwen3.8-27b` (Groq) | 10/10 | |
| `openai/gpt-oss-120b` (Groq) | 9/10 | For a line that does not exist it said “no data” instead of “no such line”. |
| `qwen3:8b` (Ollama, local CPU) | 10/10 | Runs offline at no cost; about 80 s per question on CPU. |

Full transcripts: `evals/results/`. The golden set will grow to 40–50 cases.

## Development

```bash
uv run pytest            # tool tests against recorded fixtures, no network
uv run ruff check . && uv run mypy
```

CI runs lint, type checks and tests on every push (GitHub Actions). LLM calls never run in CI.

## Limitations

- The answers can only be as good as the Késésfigyelő data. The collector had outages in late November 2026; `get_data_quality` reports the current state.
- Stop-level delays are only available from 2026-11-30 onwards (an earlier aggregation bug stored list positions instead of stop identifiers).

## About

Built by Armand Viktor Bozsik with AI assistance (Claude Code); I designed the tools and the evaluation method and reviewed every change. MIT licensed.