timetable-api-node 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INTEGRATION.md +24 -13
- package/README.md +144 -229
- package/index.js +15 -0
- package/package.json +4 -3
package/INTEGRATION.md
CHANGED
|
@@ -11,9 +11,19 @@ No API key or authentication required.
|
|
|
11
11
|
|
|
12
12
|
## MCP (Model Context Protocol)
|
|
13
13
|
|
|
14
|
-
### Claude
|
|
14
|
+
### Claude Code
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
```bash
|
|
17
|
+
claude mcp add --transport http lviv-timetable https://api.lad.lviv.ua/mcp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Claude Desktop / claude.ai
|
|
21
|
+
|
|
22
|
+
Open **Settings → Connectors → Add custom connector** and paste `https://api.lad.lviv.ua/mcp`. No authentication is needed.
|
|
23
|
+
|
|
24
|
+
`claude_desktop_config.json` only takes stdio servers (`command`/`args`), not a `url` — to go through the config file instead, use the stdio entry below.
|
|
25
|
+
|
|
26
|
+
### Cursor / Windsurf / other clients with remote MCP support
|
|
17
27
|
|
|
18
28
|
```json
|
|
19
29
|
{
|
|
@@ -25,7 +35,7 @@ Add to `~/.claude/claude_desktop_config.json` (or `claude.ai/code` MCP settings)
|
|
|
25
35
|
}
|
|
26
36
|
```
|
|
27
37
|
|
|
28
|
-
###
|
|
38
|
+
### stdio-only clients (including Claude Desktop's config file)
|
|
29
39
|
|
|
30
40
|
```bash
|
|
31
41
|
npx timetable-api-node
|
|
@@ -44,7 +54,7 @@ Or pin the config:
|
|
|
44
54
|
}
|
|
45
55
|
```
|
|
46
56
|
|
|
47
|
-
The `npx` entry is a
|
|
57
|
+
The `npx` entry is a thin stdio proxy — it forwards every request to the live API, so there is no database or config to set up. npx still installs the package's npm dependencies on first run, so expect a short download.
|
|
48
58
|
|
|
49
59
|
### MCP Inspector (testing)
|
|
50
60
|
|
|
@@ -60,15 +70,16 @@ All tools are read-only. Argument names are **exact** — pass them as shown.
|
|
|
60
70
|
|
|
61
71
|
| Tool | Arguments | Purpose |
|
|
62
72
|
|------|-----------|---------|
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
| `search_stops` | `query` (string), `limit` (int 1–25, optional) | Stop IDs by name — Ukrainian or English, partial, inflection-tolerant. |
|
|
74
|
+
| `get_stops_around_location` | `latitude`, `longitude` (numbers), `radius_meters` (int 50–3000, optional) | Stop IDs near a coordinate, with serving routes. |
|
|
75
|
+
| `get_stop_realtime` | `stop_id` (number or digit string) | Live arrivals at a stop: route, destination, minutes to arrival. |
|
|
76
|
+
| `find_routes_between` | `from_stop_id`, `to_stop_id` | Direct routes from A to B: where to board and get off, walk at each end. |
|
|
77
|
+
| `get_route_static` | `route_name` (string, e.g. `"T30"`), `include_shapes` (bool, optional) | Stop lists (both directions), first-stop timetable; polylines on request. |
|
|
78
|
+
| `get_route_realtime` | `route_name` (string) | Live vehicles on a route with destination and next stop. |
|
|
79
|
+
| `get_nearby_vehicles` | `latitude`, `longitude` (numbers), `radius_meters`, `route`, `limit` (optional) | Live vehicles near a coordinate, nearest first. |
|
|
80
|
+
| `get_vehicle_info` | `vehicle_id` (string) | One vehicle: route, destination, plate, upcoming stops with names. |
|
|
81
|
+
|
|
82
|
+
Every tool result is JSON with three keys — `view`, `data` (the payload), and `ui_blocks` (ordered map/arrival-list rendering hints that point into `data`). Resolve a stop name with `search_stops`, or an address/coordinates with `get_stops_around_location`, before calling stop-based tools.
|
|
72
83
|
|
|
73
84
|
---
|
|
74
85
|
|
package/README.md
CHANGED
|
@@ -102,7 +102,16 @@ graph LR;
|
|
|
102
102
|
<details>
|
|
103
103
|
<summary><strong>Postman / curl: call a tool on production</strong></summary>
|
|
104
104
|
|
|
105
|
-
`POST https://api.lad.lviv.ua/mcp` with `Content-Type: application/json
|
|
105
|
+
`POST https://api.lad.lviv.ua/mcp` with `Content-Type: application/json` **and** `Accept: application/json, text/event-stream` — the Streamable HTTP transport rejects a request that does not accept both. The server is stateless: there is no session, so `tools/call` works on its own without an `initialize` first. The response arrives as a single SSE `event: message` frame carrying the JSON-RPC result.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
curl -s https://api.lad.lviv.ua/mcp \
|
|
109
|
+
-H 'Content-Type: application/json' \
|
|
110
|
+
-H 'Accept: application/json, text/event-stream' \
|
|
111
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_stop_realtime","arguments":{"stop_id":101}}}'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Example **`tools/call`** body shape:
|
|
106
115
|
|
|
107
116
|
```json
|
|
108
117
|
{
|
|
@@ -116,72 +125,66 @@ graph LR;
|
|
|
116
125
|
}
|
|
117
126
|
```
|
|
118
127
|
|
|
119
|
-
Successful tool responses return a **natural-language text summary** inside MCP `content` items (`type: "text"`) — e.g. *"Stop
|
|
128
|
+
Successful tool responses return a **natural-language text summary** inside MCP `content` items (`type: "text"`) — e.g. *"Stop «Площа Ринок»: 6 arrivals. Next: Т02 → «Пасічна» in 3 min."* The full structured payload is in the `structuredContent` field (for schema-aware clients). Each `structuredContent` payload follows one contract:
|
|
120
129
|
|
|
121
130
|
```json
|
|
122
131
|
{
|
|
123
132
|
"view": "transit_realtime",
|
|
124
|
-
"data": { "...": "tool-specific
|
|
133
|
+
"data": { "...": "tool-specific payload" },
|
|
125
134
|
"ui_blocks": [
|
|
126
|
-
{ "type": "map", "data": { "
|
|
127
|
-
{ "type": "arrival_list", "data": { "
|
|
135
|
+
{ "type": "map", "data": { "center": [49.84, 24.03], "zoom": 14, "layers": { "stops": "data.stop", "vehicles": "data.arrivals" } } },
|
|
136
|
+
{ "type": "arrival_list", "data": { "source": "data.arrivals" } }
|
|
128
137
|
]
|
|
129
138
|
}
|
|
130
139
|
```
|
|
131
140
|
|
|
132
|
-
|
|
141
|
+
`ui_blocks` point into `data` instead of repeating it. A `map` block gives the centre and zoom, and `layers` maps `stops`, `vehicles` and `polylines` to a dot path in the result; every stop and vehicle there has `lat`/`lng`, vehicles also `bearing`. An `arrival_list` block names the arrivals array to render, already sorted by `arrival_minutes` (`null` = no ETA).
|
|
133
142
|
|
|
134
143
|
</details>
|
|
135
144
|
|
|
136
145
|
### Exposed tools
|
|
137
146
|
|
|
138
|
-
- `
|
|
139
|
-
- `get_route_static`
|
|
140
|
-
- `get_route_realtime`
|
|
141
|
-
- `get_stop_geometry`
|
|
142
|
-
- `get_stops_around_location`
|
|
143
|
-
- `get_nearby_vehicles`
|
|
144
|
-
- `get_vehicle_info`
|
|
145
|
-
|
|
146
|
-
<details>
|
|
147
|
-
<summary><code>get_stop_realtime</code> — input & example</summary>
|
|
147
|
+
All tools are read-only. Stop IDs are the numeric codes on stop signs, returned as strings (`"707"`). Route names are the short names on vehicles (`"Т30"`, `"А1"`); Latin `"T30"`/`"A01"` work too, and a bare number is read as an internal route ID. An unknown route or vehicle returns `isError: true` with a hint on what to pass instead.
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
| Tool | Arguments | Returns |
|
|
150
|
+
|------|-----------|---------|
|
|
151
|
+
| `search_stops` | `query` (string, ≥ 2 chars), `limit` (1–25, default 10) | Stops whose Ukrainian or English name contains every query word (inflection-tolerant: `"опера"` finds «Театр опери та балету»), with `routes`. |
|
|
152
|
+
| `get_stops_around_location` | `latitude`, `longitude`, `radius_meters` (50–3000, default 1000) | Stops near a point, nearest first, with `distance_meters` and `routes`. |
|
|
153
|
+
| `get_stop_realtime` | `stop_id` | Live arrivals: `route`, `direction` (destination), `vehicle_type`, `arrival_minutes`, vehicle position. |
|
|
154
|
+
| `find_routes_between` | `from_stop_id`, `to_stop_id` | Direct routes within a 300 m walk of each end, best first: `board_stop`, `alight_stop`, `destination`, `stops_count`, walk at each end. |
|
|
155
|
+
| `get_route_static` | `route_name`, `include_shapes` (default false) | Name, type, colour, stop lists for both directions, first-stop timetable; polylines only on request. |
|
|
156
|
+
| `get_route_realtime` | `route_name` | Vehicles on the route with `destination` and `next_stop` (`id`, `name`, ISO `arrival`). |
|
|
157
|
+
| `get_nearby_vehicles` | `latitude`, `longitude`, `radius_meters` (100–1000, default 500), `route`, `limit` (1–50, default 15) | Live vehicles nearest first, with `destination` and `distance_meters`; `total` counts all in range. |
|
|
158
|
+
| `get_vehicle_info` | `vehicle_id` | One vehicle: position, route, `destination`, plate, upcoming stops (`id`, `name`, ISO times) not yet passed. |
|
|
150
159
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
| `stop_id` | positive integer or digits-only string | yes |
|
|
154
|
-
|
|
155
|
-
**Example result** (shape only; values from upstream):
|
|
160
|
+
<details>
|
|
161
|
+
<summary><code>get_stop_realtime</code> — example</summary>
|
|
156
162
|
|
|
157
163
|
```json
|
|
158
164
|
{
|
|
159
165
|
"view": "transit_realtime",
|
|
160
166
|
"data": {
|
|
161
|
-
"stop": { "id": "
|
|
167
|
+
"stop": { "id": "61", "name": "Площа Ринок", "lat": 49.84146, "lng": 24.03227 },
|
|
162
168
|
"arrivals": [
|
|
163
169
|
{
|
|
164
|
-
"route": "
|
|
165
|
-
"direction": "
|
|
170
|
+
"route": "Т02",
|
|
171
|
+
"direction": "Пасічна",
|
|
166
172
|
"vehicle_type": "tram",
|
|
167
|
-
"arrival_minutes":
|
|
168
|
-
"vehicle_id": "
|
|
169
|
-
"lat": 49.
|
|
170
|
-
"lng": 24.
|
|
171
|
-
"bearing":
|
|
173
|
+
"arrival_minutes": 3,
|
|
174
|
+
"vehicle_id": "2393",
|
|
175
|
+
"lat": 49.83461,
|
|
176
|
+
"lng": 24.01672,
|
|
177
|
+
"bearing": 60
|
|
172
178
|
}
|
|
173
179
|
],
|
|
174
|
-
"updated_at": "2026-
|
|
180
|
+
"updated_at": "2026-09-23T09:01:21Z"
|
|
175
181
|
},
|
|
176
182
|
"ui_blocks": [
|
|
177
183
|
{
|
|
178
184
|
"type": "map",
|
|
179
|
-
"data": { "center": [49.
|
|
185
|
+
"data": { "center": [49.84146, 24.03227], "zoom": 14, "layers": { "stops": "data.stop", "vehicles": "data.arrivals" } }
|
|
180
186
|
},
|
|
181
|
-
{
|
|
182
|
-
"type": "arrival_list",
|
|
183
|
-
"data": { "arrivals": [] }
|
|
184
|
-
}
|
|
187
|
+
{ "type": "arrival_list", "data": { "source": "data.arrivals" } }
|
|
185
188
|
]
|
|
186
189
|
}
|
|
187
190
|
```
|
|
@@ -189,252 +192,164 @@ Consistency rule: each vehicle rendered on map must either have a matching ETA i
|
|
|
189
192
|
</details>
|
|
190
193
|
|
|
191
194
|
<details>
|
|
192
|
-
<summary><code>
|
|
193
|
-
|
|
194
|
-
**Arguments (JSON):**
|
|
195
|
-
|
|
196
|
-
| Field | Type | Required |
|
|
197
|
-
|-------|------|----------|
|
|
198
|
-
| `route_name` | route short name (e.g. `"T30"`, `"32A"`) or numeric external ID | yes |
|
|
199
|
-
|
|
200
|
-
**Example result** (shape only; stops truncated for brevity):
|
|
195
|
+
<summary><code>search_stops</code> — example</summary>
|
|
201
196
|
|
|
202
197
|
```json
|
|
203
198
|
{
|
|
204
199
|
"view": "transit_realtime",
|
|
205
200
|
"data": {
|
|
206
|
-
"
|
|
207
|
-
"name": "T30",
|
|
208
|
-
"long_name": "Рясне-2 — Сихів",
|
|
209
|
-
"color": "#e81717",
|
|
210
|
-
"type": "tram"
|
|
211
|
-
},
|
|
201
|
+
"query": "rynok",
|
|
212
202
|
"stops": [
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
[
|
|
222
|
-
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": [], "schedule": { "workday": [], "weekend": [] } },
|
|
223
|
-
{ "id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003, "departures": [], "schedule": { "workday": [], "weekend": [] } }
|
|
224
|
-
]
|
|
225
|
-
],
|
|
226
|
-
"shapes": [
|
|
227
|
-
[[49.841, 24.003], [49.839, 24.012], [49.838, 24.021]],
|
|
228
|
-
[[49.838, 24.021], [49.839, 24.012], [49.841, 24.003]]
|
|
203
|
+
{
|
|
204
|
+
"id": "61",
|
|
205
|
+
"name": "Площа Ринок",
|
|
206
|
+
"lat": 49.84146,
|
|
207
|
+
"lng": 24.03227,
|
|
208
|
+
"eng_name": "Rynok square",
|
|
209
|
+
"routes": ["Т01", "Т02"]
|
|
210
|
+
}
|
|
229
211
|
],
|
|
230
|
-
"updated_at": "2026-
|
|
212
|
+
"updated_at": "2026-09-23T09:36:53Z"
|
|
231
213
|
},
|
|
232
214
|
"ui_blocks": [
|
|
233
|
-
{
|
|
234
|
-
"type": "map",
|
|
235
|
-
"data": {
|
|
236
|
-
"center": [49.841, 24.003],
|
|
237
|
-
"zoom": 13,
|
|
238
|
-
"polylines": [[[49.841, 24.003], [49.839, 24.012], [49.838, 24.021]]],
|
|
239
|
-
"stops": [
|
|
240
|
-
{ "id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003 },
|
|
241
|
-
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021 }
|
|
242
|
-
],
|
|
243
|
-
"vehicles": []
|
|
244
|
-
}
|
|
245
|
-
}
|
|
215
|
+
{ "type": "map", "data": { "center": [49.84146, 24.03227], "zoom": 14, "layers": { "stops": "data.stops" } } }
|
|
246
216
|
]
|
|
247
217
|
}
|
|
248
218
|
```
|
|
249
219
|
|
|
250
|
-
|
|
220
|
+
One stop name usually covers both sides of the street under different IDs; each is returned, and `routes` tells them apart. `get_stops_around_location` returns the same stop objects plus `distance_meters`.
|
|
251
221
|
|
|
252
222
|
</details>
|
|
253
223
|
|
|
254
224
|
<details>
|
|
255
|
-
<summary><code>
|
|
225
|
+
<summary><code>find_routes_between</code> — example</summary>
|
|
256
226
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
| Field | Type | Required |
|
|
260
|
-
|-------|------|----------|
|
|
261
|
-
| `route_name` | route short name (e.g. `"T30"`, `"32A"`) or numeric external ID | yes |
|
|
262
|
-
|
|
263
|
-
**Example result:**
|
|
227
|
+
Text summary: *"3 direct routes «Площа Ринок» → «Залізничний вокзал». Best: Т01 towards «Залізничний вокзал», 8 stops, board at «Руська» (137m walk)."*
|
|
264
228
|
|
|
265
229
|
```json
|
|
266
230
|
{
|
|
267
231
|
"view": "transit_realtime",
|
|
268
232
|
"data": {
|
|
269
|
-
"
|
|
270
|
-
"
|
|
233
|
+
"from": { "id": "61", "name": "Площа Ринок", "stop_ids": ["10", "57", "58", "59", "61", "63", "855"] },
|
|
234
|
+
"to": { "id": "118", "name": "Залізничний вокзал", "stop_ids": ["117", "118", "188", "189", "190", "191"] },
|
|
235
|
+
"options": [
|
|
271
236
|
{
|
|
272
|
-
"
|
|
237
|
+
"route": "Т01",
|
|
238
|
+
"vehicle_type": "tram",
|
|
273
239
|
"direction": 0,
|
|
274
|
-
"
|
|
275
|
-
"lng": 24.
|
|
276
|
-
"
|
|
277
|
-
"
|
|
240
|
+
"destination": "Залізничний вокзал",
|
|
241
|
+
"board_stop": { "id": "58", "name": "Руська", "lat": 49.84186, "lng": 24.03408 },
|
|
242
|
+
"alight_stop": { "id": "118", "name": "Залізничний вокзал", "lat": 49.839, "lng": 23.99677 },
|
|
243
|
+
"stops_count": 8,
|
|
244
|
+
"walk_to_board_meters": 137,
|
|
245
|
+
"walk_from_alight_meters": 0
|
|
278
246
|
}
|
|
279
247
|
],
|
|
280
|
-
"updated_at": "2026-
|
|
248
|
+
"updated_at": "2026-09-23T09:36:53Z"
|
|
281
249
|
},
|
|
282
|
-
"ui_blocks": [
|
|
283
|
-
{
|
|
284
|
-
"type": "map",
|
|
285
|
-
"data": {
|
|
286
|
-
"center": [49.838, 24.021],
|
|
287
|
-
"zoom": 13,
|
|
288
|
-
"vehicles": [
|
|
289
|
-
{
|
|
290
|
-
"id": "tram_123",
|
|
291
|
-
"direction": 0,
|
|
292
|
-
"lat": 49.838,
|
|
293
|
-
"lng": 24.021,
|
|
294
|
-
"bearing": 120,
|
|
295
|
-
"lowfloor": true
|
|
296
|
-
}
|
|
297
|
-
]
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
]
|
|
250
|
+
"ui_blocks": []
|
|
301
251
|
}
|
|
302
252
|
```
|
|
303
253
|
|
|
304
|
-
|
|
254
|
+
Each end covers every stop within a 300 m walk (`stop_ids`): a line's two directions often stop on opposite sides of a street under different names, as here, where Т01 towards the station leaves from «Руська», not «Площа Ринок». Options are ranked by stops plus walking (150 m of walking weighs as one stop), one per route and direction. A direction's last stop counts as a place to get off, not to board. Only direct routes are listed; an empty `options` means a transfer is needed.
|
|
305
255
|
|
|
306
256
|
</details>
|
|
307
257
|
|
|
308
258
|
<details>
|
|
309
|
-
<summary><code>
|
|
310
|
-
|
|
311
|
-
**Arguments:**
|
|
312
|
-
|
|
313
|
-
| Field | Type | Required |
|
|
314
|
-
|-------|------|----------|
|
|
315
|
-
| `stop_id` | positive integer or digits-only string | yes |
|
|
316
|
-
|
|
317
|
-
**Example result:**
|
|
259
|
+
<summary><code>get_route_static</code> — example</summary>
|
|
318
260
|
|
|
319
261
|
```json
|
|
320
262
|
{
|
|
321
263
|
"view": "transit_realtime",
|
|
322
264
|
"data": {
|
|
323
|
-
"
|
|
324
|
-
"
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
265
|
+
"route": { "name": "Т30", "long_name": "Університет - Городоцька - вул. Ряшівська", "color": "#EF88AA", "type": "trolleybus" },
|
|
266
|
+
"stops": [
|
|
267
|
+
[
|
|
268
|
+
{
|
|
269
|
+
"id": "101", "name": "Університет", "lat": 49.841, "lng": 24.003,
|
|
270
|
+
"departures": ["05:30", "05:52"],
|
|
271
|
+
"schedule": { "workday": ["05:30", "05:52", "06:10"], "weekend": ["07:00", "07:30"] }
|
|
272
|
+
},
|
|
273
|
+
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": [], "schedule": { "workday": [], "weekend": [] } }
|
|
274
|
+
],
|
|
275
|
+
[
|
|
276
|
+
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": ["06:00"], "schedule": { "workday": ["06:00"], "weekend": [] } }
|
|
277
|
+
]
|
|
278
|
+
],
|
|
279
|
+
"updated_at": "2026-09-23T09:01:12Z"
|
|
330
280
|
},
|
|
331
|
-
"ui_blocks": [
|
|
281
|
+
"ui_blocks": [
|
|
282
|
+
{ "type": "map", "data": { "center": [49.841, 24.003], "zoom": 13, "layers": { "stops": "data.stops" } } }
|
|
283
|
+
]
|
|
332
284
|
}
|
|
333
285
|
```
|
|
334
286
|
|
|
287
|
+
`stops[0]` is direction 0 (outbound), `stops[1]` direction 1 (return). `departures` and `schedule` are populated for the **first stop of each direction**; other stops have empty arrays. `schedule.workday` is Monday–Friday, `schedule.weekend` Saturday–Sunday; `departures` keeps today's schedule for backward compatibility. With `include_shapes: true`, `data.shapes` holds one `[lat, lng]` polyline per direction and the map block adds `"polylines": "data.shapes"`.
|
|
288
|
+
|
|
335
289
|
</details>
|
|
336
290
|
|
|
337
291
|
<details>
|
|
338
|
-
<summary><code>
|
|
339
|
-
|
|
340
|
-
Returns stops near a map point (numeric **code**, name, coordinates, distance). Intended for hosts that render **`map`** UI blocks (for example ChatGPT): one block with **multiple stop markers** and the search center. Uses the same backend as **`GET /closest`** (see below).
|
|
341
|
-
|
|
342
|
-
**Arguments (JSON):**
|
|
343
|
-
|
|
344
|
-
| Field | Type | Required |
|
|
345
|
-
|-------|------|----------|
|
|
346
|
-
| `latitude` | number, −90…90 | yes |
|
|
347
|
-
| `longitude` | number, −180…180 | yes |
|
|
348
|
-
| `radius_meters` | integer, 50…3000 | no (default **1000**) |
|
|
349
|
-
|
|
350
|
-
**Example result** (shape only):
|
|
292
|
+
<summary><code>get_route_realtime</code> — example</summary>
|
|
351
293
|
|
|
352
294
|
```json
|
|
353
295
|
{
|
|
354
296
|
"view": "transit_realtime",
|
|
355
297
|
"data": {
|
|
356
|
-
"
|
|
357
|
-
"
|
|
358
|
-
"
|
|
359
|
-
"stops": [
|
|
298
|
+
"route_name": "Т01",
|
|
299
|
+
"destinations": ["Залізничний вокзал", "Погулянка"],
|
|
300
|
+
"vehicles": [
|
|
360
301
|
{
|
|
361
|
-
"id": "
|
|
362
|
-
"
|
|
363
|
-
"
|
|
364
|
-
"
|
|
365
|
-
"
|
|
302
|
+
"id": "5907",
|
|
303
|
+
"direction": 0,
|
|
304
|
+
"destination": "Залізничний вокзал",
|
|
305
|
+
"next_stop": { "id": "118", "name": "Залізничний вокзал", "arrival": "2026-09-23T09:35:00.000Z" },
|
|
306
|
+
"lat": 49.83947,
|
|
307
|
+
"lng": 23.99566,
|
|
308
|
+
"bearing": 126,
|
|
309
|
+
"lowfloor": true
|
|
366
310
|
}
|
|
367
311
|
],
|
|
368
|
-
"updated_at": "2026-
|
|
312
|
+
"updated_at": "2026-09-23T09:32:10Z"
|
|
369
313
|
},
|
|
370
314
|
"ui_blocks": [
|
|
371
|
-
{
|
|
372
|
-
"type": "map",
|
|
373
|
-
"data": {
|
|
374
|
-
"center": [49.84, 24.03],
|
|
375
|
-
"zoom": 15,
|
|
376
|
-
"stops": [
|
|
377
|
-
{
|
|
378
|
-
"id": "707",
|
|
379
|
-
"name": "Стадіон Сільмаш",
|
|
380
|
-
"lat": 49.841,
|
|
381
|
-
"lng": 24.031,
|
|
382
|
-
"distance_meters": 120
|
|
383
|
-
}
|
|
384
|
-
],
|
|
385
|
-
"vehicles": []
|
|
386
|
-
}
|
|
387
|
-
}
|
|
315
|
+
{ "type": "map", "data": { "center": [49.83947, 23.99566], "zoom": 13, "layers": { "vehicles": "data.vehicles" } } }
|
|
388
316
|
]
|
|
389
317
|
}
|
|
390
318
|
```
|
|
391
319
|
|
|
392
|
-
|
|
320
|
+
`route_name` is the canonical short name whatever form was passed. `direction` indexes `get_route_static`'s `stops` (0 = outbound, 1 = return) and `destinations`. `next_stop` is `null` when the feed has no trip update for the vehicle.
|
|
393
321
|
|
|
394
322
|
</details>
|
|
395
323
|
|
|
396
324
|
<details>
|
|
397
|
-
<summary><code>get_nearby_vehicles</code> —
|
|
398
|
-
|
|
399
|
-
Returns live positions for all transit vehicles within 1 km of given coordinates. Wraps the same backend as `GET /transport`.
|
|
400
|
-
|
|
401
|
-
**Arguments (JSON):**
|
|
402
|
-
|
|
403
|
-
| Field | Type | Required |
|
|
404
|
-
|-------|------|----------|
|
|
405
|
-
| `latitude` | number, −90…90 | yes |
|
|
406
|
-
| `longitude` | number, −180…180 | yes |
|
|
407
|
-
|
|
408
|
-
**Example result** (shape only):
|
|
325
|
+
<summary><code>get_nearby_vehicles</code> — example</summary>
|
|
409
326
|
|
|
410
327
|
```json
|
|
411
328
|
{
|
|
412
329
|
"view": "transit_realtime",
|
|
413
330
|
"data": {
|
|
414
|
-
"center_lat": 49.
|
|
415
|
-
"center_lng": 24.
|
|
331
|
+
"center_lat": 49.8419,
|
|
332
|
+
"center_lng": 24.0316,
|
|
333
|
+
"radius_meters": 500,
|
|
334
|
+
"total": 18,
|
|
416
335
|
"vehicles": [
|
|
417
336
|
{
|
|
418
|
-
"id": "
|
|
419
|
-
"route": "
|
|
337
|
+
"id": "3422",
|
|
338
|
+
"route": "Т01",
|
|
420
339
|
"vehicle_type": "tram",
|
|
421
|
-
"
|
|
422
|
-
"
|
|
423
|
-
"
|
|
424
|
-
"
|
|
340
|
+
"direction": 0,
|
|
341
|
+
"destination": "Залізничний вокзал",
|
|
342
|
+
"lat": 49.84154,
|
|
343
|
+
"lng": 24.03364,
|
|
344
|
+
"bearing": 258,
|
|
345
|
+
"lowfloor": false,
|
|
346
|
+
"distance_meters": 152
|
|
425
347
|
}
|
|
426
348
|
],
|
|
427
|
-
"updated_at": "2026-
|
|
349
|
+
"updated_at": "2026-09-23T09:32:10Z"
|
|
428
350
|
},
|
|
429
351
|
"ui_blocks": [
|
|
430
|
-
{
|
|
431
|
-
"type": "map",
|
|
432
|
-
"data": {
|
|
433
|
-
"center": [49.84, 24.03],
|
|
434
|
-
"zoom": 14,
|
|
435
|
-
"vehicles": [{ "id": "tram_123", "route": "T01", "lat": 49.841, "lng": 24.031, "bearing": 90, "eta_status": "unassigned" }]
|
|
436
|
-
}
|
|
437
|
-
}
|
|
352
|
+
{ "type": "map", "data": { "center": [49.8419, 24.0316], "zoom": 15, "layers": { "vehicles": "data.vehicles" } } }
|
|
438
353
|
]
|
|
439
354
|
}
|
|
440
355
|
```
|
|
@@ -442,47 +357,47 @@ Returns live positions for all transit vehicles within 1 km of given coordinates
|
|
|
442
357
|
</details>
|
|
443
358
|
|
|
444
359
|
<details>
|
|
445
|
-
<summary><code>get_vehicle_info</code> —
|
|
446
|
-
|
|
447
|
-
Full details for one vehicle by its ID: position, route, license plate, direction, and upcoming stop arrival times. Vehicle IDs come from `get_route_realtime`, `get_nearby_vehicles`, or `get_stop_realtime`.
|
|
448
|
-
|
|
449
|
-
**Arguments (JSON):**
|
|
450
|
-
|
|
451
|
-
| Field | Type | Required |
|
|
452
|
-
|-------|------|----------|
|
|
453
|
-
| `vehicle_id` | string | yes |
|
|
454
|
-
|
|
455
|
-
**Example result** (shape only):
|
|
360
|
+
<summary><code>get_vehicle_info</code> — example</summary>
|
|
456
361
|
|
|
457
362
|
```json
|
|
458
363
|
{
|
|
459
364
|
"view": "transit_realtime",
|
|
460
365
|
"data": {
|
|
461
|
-
"vehicle_id": "
|
|
462
|
-
"route": "
|
|
463
|
-
"license_plate": "
|
|
464
|
-
"lat": 49.
|
|
465
|
-
"lng":
|
|
466
|
-
"bearing":
|
|
366
|
+
"vehicle_id": "5907",
|
|
367
|
+
"route": "Т01",
|
|
368
|
+
"license_plate": "1238",
|
|
369
|
+
"lat": 49.83947,
|
|
370
|
+
"lng": 23.99566,
|
|
371
|
+
"bearing": 126,
|
|
467
372
|
"direction": 0,
|
|
373
|
+
"destination": "Залізничний вокзал",
|
|
468
374
|
"upcoming_stops": [
|
|
469
|
-
{ "
|
|
470
|
-
{ "
|
|
375
|
+
{ "id": "118", "name": "Залізничний вокзал", "arrival": null, "departure": "2026-09-23T09:35:00.000Z" },
|
|
376
|
+
{ "id": "188", "name": "Приміський вокзал", "arrival": "2026-09-23T09:35:49.000Z", "departure": null }
|
|
471
377
|
],
|
|
472
|
-
"updated_at": "2026-
|
|
378
|
+
"updated_at": "2026-09-23T09:32:10Z"
|
|
473
379
|
},
|
|
474
380
|
"ui_blocks": [
|
|
475
|
-
{
|
|
476
|
-
"type": "map",
|
|
477
|
-
"data": { "center": [49.841, 24.031], "zoom": 15, "vehicles": [{ "id": "tram_123", "eta_status": "unassigned" }] }
|
|
478
|
-
}
|
|
381
|
+
{ "type": "map", "data": { "center": [49.83947, 23.99566], "zoom": 15, "layers": { "vehicles": "data" } } }
|
|
479
382
|
]
|
|
480
383
|
}
|
|
481
384
|
```
|
|
482
385
|
|
|
386
|
+
`route` is the route short name, falling back to the opaque GTFS route ID only when the route is missing from the local data. Either value is accepted as `route_name` by `get_route_static` and `get_route_realtime`. `license_plate` is `null` when the feed has none.
|
|
387
|
+
|
|
483
388
|
</details>
|
|
484
389
|
|
|
485
390
|
|
|
391
|
+
### Prompts
|
|
392
|
+
|
|
393
|
+
Reusable instruction templates for rendering workflows. Each takes one argument, `stop_id` (positive integer or digits-only string).
|
|
394
|
+
|
|
395
|
+
| Prompt | Use case |
|
|
396
|
+
|--------|----------|
|
|
397
|
+
| `transit-map-view` | Map-first rendering of live vehicles for a stop. |
|
|
398
|
+
| `transit-arrival-list` | Arrival list for a stop, sorted by ETA and grouped by route. |
|
|
399
|
+
| `transit-hybrid-view` | Map block first, arrival-list block second, with ETA values kept consistent across both. |
|
|
400
|
+
|
|
486
401
|
### Resources and resource templates
|
|
487
402
|
|
|
488
403
|
In addition to tools, the server exposes MCP **resources** for reference data that doesn't require a tool call:
|
package/index.js
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
buildMcpServerCard,
|
|
34
34
|
handleMcpPostRequest,
|
|
35
35
|
} from "./mcp/timetableMcpServer.js";
|
|
36
|
+
import { renderMcpDocsPage, wantsHtmlDocs } from "./mcp/docsPage.js";
|
|
36
37
|
import healthAction from "./actions/healthAction.js";
|
|
37
38
|
import errorHandler from "./utils/errorHandler.js";
|
|
38
39
|
|
|
@@ -337,6 +338,20 @@ app.post("/mcp", mcpRateLimiter, async (req, res) => {
|
|
|
337
338
|
}
|
|
338
339
|
});
|
|
339
340
|
|
|
341
|
+
// A browser opening /mcp gets a human-readable page. Everything else that
|
|
342
|
+
// GETs it — above all a Streamable HTTP client probing for an SSE stream —
|
|
343
|
+
// falls through to the 405 below, which that client knows how to handle.
|
|
344
|
+
// Neither answer is cacheable: Cloudflare ignores Vary: Accept, so a cached
|
|
345
|
+
// docs page would be handed to MCP clients probing the same URL. Vary stays
|
|
346
|
+
// for any cache that does honour it.
|
|
347
|
+
app.get("/mcp", mcpRateLimiter, async (req, res, next) => {
|
|
348
|
+
res.vary("Accept");
|
|
349
|
+
res.set("Cache-Control", "no-store");
|
|
350
|
+
if (!wantsHtmlDocs(req.get("Accept"))) return next();
|
|
351
|
+
const baseUrl = `${req.protocol}://${req.host}`;
|
|
352
|
+
res.type("html").send(await renderMcpDocsPage(baseUrl));
|
|
353
|
+
});
|
|
354
|
+
|
|
340
355
|
app.all("/mcp", (req, res) => {
|
|
341
356
|
// RFC 9110: a 405 has to say which methods the resource does take. The
|
|
342
357
|
// transport is stateless, so there is no SSE stream for GET to open and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "timetable-api-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Lviv (Ukraine) public transport REST API and read-only Model Context Protocol (MCP) server: stops, timetables, routes, live vehicle positions, GTFS/GTFS-RT. No API key required.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -52,11 +52,12 @@
|
|
|
52
52
|
"import-slim": "node gtfs-import-slim.js",
|
|
53
53
|
"start": "node -r dotenv/config -r newrelic --import newrelic/esm-loader.mjs index.js",
|
|
54
54
|
"test": "vitest run",
|
|
55
|
-
"test:watch": "vitest"
|
|
55
|
+
"test:watch": "vitest",
|
|
56
|
+
"version": "node scripts/sync-manifest-versions.js && git add server.json openapi.yaml"
|
|
56
57
|
},
|
|
57
58
|
"author": "vbhjckfd@gmail.com",
|
|
58
59
|
"license": "WTFPL",
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"vitest": "^
|
|
61
|
+
"vitest": "^5.0.0"
|
|
61
62
|
}
|
|
62
63
|
}
|