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

[![CI](https://github.com/mohamedzeina/iett-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/mohamedzeina/iett-mcp/actions/workflows/ci.yml)

An [MCP](https://modelcontextprotocol.io) server for **Istanbul public transport**. It lets AI assistants like Claude Code, Claude Desktop or Cursor answer questions about İETT bus stops and lines using live data from İETT's official web services.

> **You:** I'm at Tersane Köprüsü in Pendik. How far is the next 500T to 4. Levent?
> **Claude:** *(calls `search_stops`, then `get_live_buses`)* The nearest one, C-397, is 5 stops away near Aydıntepe İstasyon. Its position was updated 33 seconds ago. The next one is 11 stops behind it.

No API key needed. İETT's data is public.

## Tools

| Tool | What it does |
|---|---|
| `search_stops` | Find bus stops by name, optionally within a district. Ignores Turkish accents and case, so `kadikoy` finds `KADIKÖY`. Returns stop code, direction, coordinates and accessibility. |
| `find_stops_near` | Stops near a latitude/longitude, nearest first, with distance and a rough walking time. Lets users ask about a place ("near Taksim Square") instead of a stop name. |
| `get_line_info` | Look up a line by code (`500T`, `25G`) or find lines by the places in their route name (`Sarıyer Taksim`). Returns the route ends, length, typical trip time and fare type. |
| `get_line_stops` | List a line's stops in travel order, for each direction. Optional `toward` returns only the direction heading to a place. Codes match loosely, so `78s` finds `78Ş`. |
| `get_live_buses` | Where a line's buses are right now, placed on the route by their nearest stop. With `stop_code`, lists only the buses still heading to that stop and how many stops away each one is. |
| `get_timetable` | Scheduled departures from each direction's first stop: today's next buses with the wait, first and last bus, or a whole day grouped by hour, for weekdays, Saturdays or Sundays. |

All tools are read-only.

## Setup

```bash
git clone https://github.com/mohamedzeina/iett-mcp.git && cd iett-mcp
npm install
npm run build
```

**Claude Code:**
```bash
claude mcp add iett -- node /absolute/path/to/iett-mcp/dist/index.js
```
If you open Claude Code inside this folder, it picks up the server from `.mcp.json` automatically. That version runs from source, so you don't need to build first.

**Claude Desktop / Cursor** (`claude_desktop_config.json` / `.cursor/mcp.json`):
```json
{
  "mcpServers": {
    "iett": {
      "command": "node",
      "args": ["/absolute/path/to/iett-mcp/dist/index.js"]
    }
  }
}
```

## How it works

```
AI assistant ──MCP (stdio)──► server.ts ──► search.ts (local, accent-insensitive search)
                                  │
                                  └──► iett/client.ts (12h in-memory cache)
                                           └──► iett/soap.ts ──SOAP/XML──► api.ibb.gov.tr/iett
```

- **The upstream API is SOAP.** İETT exposes ASP.NET `.asmx` services. Some return a JSON string inside the XML envelope; the stop-detail service returns an XML DataSet. `soap.ts` builds the envelope (with input escaped), parses both response styles, turns SOAP faults into readable errors, and retries network errors and 5xx responses.
- **Download once, search locally.** İETT can't search by name, so the full lists (~15k stops, ~800 lines, about 3.7 MB) are fetched on the first call and cached for 12 hours. Each line's stop list is cached the same way. A failed download is never cached.
- **Live data has a quota.** İETT's fleet service allows about 100 requests per hour. Live positions are cached for 30 seconds per line, every call goes through a 90-per-hour sliding-window budget (`rateLimit.ts`), and failed calls aren't retried. When the budget runs out, the tool says when live data will be back.
- **Positions mean more on the route.** A raw GPS point says little. `live.ts` matches each bus's nearest stop against the line's stop list, so the tool can say "5 stops away" and flag reports older than 5 minutes.
- **Service days run past midnight.** A line's day can run from 05:40 to 00:20, and night lines run 23:40 to 05:20. `schedule.ts` uses İETT's listing order, where a jump back of more than 12 hours marks midnight, so "next bus" stays right after midnight. It also checks the previous day's late departures. A "largest gap" rule would fail for lines that only run mornings and evenings.
- **Turkish-aware matching.** İETT's data mixes spellings ("Kadiköy", "Sisli", "ŞİŞLİ"), and users type without Turkish characters. `text.ts` lowercases with Turkish rules (İ→i, I→ı) and strips accents, so every spelling matches.
- **Errors the model can act on.** When İETT is down, tools return `isError` with a message the assistant can explain, instead of crashing.

## Development

```bash
npm run dev        # run the server from source
npm test           # unit + MCP protocol tests (İETT is faked from fixtures)
npm run smoke      # live check against the real İETT service
npm run inspect    # open the MCP Inspector to call tools by hand
```

The tests connect a real MCP client to the server over an in-memory transport, so they cover tool registration, input validation and response format, not just helper functions.

## Roadmap

- [x] `get_line_stops`: ordered stops along a line
- [x] `get_timetable`: scheduled departures
- [x] `get_live_buses`: real-time bus positions for a line
- [x] `find_stops_near`: stops near a coordinate
- [ ] İsbike bike-share stations
- [ ] Publish to npm and an MCP server registry

## Data

Data comes from İETT via the [İBB Open Data Portal](https://data.ibb.gov.tr/en/dataset/iett-ibb-web-servisi). This project is not affiliated with İETT or İBB.

## License

MIT

TDQS

A4.1/5.0

Scored across 6 tools

Disambiguation4/5

The six tools are largely distinct: line metadata, line stops, live positions, and timetables don't overlap. The only mild overlap is search_stops vs find_stops_near, both of which return stop codes, and a request like "stops near Kadıköy" could plausibly route to either, though the descriptions do explain when to use each.

Naming Consistency4/5

All names are snake_case with a verb_noun shape (search_stops, find_stops_near, get_line_info, get_line_stops, get_live_buses, get_timetable). The verb mix between 'search' and 'find' for the two stop-lookup tools is a minor deviation but still predictable.

Tool Count5/5

Six tools is a well-scoped surface for a bus transit API, with each tool covering a distinct query type (stops by name, stops by location, line info, line stops, live vehicles, schedule). Nothing feels redundant or missing at the count level.

Completeness4/5

The core lifecycle for a transit use case—locate stops, identify a line, list its stops, see live buses, get scheduled departures—is covered, and the descriptions cross-reference how to combine tools. Minor gaps exist: timetables only show departures from the first stop per direction, and there is no journey/route-planning or service-alert tool.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues