timetable-api-node 1.1.2
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 +182 -0
- package/LICENSE +14 -0
- package/README.md +447 -0
- package/index.js +294 -0
- package/mcp/config.json +7 -0
- package/mcp/stdio.js +68 -0
- package/package.json +58 -0
package/INTEGRATION.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Integration Guide
|
|
2
|
+
|
|
3
|
+
Lviv Public Transport API — integration recipes for common AI agent frameworks.
|
|
4
|
+
|
|
5
|
+
Base URL: `https://api.lad.lviv.ua`
|
|
6
|
+
MCP endpoint: `https://api.lad.lviv.ua/mcp`
|
|
7
|
+
OpenAPI spec: `https://api.lad.lviv.ua/openapi.yaml`
|
|
8
|
+
No API key or authentication required.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## MCP (Model Context Protocol)
|
|
13
|
+
|
|
14
|
+
### Claude Desktop / Claude Code
|
|
15
|
+
|
|
16
|
+
Add to `~/.claude/claude_desktop_config.json` (or `claude.ai/code` MCP settings):
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"mcpServers": {
|
|
21
|
+
"lviv-timetable": {
|
|
22
|
+
"url": "https://api.lad.lviv.ua/mcp"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Cursor / Windsurf / any stdio MCP client
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx timetable-api-node
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or pin the config:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"mcpServers": {
|
|
39
|
+
"lviv-timetable": {
|
|
40
|
+
"command": "npx",
|
|
41
|
+
"args": ["-y", "timetable-api-node"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The `npx` entry is a zero-dependency stdio proxy — it forwards requests to the live API with no local setup.
|
|
48
|
+
|
|
49
|
+
### MCP Inspector (testing)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx @modelcontextprotocol/inspector \
|
|
53
|
+
--transport streamable-http \
|
|
54
|
+
--url https://api.lad.lviv.ua/mcp
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## LangChain (Python)
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from langchain_community.agent_toolkits.openapi.toolkit import RequestsToolkit
|
|
63
|
+
from langchain_community.utilities.requests import TextRequestsWrapper
|
|
64
|
+
from langchain_community.tools.json.tool import JsonSpec
|
|
65
|
+
import httpx, yaml
|
|
66
|
+
|
|
67
|
+
# Load spec
|
|
68
|
+
spec_text = httpx.get("https://api.lad.lviv.ua/openapi.yaml").text
|
|
69
|
+
spec = JsonSpec(dict_=yaml.safe_load(spec_text), max_value_length=4000)
|
|
70
|
+
|
|
71
|
+
toolkit = RequestsToolkit(
|
|
72
|
+
requests_wrapper=TextRequestsWrapper(headers={}),
|
|
73
|
+
allow_dangerous_requests=True,
|
|
74
|
+
)
|
|
75
|
+
tools = toolkit.get_tools()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Or use the `NLAToolkit` for natural-language-first access:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from langchain_community.agent_toolkits.openapi.toolkit import OpenAPIToolkit
|
|
82
|
+
from langchain_community.utilities.requests import TextRequestsWrapper
|
|
83
|
+
from langchain.agents import AgentType, initialize_agent
|
|
84
|
+
|
|
85
|
+
toolkit = OpenAPIToolkit.from_llm(
|
|
86
|
+
llm=your_llm,
|
|
87
|
+
json_spec=spec,
|
|
88
|
+
requests_wrapper=TextRequestsWrapper(headers={}),
|
|
89
|
+
allow_dangerous_requests=True,
|
|
90
|
+
)
|
|
91
|
+
agent = initialize_agent(
|
|
92
|
+
toolkit.get_tools(),
|
|
93
|
+
your_llm,
|
|
94
|
+
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
|
|
95
|
+
verbose=True,
|
|
96
|
+
)
|
|
97
|
+
agent.run("What buses are arriving at stop 707 in Lviv?")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### LangChain (JS/TS)
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { OpenApiToolkit } from "langchain/agents/toolkits";
|
|
104
|
+
import { ChatOpenAI } from "@langchain/openai"; // or any LLM
|
|
105
|
+
|
|
106
|
+
const toolkit = await OpenApiToolkit.fromLLM(yourLLM, {
|
|
107
|
+
openApiSpecUrl: "https://api.lad.lviv.ua/openapi.yaml",
|
|
108
|
+
});
|
|
109
|
+
const tools = toolkit.getTools();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## LlamaIndex (Python)
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from llama_index.tools.openapi import OpenAPIToolSpec
|
|
118
|
+
from llama_index.agent.openai import OpenAIAgent
|
|
119
|
+
|
|
120
|
+
tool_spec = OpenAPIToolSpec(url="https://api.lad.lviv.ua/openapi.yaml")
|
|
121
|
+
tools = tool_spec.to_tool_list()
|
|
122
|
+
|
|
123
|
+
agent = OpenAIAgent.from_tools(tools, verbose=True)
|
|
124
|
+
agent.chat("Find stops near latitude 49.84, longitude 24.03")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## OpenAI GPT Actions / Assistants API
|
|
130
|
+
|
|
131
|
+
1. Create a new GPT (or Assistant).
|
|
132
|
+
2. Under **Actions**, click **Import from URL** and paste:
|
|
133
|
+
`https://api.lad.lviv.ua/openapi.yaml`
|
|
134
|
+
3. Set authentication to **None**.
|
|
135
|
+
4. Save and test with: "What trams are running on route T30 right now?"
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Vercel AI SDK (JS/TS)
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { openapi } from "@ai-sdk/openapi";
|
|
143
|
+
import { generateText } from "ai";
|
|
144
|
+
|
|
145
|
+
const tools = await openapi("https://api.lad.lviv.ua/openapi.yaml");
|
|
146
|
+
|
|
147
|
+
const { text } = await generateText({
|
|
148
|
+
model: yourModel,
|
|
149
|
+
tools,
|
|
150
|
+
prompt: "When is the next bus at stop 707?",
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## n8n
|
|
157
|
+
|
|
158
|
+
1. Add an **HTTP Request** node.
|
|
159
|
+
2. Set method to `GET`, URL to `https://api.lad.lviv.ua/stops/707/timetable`.
|
|
160
|
+
3. Connect to an **AI Agent** node (Tools Agent) and pass the response to your LLM.
|
|
161
|
+
|
|
162
|
+
Or use the built-in **OpenAPI** credential type with spec URL `https://api.lad.lviv.ua/openapi.yaml`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Direct REST (fetch / curl)
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Live arrivals at stop 707
|
|
170
|
+
curl https://api.lad.lviv.ua/stops/707/timetable
|
|
171
|
+
|
|
172
|
+
# Stops within 300m of a coordinate
|
|
173
|
+
curl "https://api.lad.lviv.ua/closest?latitude=49.8397&longitude=24.0297&radius=300"
|
|
174
|
+
|
|
175
|
+
# Live vehicles on route T30
|
|
176
|
+
curl https://api.lad.lviv.ua/routes/dynamic/T30
|
|
177
|
+
|
|
178
|
+
# Route static data (stops + polylines)
|
|
179
|
+
curl https://api.lad.lviv.ua/routes/static/32A
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Full endpoint reference: [`/openapi.yaml`](https://api.lad.lviv.ua/openapi.yaml) or [`/llms.txt`](https://api.lad.lviv.ua/llms.txt).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
2
|
+
Version 2, December 2004
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
|
5
|
+
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
|
7
|
+
copies of this license document, and changing it is allowed as long
|
|
8
|
+
as the name is changed.
|
|
9
|
+
|
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
11
|
+
|
|
12
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
13
|
+
|
|
14
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
package/README.md
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
# Timetable API Node
|
|
2
|
+
|
|
3
|
+
[](https://github.com/vbhjckfd/timetable-api-node/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/vbhjckfd/timetable-api-node/blob/master/.nvmrc)
|
|
5
|
+
[](https://github.com/vbhjckfd/timetable-api-node/blob/master/LICENSE)
|
|
6
|
+
[](https://registry.modelcontextprotocol.io/v0/servers/io.github.vbhjckfd%2Ftimetable-api-node/versions)
|
|
7
|
+
|
|
8
|
+
Express-based API for Lviv transport timetable data with a read-only MCP endpoint.
|
|
9
|
+
|
|
10
|
+
[](https://smithery.ai/servers/vbhjckfd/lad-lviv-ua)
|
|
11
|
+
[](https://glama.ai/mcp/servers/vbhjckfd/timetable-api-node)
|
|
12
|
+
|
|
13
|
+
[](https://glama.ai/mcp/servers/vbhjckfd/timetable-api-node)
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Node.js 24 (see `.nvmrc`)
|
|
18
|
+
|
|
19
|
+
## Run locally
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
nvm use
|
|
23
|
+
make start
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Test
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
nvm use && make test
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## MCP Server
|
|
33
|
+
|
|
34
|
+
This service exposes a public read-only MCP endpoint over Streamable HTTP.
|
|
35
|
+
|
|
36
|
+
- MCP endpoint: `/mcp`
|
|
37
|
+
- Server card: `/.well-known/mcp/server-card.json`
|
|
38
|
+
- Discovery hint: `/robots.txt` (non-standard comment hint)
|
|
39
|
+
|
|
40
|
+
Production deployment (see `cloudbuild.yaml` for Cloud Run) serves **REST and MCP** from **[api.lad.lviv.ua](https://api.lad.lviv.ua)**. The main site **[lad.lviv.ua](https://lad.lviv.ua)** is the public transport website (this repo still links there in HTML sitemap and tables for people, not for the API host). Use your own origin when running locally.
|
|
41
|
+
|
|
42
|
+
### LLM and `/mcp` flow
|
|
43
|
+
|
|
44
|
+
An MCP client (Claude, Cursor, or the MCP SDK) talks JSON-RPC over **Streamable HTTP** to `POST /mcp`. Tool handlers reuse the same Express actions as the REST API, backed by **LokiJS** timetable data, **GTFS** SQLite (via `gtfs`), and **live GTFS-RT** feeds (for example `track.ua-gis.com`).
|
|
45
|
+
|
|
46
|
+
```mermaid
|
|
47
|
+
graph LR;
|
|
48
|
+
Client[LLM or MCP client] -->|JSON-RPC Streamable HTTP| Mcp["POST /mcp"];
|
|
49
|
+
Mcp --> Tools[Tool handlers];
|
|
50
|
+
Tools --> Actions[Express actions];
|
|
51
|
+
Actions --> Loki[(LokiJS)];
|
|
52
|
+
Actions --> Gtfs[(GTFS SQLite)];
|
|
53
|
+
Actions --> Rt[GTFS-RT upstream];
|
|
54
|
+
Loki --> Actions;
|
|
55
|
+
Gtfs --> Actions;
|
|
56
|
+
Rt --> Actions;
|
|
57
|
+
Actions --> Tools;
|
|
58
|
+
Tools --> Mcp;
|
|
59
|
+
Mcp -->|MCP tool result| Client;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Try the live API
|
|
63
|
+
|
|
64
|
+
[](https://api.lad.lviv.ua/.well-known/mcp/server-card.json)
|
|
65
|
+
[](https://api.lad.lviv.ua/stops.json)
|
|
66
|
+
[](https://api.lad.lviv.ua/routes.json)
|
|
67
|
+
|
|
68
|
+
**MCP Inspector (local):** run `npx @modelcontextprotocol/inspector`, then open the UI with transport and server URL prefilled (from the [inspector README](https://github.com/modelcontextprotocol/inspector/blob/main/README.md)):
|
|
69
|
+
|
|
70
|
+
`http://localhost:6274/?transport=streamable-http&serverUrl=https%3A%2F%2Fapi.lad.lviv.ua%2Fmcp`
|
|
71
|
+
|
|
72
|
+
<details>
|
|
73
|
+
<summary><strong>Postman / curl: call a tool on production</strong></summary>
|
|
74
|
+
|
|
75
|
+
`POST https://api.lad.lviv.ua/mcp` with `Content-Type: application/json`. The Streamable HTTP transport may require additional headers your MCP client sets automatically; for a quick manual test, follow the same sequence your MCP SDK uses (session `initialize`, then `tools/call`). Example **`tools/call`** body shape:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"jsonrpc": "2.0",
|
|
80
|
+
"id": 1,
|
|
81
|
+
"method": "tools/call",
|
|
82
|
+
"params": {
|
|
83
|
+
"name": "get_stop_realtime",
|
|
84
|
+
"arguments": { "stop_id": 101 }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Successful tool responses return **stringified JSON** inside MCP `content` items (`type: "text"`), and each payload follows a strict UI contract:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"view": "transit_realtime",
|
|
94
|
+
"data": { "...": "tool-specific source data" },
|
|
95
|
+
"ui_blocks": [
|
|
96
|
+
{ "type": "map", "data": { "...": "map renderer input" } },
|
|
97
|
+
{ "type": "arrival_list", "data": { "...": "arrival list renderer input" } }
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Consistency rule: each vehicle rendered on map must either have a matching ETA in list data or `eta_status: "unassigned"`.
|
|
103
|
+
|
|
104
|
+
</details>
|
|
105
|
+
|
|
106
|
+
### Exposed tools
|
|
107
|
+
|
|
108
|
+
- `get_stop_realtime`
|
|
109
|
+
- `get_route_static`
|
|
110
|
+
- `get_route_realtime`
|
|
111
|
+
- `get_stop_geometry`
|
|
112
|
+
- `get_stops_around_location`
|
|
113
|
+
|
|
114
|
+
<details>
|
|
115
|
+
<summary><code>get_stop_realtime</code> — input & example</summary>
|
|
116
|
+
|
|
117
|
+
**Arguments (JSON):**
|
|
118
|
+
|
|
119
|
+
| Field | Type | Required |
|
|
120
|
+
|-------|------|----------|
|
|
121
|
+
| `stop_id` | positive integer or digits-only string | yes |
|
|
122
|
+
|
|
123
|
+
**Example result** (shape only; values from upstream):
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"view": "transit_realtime",
|
|
128
|
+
"data": {
|
|
129
|
+
"stop": { "id": "707", "name": "Стадіон Сільмаш", "lat": 49.84, "lng": 24.03 },
|
|
130
|
+
"arrivals": [
|
|
131
|
+
{
|
|
132
|
+
"route": "T30",
|
|
133
|
+
"direction": "Рясівська",
|
|
134
|
+
"vehicle_type": "tram",
|
|
135
|
+
"arrival_minutes": 4,
|
|
136
|
+
"vehicle_id": "tram_123",
|
|
137
|
+
"lat": 49.83,
|
|
138
|
+
"lng": 24.02,
|
|
139
|
+
"bearing": 120
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"updated_at": "2026-01-23T12:00:00Z"
|
|
143
|
+
},
|
|
144
|
+
"ui_blocks": [
|
|
145
|
+
{
|
|
146
|
+
"type": "map",
|
|
147
|
+
"data": { "center": [49.84, 24.03], "vehicles": [] }
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"type": "arrival_list",
|
|
151
|
+
"data": { "arrivals": [] }
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
</details>
|
|
158
|
+
|
|
159
|
+
<details>
|
|
160
|
+
<summary><code>get_route_static</code> — input & example</summary>
|
|
161
|
+
|
|
162
|
+
**Arguments (JSON):**
|
|
163
|
+
|
|
164
|
+
| Field | Type | Required |
|
|
165
|
+
|-------|------|----------|
|
|
166
|
+
| `route_name` | route short name (e.g. `"T30"`, `"32A"`) or numeric external ID | yes |
|
|
167
|
+
|
|
168
|
+
**Example result** (shape only; stops truncated for brevity):
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"view": "transit_realtime",
|
|
173
|
+
"data": {
|
|
174
|
+
"route": {
|
|
175
|
+
"name": "T30",
|
|
176
|
+
"long_name": "Рясне-2 — Сихів",
|
|
177
|
+
"color": "#e81717",
|
|
178
|
+
"type": "tram"
|
|
179
|
+
},
|
|
180
|
+
"stops": [
|
|
181
|
+
[
|
|
182
|
+
{ "id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003, "departures": ["05:30", "05:52"] },
|
|
183
|
+
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": [] }
|
|
184
|
+
],
|
|
185
|
+
[
|
|
186
|
+
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021, "departures": [] },
|
|
187
|
+
{ "id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003, "departures": [] }
|
|
188
|
+
]
|
|
189
|
+
],
|
|
190
|
+
"shapes": [
|
|
191
|
+
[[49.841, 24.003], [49.839, 24.012], [49.838, 24.021]],
|
|
192
|
+
[[49.838, 24.021], [49.839, 24.012], [49.841, 24.003]]
|
|
193
|
+
],
|
|
194
|
+
"updated_at": "2026-01-23T12:00:00Z"
|
|
195
|
+
},
|
|
196
|
+
"ui_blocks": [
|
|
197
|
+
{
|
|
198
|
+
"type": "map",
|
|
199
|
+
"data": {
|
|
200
|
+
"center": [49.841, 24.003],
|
|
201
|
+
"zoom": 13,
|
|
202
|
+
"polylines": [[[49.841, 24.003], [49.839, 24.012], [49.838, 24.021]]],
|
|
203
|
+
"stops": [
|
|
204
|
+
{ "id": "101", "name": "Головний вокзал", "lat": 49.841, "lng": 24.003 },
|
|
205
|
+
{ "id": "707", "name": "Стадіон Сільмаш", "lat": 49.838, "lng": 24.021 }
|
|
206
|
+
],
|
|
207
|
+
"vehicles": []
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`stops[0]` is direction 0 (outbound), `stops[1]` is direction 1 (return). `departures` is populated only for direction 0. `shapes` follows the same two-element order. The map block uses direction-0 polyline and all unique stops as markers.
|
|
215
|
+
|
|
216
|
+
</details>
|
|
217
|
+
|
|
218
|
+
<details>
|
|
219
|
+
<summary><code>get_route_realtime</code> — input & example</summary>
|
|
220
|
+
|
|
221
|
+
**Arguments (JSON):**
|
|
222
|
+
|
|
223
|
+
| Field | Type | Required |
|
|
224
|
+
|-------|------|----------|
|
|
225
|
+
| `route_name` | route short name (e.g. `"T30"`, `"32A"`) or numeric external ID | yes |
|
|
226
|
+
|
|
227
|
+
**Example result:**
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"view": "transit_realtime",
|
|
232
|
+
"data": {
|
|
233
|
+
"route_name": "T30",
|
|
234
|
+
"vehicles": [
|
|
235
|
+
{
|
|
236
|
+
"id": "tram_123",
|
|
237
|
+
"direction": 0,
|
|
238
|
+
"lat": 49.838,
|
|
239
|
+
"lng": 24.021,
|
|
240
|
+
"bearing": 120,
|
|
241
|
+
"lowfloor": true
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
"updated_at": "2026-01-23T12:00:00Z"
|
|
245
|
+
},
|
|
246
|
+
"ui_blocks": [
|
|
247
|
+
{
|
|
248
|
+
"type": "map",
|
|
249
|
+
"data": {
|
|
250
|
+
"center": [49.838, 24.021],
|
|
251
|
+
"zoom": 13,
|
|
252
|
+
"vehicles": [
|
|
253
|
+
{
|
|
254
|
+
"id": "tram_123",
|
|
255
|
+
"direction": 0,
|
|
256
|
+
"lat": 49.838,
|
|
257
|
+
"lng": 24.021,
|
|
258
|
+
"bearing": 120,
|
|
259
|
+
"lowfloor": true
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`direction` matches the index into `get_route_static`'s `stops` array (0 = outbound, 1 = return). `lowfloor: true` indicates a low-floor vehicle. Returns an empty `vehicles` array when no vehicles are currently active on the route.
|
|
269
|
+
|
|
270
|
+
</details>
|
|
271
|
+
|
|
272
|
+
<details>
|
|
273
|
+
<summary><code>get_stop_geometry</code> — input & example</summary>
|
|
274
|
+
|
|
275
|
+
**Arguments:**
|
|
276
|
+
|
|
277
|
+
| Field | Type | Required |
|
|
278
|
+
|-------|------|----------|
|
|
279
|
+
| `stop_id` | positive integer or digits-only string | yes |
|
|
280
|
+
|
|
281
|
+
**Example result:**
|
|
282
|
+
|
|
283
|
+
```json
|
|
284
|
+
{
|
|
285
|
+
"view": "transit_realtime",
|
|
286
|
+
"data": {
|
|
287
|
+
"stop": { "id": "707", "name": "Стадіон Сільмаш", "lat": 49.84, "lng": 24.03 },
|
|
288
|
+
"routes": [
|
|
289
|
+
{
|
|
290
|
+
"route": "T30",
|
|
291
|
+
"polyline": [[49.84, 24.03], [49.83, 24.02]]
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
},
|
|
295
|
+
"ui_blocks": [{ "type": "map", "data": { "routes": [] } }]
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
</details>
|
|
300
|
+
|
|
301
|
+
<details>
|
|
302
|
+
<summary><code>get_stops_around_location</code> — input & example</summary>
|
|
303
|
+
|
|
304
|
+
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).
|
|
305
|
+
|
|
306
|
+
**Arguments (JSON):**
|
|
307
|
+
|
|
308
|
+
| Field | Type | Required |
|
|
309
|
+
|-------|------|----------|
|
|
310
|
+
| `latitude` | number, −90…90 | yes |
|
|
311
|
+
| `longitude` | number, −180…180 | yes |
|
|
312
|
+
| `radius_meters` | integer, 50…3000 | no (default **1000**) |
|
|
313
|
+
|
|
314
|
+
**Example result** (shape only):
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{
|
|
318
|
+
"view": "transit_realtime",
|
|
319
|
+
"data": {
|
|
320
|
+
"center_lat": 49.84,
|
|
321
|
+
"center_lng": 24.03,
|
|
322
|
+
"radius_meters": 1000,
|
|
323
|
+
"stops": [
|
|
324
|
+
{
|
|
325
|
+
"id": "707",
|
|
326
|
+
"name": "Стадіон Сільмаш",
|
|
327
|
+
"lat": 49.841,
|
|
328
|
+
"lng": 24.031,
|
|
329
|
+
"distance_meters": 120
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
"updated_at": "2026-01-23T12:00:00Z"
|
|
333
|
+
},
|
|
334
|
+
"ui_blocks": [
|
|
335
|
+
{
|
|
336
|
+
"type": "map",
|
|
337
|
+
"data": {
|
|
338
|
+
"center": [49.84, 24.03],
|
|
339
|
+
"zoom": 15,
|
|
340
|
+
"stops": [
|
|
341
|
+
{
|
|
342
|
+
"id": "707",
|
|
343
|
+
"name": "Стадіон Сільмаш",
|
|
344
|
+
"lat": 49.841,
|
|
345
|
+
"lng": 24.031,
|
|
346
|
+
"distance_meters": 120
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
"vehicles": []
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Map zoom is **15** for radius ≤ 1500 m and **14** for larger radii (up to 3000 m).
|
|
357
|
+
|
|
358
|
+
</details>
|
|
359
|
+
|
|
360
|
+
### Security model
|
|
361
|
+
|
|
362
|
+
- Public read-only (no authentication).
|
|
363
|
+
- No mutating tools are exposed.
|
|
364
|
+
- `robots.txt` is only a best-effort discovery hint and not a protocol contract.
|
|
365
|
+
|
|
366
|
+
## REST API
|
|
367
|
+
|
|
368
|
+
All endpoints return JSON. `:code` is a numeric stop code; `:name` is a route short name (e.g. `T1`, `32A`) or numeric external ID.
|
|
369
|
+
|
|
370
|
+
### Stops
|
|
371
|
+
|
|
372
|
+
#### `GET /stops.json`
|
|
373
|
+
|
|
374
|
+
All stops as a JSON array, sorted by code.
|
|
375
|
+
|
|
376
|
+
- **Response:** array of `{ code, name, eng_name, location: [lat, lng], routes, sign, sign_pdf }`.
|
|
377
|
+
|
|
378
|
+
(`GET /stops` returns an HTML table instead.)
|
|
379
|
+
|
|
380
|
+
#### `GET /stops/:code`
|
|
381
|
+
|
|
382
|
+
Single stop with live realtime timetable. Short-cached (5–10 s).
|
|
383
|
+
|
|
384
|
+
- **Optional:** `skipTimetableData=1` — omit live arrivals (long-cached response).
|
|
385
|
+
- **Response:** `{ code, name, eng_name, latitude, longitude, transfers, timetable }`.
|
|
386
|
+
|
|
387
|
+
#### `GET /stops/:code/timetable`
|
|
388
|
+
|
|
389
|
+
Live timetable only for a stop. Short-cached (5–10 s).
|
|
390
|
+
|
|
391
|
+
- **Response:** array of timetable items.
|
|
392
|
+
|
|
393
|
+
#### `GET /stops/:code/static`
|
|
394
|
+
|
|
395
|
+
Static stop info without live data. Long-cached (30 days).
|
|
396
|
+
|
|
397
|
+
- **Response:** `{ code, name, eng_name, latitude, longitude, transfers }`.
|
|
398
|
+
|
|
399
|
+
#### `GET /closest?latitude={lat}&longitude={lng}`
|
|
400
|
+
|
|
401
|
+
Nearby stops — same search as `get_stops_around_location`, for non-MCP clients.
|
|
402
|
+
|
|
403
|
+
- **Optional:** `radius` — meters, clamped between **50** and **3000** (default **1000**).
|
|
404
|
+
- **Response:** JSON array of `{ code, name, latitude, longitude, distance_meters }` (sorted by distance).
|
|
405
|
+
|
|
406
|
+
### Routes
|
|
407
|
+
|
|
408
|
+
#### `GET /routes.json`
|
|
409
|
+
|
|
410
|
+
All routes as a JSON array, sorted by short name.
|
|
411
|
+
|
|
412
|
+
- **Response:** raw route objects from the timetable store.
|
|
413
|
+
|
|
414
|
+
(`GET /routes` returns an HTML table.)
|
|
415
|
+
|
|
416
|
+
#### `GET /routes/static/:name`
|
|
417
|
+
|
|
418
|
+
Route shape, stop list, and metadata. Long-cached (30 days).
|
|
419
|
+
|
|
420
|
+
- **Response:** `{ id, color, type, route_short_name, route_long_name, stops: [[dir0…], [dir1…]], shapes }`.
|
|
421
|
+
|
|
422
|
+
#### `GET /routes/dynamic/:name`
|
|
423
|
+
|
|
424
|
+
Live vehicle positions for a route. Short-cached (10 s).
|
|
425
|
+
|
|
426
|
+
- **Response:** array of `{ id, direction, location: [lat, lng], bearing, lowfloor }`.
|
|
427
|
+
|
|
428
|
+
### Vehicles
|
|
429
|
+
|
|
430
|
+
#### `GET /vehicle/:vehicleId`
|
|
431
|
+
|
|
432
|
+
Live position and upcoming stop arrivals for one vehicle. Short-cached (5 s).
|
|
433
|
+
|
|
434
|
+
- **Response:** `{ location: [lat, lng], routeId, bearing, direction, licensePlate, arrivals }`.
|
|
435
|
+
|
|
436
|
+
#### `GET /vehicle-by-plate/:plate`
|
|
437
|
+
|
|
438
|
+
Look up a vehicle ID by its license plate. Short-cached (5 s).
|
|
439
|
+
|
|
440
|
+
- The plate is matched case-insensitively with spaces and dashes ignored (`BC-1234-AA`, `bc 1234 aa`, and `bc1234aa` are all equivalent).
|
|
441
|
+
- **Response:** `{ vehicleId }` — use the returned ID with `GET /vehicle/:vehicleId`.
|
|
442
|
+
|
|
443
|
+
#### `GET /transport?latitude={lat}&longitude={lng}`
|
|
444
|
+
|
|
445
|
+
Vehicles within 1 km of a point. Short-cached (10 s).
|
|
446
|
+
|
|
447
|
+
- **Response:** array of `{ id, route, vehicle_type, color, location: [lat, lng], bearing, lowfloor }`.
|
package/index.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import "./instrument.js";
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
|
|
4
|
+
import * as Sentry from "@sentry/node";
|
|
5
|
+
import path from "path";
|
|
6
|
+
const __dirname = import.meta.dirname;
|
|
7
|
+
const PORT = process.env.PORT || 8080;
|
|
8
|
+
|
|
9
|
+
import { openDb } from "gtfs";
|
|
10
|
+
import { readFile } from "fs/promises";
|
|
11
|
+
import cors from "cors";
|
|
12
|
+
import express from "express";
|
|
13
|
+
import bodyParser from "body-parser";
|
|
14
|
+
import localDb from "./connections/timetableSqliteDb.js";
|
|
15
|
+
|
|
16
|
+
import notFoundAction from "./actions/notFoundAction.js";
|
|
17
|
+
import validateStopCode from "./utils/stopCodeMiddleware.js";
|
|
18
|
+
|
|
19
|
+
import getClosestStopsAction from "./actions/getClosestStopsAction.js";
|
|
20
|
+
import getSingleStopAction from "./actions/getSingleStopAction.js";
|
|
21
|
+
import getStopTimetableAction from "./actions/getStopTimetableAction.js";
|
|
22
|
+
import getStopStaticDataAction from "./actions/getStopStaticDataAction.js";
|
|
23
|
+
import getAllStopsAction from "./actions/getAllStopsAction.js";
|
|
24
|
+
import routeInfoDynamicAction from "./actions/routeDynamicInfoAction.js";
|
|
25
|
+
import routeInfoStaticAction from "./actions/routeStaticInfoAction.js";
|
|
26
|
+
import vehicleInfoAction from "./actions/vehicleInfoAction.js";
|
|
27
|
+
import vehicleByPlateAction from "./actions/vehicleByPlateAction.js";
|
|
28
|
+
import closestTransportAction from "./actions/closestTransportAction.js";
|
|
29
|
+
import getAllRoutesAction from "./actions/getAllRoutesAction.js";
|
|
30
|
+
import sitemapAction from "./actions/sitemapAction.js";
|
|
31
|
+
import {
|
|
32
|
+
buildMcpServerCard,
|
|
33
|
+
handleMcpPostRequest,
|
|
34
|
+
} from "./mcp/timetableMcpServer.js";
|
|
35
|
+
|
|
36
|
+
const app = express();
|
|
37
|
+
|
|
38
|
+
app.use(cors());
|
|
39
|
+
|
|
40
|
+
app.use((req, res, next) => {
|
|
41
|
+
const baseUrl = `https://${req.get("host")}`;
|
|
42
|
+
res.set("Link", '</openapi.yaml>; rel="describedby"');
|
|
43
|
+
res.set("X-MCP-Server", `${baseUrl}/.well-known/mcp/server-card.json`);
|
|
44
|
+
next();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
app.use(bodyParser.json({ limit: "100kb" }));
|
|
48
|
+
|
|
49
|
+
app.get("/stops/:code/timetable", validateStopCode, getStopTimetableAction);
|
|
50
|
+
app.get("/stops/:code/static", validateStopCode, getStopStaticDataAction);
|
|
51
|
+
app.get("/stops/:code", validateStopCode, getSingleStopAction);
|
|
52
|
+
app.get("/stops.json", getAllStopsAction);
|
|
53
|
+
app.get("/stops", getAllStopsAction);
|
|
54
|
+
app.get("/closest", getClosestStopsAction);
|
|
55
|
+
|
|
56
|
+
app.get("/routes.json", getAllRoutesAction);
|
|
57
|
+
app.get("/routes", getAllRoutesAction);
|
|
58
|
+
app.get("/routes/dynamic/:name", routeInfoDynamicAction);
|
|
59
|
+
app.get("/routes/static/:name", routeInfoStaticAction);
|
|
60
|
+
app.get("/vehicle/:vehicleId", vehicleInfoAction);
|
|
61
|
+
app.get("/vehicle-by-plate/:plate", vehicleByPlateAction);
|
|
62
|
+
app.get("/transport", closestTransportAction);
|
|
63
|
+
|
|
64
|
+
app.get("/sitemap.xml", sitemapAction);
|
|
65
|
+
|
|
66
|
+
app.get("/openapi.yaml", (req, res) => {
|
|
67
|
+
res.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24}`);
|
|
68
|
+
res.type("application/yaml");
|
|
69
|
+
res.sendFile(path.join(__dirname, "openapi.yaml"));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
app.get("/.well-known/openapi.yaml", (req, res) => {
|
|
73
|
+
res.redirect(301, "/openapi.yaml");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
app.get("/.well-known/ai-plugin.json", (req, res) => {
|
|
77
|
+
const baseUrl = `https://${req.get("host")}`;
|
|
78
|
+
res.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24}`);
|
|
79
|
+
res.json({
|
|
80
|
+
schema_version: "v1",
|
|
81
|
+
name_for_human: "Lviv Public Transport",
|
|
82
|
+
name_for_model: "lviv_timetable",
|
|
83
|
+
description_for_human:
|
|
84
|
+
"Real-time and static public transport data for Lviv, Ukraine — stops, routes, timetables, live vehicle positions. No API key required.",
|
|
85
|
+
description_for_model:
|
|
86
|
+
"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).",
|
|
87
|
+
auth: { type: "none" },
|
|
88
|
+
api: {
|
|
89
|
+
type: "openapi",
|
|
90
|
+
url: `${baseUrl}/openapi.yaml`,
|
|
91
|
+
},
|
|
92
|
+
logo_url: `${baseUrl}/favicon.png`,
|
|
93
|
+
contact_email: "vbhjckfd@gmail.com",
|
|
94
|
+
legal_info_url: "https://lad.lviv.ua",
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
app.get("/.well-known/agent.json", (req, res) => {
|
|
99
|
+
const baseUrl = `https://${req.get("host")}`;
|
|
100
|
+
res.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24}`);
|
|
101
|
+
res.json({
|
|
102
|
+
name: "Lviv Public Transport",
|
|
103
|
+
description:
|
|
104
|
+
"Real-time and static public transport data for Lviv, Ukraine: stops, routes, timetables, and live vehicle positions. No API key required.",
|
|
105
|
+
url: baseUrl,
|
|
106
|
+
version: "1.1.0",
|
|
107
|
+
iconUrl: `${baseUrl}/favicon.png`,
|
|
108
|
+
documentationUrl: `${baseUrl}/llms.txt`,
|
|
109
|
+
capabilities: {
|
|
110
|
+
streaming: false,
|
|
111
|
+
pushNotifications: false,
|
|
112
|
+
stateTransitionHistory: false,
|
|
113
|
+
},
|
|
114
|
+
defaultInputModes: ["text/plain", "application/json"],
|
|
115
|
+
defaultOutputModes: ["application/json"],
|
|
116
|
+
skills: [
|
|
117
|
+
{
|
|
118
|
+
id: "get_stop_realtime",
|
|
119
|
+
name: "Get Stop Realtime",
|
|
120
|
+
description:
|
|
121
|
+
"Live arrivals and vehicle positions at a stop by numeric stop code (e.g. 707).",
|
|
122
|
+
tags: ["transit", "realtime", "arrivals", "lviv"],
|
|
123
|
+
inputModes: ["text/plain"],
|
|
124
|
+
outputModes: ["application/json"],
|
|
125
|
+
examples: ["What buses are arriving at stop 707?", "Live arrivals for stop 1234"],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "get_route_static",
|
|
129
|
+
name: "Get Route Static",
|
|
130
|
+
description:
|
|
131
|
+
"Route metadata, stop lists, departure times, and polylines for both directions.",
|
|
132
|
+
tags: ["transit", "route", "timetable", "lviv"],
|
|
133
|
+
inputModes: ["text/plain"],
|
|
134
|
+
outputModes: ["application/json"],
|
|
135
|
+
examples: ["Show me route T30 stops", "Route 32A schedule"],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "get_route_realtime",
|
|
139
|
+
name: "Get Route Realtime",
|
|
140
|
+
description: "Live vehicle positions for all vehicles currently running on a route.",
|
|
141
|
+
tags: ["transit", "realtime", "vehicles", "lviv"],
|
|
142
|
+
inputModes: ["text/plain"],
|
|
143
|
+
outputModes: ["application/json"],
|
|
144
|
+
examples: ["Where are all tram 6 vehicles right now?"],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "get_stops_around_location",
|
|
148
|
+
name: "Get Stops Around Location",
|
|
149
|
+
description: "Discover transit stops near a given latitude/longitude within a radius.",
|
|
150
|
+
tags: ["transit", "location", "stops", "lviv"],
|
|
151
|
+
inputModes: ["text/plain", "application/json"],
|
|
152
|
+
outputModes: ["application/json"],
|
|
153
|
+
examples: ["Find stops near 49.84, 24.03", "Stops within 300m of my location"],
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "get_stop_geometry",
|
|
157
|
+
name: "Get Stop Geometry",
|
|
158
|
+
description:
|
|
159
|
+
"Static map context for a stop: stop marker and route polylines for all serving routes.",
|
|
160
|
+
tags: ["transit", "geometry", "map", "lviv"],
|
|
161
|
+
inputModes: ["text/plain"],
|
|
162
|
+
outputModes: ["application/json"],
|
|
163
|
+
examples: ["Get map data for stop 707"],
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
authentication: { schemes: [] },
|
|
167
|
+
provider: {
|
|
168
|
+
organization: "lad.lviv.ua",
|
|
169
|
+
url: "https://lad.lviv.ua",
|
|
170
|
+
},
|
|
171
|
+
mcpEndpoint: `${baseUrl}/mcp`,
|
|
172
|
+
mcpServerCard: `${baseUrl}/.well-known/mcp/server-card.json`,
|
|
173
|
+
openApiUrl: `${baseUrl}/openapi.yaml`,
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
app.get("/llms.txt", (req, res) => {
|
|
178
|
+
res.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24}`);
|
|
179
|
+
res.type("text/plain");
|
|
180
|
+
res.sendFile(path.join(__dirname, "llms.txt"));
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
app.get("/INTEGRATION.md", (req, res) => {
|
|
184
|
+
res.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24}`);
|
|
185
|
+
res.type("text/markdown");
|
|
186
|
+
res.sendFile(path.join(__dirname, "INTEGRATION.md"));
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
app.get("/ping", (req, res) => {
|
|
190
|
+
res.json({});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
app.post("/mcp", async (req, res) => {
|
|
194
|
+
try {
|
|
195
|
+
await handleMcpPostRequest(req, res);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error("MCP request handling failed", error);
|
|
198
|
+
if (!res.headersSent) {
|
|
199
|
+
res.status(500).json({
|
|
200
|
+
jsonrpc: "2.0",
|
|
201
|
+
error: {
|
|
202
|
+
code: -32603,
|
|
203
|
+
message: "Internal server error",
|
|
204
|
+
},
|
|
205
|
+
id: null,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
app.all("/mcp", (req, res) => {
|
|
212
|
+
res.status(405).json({
|
|
213
|
+
jsonrpc: "2.0",
|
|
214
|
+
error: {
|
|
215
|
+
code: -32000,
|
|
216
|
+
message: "Method not allowed.",
|
|
217
|
+
},
|
|
218
|
+
id: null,
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
app.get("/.well-known/mcp/server-card.json", (req, res) => {
|
|
223
|
+
const baseUrl = `https://${req.get("host")}`;
|
|
224
|
+
res.json(buildMcpServerCard(baseUrl));
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
app.get("/mcp-icon.svg", (req, res) => {
|
|
228
|
+
res.type("image/svg+xml");
|
|
229
|
+
res.set("Cache-Control", "public, max-age=86400");
|
|
230
|
+
res.sendFile(path.join(__dirname, "mcp", "mcp-icon.svg"));
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
app.get("/robots.txt", (req, res) => {
|
|
234
|
+
const baseUrl = `https://${req.get("host")}`;
|
|
235
|
+
const lines = [
|
|
236
|
+
"User-agent: *",
|
|
237
|
+
"Disallow: /private/",
|
|
238
|
+
"",
|
|
239
|
+
"# Non-standard hint for AI agent discovery:",
|
|
240
|
+
`# mcp-server: ${baseUrl}/.well-known/mcp/server-card.json`,
|
|
241
|
+
];
|
|
242
|
+
res.type("text/plain").send(lines.join("\n"));
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
app.get("/last-modified.txt", (req, res, next) => {
|
|
246
|
+
res.set("Cache-Control", `public, max-age=0, s-maxage=${5 * 60}`);
|
|
247
|
+
res.sendFile(path.join(__dirname, "last-modified.txt"));
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
app.get("/favicon.ico", (req, res, next) => {
|
|
251
|
+
res
|
|
252
|
+
.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24 * 31}`)
|
|
253
|
+
.set("Cache-Tag", "long");
|
|
254
|
+
res.sendFile(path.join(__dirname, "favicon.ico"));
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
app.get("/smithery.json", (req, res) => {
|
|
258
|
+
res
|
|
259
|
+
.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24 * 7}`)
|
|
260
|
+
.set("Cache-Tag", "long");
|
|
261
|
+
res.sendFile(path.join(__dirname, "smithery.json"));
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
app.get("/server.json", (req, res) => {
|
|
265
|
+
res
|
|
266
|
+
.set("Cache-Control", `public, max-age=0, s-maxage=${3600 * 24 * 7}`)
|
|
267
|
+
.set("Cache-Tag", "long");
|
|
268
|
+
res.sendFile(path.join(__dirname, "server.json"));
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
app.use(notFoundAction);
|
|
272
|
+
|
|
273
|
+
Sentry.setupExpressErrorHandler(app);
|
|
274
|
+
|
|
275
|
+
app.use(function (err, req, res, next) {
|
|
276
|
+
console.error(err.stack);
|
|
277
|
+
res.status(500).send("Something broke!");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
app.on("ready", () => {
|
|
281
|
+
app.listen(PORT, () => {
|
|
282
|
+
console.log("Started!");
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
localDb.loadDatabase({}, async () => {
|
|
287
|
+
const gtfsDbConfig = JSON.parse(
|
|
288
|
+
await readFile(new URL("./gtfs-import-config.json", import.meta.url)),
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
await openDb(gtfsDbConfig);
|
|
292
|
+
|
|
293
|
+
app.emit("ready");
|
|
294
|
+
});
|
package/mcp/config.json
ADDED
package/mcp/stdio.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Stdio-to-HTTP proxy — bridges local MCP clients (Claude Desktop, Cursor, etc.)
|
|
3
|
+
// to the live Lviv Public Transport MCP server without requiring a local database.
|
|
4
|
+
import "dotenv/config";
|
|
5
|
+
|
|
6
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
8
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
9
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
10
|
+
import {
|
|
11
|
+
CallToolRequestSchema,
|
|
12
|
+
ListToolsRequestSchema,
|
|
13
|
+
ListResourcesRequestSchema,
|
|
14
|
+
ReadResourceRequestSchema,
|
|
15
|
+
ListPromptsRequestSchema,
|
|
16
|
+
GetPromptRequestSchema,
|
|
17
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
18
|
+
|
|
19
|
+
const upstreamUrl = new URL(
|
|
20
|
+
process.env.MCP_URL || "https://api.lad.lviv.ua/mcp",
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
async function main() {
|
|
24
|
+
const upstream = new Client(
|
|
25
|
+
{ name: "lviv-timetable-stdio-proxy", version: "1.0.0" },
|
|
26
|
+
{ capabilities: {} },
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
await upstream.connect(new StreamableHTTPClientTransport(upstreamUrl));
|
|
30
|
+
|
|
31
|
+
const [{ tools }, { resources }, { prompts }] = await Promise.all([
|
|
32
|
+
upstream.listTools(),
|
|
33
|
+
upstream.listResources(),
|
|
34
|
+
upstream.listPrompts(),
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const server = new Server(
|
|
38
|
+
{ name: "com.lad.lviv/timetable-api", version: "1.0.0" },
|
|
39
|
+
{
|
|
40
|
+
capabilities: {
|
|
41
|
+
...(tools.length && { tools: {} }),
|
|
42
|
+
...(resources.length && { resources: {} }),
|
|
43
|
+
...(prompts.length && { prompts: {} }),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
|
|
49
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => ({ resources }));
|
|
50
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts }));
|
|
51
|
+
|
|
52
|
+
server.setRequestHandler(CallToolRequestSchema, async (req) =>
|
|
53
|
+
upstream.callTool(req.params),
|
|
54
|
+
);
|
|
55
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (req) =>
|
|
56
|
+
upstream.readResource(req.params),
|
|
57
|
+
);
|
|
58
|
+
server.setRequestHandler(GetPromptRequestSchema, async (req) =>
|
|
59
|
+
upstream.getPrompt(req.params),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
await server.connect(new StdioServerTransport());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main().catch((err) => {
|
|
66
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "timetable-api-node",
|
|
3
|
+
"version": "1.1.2",
|
|
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
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"timetable-mcp": "./mcp/stdio.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"mcp/stdio.js",
|
|
12
|
+
"mcp/config.json",
|
|
13
|
+
"INTEGRATION.md"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://lad.lviv.ua",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/vbhjckfd/timetable-api-node.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"mcp",
|
|
22
|
+
"model-context-protocol",
|
|
23
|
+
"lviv",
|
|
24
|
+
"transit",
|
|
25
|
+
"gtfs",
|
|
26
|
+
"timetable",
|
|
27
|
+
"public-transport",
|
|
28
|
+
"ukraine",
|
|
29
|
+
"api"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
33
|
+
"@sentry/node": "^10.52.0",
|
|
34
|
+
"cors": "^2.8.5",
|
|
35
|
+
"dotenv": "^17.4",
|
|
36
|
+
"express": "^5.2.1",
|
|
37
|
+
"gtfs": "^4.18.5",
|
|
38
|
+
"gtfs-realtime-bindings": "^1.1.1",
|
|
39
|
+
"lokijs": "^1.5.12",
|
|
40
|
+
"npm-config": "^0.2.0",
|
|
41
|
+
"protobufjs": ">=8.2.0",
|
|
42
|
+
"public-google-sheets-parser": "^1.3.2",
|
|
43
|
+
"tar": ">=7.5.15",
|
|
44
|
+
"zod": "^4.4.3"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"import": "node gtfs-import.js",
|
|
48
|
+
"import-slim": "node gtfs-import-slim.js",
|
|
49
|
+
"start": "node index.js",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"test:watch": "vitest"
|
|
52
|
+
},
|
|
53
|
+
"author": "vbhjckfd@gmail.com",
|
|
54
|
+
"license": "WTFPL",
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"vitest": "^4.1.5"
|
|
57
|
+
}
|
|
58
|
+
}
|