sbb-mcp 0.4.1 → 0.4.3

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 (54) hide show
  1. package/LICENSE +57 -57
  2. package/README.md +258 -314
  3. package/dist/cache.d.ts +2 -0
  4. package/dist/cache.js +4 -0
  5. package/dist/cache.js.map +1 -1
  6. package/dist/formatters.d.ts +13 -0
  7. package/dist/formatters.js +94 -19
  8. package/dist/formatters.js.map +1 -1
  9. package/dist/http.js +59 -3
  10. package/dist/http.js.map +1 -1
  11. package/dist/index.js +2 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/look2book.d.ts +98 -0
  14. package/dist/look2book.js +212 -0
  15. package/dist/look2book.js.map +1 -0
  16. package/dist/profile.js +15 -8
  17. package/dist/profile.js.map +1 -1
  18. package/dist/shortlink.d.ts +60 -0
  19. package/dist/shortlink.js +122 -0
  20. package/dist/shortlink.js.map +1 -0
  21. package/dist/structured.d.ts +7 -1
  22. package/dist/structured.js +2 -1
  23. package/dist/structured.js.map +1 -1
  24. package/dist/swisstrip.js +21 -5
  25. package/dist/swisstrip.js.map +1 -1
  26. package/dist/tools.d.ts +38 -0
  27. package/dist/tools.js +122 -77
  28. package/dist/tools.js.map +1 -1
  29. package/dist/transport/index.d.ts +1 -0
  30. package/dist/transport/index.js +4 -0
  31. package/dist/transport/index.js.map +1 -1
  32. package/dist/transport/setup.d.ts +1 -0
  33. package/dist/transport/setup.js +59 -0
  34. package/dist/transport/setup.js.map +1 -0
  35. package/dist/transport/smapi-auth.d.ts +14 -2
  36. package/dist/transport/smapi-auth.js +67 -17
  37. package/dist/transport/smapi-auth.js.map +1 -1
  38. package/dist/transport/smapi-client.d.ts +25 -1
  39. package/dist/transport/smapi-client.js +112 -9
  40. package/dist/transport/smapi-client.js.map +1 -1
  41. package/dist/transport/smapi-journey.d.ts +11 -5
  42. package/dist/transport/smapi-journey.js +16 -7
  43. package/dist/transport/smapi-journey.js.map +1 -1
  44. package/dist/transport/smapi-mock.js.map +1 -1
  45. package/dist/transport/smapi-prices.d.ts +43 -9
  46. package/dist/transport/smapi-prices.js +112 -41
  47. package/dist/transport/smapi-prices.js.map +1 -1
  48. package/dist/transport/smapi-types.d.ts +28 -0
  49. package/dist/widgets.d.ts +30 -3
  50. package/dist/widgets.js +78 -14
  51. package/dist/widgets.js.map +1 -1
  52. package/package.json +79 -73
  53. package/web/dist/widgets.css +1 -1
  54. package/web/dist/widgets.js +1 -1
package/README.md CHANGED
@@ -1,314 +1,258 @@
1
- # sbb-mcp
2
-
3
- [![npm version](https://img.shields.io/npm/v/sbb-mcp.svg)](https://www.npmjs.com/package/sbb-mcp)
4
- [![License: FSL-1.1-MIT](https://img.shields.io/badge/License-FSL--1.1--MIT-blue.svg)](https://fsl.software/)
5
- [![smithery badge](https://smithery.ai/badge/fabsforward2-zhoi/sbb-mcp)](https://smithery.ai/servers/fabsforward2-zhoi/sbb-mcp)
6
-
7
- MCP server for **Swiss Federal Railways** (SBB/CFF/FFS) -- real-time train schedules, prices, and ticket purchase links for any AI assistant.
8
-
9
- Works with Claude Desktop, Claude Code, Cursor, Windsurf, VS Code Copilot, ChatGPT, and any MCP-compatible AI client.
10
-
11
- ## Features
12
-
13
- - **Search stations** -- find any Swiss train station by name
14
- - **Train connections** -- real-time schedules with departure/arrival times, platforms, transfers
15
- - **Ticket prices** -- 1st/2nd class with Half-Fare (Halbtax) and GA travelcard support
16
- - **Purchase links** -- direct deep links to buy tickets on SBB.ch
17
- - **Pagination** -- browse earlier/later connections
18
- - **Trip details** -- intermediate stops, occupancy, platform changes
19
- - **Journey planning** -- built-in prompt for end-to-end trip planning
20
- - **Destination weather** -- automatic weather forecast for your destination (powered by [swiss-weather-mcp](https://www.npmjs.com/package/swiss-weather-mcp))
21
- - **Multi-traveler** -- family trip pricing when connected to SwissTrip (partner, kids, each with their own reduction card)
22
- - **Multilingual** -- output in 9 languages: de, fr, it, en, es, pt, ru, ar, zh (v0.4.0+)
23
- - **Mock mode** -- works without credentials for testing and demos
24
-
25
- ## Quick Start
26
-
27
- ### Claude Desktop
28
-
29
- Add to your `claude_desktop_config.json`:
30
-
31
- ```json
32
- {
33
- "mcpServers": {
34
- "sbb": {
35
- "command": "npx",
36
- "args": ["-y", "sbb-mcp"],
37
- "env": {
38
- "SMAPI_CLIENT_ID": "your-client-id",
39
- "SMAPI_CLIENT_SECRET": "your-secret",
40
- "SMAPI_SCOPE": "your-scope",
41
- "SMAPI_CONTRACT_ID": "your-contract-id"
42
- }
43
- }
44
- }
45
- }
46
- ```
47
-
48
- ### Claude Code
49
-
50
- ```bash
51
- claude mcp add sbb -- npx -y sbb-mcp
52
- ```
53
-
54
- ### Cursor
55
-
56
- Add to `.cursor/mcp.json`:
57
-
58
- ```json
59
- {
60
- "mcpServers": {
61
- "sbb": {
62
- "command": "npx",
63
- "args": ["-y", "sbb-mcp"],
64
- "env": {
65
- "SMAPI_CLIENT_ID": "your-client-id",
66
- "SMAPI_CLIENT_SECRET": "your-secret",
67
- "SMAPI_SCOPE": "your-scope",
68
- "SMAPI_CONTRACT_ID": "your-contract-id"
69
- }
70
- }
71
- }
72
- }
73
- ```
74
-
75
- ### Windsurf
76
-
77
- Add to `~/.codeium/windsurf/mcp_config.json`:
78
-
79
- ```json
80
- {
81
- "mcpServers": {
82
- "sbb": {
83
- "command": "npx",
84
- "args": ["-y", "sbb-mcp"],
85
- "env": {
86
- "SMAPI_CLIENT_ID": "your-client-id",
87
- "SMAPI_CLIENT_SECRET": "your-secret",
88
- "SMAPI_SCOPE": "your-scope",
89
- "SMAPI_CONTRACT_ID": "your-contract-id"
90
- }
91
- }
92
- }
93
- }
94
- ```
95
-
96
- ### VS Code Copilot
97
-
98
- Add to `.vscode/mcp.json`:
99
-
100
- ```json
101
- {
102
- "servers": {
103
- "sbb": {
104
- "command": "npx",
105
- "args": ["-y", "sbb-mcp"],
106
- "env": {
107
- "SMAPI_CLIENT_ID": "your-client-id",
108
- "SMAPI_CLIENT_SECRET": "your-secret",
109
- "SMAPI_SCOPE": "your-scope",
110
- "SMAPI_CONTRACT_ID": "your-contract-id"
111
- }
112
- }
113
- }
114
- }
115
- ```
116
-
117
- ### Smithery
118
-
119
- Install via [Smithery](https://smithery.ai/servers/fabsforward2-zhoi/sbb-mcp):
120
-
121
- ```bash
122
- npx @smithery/cli mcp add fabsforward2-zhoi/sbb-mcp
123
- ```
124
-
125
- ### Demo Mode (No Credentials)
126
-
127
- Run without any environment variables to use mock data:
128
-
129
- ```bash
130
- npx sbb-mcp
131
- ```
132
-
133
- This lets you test the MCP server with realistic Swiss station data without SBB API credentials.
134
-
135
- ## Multilingual output (v0.4.0+)
136
-
137
- Every tool accepts an optional `language` argument — one of `de`, `fr`, `it`, `en`, `es`, `pt`, `ru`, `ar`, `zh`. This controls the output language for labels, date/time formatting, and the ticket-buy button text. It also sets the `Accept-Language` header on SBB API calls so station names come back in the requested language where the SBB API supports it (de/fr/it/en).
138
-
139
- Resolution order: `language` arg saved profile language (`save_profile`) → English.
140
-
141
- ```jsonc
142
- // Example: French output
143
- { "from": "Zurich HB", "to": "Bern", "language": "fr" }
144
- ```
145
-
146
- The SBB deep link path uses `de/fr/it/en` where supported and falls back to `en` for other languages (SBB.ch serves those four).
147
-
148
- Save a default language once per user:
149
-
150
- ```jsonc
151
- { "tool": "save_profile", "language": "de" }
152
- ```
153
-
154
- ## Tools
155
-
156
- ### search_stations
157
-
158
- Search for Swiss train stations by name. Returns station IDs needed for other tools.
159
-
160
- **Input:**
161
- - `query` (string, required) -- Station name, e.g. "Zurich", "Bern", "Interlaken"
162
- - `limit` (number, optional) -- Max results (default: 10)
163
-
164
- **Example:** "Find stations matching Luzern"
165
-
166
- ### search_connections
167
-
168
- Find train connections between two stations. Automatically resolves station names to IDs.
169
-
170
- **Input:**
171
- - `from` (string, required) -- Origin station name or ID (e.g. "Zurich HB" or "8503000")
172
- - `to` (string, required) -- Destination station name or ID
173
- - `date` (string, optional) -- Travel date YYYY-MM-DD
174
- - `time` (string, optional) -- Departure time HH:MM
175
- - `arrival_time` (boolean, optional) -- Treat time as arrival time
176
-
177
- **Example:** "Show me trains from Zurich to Bern tomorrow at 9am"
178
-
179
- Results automatically include destination weather when coordinates are available (e.g. **Bern weather:** 6-18°C, mostly sunny, 10% rain).
180
-
181
- ### get_trip_details
182
-
183
- Get detailed stop-by-stop information for a connection including intermediate stops, platforms, and occupancy forecasts.
184
-
185
- **Input:**
186
- - `trip_id` (string, required) -- Trip ID from search_connections
187
-
188
- ### get_more_connections
189
-
190
- Load earlier or later trains for a previous search.
191
-
192
- **Input:**
193
- - `collection_id` (string, required) -- Collection ID from search_connections
194
- - `direction` ("next" | "previous") -- Later or earlier trains
195
-
196
- ### get_prices
197
-
198
- Get ticket prices with Swiss reduction card support. Supports multi-traveler family pricing when connected to SwissTrip.
199
-
200
- **Input:**
201
- - `trip_ids` (string[], required) -- Trip IDs from search_connections
202
- - `traveler_type` ("ADULT" | "CHILD", default: "ADULT") -- used when no traveler_names given
203
- - `reduction_card` ("HALF_FARE" | "GA" | "NONE", default: "HALF_FARE") -- used when no traveler_names given
204
- - `traveler_names` (string[], optional) -- SwissTrip traveler names for family pricing (requires `SWISSTRIP_TOKEN`)
205
-
206
- **Example:** "How much for Zurich to Zermatt for Fabian and Anna?" (with SwissTrip connected, each traveler's reduction card is applied automatically)
207
-
208
- ### get_ticket_link
209
-
210
- Get a direct purchase link to buy the ticket on SBB.ch. On mobile with the SBB app installed, opens directly in the app with Halbtax/GA applied automatically. Supports multi-traveler tickets when connected to SwissTrip.
211
-
212
- **Input:**
213
- - `trip_id` (string, required) -- Trip ID to purchase
214
- - `from_name` (string, required) -- Origin station name
215
- - `from_id` (string, required) -- Origin station ID
216
- - `to_name` (string, required) -- Destination station name
217
- - `to_id` (string, required) -- Destination station ID
218
- - `date` (string, required) -- Travel date YYYY-MM-DD
219
- - `time` (string, required) -- Departure time HH:MM
220
- - `traveler_type` ("ADULT" | "CHILD", default: "ADULT") -- used when no traveler_names given
221
- - `reduction_card` ("HALF_FARE" | "GA" | "NONE", default: "HALF_FARE") -- used when no traveler_names given
222
- - `traveler_names` (string[], optional) -- SwissTrip traveler names for family tickets (requires `SWISSTRIP_TOKEN`)
223
-
224
- ### list_travelers
225
-
226
- List all travelers in the user's SwissTrip account (self, partner, kids). Each traveler has their own reduction card. Requires `SWISSTRIP_TOKEN`.
227
-
228
- **Example:** "Who are my travelers?" → shows all saved travelers with their reduction cards
229
-
230
- ## Prompts
231
-
232
- ### plan_journey
233
-
234
- End-to-end journey planning prompt. Searches connections, compares prices, and provides ticket links.
235
-
236
- **Input:**
237
- - `from` (string, required) -- Origin station
238
- - `to` (string, required) -- Destination station
239
- - `date` (string, optional) -- Travel date
240
-
241
- ## Environment Variables
242
-
243
- | Variable | Required | Description |
244
- |----------|----------|-------------|
245
- | `SMAPI_CLIENT_ID` | Yes* | OAuth 2.0 client ID from SBB Developer Portal |
246
- | `SMAPI_CLIENT_SECRET` | Yes* | OAuth 2.0 client secret |
247
- | `SMAPI_SCOPE` | Yes* | OAuth scope |
248
- | `SMAPI_CONTRACT_ID` | Yes* | SBB business contract ID |
249
- | `SMAPI_ENV` | No | `int` (default) or `prod` |
250
- | `SMAPI_TENANT_ID` | No | Azure AD tenant (defaults to SBB tenant) |
251
- | `SWISSTRIP_TOKEN` | No | SwissTrip auth token for cloud profiles and multi-traveler support |
252
- | `SWISSTRIP_URL` | No | SwissTrip API base URL (defaults to `https://swisstrip.ch`) |
253
-
254
- *Without SMAPI credentials, the server runs in mock mode with realistic demo data.
255
-
256
- ## SwissTrip Integration (Optional)
257
-
258
- Set `SWISSTRIP_TOKEN` to connect sbb-mcp to your [SwissTrip](https://swisstrip.ch) account. This enables:
259
-
260
- - **Cloud-synced profiles** -- your travel profile (name, DOB, reduction card) syncs from SwissTrip instead of local `~/.sbb-mcp/profile.json`
261
- - **Multi-traveler pricing** -- add your partner, kids, or travel companions on SwissTrip and get per-person pricing with correct reduction cards
262
- - **Family tickets** -- pass `traveler_names` to `get_prices` and `get_ticket_link` for group pricing
263
-
264
- ```json
265
- {
266
- "mcpServers": {
267
- "sbb": {
268
- "command": "npx",
269
- "args": ["-y", "sbb-mcp"],
270
- "env": {
271
- "SMAPI_CLIENT_ID": "your-client-id",
272
- "SMAPI_CLIENT_SECRET": "your-secret",
273
- "SMAPI_SCOPE": "your-scope",
274
- "SWISSTRIP_TOKEN": "your-swisstrip-auth-token"
275
- }
276
- }
277
- }
278
- }
279
- ```
280
-
281
- Without `SWISSTRIP_TOKEN`, sbb-mcp uses local file-based profiles as before -- no SwissTrip account required.
282
-
283
- ## Available on
284
-
285
- - [npm](https://www.npmjs.com/package/sbb-mcp)
286
- - [Official MCP Registry](https://registry.modelcontextprotocol.io)
287
- - [Smithery](https://smithery.ai/servers/fabsforward2-zhoi/sbb-mcp)
288
-
289
- Also available as: [sbb-mcp-official](https://www.npmjs.com/package/sbb-mcp-official) | [swiss-rail-mcp](https://www.npmjs.com/package/swiss-rail-mcp) | [sbb-cff-ffs-mcp](https://www.npmjs.com/package/sbb-cff-ffs-mcp) | [swiss-train-mcp](https://www.npmjs.com/package/swiss-train-mcp) | [swiss-railways-mcp](https://www.npmjs.com/package/swiss-railways-mcp)
290
-
291
- ## About
292
-
293
- Built on the official SBB Swiss Mobility API (SMAPI) with OSDM-compliant journey planning and pricing. Covers the entire Swiss public transport network including SBB, BLS, SOB, and regional operators. Weather data powered by [swiss-weather-mcp](https://www.npmjs.com/package/swiss-weather-mcp) (MeteoSwiss + Open-Meteo).
294
-
295
- **SBB** (Schweizerische Bundesbahnen) / **CFF** (Chemins de fer federaux suisses) / **FFS** (Ferrovie federali svizzere) -- Swiss Federal Railways operates one of the densest rail networks in the world with over 10,000 daily connections.
296
-
297
- ## Changelog
298
-
299
- ### v0.4.0 — Multilingual
300
-
301
- - Every tool now accepts an optional `language` parameter (`de | fr | it | en | es | pt | ru | ar | zh`).
302
- - Labels, date/time formatting, and the SBB ticket-buy button text are translated.
303
- - `Accept-Language` is passed to SBB SMAPI so station names come back in the requested language where supported (de/fr/it/en).
304
- - `save_profile` stores a preferred language; later tool calls default to it when `language` is omitted.
305
- - **Breaking:** default output locale with no profile and no tool arg is now `en` (was implicitly `de-CH`). Set a profile or pass `language: 'de'` to restore the old behavior.
306
- - Translations shared with the WhatsApp/Telegram bots via the new [`sbb-i18n`](https://www.npmjs.com/package/sbb-i18n) package.
307
-
308
- ### v0.3.0 — Destination weather
309
-
310
- - Automatic weather forecast appended to `search_connections` results via [`swiss-weather-mcp`](https://www.npmjs.com/package/swiss-weather-mcp).
311
-
312
- ## License
313
-
314
- [FSL-1.1-MIT](https://fsl.software/) -- Functional Source License. Free to use for any non-competing purpose. Converts to MIT after 2 years. See [LICENSE](LICENSE) for details.
1
+ # sbb-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/sbb-mcp.svg)](https://www.npmjs.com/package/sbb-mcp)
4
+ [![License: FSL-1.1-MIT](https://img.shields.io/badge/License-FSL--1.1--MIT-blue.svg)](https://fsl.software/)
5
+ [![smithery](https://smithery.ai/badge/fabsforward2-zhoi/sbb-mcp)](https://smithery.ai/servers/fabsforward2-zhoi/sbb-mcp)
6
+
7
+ > **Swiss trains in any AI assistant.** Real-time schedules, ticket prices with Half-Fare/GA discounts, and direct purchase links for Claude Desktop, ChatGPT, Cursor, and any MCP-compatible client.
8
+
9
+ ```
10
+ You: trains from Bern to Zermatt tomorrow at 9am, with Halbtax
11
+ AI: IC 8 14:32 → 17:24 (2h52, 1 transfer in Visp, Pl. 8) — CHF 42.50
12
+ IC 8 15:02 → 17:54 (2h52, 1 transfer in Visp, Pl. 8) — CHF 42.50
13
+ [Buy on SBB.ch ↗]
14
+ ```
15
+
16
+ Ask any AI assistant to find Swiss trains. It returns connections, prices with your reduction card applied, and a direct ticket-purchase link to sbb.ch all through natural language.
17
+
18
+ > **Not affiliated with SBB.** Independent, community-maintained MCP server built on SBB's public Swiss Mobility API (SMAPI). Not affiliated with or endorsed by SBB (Schweizerische Bundesbahnen).
19
+
20
+ ---
21
+
22
+ ## Quick install
23
+
24
+ ### ChatGPT (no install — hosted)
25
+
26
+ ChatGPT Plus / Pro / Business / Enterprise with Developer Mode enabled:
27
+
28
+ 1. **Settings → Connectors** → enable **Developer Mode**
29
+ 2. Click **Add custom connector**
30
+ 3. **MCP Server URL:** `https://mcp.swisstrip.app/mcp`
31
+ 4. **Authentication:** None
32
+ 5. Save, then enable via the **+** button in the composer
33
+
34
+ Tool responses render as native ChatGPT widgets (connection cards, trip timelines, price tables) via the OpenAI Apps SDK.
35
+
36
+ ### Claude Code
37
+
38
+ ```bash
39
+ claude mcp add sbb -- npx -y sbb-mcp
40
+ ```
41
+
42
+ Done — try `/mcp` in Claude to confirm it's loaded, then ask about Swiss trains.
43
+
44
+ ### Claude Desktop
45
+
46
+ Add to `claude_desktop_config.json`:
47
+
48
+ ```json
49
+ {
50
+ "mcpServers": {
51
+ "sbb": {
52
+ "command": "npx",
53
+ "args": ["-y", "sbb-mcp"]
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ Restart Claude Desktop. That's it — works in **mock mode** out of the box with realistic Swiss station data. Add credentials later for live SBB data (see below).
60
+
61
+ ### Cursor / Windsurf / VS Code Copilot
62
+
63
+ Same `mcpServers` block as Claude Desktop, in the respective config file:
64
+
65
+ | Client | Config path |
66
+ |---|---|
67
+ | Cursor | `.cursor/mcp.json` |
68
+ | Windsurf | `~/.codeium/windsurf/mcp_config.json` |
69
+ | VS Code Copilot | `.vscode/mcp.json` (use top-level `servers` instead of `mcpServers`) |
70
+
71
+ ### Try it without installing
72
+
73
+ ```bash
74
+ npx sbb-mcp
75
+ ```
76
+
77
+ Runs in mock mode with realistic Swiss station data — no setup, no credentials. Useful for testing the protocol or building demos.
78
+
79
+ ---
80
+
81
+ ## Live SBB data (optional)
82
+
83
+ Mock mode works out of the box. For real-time schedules and prices, get credentials from the [SBB Developer Portal](https://developer.sbb.ch) (free signup, OAuth 2.0 + business contract).
84
+
85
+ Add to your config's `env` block:
86
+
87
+ ```json
88
+ {
89
+ "mcpServers": {
90
+ "sbb": {
91
+ "command": "npx",
92
+ "args": ["-y", "sbb-mcp"],
93
+ "env": {
94
+ "SMAPI_JOURNEY_CLIENT_ID": "...",
95
+ "SMAPI_JOURNEY_CLIENT_SECRET": "...",
96
+ "SMAPI_JOURNEY_SCOPE": "api://.../.default",
97
+ "SMAPI_TICKETING_CLIENT_ID": "...",
98
+ "SMAPI_TICKETING_CLIENT_SECRET": "...",
99
+ "SMAPI_TICKETING_SCOPE": "api://.../.default",
100
+ "SMAPI_CONTRACT_ID": "..."
101
+ }
102
+ }
103
+ }
104
+ }
105
+ ```
106
+
107
+ SBB issues separate AAD apps per API. The Journey API is for schedules/stations; the Ticketing API for prices/booking links. Set whichever you have approved — the server falls back to mock data per family if a credential set is missing.
108
+
109
+ For backwards compatibility, single-app setups can use the generic `SMAPI_CLIENT_ID` / `SMAPI_CLIENT_SECRET` / `SMAPI_SCOPE` for both APIs.
110
+
111
+ ---
112
+
113
+ ## What it does
114
+
115
+ - **Search stations** — find any Swiss train station by name, get UIC IDs
116
+ - **Train connections** — schedules with departure/arrival times, platforms, transfer info, occupancy forecasts
117
+ - **Ticket prices** — 1st/2nd class with Half-Fare (Halbtax) and GA travelcard support
118
+ - **Purchase links** — direct deep links to buy on SBB.ch (opens the SBB app on mobile with discounts applied)
119
+ - **Pagination** — browse earlier/later connections without losing context
120
+ - **Trip details** — intermediate stops, platforms, real-time status
121
+ - **Destination weather** — auto-included in connection results via [`swiss-weather-mcp`](https://www.npmjs.com/package/swiss-weather-mcp)
122
+ - **Multilingual** output in 9 languages (`de fr it en es pt ru ar zh`)
123
+ - **ChatGPT widgets** — connection cards, price tables, ticket cards rendered as native UI via OpenAI Apps SDK
124
+ - **Mock mode** — full demo data without credentials
125
+
126
+ ---
127
+
128
+ ## Tools
129
+
130
+ 9 MCP tools, all support an optional `language` argument.
131
+
132
+ | Tool | What it does |
133
+ |---|---|
134
+ | `search_stations` | Find stations by name → UIC IDs |
135
+ | `search_connections` | Schedules between two stations (returns trip IDs) |
136
+ | `get_trip_details` | Stop-by-stop info, platforms, occupancy |
137
+ | `get_more_connections` | Earlier/later trains via pagination |
138
+ | `get_prices` | Ticket prices with reduction card applied |
139
+ | `get_ticket_link` | Direct purchase link to SBB.ch (mobile-app deep link) |
140
+ | `save_profile` | Save user's reduction card + DOB locally for auto-apply |
141
+ | `get_profile` | Read saved profile |
142
+ | `list_travelers` | Multi-traveler family pricing (requires SwissTrip account) |
143
+
144
+ Plus a `plan_journey` prompt for end-to-end trip planning.
145
+
146
+ ### Multilingual
147
+
148
+ Every tool accepts `language: "de" | "fr" | "it" | "en" | "es" | "pt" | "ru" | "ar" | "zh"`. Sets `Accept-Language` on SBB API calls so station names come back in the requested language; localizes the buy-button text on deep links.
149
+
150
+ ```jsonc
151
+ // French output
152
+ { "from": "Zürich HB", "to": "Genève", "language": "fr" }
153
+ ```
154
+
155
+ Save a default once via `save_profile` — subsequent calls use it automatically.
156
+
157
+ ---
158
+
159
+ ## Hosted MCP endpoint
160
+
161
+ A public HTTPS endpoint is live at `https://mcp.swisstrip.app/mcp` for clients that prefer remote MCP over local stdio (ChatGPT, Claude Pro remote MCPs, etc.). Same tools, plus rich widgets for ChatGPT.
162
+
163
+ ```bash
164
+ # Test from your terminal
165
+ curl -X POST https://mcp.swisstrip.app/mcp \
166
+ -H 'Content-Type: application/json' \
167
+ -H 'Accept: application/json, text/event-stream' \
168
+ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Environment variables
174
+
175
+ | Variable | Required | Description |
176
+ |---|---|---|
177
+ | `SMAPI_JOURNEY_CLIENT_ID` / `_CLIENT_SECRET` / `_SCOPE` | For schedules + stations | OAuth credentials for SBB Journey API |
178
+ | `SMAPI_TICKETING_CLIENT_ID` / `_CLIENT_SECRET` / `_SCOPE` | For prices + booking links | OAuth credentials for SBB Ticketing API (b2p) |
179
+ | `SMAPI_CLIENT_ID` / `_CLIENT_SECRET` / `_SCOPE` | Fallback | Single-app credentials, used for any family without specific vars |
180
+ | `SMAPI_CONTRACT_ID` | With any creds | SBB partner contract identifier |
181
+ | `SMAPI_ENV` | No | `int` (default) \| `prod` \| `mock` |
182
+ | `SMAPI_TENANT_ID` | No | Azure AD tenant override (defaults to SBB's) |
183
+ | `SWISSTRIP_TOKEN` | No | SwissTrip account token for cloud-synced multi-traveler profiles |
184
+
185
+ Without any SMAPI credentials → mock mode (realistic demo data).
186
+
187
+ ---
188
+
189
+ ## SwissTrip integration (optional)
190
+
191
+ Connect your [SwissTrip](https://swisstrip.app) account via `SWISSTRIP_TOKEN` to enable:
192
+
193
+ - Cloud-synced travel profile (name, DOB, reduction card) instead of local file
194
+ - Multi-traveler family pricing (partner, kids, each with their own card)
195
+ - Mint a token at https://swisstrip.app/settings/developer
196
+
197
+ ---
198
+
199
+ ## Available everywhere
200
+
201
+ - [npm](https://www.npmjs.com/package/sbb-mcp)
202
+ - [Official MCP Registry](https://registry.modelcontextprotocol.io)
203
+ - [Smithery](https://smithery.ai/servers/fabsforward2-zhoi/sbb-mcp)
204
+ - [PulseMCP](https://www.pulsemcp.com/servers/fabsbags-sbb)
205
+ - [LobeHub](https://lobehub.com/mcp)
206
+ - ChatGPT custom connector at `https://mcp.swisstrip.app/mcp`
207
+
208
+ Also published under alias names that all forward to `sbb-mcp`: [swiss-rail-mcp](https://www.npmjs.com/package/swiss-rail-mcp), [sbb-cff-ffs-mcp](https://www.npmjs.com/package/sbb-cff-ffs-mcp), [swiss-train-mcp](https://www.npmjs.com/package/swiss-train-mcp), [swiss-railways-mcp](https://www.npmjs.com/package/swiss-railways-mcp).
209
+
210
+ ---
211
+
212
+ ## About
213
+
214
+ Built on SBB's commercial Swiss Mobility API (SMAPI) with OSDM-compliant journey planning and Azure AD OAuth. Covers SBB plus regional operators (BLS, SOB, MOB, RhB, etc.) the entire Swiss public transport network with 10,000+ daily connections.
215
+
216
+ Weather data via [`swiss-weather-mcp`](https://www.npmjs.com/package/swiss-weather-mcp) (MeteoSwiss + Open-Meteo).
217
+
218
+ Repository: [Fabsbags/swisstrip-web](https://github.com/Fabsbags/swisstrip-web/tree/main/packages/sbb-mcp). Issues: [tracker](https://github.com/Fabsbags/swisstrip-web/issues).
219
+
220
+ **SBB** (Schweizerische Bundesbahnen) / **CFF** (Chemins de fer fédéraux suisses) / **FFS** (Ferrovie federali svizzere) — Swiss Federal Railways.
221
+
222
+ ---
223
+
224
+ ## License
225
+
226
+ [FSL-1.1-MIT](https://fsl.software/) Functional Source License. Free for any non-competing purpose. Converts to MIT after 2 years. See [LICENSE](LICENSE).
227
+
228
+ ---
229
+
230
+ ## Changelog
231
+
232
+ ### v0.4.3 — README polish
233
+
234
+ Launch-focused README rewrite: install-first structure, ChatGPT custom connector promoted to top, mock-mode-by-default messaging, 9-tool reference table, per-family SBB credential env vars documented. No runtime changes — `sbb-mcp@0.4.2` behavior is identical to `0.4.3`.
235
+
236
+ ### v0.4.2 — Repository metadata
237
+
238
+ Point `repository`, `homepage`, and `bugs` at the monorepo source of truth. No runtime changes.
239
+
240
+ ### v0.4.1 — Apps SDK widgets
241
+
242
+ - Five Preact widgets registered as `ui://widget/*.html` resources: stations list, connection list, trip details, prices table, ticket card
243
+ - Tool responses include `structuredContent` + `_meta["openai/outputTemplate"]` so ChatGPT renders rich UI
244
+ - Hosted endpoint live at `https://mcp.swisstrip.app/mcp` for use as a ChatGPT custom connector
245
+ - Widget bundle ~25KB (single IIFE, inlined CSS) built via Vite under `web/`
246
+ - Server rendering unchanged for stdio clients
247
+
248
+ ### v0.4.0 Multilingual
249
+
250
+ - Optional `language` argument on every tool (9 languages)
251
+ - `Accept-Language` passed to SBB SMAPI for localized station names
252
+ - `save_profile` stores preferred language as default
253
+ - **Breaking:** default output locale with no profile is now `en` (was `de-CH`). Set a profile or pass `language: 'de'` to restore previous behavior.
254
+ - Translations shared with WhatsApp/Telegram bots via [`sbb-i18n`](https://www.npmjs.com/package/sbb-i18n)
255
+
256
+ ### v0.3.0 Destination weather
257
+
258
+ Auto-include weather forecast in `search_connections` results via [`swiss-weather-mcp`](https://www.npmjs.com/package/swiss-weather-mcp).
package/dist/cache.d.ts CHANGED
@@ -10,3 +10,5 @@ export declare const TTL: {
10
10
  readonly PRICES: number;
11
11
  readonly TRIP_DETAILS: number;
12
12
  };
13
+ /** Test-only: clear all entries. No effect in production. */
14
+ export declare function __clearCacheForTesting(): void;
package/dist/cache.js CHANGED
@@ -55,4 +55,8 @@ export const TTL = {
55
55
  PRICES: 2 * 60 * 1000, // 2 minutes
56
56
  TRIP_DETAILS: 5 * 60 * 1000, // 5 minutes
57
57
  };
58
+ /** Test-only: clear all entries. No effect in production. */
59
+ export function __clearCacheForTesting() {
60
+ store.clear();
61
+ }
58
62
  //# sourceMappingURL=cache.js.map
package/dist/cache.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAA;AAEpD,MAAM,WAAW,GAAG,KAAK,CAAA;AAEzB,SAAS,YAAY;IACnB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACtB,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;QACjC,IAAI,GAAG,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;YAC3B,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YACjB,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,wDAAwD;IACxD,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC/B,IA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AAG,CAAC,CAAA;QACjB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,qDAAqD;IACrD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACjB,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACrB,OAAO,KAAK,CAAC,IAAS,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,QAAQ,CAAI,GAAW,EAAE,IAAO,EAAE,KAAa;IAC7D,IAAI,KAAK,CAAC,IAAI,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,YAAY,EAAE,CAAA;QAC9B,0DAA0D;QAC1D,IAAI,OAAO,GAAG,WAAW,GAAG,GAAG,EAAE,CAAC;YAChC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAA;AACzD,CAAC;AAED,OAAO;AACP,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAK,WAAW;IAC7C,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAS,YAAY;IAC/C,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAc,YAAY;IAC/C,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAQ,YAAY;CACvC,CAAA;AAEV,6DAA6D;AAC7D,MAAM,UAAU,sBAAsB;IACpC,KAAK,CAAC,KAAK,EAAE,CAAA;AACf,CAAC"}
@@ -1,5 +1,18 @@
1
1
  import type { SmapiPlace, SmapiTrip, SmapiTripsCollection, SmapiPriceResult } from './transport/smapi-types.js';
2
2
  import type { Lang } from './i18n.js';
3
+ /**
4
+ * Terse one-line summary used when the client renders the Apps SDK widget
5
+ * (see `isWidgetRenderingClient`). Widget clients already show a full card
6
+ * list — returning the long markdown table here just causes the LLM to
7
+ * paraphrase it into a redundant narration right next to the iframe. The
8
+ * structured content still carries all the data the model needs to answer
9
+ * follow-up questions; this string is purely for the chat bubble above the
10
+ * widget.
11
+ */
12
+ export declare function formatStationsTerse(stations: SmapiPlace[], _lang?: Lang): string;
13
+ export declare function formatConnectionsTerse(collection: SmapiTripsCollection, lang?: Lang): string;
14
+ export declare function formatTripDetailsTerse(trip: SmapiTrip, lang?: Lang): string;
15
+ export declare function formatPricesTerse(results: SmapiPriceResult[], lang?: Lang): string;
3
16
  export declare function formatStations(stations: SmapiPlace[], lang?: Lang): string;
4
17
  export declare function formatConnections(collection: SmapiTripsCollection, lang?: Lang): string;
5
18
  export declare function formatTripDetails(trip: SmapiTrip, lang?: Lang): string;