timetable-api-node 1.1.9 → 1.3.4
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 +17 -0
- package/README.md +190 -9
- package/index.js +64 -3
- package/mcp/stdio.js +8 -4
- package/package.json +1 -1
package/INTEGRATION.md
CHANGED
|
@@ -54,6 +54,23 @@ npx @modelcontextprotocol/inspector \
|
|
|
54
54
|
--url https://api.lad.lviv.ua/mcp
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
### MCP tools & arguments
|
|
58
|
+
|
|
59
|
+
All tools are read-only. Argument names are **exact** — pass them as shown.
|
|
60
|
+
|
|
61
|
+
| Tool | Arguments | Purpose |
|
|
62
|
+
|------|-----------|---------|
|
|
63
|
+
| `get_stop_realtime` | `stop_id` (number or digit string) | Live arrivals + vehicle positions for a stop. |
|
|
64
|
+
| `get_route_static` | `route_name` (string, e.g. `"T30"`) | Stop lists (both directions), departures, polylines. |
|
|
65
|
+
| `get_route_realtime` | `route_name` (string) | Live positions of all vehicles on a route. |
|
|
66
|
+
| `get_stop_geometry` | `stop_id` (number or digit string) | Stop marker + route polylines (no live data). |
|
|
67
|
+
| `get_stops_around_location` | `latitude`, `longitude` (numbers), `radius_meters` (int 50–3000, optional) | Discover stops near a coordinate. |
|
|
68
|
+
| `get_nearby_vehicles` | `latitude`, `longitude` (numbers) | Live vehicles within 1 km of a coordinate. |
|
|
69
|
+
| `get_vehicle_info` | `vehicle_id` (string) | Position, route, plate, upcoming stops for one vehicle. |
|
|
70
|
+
| `plan_trip` | `origin_stop_id`, `destination_stop_id` (numbers) | Direct and 1-transfer route options between two stops. |
|
|
71
|
+
|
|
72
|
+
Every tool result is JSON with three keys — `view`, `data` (raw payload), and `ui_blocks` (ordered map/arrival-list rendering hints). Resolve a place name or address to a `stop_id` with `get_stops_around_location` before calling stop- or trip-based tools.
|
|
73
|
+
|
|
57
74
|
---
|
|
58
75
|
|
|
59
76
|
## LangChain (Python)
|
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ graph LR;
|
|
|
86
86
|
}
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
Successful tool responses return **
|
|
89
|
+
Successful tool responses return a **natural-language text summary** inside MCP `content` items (`type: "text"`) — e.g. *"Stop «Opera»: 3 arrivals. Next: T01 → «Rynok» in 2 min."* The full structured payload is in the `structuredContent` field (for schema-aware clients). Each `structuredContent` payload follows a strict UI contract:
|
|
90
90
|
|
|
91
91
|
```json
|
|
92
92
|
{
|
|
@@ -110,6 +110,9 @@ Consistency rule: each vehicle rendered on map must either have a matching ETA i
|
|
|
110
110
|
- `get_route_realtime`
|
|
111
111
|
- `get_stop_geometry`
|
|
112
112
|
- `get_stops_around_location`
|
|
113
|
+
- `get_nearby_vehicles`
|
|
114
|
+
- `get_vehicle_info`
|
|
115
|
+
- `plan_trip`
|
|
113
116
|
|
|
114
117
|
<details>
|
|
115
118
|
<summary><code>get_stop_realtime</code> — input & example</summary>
|
|
@@ -179,12 +182,16 @@ Consistency rule: each vehicle rendered on map must either have a matching ETA i
|
|
|
179
182
|
},
|
|
180
183
|
"stops": [
|
|
181
184
|
[
|
|
182
|
-
{
|
|
183
|
-
|
|
185
|
+
{
|
|
186
|
+
"id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003,
|
|
187
|
+
"departures": ["05:30", "05:52"],
|
|
188
|
+
"schedule": { "workday": ["05:30", "05:52", "06:10"], "weekend": ["07:00", "07:30"] }
|
|
189
|
+
},
|
|
190
|
+
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": [], "schedule": { "workday": [], "weekend": [] } }
|
|
184
191
|
],
|
|
185
192
|
[
|
|
186
|
-
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": [] },
|
|
187
|
-
{ "id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003, "departures": [] }
|
|
193
|
+
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": [], "schedule": { "workday": [], "weekend": [] } },
|
|
194
|
+
{ "id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003, "departures": [], "schedule": { "workday": [], "weekend": [] } }
|
|
188
195
|
]
|
|
189
196
|
],
|
|
190
197
|
"shapes": [
|
|
@@ -211,7 +218,7 @@ Consistency rule: each vehicle rendered on map must either have a matching ETA i
|
|
|
211
218
|
}
|
|
212
219
|
```
|
|
213
220
|
|
|
214
|
-
`stops[0]` is direction 0 (outbound), `stops[1]` is direction 1 (return). `departures`
|
|
221
|
+
`stops[0]` is direction 0 (outbound), `stops[1]` is direction 1 (return). `departures` and `schedule` are populated only for the **first stop of direction 0**; all other stops have empty arrays. `schedule.workday` contains Monday–Friday departure times; `schedule.weekend` contains Saturday–Sunday departure times. `departures` keeps today's schedule for backward compatibility. `shapes` follows the same two-element order. The map block uses direction-0 polyline and all unique stops as markers.
|
|
215
222
|
|
|
216
223
|
</details>
|
|
217
224
|
|
|
@@ -357,10 +364,172 @@ Map zoom is **15** for radius ≤ 1500 m and **14** for larger radii (up to 3000
|
|
|
357
364
|
|
|
358
365
|
</details>
|
|
359
366
|
|
|
367
|
+
<details>
|
|
368
|
+
<summary><code>get_nearby_vehicles</code> — input & example</summary>
|
|
369
|
+
|
|
370
|
+
Returns live positions for all transit vehicles within 1 km of given coordinates. Wraps the same backend as `GET /transport`.
|
|
371
|
+
|
|
372
|
+
**Arguments (JSON):**
|
|
373
|
+
|
|
374
|
+
| Field | Type | Required |
|
|
375
|
+
|-------|------|----------|
|
|
376
|
+
| `latitude` | number, −90…90 | yes |
|
|
377
|
+
| `longitude` | number, −180…180 | yes |
|
|
378
|
+
|
|
379
|
+
**Example result** (shape only):
|
|
380
|
+
|
|
381
|
+
```json
|
|
382
|
+
{
|
|
383
|
+
"view": "transit_realtime",
|
|
384
|
+
"data": {
|
|
385
|
+
"center_lat": 49.84,
|
|
386
|
+
"center_lng": 24.03,
|
|
387
|
+
"vehicles": [
|
|
388
|
+
{
|
|
389
|
+
"id": "tram_123",
|
|
390
|
+
"route": "T01",
|
|
391
|
+
"vehicle_type": "tram",
|
|
392
|
+
"lat": 49.841,
|
|
393
|
+
"lng": 24.031,
|
|
394
|
+
"bearing": 90,
|
|
395
|
+
"lowfloor": true
|
|
396
|
+
}
|
|
397
|
+
],
|
|
398
|
+
"updated_at": "2026-01-23T12:00:00Z"
|
|
399
|
+
},
|
|
400
|
+
"ui_blocks": [
|
|
401
|
+
{
|
|
402
|
+
"type": "map",
|
|
403
|
+
"data": {
|
|
404
|
+
"center": [49.84, 24.03],
|
|
405
|
+
"zoom": 14,
|
|
406
|
+
"vehicles": [{ "id": "tram_123", "route": "T01", "lat": 49.841, "lng": 24.031, "bearing": 90, "eta_status": "unassigned" }]
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
</details>
|
|
414
|
+
|
|
415
|
+
<details>
|
|
416
|
+
<summary><code>get_vehicle_info</code> — input & example</summary>
|
|
417
|
+
|
|
418
|
+
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`.
|
|
419
|
+
|
|
420
|
+
**Arguments (JSON):**
|
|
421
|
+
|
|
422
|
+
| Field | Type | Required |
|
|
423
|
+
|-------|------|----------|
|
|
424
|
+
| `vehicle_id` | string | yes |
|
|
425
|
+
|
|
426
|
+
**Example result** (shape only):
|
|
427
|
+
|
|
428
|
+
```json
|
|
429
|
+
{
|
|
430
|
+
"view": "transit_realtime",
|
|
431
|
+
"data": {
|
|
432
|
+
"vehicle_id": "tram_123",
|
|
433
|
+
"route": "route-ext-1",
|
|
434
|
+
"license_plate": "BC-1234-AB",
|
|
435
|
+
"lat": 49.841,
|
|
436
|
+
"lng": 24.031,
|
|
437
|
+
"bearing": 90,
|
|
438
|
+
"direction": 0,
|
|
439
|
+
"upcoming_stops": [
|
|
440
|
+
{ "code": 707, "arrival": "2026-01-23T12:05:00Z", "departure": null },
|
|
441
|
+
{ "code": 708, "arrival": "2026-01-23T12:08:00Z", "departure": null }
|
|
442
|
+
],
|
|
443
|
+
"updated_at": "2026-01-23T12:00:00Z"
|
|
444
|
+
},
|
|
445
|
+
"ui_blocks": [
|
|
446
|
+
{
|
|
447
|
+
"type": "map",
|
|
448
|
+
"data": { "center": [49.841, 24.031], "zoom": 15, "vehicles": [{ "id": "tram_123", "eta_status": "unassigned" }] }
|
|
449
|
+
}
|
|
450
|
+
]
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
</details>
|
|
455
|
+
|
|
456
|
+
<details>
|
|
457
|
+
<summary><code>plan_trip</code> — input & example</summary>
|
|
458
|
+
|
|
459
|
+
Plans a transit trip from an origin stop to a destination stop using the static route graph. Returns direct options (one route) and 1-transfer options sorted by fewest stops. Does **not** account for realtime disruptions — combine with `get_stop_realtime` for live ETAs after planning.
|
|
460
|
+
|
|
461
|
+
**Arguments (JSON):**
|
|
462
|
+
|
|
463
|
+
| Field | Type | Required |
|
|
464
|
+
|-------|------|----------|
|
|
465
|
+
| `origin_stop_id` | positive integer or digits-only string | yes |
|
|
466
|
+
| `destination_stop_id` | positive integer or digits-only string | yes |
|
|
467
|
+
|
|
468
|
+
**Example result** (direct trip):
|
|
469
|
+
|
|
470
|
+
```json
|
|
471
|
+
{
|
|
472
|
+
"view": "transit_realtime",
|
|
473
|
+
"data": {
|
|
474
|
+
"origin": { "id": "101", "name": "Головний вокзал" },
|
|
475
|
+
"destination": { "id": "707", "name": "Стадіон Сільмаш" },
|
|
476
|
+
"options": [
|
|
477
|
+
{
|
|
478
|
+
"type": "direct",
|
|
479
|
+
"route": "T30",
|
|
480
|
+
"direction": 0,
|
|
481
|
+
"board_stop_code": 101,
|
|
482
|
+
"board_stop_name": "Головний вокзал",
|
|
483
|
+
"alight_stop_code": 707,
|
|
484
|
+
"alight_stop_name": "Стадіон Сільмаш",
|
|
485
|
+
"stops_count": 4
|
|
486
|
+
}
|
|
487
|
+
],
|
|
488
|
+
"updated_at": "2026-01-23T12:00:00Z"
|
|
489
|
+
},
|
|
490
|
+
"ui_blocks": []
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
**Transfer trip** option shape:
|
|
495
|
+
|
|
496
|
+
```json
|
|
497
|
+
{
|
|
498
|
+
"type": "transfer",
|
|
499
|
+
"route1": "T01",
|
|
500
|
+
"route2": "А05",
|
|
501
|
+
"board_stop_code": 101,
|
|
502
|
+
"board_stop_name": "Головний вокзал",
|
|
503
|
+
"transfer_stop_code": 303,
|
|
504
|
+
"transfer_stop_name": "Площа Ринок",
|
|
505
|
+
"alight_stop_code": 707,
|
|
506
|
+
"alight_stop_name": "Стадіон Сільмаш",
|
|
507
|
+
"stops_count_1": 3,
|
|
508
|
+
"stops_count_2": 2
|
|
509
|
+
}
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
Up to 5 direct and 3 transfer options are returned. Use `get_stops_around_location` to resolve addresses or coordinates to stop codes before calling this tool.
|
|
513
|
+
|
|
514
|
+
</details>
|
|
515
|
+
|
|
516
|
+
### Resources and resource templates
|
|
517
|
+
|
|
518
|
+
In addition to tools, the server exposes MCP **resources** for reference data that doesn't require a tool call:
|
|
519
|
+
|
|
520
|
+
| URI | Description |
|
|
521
|
+
|-----|-------------|
|
|
522
|
+
| `timetable://about` | Scope, usage, and data caveats for this server (Markdown) |
|
|
523
|
+
| `timetable://reference/tools` | Tools reference table (Markdown) |
|
|
524
|
+
| `timetable://reference/prompts` | Prompt templates catalog (Markdown) |
|
|
525
|
+
| `timetable://stop/{code}` | Static info for a stop by numeric code — name, coordinates, serving routes (JSON) |
|
|
526
|
+
| `timetable://route/{name}` | Static metadata for a route by short name — color, type, stop counts (JSON) |
|
|
527
|
+
|
|
360
528
|
### Security model
|
|
361
529
|
|
|
362
530
|
- Public read-only (no authentication).
|
|
363
531
|
- No mutating tools are exposed.
|
|
532
|
+
- `POST /mcp` is rate-limited to **60 requests/min per IP** (in-memory, resets on restart). Excess requests receive HTTP 429 with a JSON-RPC error body.
|
|
364
533
|
- `robots.txt` is only a best-effort discovery hint and not a protocol contract.
|
|
365
534
|
|
|
366
535
|
## REST API
|
|
@@ -418,12 +587,15 @@ All routes as a JSON array, sorted by short name.
|
|
|
418
587
|
Route shape, stop list, and metadata. Long-cached (30 days).
|
|
419
588
|
|
|
420
589
|
- **Response:** `{ id, color, type, route_short_name, route_long_name, stops: [[dir0…], [dir1…]], shapes }`.
|
|
590
|
+
- Each stop object: `{ code, name, loc, transfers, departures, schedule }`.
|
|
591
|
+
- `departures` — today's departure times (HH:MM), populated only for direction 0 first stop. Kept for backward compatibility.
|
|
592
|
+
- `schedule` — `{ workday: string[], weekend: string[] }` departure times by day type, populated only for direction 0 first stop.
|
|
421
593
|
|
|
422
594
|
#### `GET /routes/dynamic/:name`
|
|
423
595
|
|
|
424
596
|
Live vehicle positions for a route. Short-cached (10 s).
|
|
425
597
|
|
|
426
|
-
- **Response:** array of `{ id, direction, location: [lat, lng], bearing, lowfloor }`.
|
|
598
|
+
- **Response:** array of `{ id, direction, location: [lat, lng], bearing, speed, lowfloor }`. `speed` is m/s from the GPS unit, or `null` when not reported.
|
|
427
599
|
|
|
428
600
|
### Vehicles
|
|
429
601
|
|
|
@@ -431,7 +603,7 @@ Live vehicle positions for a route. Short-cached (10 s).
|
|
|
431
603
|
|
|
432
604
|
Live position and upcoming stop arrivals for one vehicle. Short-cached (5 s).
|
|
433
605
|
|
|
434
|
-
- **Response:** `{ location: [lat, lng], routeId, bearing, direction, licensePlate, arrivals }`.
|
|
606
|
+
- **Response:** `{ location: [lat, lng], routeId, bearing, speed, direction, licensePlate, arrivals }`. `speed` is m/s from the GPS unit, or `null` when not reported.
|
|
435
607
|
|
|
436
608
|
#### `GET /vehicle-by-plate/:plate`
|
|
437
609
|
|
|
@@ -444,4 +616,13 @@ Look up a vehicle ID by its license plate. Short-cached (5 s).
|
|
|
444
616
|
|
|
445
617
|
Vehicles within 1 km of a point. Short-cached (10 s).
|
|
446
618
|
|
|
447
|
-
- **Response:** array of `{ id, route, vehicle_type, color, location: [lat, lng], bearing, lowfloor }`.
|
|
619
|
+
- **Response:** array of `{ id, route, routeId, direction, vehicle_type, color, location: [lat, lng], bearing, speed, lowfloor }`. `routeId` is usable as `:name` in `/routes/static/:name`; `direction` matches the index into `stops`/`shapes` (0 = outbound, 1 = return, null if unknown). `speed` is m/s or `null`.
|
|
620
|
+
|
|
621
|
+
### Trip planning
|
|
622
|
+
|
|
623
|
+
#### `GET /trip-plan?origin={code}&destination={code}`
|
|
624
|
+
|
|
625
|
+
Static trip planning between two stops using the route graph.
|
|
626
|
+
|
|
627
|
+
- **Response:** `{ origin, destination, options }` where each option is either a `direct` trip (single route) or a `transfer` trip (two routes with a transfer stop). Up to 5 direct and 3 transfer options, sorted by fewest stops.
|
|
628
|
+
- Cached for 60 s.
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import "./instrument.js";
|
|
|
2
2
|
import "dotenv/config";
|
|
3
3
|
|
|
4
4
|
import * as Sentry from "@sentry/node";
|
|
5
|
+
import pkg from "./package.json" with { type: "json" };
|
|
5
6
|
import path from "path";
|
|
6
7
|
const __dirname = import.meta.dirname;
|
|
7
8
|
const PORT = process.env.PORT || 8080;
|
|
@@ -32,6 +33,8 @@ import {
|
|
|
32
33
|
buildMcpServerCard,
|
|
33
34
|
handleMcpPostRequest,
|
|
34
35
|
} from "./mcp/timetableMcpServer.js";
|
|
36
|
+
import planTripAction from "./actions/planTripAction.js";
|
|
37
|
+
import healthAction from "./actions/healthAction.js";
|
|
35
38
|
|
|
36
39
|
const app = express();
|
|
37
40
|
|
|
@@ -69,6 +72,7 @@ app.get("/routes/static/:name", routeInfoStaticAction);
|
|
|
69
72
|
app.get("/vehicle/:vehicleId", vehicleInfoAction);
|
|
70
73
|
app.get("/vehicle-by-plate/:plate", vehicleByPlateAction);
|
|
71
74
|
app.get("/transport", closestTransportAction);
|
|
75
|
+
app.get("/trip-plan", planTripAction);
|
|
72
76
|
|
|
73
77
|
app.get("/sitemap.xml", sitemapAction);
|
|
74
78
|
|
|
@@ -112,7 +116,7 @@ app.get("/.well-known/agent.json", (req, res) => {
|
|
|
112
116
|
description:
|
|
113
117
|
"Real-time and static public transport data for Lviv, Ukraine: stops, routes, timetables, and live vehicle positions. No API key required.",
|
|
114
118
|
url: baseUrl,
|
|
115
|
-
version:
|
|
119
|
+
version: pkg.version,
|
|
116
120
|
iconUrl: `${baseUrl}/favicon.png`,
|
|
117
121
|
documentationUrl: `${baseUrl}/llms.txt`,
|
|
118
122
|
capabilities: {
|
|
@@ -171,6 +175,36 @@ app.get("/.well-known/agent.json", (req, res) => {
|
|
|
171
175
|
outputModes: ["application/json"],
|
|
172
176
|
examples: ["Get map data for stop 707"],
|
|
173
177
|
},
|
|
178
|
+
{
|
|
179
|
+
id: "get_nearby_vehicles",
|
|
180
|
+
name: "Get Nearby Vehicles",
|
|
181
|
+
description:
|
|
182
|
+
"Live positions for all transit vehicles within 1 km of a given latitude/longitude.",
|
|
183
|
+
tags: ["transit", "realtime", "vehicles", "location", "lviv"],
|
|
184
|
+
inputModes: ["text/plain", "application/json"],
|
|
185
|
+
outputModes: ["application/json"],
|
|
186
|
+
examples: ["What transport is near 49.84, 24.03?", "Live vehicles around me"],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: "get_vehicle_info",
|
|
190
|
+
name: "Get Vehicle Info",
|
|
191
|
+
description:
|
|
192
|
+
"Full details for one vehicle by ID: position, bearing, route, license plate, and upcoming stops.",
|
|
193
|
+
tags: ["transit", "realtime", "vehicle", "tracking", "lviv"],
|
|
194
|
+
inputModes: ["text/plain"],
|
|
195
|
+
outputModes: ["application/json"],
|
|
196
|
+
examples: ["Track vehicle 12345", "Where is vehicle 12345 heading?"],
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: "plan_trip",
|
|
200
|
+
name: "Plan Trip",
|
|
201
|
+
description:
|
|
202
|
+
"Plan a transit trip between two stop codes; returns direct and 1-transfer route options.",
|
|
203
|
+
tags: ["transit", "trip-planning", "routing", "lviv"],
|
|
204
|
+
inputModes: ["text/plain", "application/json"],
|
|
205
|
+
outputModes: ["application/json"],
|
|
206
|
+
examples: ["How do I get from stop 707 to stop 808?", "Plan a trip from 707 to 1234"],
|
|
207
|
+
},
|
|
174
208
|
],
|
|
175
209
|
authentication: { schemes: [] },
|
|
176
210
|
provider: {
|
|
@@ -199,7 +233,34 @@ app.get("/ping", (req, res) => {
|
|
|
199
233
|
res.json({});
|
|
200
234
|
});
|
|
201
235
|
|
|
202
|
-
app.
|
|
236
|
+
app.get("/health", healthAction);
|
|
237
|
+
|
|
238
|
+
// Simple in-memory rate limiter: 60 requests/min per IP
|
|
239
|
+
const _mcpRateLimitMap = new Map();
|
|
240
|
+
const MCP_RATE_LIMIT = 60;
|
|
241
|
+
const MCP_RATE_WINDOW_MS = 60_000;
|
|
242
|
+
|
|
243
|
+
function mcpRateLimiter(req, res, next) {
|
|
244
|
+
const ip = req.ip ?? "unknown";
|
|
245
|
+
const now = Date.now();
|
|
246
|
+
const entry = _mcpRateLimitMap.get(ip) ?? { count: 0, windowStart: now };
|
|
247
|
+
if (now - entry.windowStart > MCP_RATE_WINDOW_MS) {
|
|
248
|
+
entry.count = 0;
|
|
249
|
+
entry.windowStart = now;
|
|
250
|
+
}
|
|
251
|
+
entry.count++;
|
|
252
|
+
_mcpRateLimitMap.set(ip, entry);
|
|
253
|
+
if (entry.count > MCP_RATE_LIMIT) {
|
|
254
|
+
return res.status(429).json({
|
|
255
|
+
jsonrpc: "2.0",
|
|
256
|
+
error: { code: -32000, message: "Rate limit exceeded. Try again later." },
|
|
257
|
+
id: null,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
next();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
app.post("/mcp", mcpRateLimiter, async (req, res) => {
|
|
203
264
|
try {
|
|
204
265
|
await handleMcpPostRequest(req, res);
|
|
205
266
|
} catch (error) {
|
|
@@ -304,7 +365,7 @@ app.use(function (err, req, res, next) {
|
|
|
304
365
|
|
|
305
366
|
app.on("ready", () => {
|
|
306
367
|
app.listen(PORT, () => {
|
|
307
|
-
console.log(
|
|
368
|
+
console.log(`Started! http://localhost:${PORT}`);
|
|
308
369
|
});
|
|
309
370
|
});
|
|
310
371
|
|
package/mcp/stdio.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// to the live Lviv Public Transport MCP server without requiring a local database.
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
|
|
6
|
+
import pkg from "../package.json" with { type: "json" };
|
|
6
7
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
8
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
8
9
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
CallToolRequestSchema,
|
|
12
13
|
ListToolsRequestSchema,
|
|
13
14
|
ListResourcesRequestSchema,
|
|
15
|
+
ListResourceTemplatesRequestSchema,
|
|
14
16
|
ReadResourceRequestSchema,
|
|
15
17
|
ListPromptsRequestSchema,
|
|
16
18
|
GetPromptRequestSchema,
|
|
@@ -22,24 +24,25 @@ const upstreamUrl = new URL(
|
|
|
22
24
|
|
|
23
25
|
async function main() {
|
|
24
26
|
const upstream = new Client(
|
|
25
|
-
{ name: "lviv-timetable-stdio-proxy", version:
|
|
27
|
+
{ name: "lviv-timetable-stdio-proxy", version: pkg.version },
|
|
26
28
|
{ capabilities: {} },
|
|
27
29
|
);
|
|
28
30
|
|
|
29
31
|
await upstream.connect(new StreamableHTTPClientTransport(upstreamUrl));
|
|
30
32
|
|
|
31
|
-
const [{ tools }, { resources }, { prompts }] = await Promise.all([
|
|
33
|
+
const [{ tools }, { resources }, { resourceTemplates }, { prompts }] = await Promise.all([
|
|
32
34
|
upstream.listTools(),
|
|
33
35
|
upstream.listResources(),
|
|
36
|
+
upstream.listResourceTemplates(),
|
|
34
37
|
upstream.listPrompts(),
|
|
35
38
|
]);
|
|
36
39
|
|
|
37
40
|
const server = new Server(
|
|
38
|
-
{ name: "com.lad.lviv/timetable-api", version:
|
|
41
|
+
{ name: "com.lad.lviv/timetable-api", version: pkg.version },
|
|
39
42
|
{
|
|
40
43
|
capabilities: {
|
|
41
44
|
...(tools.length && { tools: {} }),
|
|
42
|
-
...(resources.length
|
|
45
|
+
...(resources.length || resourceTemplates.length ? { resources: {} } : {}),
|
|
43
46
|
...(prompts.length && { prompts: {} }),
|
|
44
47
|
},
|
|
45
48
|
},
|
|
@@ -47,6 +50,7 @@ async function main() {
|
|
|
47
50
|
|
|
48
51
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
|
|
49
52
|
server.setRequestHandler(ListResourcesRequestSchema, async () => ({ resources }));
|
|
53
|
+
server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({ resourceTemplates }));
|
|
50
54
|
server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts }));
|
|
51
55
|
|
|
52
56
|
server.setRequestHandler(CallToolRequestSchema, async (req) =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "timetable-api-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.4",
|
|
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",
|