timetable-api-node 1.8.10 → 1.8.12
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/README.md +3 -3
- package/mcp/stdio.js +48 -29
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ gcloud run services update timetable-api-node --region=europe-north1 --project=t
|
|
|
101
101
|
|
|
102
102
|
## MCP Server
|
|
103
103
|
|
|
104
|
-
This service exposes a public read-only MCP endpoint over Streamable HTTP.
|
|
104
|
+
This service exposes a public read-only MCP endpoint over Streamable HTTP. It speaks MCP revision **2026-07-28** (stateless: `server/discover`, a per-request `_meta` envelope, cacheable list results) and still serves 2025-era clients that open with `initialize` (2025-11-25 back to 2024-11-05).
|
|
105
105
|
|
|
106
106
|
- MCP endpoint: `/mcp`
|
|
107
107
|
- Server card: `/.well-known/mcp/server-card.json`
|
|
@@ -142,7 +142,7 @@ graph LR;
|
|
|
142
142
|
<details>
|
|
143
143
|
<summary><strong>Postman / curl: call a tool on production</strong></summary>
|
|
144
144
|
|
|
145
|
-
`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.
|
|
145
|
+
`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. This is the 2025-era request shape; a 2026-07-28 request also sends `MCP-Protocol-Version: 2026-07-28` and `Mcp-Method` headers, plus `io.modelcontextprotocol/protocolVersion` and `io.modelcontextprotocol/clientCapabilities` in `params._meta`.
|
|
146
146
|
|
|
147
147
|
```bash
|
|
148
148
|
curl -s https://api.lad.lviv.ua/mcp \
|
|
@@ -464,7 +464,7 @@ In addition to tools, the server exposes MCP **resources** for reference data th
|
|
|
464
464
|
| `timetable://stop/{code}` | Static info for a stop by numeric code — name, coordinates, serving routes (JSON) |
|
|
465
465
|
| `timetable://route/{name}` | Static metadata for a route by short name — color, type, stop counts (JSON) |
|
|
466
466
|
|
|
467
|
-
`{name}` in `timetable://route/{name}` supports `completion/complete` ("t3" → "Т30", "a1" → "А01"). Unknown stops or routes fail with JSON-RPC error `-
|
|
467
|
+
`{name}` in `timetable://route/{name}` supports `completion/complete` ("t3" → "Т30", "a1" → "А01"). Unknown stops or routes fail with JSON-RPC error `-32602` and `data.uri` (resource not found, per MCP 2026-07-28).
|
|
468
468
|
|
|
469
469
|
### Security model
|
|
470
470
|
|
package/mcp/stdio.js
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
// to the live Lviv Public Transport MCP server without requiring a local database.
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
import pkg from "../package.json" with { type: "json" };
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ListResourceTemplatesRequestSchema, ReadResourceRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, CompleteRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
7
|
+
import { Server } from "@modelcontextprotocol/server";
|
|
8
|
+
import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
11
9
|
const upstreamUrl = new URL(process.env.MCP_URL || "https://api.lad.lviv.ua/mcp");
|
|
10
|
+
/** Lists only change with an upstream deploy; mirrors the upstream's own hints. */
|
|
11
|
+
const STATIC_CACHE_HINT = { ttlMs: 60 * 60 * 1000, cacheScope: "public" };
|
|
12
12
|
async function main() {
|
|
13
|
-
const upstream = new Client({ name: "lviv-timetable-stdio-proxy", version: pkg.version },
|
|
13
|
+
const upstream = new Client({ name: "lviv-timetable-stdio-proxy", version: pkg.version },
|
|
14
|
+
// Speak 2026-07-28 to the upstream when it offers it, else fall back to 2025.
|
|
15
|
+
{ capabilities: {}, versionNegotiation: { mode: "auto" } });
|
|
14
16
|
await upstream.connect(new StreamableHTTPClientTransport(upstreamUrl));
|
|
15
17
|
const [{ tools }, { resources }, { resourceTemplates }, { prompts }] = await Promise.all([
|
|
16
18
|
upstream.listTools(),
|
|
@@ -23,30 +25,47 @@ async function main() {
|
|
|
23
25
|
// the bare tool list only.
|
|
24
26
|
const upstreamInfo = upstream.getServerVersion() ?? {};
|
|
25
27
|
const upstreamCapabilities = upstream.getServerCapabilities() ?? {};
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
...
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
const instructions = upstream.getInstructions();
|
|
29
|
+
// serveStdio picks the era from the client's opening message (a 2025
|
|
30
|
+
// `initialize` or a 2026-07-28 `server/discover` / enveloped request) and
|
|
31
|
+
// pins one instance from this factory to the connection.
|
|
32
|
+
const createProxyServer = () => {
|
|
33
|
+
const server = new Server({
|
|
34
|
+
...upstreamInfo,
|
|
35
|
+
name: upstreamInfo.name ?? "io.github.vbhjckfd/timetable-api-node",
|
|
36
|
+
version: pkg.version,
|
|
37
|
+
}, {
|
|
38
|
+
capabilities: {
|
|
39
|
+
...(tools.length && { tools: {} }),
|
|
40
|
+
...(resources.length || resourceTemplates.length ? { resources: {} } : {}),
|
|
41
|
+
...(prompts.length && { prompts: {} }),
|
|
42
|
+
...(upstreamCapabilities.completions && { completions: {} }),
|
|
43
|
+
},
|
|
44
|
+
instructions,
|
|
45
|
+
cacheHints: {
|
|
46
|
+
"server/discover": STATIC_CACHE_HINT,
|
|
47
|
+
"tools/list": STATIC_CACHE_HINT,
|
|
48
|
+
"prompts/list": STATIC_CACHE_HINT,
|
|
49
|
+
"resources/list": STATIC_CACHE_HINT,
|
|
50
|
+
"resources/templates/list": STATIC_CACHE_HINT,
|
|
51
|
+
"resources/read": STATIC_CACHE_HINT,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
server.setRequestHandler("tools/list", async () => ({ tools }));
|
|
55
|
+
server.setRequestHandler("resources/list", async () => ({ resources }));
|
|
56
|
+
server.setRequestHandler("resources/templates/list", async () => ({ resourceTemplates }));
|
|
57
|
+
server.setRequestHandler("prompts/list", async () => ({ prompts }));
|
|
58
|
+
server.setRequestHandler("tools/call", async (req) => upstream.callTool(req.params));
|
|
59
|
+
server.setRequestHandler("resources/read", async (req) => upstream.readResource(req.params));
|
|
60
|
+
server.setRequestHandler("prompts/get", async (req) => upstream.getPrompt(req.params));
|
|
61
|
+
if (upstreamCapabilities.completions) {
|
|
62
|
+
server.setRequestHandler("completion/complete", async (req) => upstream.complete(req.params));
|
|
63
|
+
}
|
|
64
|
+
return server;
|
|
65
|
+
};
|
|
66
|
+
serveStdio(createProxyServer, {
|
|
67
|
+
onerror: (error) => process.stderr.write(`Error: ${error.message}\n`),
|
|
38
68
|
});
|
|
39
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
|
|
40
|
-
server.setRequestHandler(ListResourcesRequestSchema, async () => ({ resources }));
|
|
41
|
-
server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({ resourceTemplates }));
|
|
42
|
-
server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts }));
|
|
43
|
-
server.setRequestHandler(CallToolRequestSchema, async (req) => upstream.callTool(req.params));
|
|
44
|
-
server.setRequestHandler(ReadResourceRequestSchema, async (req) => upstream.readResource(req.params));
|
|
45
|
-
server.setRequestHandler(GetPromptRequestSchema, async (req) => upstream.getPrompt(req.params));
|
|
46
|
-
if (upstreamCapabilities.completions) {
|
|
47
|
-
server.setRequestHandler(CompleteRequestSchema, async (req) => upstream.complete(req.params));
|
|
48
|
-
}
|
|
49
|
-
await server.connect(new StdioServerTransport());
|
|
50
69
|
}
|
|
51
70
|
main().catch((err) => {
|
|
52
71
|
process.stderr.write(`Error: ${err.message}\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "timetable-api-node",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.12",
|
|
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",
|
|
@@ -32,7 +32,9 @@
|
|
|
32
32
|
"api"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@modelcontextprotocol/
|
|
35
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
36
|
+
"@modelcontextprotocol/node": "^2.1.2",
|
|
37
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
36
38
|
"cors": "^2.8.5",
|
|
37
39
|
"dotenv": "^18.0",
|
|
38
40
|
"express": "^5.2.1",
|