rzd-api 1.2.1__tar.gz → 3.0.0__tar.gz
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.
- rzd_api-3.0.0/LICENSE +21 -0
- rzd_api-3.0.0/PKG-INFO +230 -0
- rzd_api-3.0.0/README.md +187 -0
- rzd_api-3.0.0/mcp_server/server.py +398 -0
- rzd_api-3.0.0/pyproject.toml +101 -0
- rzd_api-3.0.0/rzd_api/__init__.py +57 -0
- rzd_api-3.0.0/rzd_api/api.py +711 -0
- rzd_api-3.0.0/rzd_api/client.py +462 -0
- rzd_api-3.0.0/rzd_api/config.py +60 -0
- rzd_api-3.0.0/rzd_api/exceptions.py +60 -0
- rzd_api-3.0.0/rzd_api/models.py +193 -0
- rzd_api-3.0.0/rzd_api/py.typed +0 -0
- rzd_api-3.0.0/rzd_api/query.py +140 -0
- rzd_api-3.0.0/rzd_api.egg-info/PKG-INFO +230 -0
- {rzd_api-1.2.1 → rzd_api-3.0.0}/rzd_api.egg-info/SOURCES.txt +9 -1
- rzd_api-3.0.0/rzd_api.egg-info/requires.txt +18 -0
- rzd_api-3.0.0/tests/test_api.py +388 -0
- rzd_api-3.0.0/tests/test_client.py +323 -0
- rzd_api-3.0.0/tests/test_config_models.py +74 -0
- rzd_api-3.0.0/tests/test_mcp_protocol.py +37 -0
- rzd_api-3.0.0/tests/test_mcp_server.py +173 -0
- rzd_api-3.0.0/tests/test_query.py +154 -0
- rzd_api-1.2.1/PKG-INFO +0 -405
- rzd_api-1.2.1/README.md +0 -373
- rzd_api-1.2.1/mcp_server/server.py +0 -197
- rzd_api-1.2.1/pyproject.toml +0 -57
- rzd_api-1.2.1/rzd_api/__init__.py +0 -6
- rzd_api-1.2.1/rzd_api/api.py +0 -268
- rzd_api-1.2.1/rzd_api/client.py +0 -216
- rzd_api-1.2.1/rzd_api/config.py +0 -12
- rzd_api-1.2.1/rzd_api/query.py +0 -103
- rzd_api-1.2.1/rzd_api.egg-info/PKG-INFO +0 -405
- rzd_api-1.2.1/rzd_api.egg-info/requires.txt +0 -9
- rzd_api-1.2.1/tests/test_api.py +0 -114
- rzd_api-1.2.1/tests/test_client.py +0 -127
- {rzd_api-1.2.1 → rzd_api-3.0.0}/mcp_server/__init__.py +0 -0
- {rzd_api-1.2.1 → rzd_api-3.0.0}/rzd_api.egg-info/dependency_links.txt +0 -0
- {rzd_api-1.2.1 → rzd_api-3.0.0}/rzd_api.egg-info/entry_points.txt +0 -0
- {rzd_api-1.2.1 → rzd_api-3.0.0}/rzd_api.egg-info/top_level.txt +0 -0
- {rzd_api-1.2.1 → rzd_api-3.0.0}/setup.cfg +0 -0
rzd_api-3.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 drgod
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rzd_api-3.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rzd-api
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Typed Python client and MCP server for the unofficial ticket.rzd.ru API
|
|
5
|
+
Author: drgod
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/drGOD/rzd-api
|
|
8
|
+
Project-URL: Repository, https://github.com/drGOD/rzd-api
|
|
9
|
+
Project-URL: Issues, https://github.com/drGOD/rzd-api/issues
|
|
10
|
+
Keywords: rzd,railway,trains,tickets,api,mcp
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: requests<3,>=2.31
|
|
27
|
+
Requires-Dist: urllib3<3,>=2
|
|
28
|
+
Provides-Extra: mcp
|
|
29
|
+
Requires-Dist: mcp<1.29,>=1.28.1; extra == "mcp"
|
|
30
|
+
Requires-Dist: uvicorn<0.52,>=0.51; extra == "mcp"
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: build<2,>=1.3; extra == "dev"
|
|
33
|
+
Requires-Dist: mcp<1.29,>=1.28.1; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy<2,>=1.18; extra == "dev"
|
|
35
|
+
Requires-Dist: pip-audit<3,>=2.9; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest<10,>=9; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-cov<8,>=7; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff<0.15,>=0.14; extra == "dev"
|
|
39
|
+
Requires-Dist: twine<7,>=6.2; extra == "dev"
|
|
40
|
+
Requires-Dist: types-requests<3,>=2.31; extra == "dev"
|
|
41
|
+
Requires-Dist: uvicorn<0.52,>=0.51; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# RZD API
|
|
45
|
+
|
|
46
|
+
Типизированный Python-клиент и MCP-сервер для неофициального API
|
|
47
|
+
[`ticket.rzd.ru`](https://ticket.rzd.ru). Проект не связан с ОАО «РЖД»; внутренние
|
|
48
|
+
endpoint и схема ответов могут изменяться без предупреждения.
|
|
49
|
+
|
|
50
|
+
Поведение TLS намеренно сохранено от версии 1.x: проверка сертификата API РЖД
|
|
51
|
+
отключена. Не передавайте клиенту собственные секреты или учётные данные.
|
|
52
|
+
|
|
53
|
+
## Возможности
|
|
54
|
+
|
|
55
|
+
- поиск прямых поездов в одну сторону и туда-обратно;
|
|
56
|
+
- поиск станций по названию и синонимам;
|
|
57
|
+
- календарь доступности и минимальные цены по датам;
|
|
58
|
+
- информация о вагонах, местах, схемах, изображениях и станциях маршрута;
|
|
59
|
+
- dataclass-модели с полным исходным объектом в `raw`;
|
|
60
|
+
- MCP через `stdio` и защищённый `streamable-http`;
|
|
61
|
+
- retries, раздельные таймауты и кэш поиска станций.
|
|
62
|
+
|
|
63
|
+
Требуется Python 3.10–3.14.
|
|
64
|
+
|
|
65
|
+
## Установка
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
pip install rzd-api
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
С MCP-сервером:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
pip install "rzd-api[mcp]"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Python API
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from datetime import date, timedelta
|
|
81
|
+
|
|
82
|
+
from rzd_api import RoundTripResult, RzdClient
|
|
83
|
+
|
|
84
|
+
departure = date.today() + timedelta(days=14)
|
|
85
|
+
return_date = departure + timedelta(days=3)
|
|
86
|
+
|
|
87
|
+
with RzdClient() as client:
|
|
88
|
+
result = client.search_tickets(
|
|
89
|
+
"Москва",
|
|
90
|
+
"Санкт-Петербург",
|
|
91
|
+
departure,
|
|
92
|
+
return_date=return_date,
|
|
93
|
+
adults=1,
|
|
94
|
+
children=0,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
if isinstance(result, RoundTripResult):
|
|
98
|
+
for train in result.forward:
|
|
99
|
+
print(train.number, train.departure_time, train.min_price)
|
|
100
|
+
for train in result.back:
|
|
101
|
+
print(train.number, train.departure_time, train.min_price)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Все модели поддерживают `to_dict()` и содержат необработанный узел ответа в `raw`.
|
|
105
|
+
|
|
106
|
+
### Методы `RzdClient`
|
|
107
|
+
|
|
108
|
+
| Метод | Результат |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `search_tickets(...)` | `list[TrainRoute]` или `RoundTripResult` |
|
|
111
|
+
| `find_stations(query, ...)` | `list[Station]` |
|
|
112
|
+
| `resolve_station_code(station)` | код станции |
|
|
113
|
+
| `get_carriages(...)` | `CarriageResult` |
|
|
114
|
+
| `get_train_availability(...)` | `TrainAvailabilityResult` |
|
|
115
|
+
| `get_minimal_prices(...)` | `MinimalPricingResult` |
|
|
116
|
+
| `get_car_scheme(...)` | `CarScheme` |
|
|
117
|
+
| `get_car_images(...)` | `CarImagesResult` |
|
|
118
|
+
| `get_route_stations(...)` | `RouteStationsResult` |
|
|
119
|
+
|
|
120
|
+
`get_carriages()` использует актуальный `CarPricing` и сразу возвращает все вагоны
|
|
121
|
+
поезда. `car_number` этому методу больше не передаётся. Значения `number`,
|
|
122
|
+
`car_sub_type`, `service_class`, `carrier` и `numeration` из выбранного `Carriage`
|
|
123
|
+
можно передать в `get_car_scheme()` и `get_car_images()`.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
with RzdClient() as client:
|
|
127
|
+
carriages = client.get_carriages(
|
|
128
|
+
"2001025", "2004001", departure, "00:48", "059Г"
|
|
129
|
+
)
|
|
130
|
+
car = carriages.cars[0]
|
|
131
|
+
scheme = client.get_car_scheme(
|
|
132
|
+
departure,
|
|
133
|
+
"00:48",
|
|
134
|
+
car.train_number or "059Г",
|
|
135
|
+
car.number or "",
|
|
136
|
+
car.car_sub_type or "",
|
|
137
|
+
car.service_class or "",
|
|
138
|
+
car.carrier or "",
|
|
139
|
+
car_numeration=car.numeration or "FromHead",
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`only_with_seats=True` фильтрует по доступности мест из `CarGroups`. Современный
|
|
144
|
+
pricing endpoint не поддерживает маршруты с пересадками и фильтр типа транспорта,
|
|
145
|
+
поэтому `include_transfers=True` и `transport_type="trains"|"suburban"` явно
|
|
146
|
+
возвращают `NotImplementedError`.
|
|
147
|
+
|
|
148
|
+
### Конфигурация
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from rzd_api import Config, RzdClient
|
|
152
|
+
|
|
153
|
+
config = Config(
|
|
154
|
+
language="ru",
|
|
155
|
+
# По умолчанию выводится из base_url.
|
|
156
|
+
b2b_base_url=None,
|
|
157
|
+
connect_timeout=5,
|
|
158
|
+
read_timeout=20,
|
|
159
|
+
retry_total=3,
|
|
160
|
+
retry_backoff=0.5,
|
|
161
|
+
station_cache_ttl=3600,
|
|
162
|
+
station_cache_size=256,
|
|
163
|
+
proxy=None,
|
|
164
|
+
)
|
|
165
|
+
client = RzdClient(config)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Ошибки наследуются от `RzdError`: validation, transport, HTTP, API, schema,
|
|
169
|
+
station-not-found и ambiguous-station.
|
|
170
|
+
|
|
171
|
+
## MCP
|
|
172
|
+
|
|
173
|
+
Инструменты: `search_tickets`, `find_stations`, `get_carriages`,
|
|
174
|
+
`get_train_availability`, `get_minimal_prices`, `get_car_scheme`,
|
|
175
|
+
`get_car_images`, `get_route_stations`.
|
|
176
|
+
|
|
177
|
+
Локальный stdio:
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
rzd-mcp-server
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Streamable HTTP на loopback без токена:
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
MCP_TRANSPORT=streamable-http MCP_HOST=127.0.0.1 rzd-mcp-server
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
При привязке к non-loopback адресу требуется Bearer-токен минимум из 32 символов:
|
|
190
|
+
|
|
191
|
+
```sh
|
|
192
|
+
export MCP_AUTH_TOKEN="replace-with-a-random-token-at-least-32-characters"
|
|
193
|
+
MCP_TRANSPORT=streamable-http MCP_HOST=0.0.0.0 rzd-mcp-server
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Endpoint MCP: `http://localhost:8000/mcp`; healthcheck: `/health`. Лимит по
|
|
197
|
+
умолчанию — 60 запросов в минуту, настраивается через
|
|
198
|
+
`MCP_RATE_LIMIT_PER_MINUTE`. Допустимые Host headers можно перечислить через
|
|
199
|
+
`MCP_ALLOWED_HOSTS`.
|
|
200
|
+
|
|
201
|
+
## Docker
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
export MCP_AUTH_TOKEN="replace-with-a-random-token-at-least-32-characters"
|
|
205
|
+
docker compose up -d
|
|
206
|
+
curl http://127.0.0.1:8000/health
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Контейнер запускается от UID 10001, без Linux capabilities, и публикует порт
|
|
210
|
+
только на loopback хоста.
|
|
211
|
+
|
|
212
|
+
## Разработка
|
|
213
|
+
|
|
214
|
+
```sh
|
|
215
|
+
python -m pip install -e ".[dev]"
|
|
216
|
+
make check
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Live smoke test является opt-in:
|
|
220
|
+
|
|
221
|
+
```sh
|
|
222
|
+
RZD_LIVE_TEST=1 pytest tests/integration -m integration -v
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Переход с 1.x описан в [MIGRATION.md](MIGRATION.md), изменения релизов — в
|
|
226
|
+
[CHANGELOG.md](CHANGELOG.md).
|
|
227
|
+
|
|
228
|
+
## Лицензия
|
|
229
|
+
|
|
230
|
+
MIT
|
rzd_api-3.0.0/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# RZD API
|
|
2
|
+
|
|
3
|
+
Типизированный Python-клиент и MCP-сервер для неофициального API
|
|
4
|
+
[`ticket.rzd.ru`](https://ticket.rzd.ru). Проект не связан с ОАО «РЖД»; внутренние
|
|
5
|
+
endpoint и схема ответов могут изменяться без предупреждения.
|
|
6
|
+
|
|
7
|
+
Поведение TLS намеренно сохранено от версии 1.x: проверка сертификата API РЖД
|
|
8
|
+
отключена. Не передавайте клиенту собственные секреты или учётные данные.
|
|
9
|
+
|
|
10
|
+
## Возможности
|
|
11
|
+
|
|
12
|
+
- поиск прямых поездов в одну сторону и туда-обратно;
|
|
13
|
+
- поиск станций по названию и синонимам;
|
|
14
|
+
- календарь доступности и минимальные цены по датам;
|
|
15
|
+
- информация о вагонах, местах, схемах, изображениях и станциях маршрута;
|
|
16
|
+
- dataclass-модели с полным исходным объектом в `raw`;
|
|
17
|
+
- MCP через `stdio` и защищённый `streamable-http`;
|
|
18
|
+
- retries, раздельные таймауты и кэш поиска станций.
|
|
19
|
+
|
|
20
|
+
Требуется Python 3.10–3.14.
|
|
21
|
+
|
|
22
|
+
## Установка
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
pip install rzd-api
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
С MCP-сервером:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pip install "rzd-api[mcp]"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Python API
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from datetime import date, timedelta
|
|
38
|
+
|
|
39
|
+
from rzd_api import RoundTripResult, RzdClient
|
|
40
|
+
|
|
41
|
+
departure = date.today() + timedelta(days=14)
|
|
42
|
+
return_date = departure + timedelta(days=3)
|
|
43
|
+
|
|
44
|
+
with RzdClient() as client:
|
|
45
|
+
result = client.search_tickets(
|
|
46
|
+
"Москва",
|
|
47
|
+
"Санкт-Петербург",
|
|
48
|
+
departure,
|
|
49
|
+
return_date=return_date,
|
|
50
|
+
adults=1,
|
|
51
|
+
children=0,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if isinstance(result, RoundTripResult):
|
|
55
|
+
for train in result.forward:
|
|
56
|
+
print(train.number, train.departure_time, train.min_price)
|
|
57
|
+
for train in result.back:
|
|
58
|
+
print(train.number, train.departure_time, train.min_price)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Все модели поддерживают `to_dict()` и содержат необработанный узел ответа в `raw`.
|
|
62
|
+
|
|
63
|
+
### Методы `RzdClient`
|
|
64
|
+
|
|
65
|
+
| Метод | Результат |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `search_tickets(...)` | `list[TrainRoute]` или `RoundTripResult` |
|
|
68
|
+
| `find_stations(query, ...)` | `list[Station]` |
|
|
69
|
+
| `resolve_station_code(station)` | код станции |
|
|
70
|
+
| `get_carriages(...)` | `CarriageResult` |
|
|
71
|
+
| `get_train_availability(...)` | `TrainAvailabilityResult` |
|
|
72
|
+
| `get_minimal_prices(...)` | `MinimalPricingResult` |
|
|
73
|
+
| `get_car_scheme(...)` | `CarScheme` |
|
|
74
|
+
| `get_car_images(...)` | `CarImagesResult` |
|
|
75
|
+
| `get_route_stations(...)` | `RouteStationsResult` |
|
|
76
|
+
|
|
77
|
+
`get_carriages()` использует актуальный `CarPricing` и сразу возвращает все вагоны
|
|
78
|
+
поезда. `car_number` этому методу больше не передаётся. Значения `number`,
|
|
79
|
+
`car_sub_type`, `service_class`, `carrier` и `numeration` из выбранного `Carriage`
|
|
80
|
+
можно передать в `get_car_scheme()` и `get_car_images()`.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
with RzdClient() as client:
|
|
84
|
+
carriages = client.get_carriages(
|
|
85
|
+
"2001025", "2004001", departure, "00:48", "059Г"
|
|
86
|
+
)
|
|
87
|
+
car = carriages.cars[0]
|
|
88
|
+
scheme = client.get_car_scheme(
|
|
89
|
+
departure,
|
|
90
|
+
"00:48",
|
|
91
|
+
car.train_number or "059Г",
|
|
92
|
+
car.number or "",
|
|
93
|
+
car.car_sub_type or "",
|
|
94
|
+
car.service_class or "",
|
|
95
|
+
car.carrier or "",
|
|
96
|
+
car_numeration=car.numeration or "FromHead",
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`only_with_seats=True` фильтрует по доступности мест из `CarGroups`. Современный
|
|
101
|
+
pricing endpoint не поддерживает маршруты с пересадками и фильтр типа транспорта,
|
|
102
|
+
поэтому `include_transfers=True` и `transport_type="trains"|"suburban"` явно
|
|
103
|
+
возвращают `NotImplementedError`.
|
|
104
|
+
|
|
105
|
+
### Конфигурация
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from rzd_api import Config, RzdClient
|
|
109
|
+
|
|
110
|
+
config = Config(
|
|
111
|
+
language="ru",
|
|
112
|
+
# По умолчанию выводится из base_url.
|
|
113
|
+
b2b_base_url=None,
|
|
114
|
+
connect_timeout=5,
|
|
115
|
+
read_timeout=20,
|
|
116
|
+
retry_total=3,
|
|
117
|
+
retry_backoff=0.5,
|
|
118
|
+
station_cache_ttl=3600,
|
|
119
|
+
station_cache_size=256,
|
|
120
|
+
proxy=None,
|
|
121
|
+
)
|
|
122
|
+
client = RzdClient(config)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Ошибки наследуются от `RzdError`: validation, transport, HTTP, API, schema,
|
|
126
|
+
station-not-found и ambiguous-station.
|
|
127
|
+
|
|
128
|
+
## MCP
|
|
129
|
+
|
|
130
|
+
Инструменты: `search_tickets`, `find_stations`, `get_carriages`,
|
|
131
|
+
`get_train_availability`, `get_minimal_prices`, `get_car_scheme`,
|
|
132
|
+
`get_car_images`, `get_route_stations`.
|
|
133
|
+
|
|
134
|
+
Локальный stdio:
|
|
135
|
+
|
|
136
|
+
```sh
|
|
137
|
+
rzd-mcp-server
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Streamable HTTP на loopback без токена:
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
MCP_TRANSPORT=streamable-http MCP_HOST=127.0.0.1 rzd-mcp-server
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
При привязке к non-loopback адресу требуется Bearer-токен минимум из 32 символов:
|
|
147
|
+
|
|
148
|
+
```sh
|
|
149
|
+
export MCP_AUTH_TOKEN="replace-with-a-random-token-at-least-32-characters"
|
|
150
|
+
MCP_TRANSPORT=streamable-http MCP_HOST=0.0.0.0 rzd-mcp-server
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Endpoint MCP: `http://localhost:8000/mcp`; healthcheck: `/health`. Лимит по
|
|
154
|
+
умолчанию — 60 запросов в минуту, настраивается через
|
|
155
|
+
`MCP_RATE_LIMIT_PER_MINUTE`. Допустимые Host headers можно перечислить через
|
|
156
|
+
`MCP_ALLOWED_HOSTS`.
|
|
157
|
+
|
|
158
|
+
## Docker
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
export MCP_AUTH_TOKEN="replace-with-a-random-token-at-least-32-characters"
|
|
162
|
+
docker compose up -d
|
|
163
|
+
curl http://127.0.0.1:8000/health
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Контейнер запускается от UID 10001, без Linux capabilities, и публикует порт
|
|
167
|
+
только на loopback хоста.
|
|
168
|
+
|
|
169
|
+
## Разработка
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
python -m pip install -e ".[dev]"
|
|
173
|
+
make check
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Live smoke test является opt-in:
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
RZD_LIVE_TEST=1 pytest tests/integration -m integration -v
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Переход с 1.x описан в [MIGRATION.md](MIGRATION.md), изменения релизов — в
|
|
183
|
+
[CHANGELOG.md](CHANGELOG.md).
|
|
184
|
+
|
|
185
|
+
## Лицензия
|
|
186
|
+
|
|
187
|
+
MIT
|