timetable-api-node 1.4.0 → 1.4.1

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.
Files changed (2) hide show
  1. package/index.js +15 -0
  2. package/package.json +2 -2
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.4.0",
3
+ "version": "1.4.1",
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",
@@ -57,6 +57,6 @@
57
57
  "author": "vbhjckfd@gmail.com",
58
58
  "license": "WTFPL",
59
59
  "devDependencies": {
60
- "vitest": "^4.1.5"
60
+ "vitest": "^5.0.0"
61
61
  }
62
62
  }