timetable-api-node 1.8.7 → 1.8.9
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/index.ts +39 -138
- package/mcp/stdio.js +1 -1
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
|
|
3
|
-
import pkg from "./package.json" with { type: "json" };
|
|
4
3
|
import path from "path";
|
|
5
4
|
const __dirname = import.meta.dirname;
|
|
6
5
|
const PORT = process.env.PORT || 8080;
|
|
@@ -33,7 +32,14 @@ import getDisruptionsAction from "./actions/getDisruptionsAction.ts";
|
|
|
33
32
|
import {
|
|
34
33
|
buildMcpServerCard,
|
|
35
34
|
handleMcpPostRequest,
|
|
35
|
+
mcpManifest,
|
|
36
36
|
} from "./mcp/timetableMcpServer.ts";
|
|
37
|
+
import {
|
|
38
|
+
buildAgentCard,
|
|
39
|
+
buildAiPluginManifest,
|
|
40
|
+
buildLlmsFullTxt,
|
|
41
|
+
buildRobotsTxt,
|
|
42
|
+
} from "./mcp/discovery.ts";
|
|
37
43
|
import { renderMcpDocsPage, wantsHtmlDocs } from "./mcp/docsPage.ts";
|
|
38
44
|
import healthAction from "./actions/healthAction.ts";
|
|
39
45
|
import errorHandler from "./utils/errorHandler.ts";
|
|
@@ -56,14 +62,21 @@ const setStaticAssetCache = (res: Response, maxAgeSeconds = 3600 * 24) =>
|
|
|
56
62
|
|
|
57
63
|
app.use(cors());
|
|
58
64
|
|
|
65
|
+
// RFC 8288 Link headers for agent discovery. service-desc is the API
|
|
66
|
+
// description (RFC 8631), so it names the OpenAPI document; the MCP card gets
|
|
67
|
+
// the same rel the website's <link> tag uses. There is no
|
|
68
|
+
// oauth-protected-resource link: nothing here needs auth, and advertising
|
|
69
|
+
// protected-resource metadata invites a client to start an OAuth flow that
|
|
70
|
+
// has no authorization server to go to.
|
|
59
71
|
app.use((req, res, next) => {
|
|
60
72
|
const baseUrl = `${req.protocol}://${req.host}`;
|
|
61
73
|
res.set(
|
|
62
74
|
"Link",
|
|
63
75
|
[
|
|
64
|
-
`<${baseUrl}
|
|
65
|
-
`<${baseUrl}/.well-known/mcp/server-card.json>; rel="
|
|
76
|
+
`<${baseUrl}/openapi.yaml>; rel="service-desc"; type="application/yaml"`,
|
|
77
|
+
`<${baseUrl}/.well-known/mcp/server-card.json>; rel="mcp-server-card"; type="application/json"`,
|
|
66
78
|
`<${baseUrl}/mcp>; rel="mcp-server"`,
|
|
79
|
+
`<${baseUrl}/llms.txt>; rel="describedby"; type="text/plain"`,
|
|
67
80
|
].join(", "),
|
|
68
81
|
);
|
|
69
82
|
res.set("X-MCP-Server", `${baseUrl}/.well-known/mcp/server-card.json`);
|
|
@@ -174,134 +187,14 @@ app.get("/.well-known/openapi.yaml", (req, res) => {
|
|
|
174
187
|
});
|
|
175
188
|
|
|
176
189
|
app.get("/.well-known/ai-plugin.json", (req, res) => {
|
|
177
|
-
const baseUrl = `${req.protocol}://${req.host}`;
|
|
178
190
|
setStaticAssetCache(res);
|
|
179
|
-
res.json({
|
|
180
|
-
schema_version: "v1",
|
|
181
|
-
name_for_human: "Lviv Public Transport",
|
|
182
|
-
name_for_model: "lviv_timetable",
|
|
183
|
-
description_for_human:
|
|
184
|
-
"Real-time and static public transport data for Lviv, Ukraine — stops, routes, timetables, live vehicle positions. No API key required.",
|
|
185
|
-
description_for_model:
|
|
186
|
-
"Provides real-time arrivals, live vehicle positions, static timetables, route shapes, and stop discovery for public transport in Lviv, Ukraine. Data sourced from municipal GTFS-RT feeds. All endpoints are read-only and require no authentication. Use stop numeric codes (e.g. 707) and route short names (e.g. T30, 32A).",
|
|
187
|
-
auth: { type: "none" },
|
|
188
|
-
api: {
|
|
189
|
-
type: "openapi",
|
|
190
|
-
url: `${baseUrl}/openapi.yaml`,
|
|
191
|
-
},
|
|
192
|
-
logo_url: `${baseUrl}/favicon.png`,
|
|
193
|
-
contact_email: "vbhjckfd@gmail.com",
|
|
194
|
-
legal_info_url: "https://lad.lviv.ua",
|
|
195
|
-
});
|
|
191
|
+
res.json(buildAiPluginManifest(`${req.protocol}://${req.host}`));
|
|
196
192
|
});
|
|
197
193
|
|
|
198
|
-
|
|
199
|
-
|
|
194
|
+
// A2A renamed the card from agent.json to agent-card.json; serve both.
|
|
195
|
+
app.get(["/.well-known/agent-card.json", "/.well-known/agent.json"], async (req, res) => {
|
|
200
196
|
setStaticAssetCache(res);
|
|
201
|
-
res.json({
|
|
202
|
-
name: "Lviv Public Transport",
|
|
203
|
-
description:
|
|
204
|
-
"Real-time and static public transport data for Lviv, Ukraine: stops, routes, timetables, and live vehicle positions. No API key required.",
|
|
205
|
-
url: baseUrl,
|
|
206
|
-
version: pkg.version,
|
|
207
|
-
iconUrl: `${baseUrl}/favicon.png`,
|
|
208
|
-
documentationUrl: `${baseUrl}/llms.txt`,
|
|
209
|
-
capabilities: {
|
|
210
|
-
streaming: false,
|
|
211
|
-
pushNotifications: false,
|
|
212
|
-
stateTransitionHistory: false,
|
|
213
|
-
},
|
|
214
|
-
defaultInputModes: ["text/plain", "application/json"],
|
|
215
|
-
defaultOutputModes: ["application/json"],
|
|
216
|
-
skills: [
|
|
217
|
-
{
|
|
218
|
-
id: "get_stop_realtime",
|
|
219
|
-
name: "Get Stop Realtime",
|
|
220
|
-
description:
|
|
221
|
-
"Live arrivals and vehicle positions at a stop by numeric stop code (e.g. 707).",
|
|
222
|
-
tags: ["transit", "realtime", "arrivals", "lviv"],
|
|
223
|
-
inputModes: ["text/plain"],
|
|
224
|
-
outputModes: ["application/json"],
|
|
225
|
-
examples: ["What buses are arriving at stop 707?", "Live arrivals for stop 1234"],
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
id: "get_route_static",
|
|
229
|
-
name: "Get Route Static",
|
|
230
|
-
description:
|
|
231
|
-
"Route metadata, stop lists, departure times, and polylines for both directions.",
|
|
232
|
-
tags: ["transit", "route", "timetable", "lviv"],
|
|
233
|
-
inputModes: ["text/plain"],
|
|
234
|
-
outputModes: ["application/json"],
|
|
235
|
-
examples: ["Show me route T30 stops", "Route 32A schedule"],
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
id: "get_route_realtime",
|
|
239
|
-
name: "Get Route Realtime",
|
|
240
|
-
description: "Live vehicle positions for all vehicles currently running on a route.",
|
|
241
|
-
tags: ["transit", "realtime", "vehicles", "lviv"],
|
|
242
|
-
inputModes: ["text/plain"],
|
|
243
|
-
outputModes: ["application/json"],
|
|
244
|
-
examples: ["Where are all tram 6 vehicles right now?"],
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
id: "get_stops_around_location",
|
|
248
|
-
name: "Get Stops Around Location",
|
|
249
|
-
description: "Discover transit stops near a given latitude/longitude within a radius.",
|
|
250
|
-
tags: ["transit", "location", "stops", "lviv"],
|
|
251
|
-
inputModes: ["text/plain", "application/json"],
|
|
252
|
-
outputModes: ["application/json"],
|
|
253
|
-
examples: ["Find stops near 49.84, 24.03", "Stops within 300m of my location"],
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
id: "get_stop_geometry",
|
|
257
|
-
name: "Get Stop Geometry",
|
|
258
|
-
description:
|
|
259
|
-
"Static map context for a stop: stop marker and route polylines for all serving routes.",
|
|
260
|
-
tags: ["transit", "geometry", "map", "lviv"],
|
|
261
|
-
inputModes: ["text/plain"],
|
|
262
|
-
outputModes: ["application/json"],
|
|
263
|
-
examples: ["Get map data for stop 707"],
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
id: "get_nearby_vehicles",
|
|
267
|
-
name: "Get Nearby Vehicles",
|
|
268
|
-
description:
|
|
269
|
-
"Live positions for all transit vehicles within 1 km of a given latitude/longitude.",
|
|
270
|
-
tags: ["transit", "realtime", "vehicles", "location", "lviv"],
|
|
271
|
-
inputModes: ["text/plain", "application/json"],
|
|
272
|
-
outputModes: ["application/json"],
|
|
273
|
-
examples: ["What transport is near 49.84, 24.03?", "Live vehicles around me"],
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
id: "get_vehicle_info",
|
|
277
|
-
name: "Get Vehicle Info",
|
|
278
|
-
description:
|
|
279
|
-
"Full details for one vehicle by ID: position, bearing, route, license plate, and upcoming stops.",
|
|
280
|
-
tags: ["transit", "realtime", "vehicle", "tracking", "lviv"],
|
|
281
|
-
inputModes: ["text/plain"],
|
|
282
|
-
outputModes: ["application/json"],
|
|
283
|
-
examples: ["Track vehicle 12345", "Where is vehicle 12345 heading?"],
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
id: "get_disruptions",
|
|
287
|
-
name: "Get Disruptions",
|
|
288
|
-
description:
|
|
289
|
-
"Announced closures, detours and moved stops in force today, optionally for one route or stop.",
|
|
290
|
-
tags: ["transit", "disruptions", "detours", "road-works", "lviv"],
|
|
291
|
-
inputModes: ["text/plain"],
|
|
292
|
-
outputModes: ["application/json"],
|
|
293
|
-
examples: ["Is bus А34 on a detour?", "Which routes are affected by road works?"],
|
|
294
|
-
},
|
|
295
|
-
],
|
|
296
|
-
authentication: { schemes: [] },
|
|
297
|
-
provider: {
|
|
298
|
-
organization: "lad.lviv.ua",
|
|
299
|
-
url: "https://lad.lviv.ua",
|
|
300
|
-
},
|
|
301
|
-
mcpEndpoint: `${baseUrl}/mcp`,
|
|
302
|
-
mcpServerCard: `${baseUrl}/.well-known/mcp/server-card.json`,
|
|
303
|
-
openApiUrl: `${baseUrl}/openapi.yaml`,
|
|
304
|
-
});
|
|
197
|
+
res.json(buildAgentCard(`${req.protocol}://${req.host}`, await mcpManifest()));
|
|
305
198
|
});
|
|
306
199
|
|
|
307
200
|
app.get("/llms.txt", (req, res) => {
|
|
@@ -310,6 +203,11 @@ app.get("/llms.txt", (req, res) => {
|
|
|
310
203
|
res.sendFile(path.join(__dirname, "llms.txt"));
|
|
311
204
|
});
|
|
312
205
|
|
|
206
|
+
app.get("/llms-full.txt", async (req, res) => {
|
|
207
|
+
setStaticAssetCache(res);
|
|
208
|
+
res.type("text/plain").send(buildLlmsFullTxt(`${req.protocol}://${req.host}`, await mcpManifest()));
|
|
209
|
+
});
|
|
210
|
+
|
|
313
211
|
app.get("/INTEGRATION.md", (req, res) => {
|
|
314
212
|
setStaticAssetCache(res);
|
|
315
213
|
res.type("text/markdown");
|
|
@@ -403,13 +301,18 @@ app.get("/.well-known/oauth-protected-resource", (req, res) => {
|
|
|
403
301
|
});
|
|
404
302
|
});
|
|
405
303
|
|
|
406
|
-
app.get("/.well-known/mcp/server-card.json", (req, res) => {
|
|
304
|
+
app.get("/.well-known/mcp/server-card.json", async (req, res) => {
|
|
407
305
|
const baseUrl = `${req.protocol}://${req.host}`;
|
|
408
306
|
// The card carries pkg.version, so a code push has to be able to purge it;
|
|
409
307
|
// without the "long" tag the DropCache step in cloudbuild.yaml could not
|
|
410
308
|
// reach it and clients kept a stale version for a day.
|
|
411
309
|
setStaticAssetCache(res);
|
|
412
|
-
res.json(buildMcpServerCard(baseUrl));
|
|
310
|
+
res.json(buildMcpServerCard(baseUrl, await mcpManifest()));
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Other paths discovery proposals and crawlers try for the same card.
|
|
314
|
+
app.get(["/.well-known/mcp", "/.well-known/mcp.json"], (req, res) => {
|
|
315
|
+
res.redirect(301, "/.well-known/mcp/server-card.json");
|
|
413
316
|
});
|
|
414
317
|
|
|
415
318
|
app.get("/mcp-icon.svg", (req, res) => {
|
|
@@ -421,16 +324,8 @@ app.get("/mcp-icon.svg", (req, res) => {
|
|
|
421
324
|
});
|
|
422
325
|
|
|
423
326
|
app.get("/robots.txt", (req, res) => {
|
|
424
|
-
const baseUrl = `${req.protocol}://${req.host}`;
|
|
425
|
-
const lines = [
|
|
426
|
-
"User-agent: *",
|
|
427
|
-
"Disallow: /private/",
|
|
428
|
-
"",
|
|
429
|
-
"# Non-standard hint for AI agent discovery:",
|
|
430
|
-
`# mcp-server: ${baseUrl}/.well-known/mcp/server-card.json`,
|
|
431
|
-
];
|
|
432
327
|
setStaticAssetCache(res);
|
|
433
|
-
res.type("text/plain").send(
|
|
328
|
+
res.type("text/plain").send(buildRobotsTxt(`${req.protocol}://${req.host}`));
|
|
434
329
|
});
|
|
435
330
|
|
|
436
331
|
app.get("/last-modified.txt", (req, res, next) => {
|
|
@@ -447,6 +342,12 @@ app.get("/favicon.ico", (req, res, next) => {
|
|
|
447
342
|
res.sendFile(path.join(__dirname, "favicon.ico"));
|
|
448
343
|
});
|
|
449
344
|
|
|
345
|
+
// The plugin manifest and agent card point their logo here.
|
|
346
|
+
app.get("/favicon.png", (req, res, next) => {
|
|
347
|
+
setStaticAssetCache(res, 3600 * 24 * 31);
|
|
348
|
+
res.sendFile(path.join(__dirname, "favicon.png"));
|
|
349
|
+
});
|
|
350
|
+
|
|
450
351
|
// Applies the per-stop route overrides to the /stops listing in the browser.
|
|
451
352
|
// Tagged "long" like the other baked-in assets: it ships with the image, so a
|
|
452
353
|
// GTFS refresh leaves it alone and a code push purges it. Cloudflare caches it
|
package/mcp/stdio.js
CHANGED
|
@@ -25,7 +25,7 @@ async function main() {
|
|
|
25
25
|
const upstreamCapabilities = upstream.getServerCapabilities() ?? {};
|
|
26
26
|
const server = new Server({
|
|
27
27
|
...upstreamInfo,
|
|
28
|
-
name: upstreamInfo.name ?? "
|
|
28
|
+
name: upstreamInfo.name ?? "io.github.vbhjckfd/timetable-api-node",
|
|
29
29
|
version: pkg.version,
|
|
30
30
|
}, {
|
|
31
31
|
capabilities: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "timetable-api-node",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9",
|
|
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.ts",
|
|
6
6
|
"type": "module",
|