yyc-transit-mcp 0.1.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.
- yyc_transit_mcp-0.1.0/.gitignore +228 -0
- yyc_transit_mcp-0.1.0/CHANGELOG.md +21 -0
- yyc_transit_mcp-0.1.0/LICENSE +21 -0
- yyc_transit_mcp-0.1.0/PKG-INFO +234 -0
- yyc_transit_mcp-0.1.0/README.md +198 -0
- yyc_transit_mcp-0.1.0/pyproject.toml +97 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/__init__.py +5 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/agent/__init__.py +0 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/agent/agent.py +252 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/agent/cli.py +70 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/config.py +49 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/db/__init__.py +0 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/db/migrate.py +31 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/db/pool.py +12 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/db/queries.py +293 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/gtfs_time.py +39 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/ingest/__init__.py +0 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/ingest/cli.py +48 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/ingest/static_gtfs.py +333 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/log.py +26 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/migrations/env.py +30 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/migrations/script.py.mako +21 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/migrations/versions/0001_enable_postgis.py +25 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/migrations/versions/0002_gtfs_schema.py +127 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/migrations/versions/0003_realtime.py +105 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/migrations/versions/0004_stop_delays_scheduled_s.py +35 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/models.py +107 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/py.typed +0 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/realtime/__init__.py +0 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/realtime/feeds.py +61 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/realtime/parse.py +274 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/realtime/poller.py +306 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/server.py +152 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/service_days.py +17 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/__init__.py +4 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/alerts.py +44 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/arrivals.py +82 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/meta.py +38 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/reliability.py +96 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/routes.py +82 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/stops.py +158 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/tools/vehicles.py +36 -0
- yyc_transit_mcp-0.1.0/src/yyc_transit/worker.py +84 -0
- yyc_transit_mcp-0.1.0/tests/__init__.py +0 -0
- yyc_transit_mcp-0.1.0/tests/conftest.py +47 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/README.md +17 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/agency.txt +2 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/calendar.txt +3 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/calendar_dates.txt +3 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/routes.txt +3 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/stop_times.txt +9 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/stops.txt +9 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/gtfs_mini/trips.txt +5 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/rt/README.md +23 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/rt/alerts.pb +0 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/rt/trip_updates.pb +0 -0
- yyc_transit_mcp-0.1.0/tests/fixtures/rt/vehicle_positions.pb +0 -0
- yyc_transit_mcp-0.1.0/tests/rt_rows.py +58 -0
- yyc_transit_mcp-0.1.0/tests/test_agent.py +222 -0
- yyc_transit_mcp-0.1.0/tests/test_config.py +25 -0
- yyc_transit_mcp-0.1.0/tests/test_eval_grade.py +154 -0
- yyc_transit_mcp-0.1.0/tests/test_frozen_clock.py +26 -0
- yyc_transit_mcp-0.1.0/tests/test_gtfs_time.py +54 -0
- yyc_transit_mcp-0.1.0/tests/test_ingest_helpers.py +75 -0
- yyc_transit_mcp-0.1.0/tests/test_log.py +42 -0
- yyc_transit_mcp-0.1.0/tests/test_migrations.py +67 -0
- yyc_transit_mcp-0.1.0/tests/test_poller.py +285 -0
- yyc_transit_mcp-0.1.0/tests/test_realtime_feeds.py +89 -0
- yyc_transit_mcp-0.1.0/tests/test_release.py +39 -0
- yyc_transit_mcp-0.1.0/tests/test_routes_normalize.py +133 -0
- yyc_transit_mcp-0.1.0/tests/test_rt_parse.py +191 -0
- yyc_transit_mcp-0.1.0/tests/test_server.py +28 -0
- yyc_transit_mcp-0.1.0/tests/test_service_days.py +33 -0
- yyc_transit_mcp-0.1.0/tests/test_static_ingest.py +110 -0
- yyc_transit_mcp-0.1.0/tests/test_tools_arrivals.py +92 -0
- yyc_transit_mcp-0.1.0/tests/test_tools_live.py +113 -0
- yyc_transit_mcp-0.1.0/tests/test_tools_reliability.py +75 -0
- yyc_transit_mcp-0.1.0/tests/test_tools_stops.py +104 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs/Zensical documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
221
|
+
|
|
222
|
+
# Eval runs: keep results.jsonl, drop bulky/derived output
|
|
223
|
+
.claude/hillclimb/**/traces/
|
|
224
|
+
.claude/hillclimb/**/report.html
|
|
225
|
+
.claude/hillclimb/**/trajectory/
|
|
226
|
+
|
|
227
|
+
# Personal build notes (kept locally, not published)
|
|
228
|
+
PLAN.md
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-11-17)
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- **Six read-only tools:** `find_stops`, `next_arrivals`, `route_alerts`, `vehicles_on_route`,
|
|
8
|
+
`route_reliability`, `compare_routes`.
|
|
9
|
+
- **Worker:** loads the static schedule nightly and polls GTFS-Realtime every 30 s, keeping
|
|
10
|
+
live state and one-row-per-stop-visit delay history.
|
|
11
|
+
- **Feed cleanup:** handles the +24 h evening timestamps, junk times, split trips, CTrain
|
|
12
|
+
predictions about an hour off, and stale or truncated feeds.
|
|
13
|
+
- **Migrations:** ship in the package and run with `yyc-transit-migrate`.
|
|
14
|
+
- **Docker Compose self-hosting:** database, migrations, worker and MCP server
|
|
15
|
+
(streamable HTTP on port 8000).
|
|
16
|
+
- **Optional `agent` extra:** `yyc-transit-agent` asks Claude a question through the tools.
|
|
17
|
+
- **Route names:** stops, arrivals and alerts show CTrain and MAX lines by name
|
|
18
|
+
(`Red Line (201)`, `MAX Teal (MT)`); station searches list CTrain platforms first;
|
|
19
|
+
`find_stops` takes a `route` to keep only the stops that route serves.
|
|
20
|
+
- **Eval suite:** 40 cases with SQL ground truth. Baseline 94.2% answer accuracy with
|
|
21
|
+
Claude Haiku 5.5; 100% after the route-name fixes.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abiola Raji
|
|
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.
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: yyc-transit-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for Calgary Transit: live arrivals, alerts, and historical route reliability from GTFS + GTFS-Realtime.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Abiolr/calgary-transit-MCP
|
|
6
|
+
Project-URL: Repository, https://github.com/Abiolr/calgary-transit-MCP
|
|
7
|
+
Project-URL: Issues, https://github.com/Abiolr/calgary-transit-MCP/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Abiolr/calgary-transit-MCP/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Abiola Raji
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: calgary,gtfs,gtfs-realtime,mcp,model-context-protocol,transit
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Requires-Dist: alembic>=1.13
|
|
23
|
+
Requires-Dist: apscheduler<4,>=3.10
|
|
24
|
+
Requires-Dist: gtfs-realtime-bindings>=1.0
|
|
25
|
+
Requires-Dist: httpx>=0.27
|
|
26
|
+
Requires-Dist: mcp<3,>=2.3
|
|
27
|
+
Requires-Dist: psycopg[binary,pool]>=3.2
|
|
28
|
+
Requires-Dist: pydantic-settings>=2.3
|
|
29
|
+
Requires-Dist: pydantic>=2.7
|
|
30
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
31
|
+
Requires-Dist: structlog>=24.1
|
|
32
|
+
Requires-Dist: tzdata>=2026.5
|
|
33
|
+
Provides-Extra: agent
|
|
34
|
+
Requires-Dist: anthropic>=0.40; extra == 'agent'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# yyc-transit-mcp
|
|
38
|
+
|
|
39
|
+
[](https://github.com/Abiolr/calgary-transit-MCP/actions/workflows/ci.yml)
|
|
40
|
+
|
|
41
|
+
<!-- mcp-name: io.github.Abiolr/yyc-transit-mcp -->
|
|
42
|
+
|
|
43
|
+
An [MCP](https://modelcontextprotocol.io) server that lets AI assistants answer
|
|
44
|
+
**"when's my bus, and can I trust it?"** with Calgary Transit data:
|
|
45
|
+
- live arrivals;
|
|
46
|
+
- service alerts;
|
|
47
|
+
- bus positions;
|
|
48
|
+
- **historical on-time reliability**, which it measures itself from the live feeds.
|
|
49
|
+
|
|
50
|
+
> **When's the next 3 at Centre St and 16 Ave?**
|
|
51
|
+
> The next Route 3 at Centre St and 16 Ave is the northbound one at **11:52 PM** tonight,
|
|
52
|
+
> but that time is scheduled only, with no live tracking. The next live-tracked northbound
|
|
53
|
+
> buses are at 12:26 AM and 12:51 AM.
|
|
54
|
+
>
|
|
55
|
+
> **How reliable is route 1?**
|
|
56
|
+
> About 85.8% of observed trips were on time (within 1 minute early to 5 minutes late)…
|
|
57
|
+
> However, this is based on only 1 day of data (239 observations), so the history is too
|
|
58
|
+
> short to be a solid measure.
|
|
59
|
+
>
|
|
60
|
+
> **Plan me a trip from Tuscany to the airport with two transfers.**
|
|
61
|
+
> I can't plan multi-leg trips with transfers… Calgary Transit's trip planner or app can do that.
|
|
62
|
+
|
|
63
|
+
<sub>These are real answers from the [eval suite](#evals) (Claude Haiku 5.5), lightly trimmed.</sub>
|
|
64
|
+
|
|
65
|
+
## Tools
|
|
66
|
+
|
|
67
|
+
| Tool | What it answers |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `find_stops` | Stops by name ("Centre St and 16 Ave"), stop number ("#4585") or location, with the routes serving each |
|
|
70
|
+
| `next_arrivals` | Next arrivals at a stop in the next 3 hours: live, scheduled or cancelled |
|
|
71
|
+
| `route_alerts` | Active detours, closures and delays for a route or stop |
|
|
72
|
+
| `vehicles_on_route` | Live bus positions on a route, with headsign and delay |
|
|
73
|
+
| `route_reliability` | Historical on-time %, median and 90th-percentile delay, by time of day |
|
|
74
|
+
| `compare_routes` | Reliability for two routes side by side |
|
|
75
|
+
|
|
76
|
+
- **Route names:** riders can name routes the way they say them: "3", "route 3", "MAX Teal", "Red Line".
|
|
77
|
+
- **Times:** all times are Calgary local time.
|
|
78
|
+
- **Freshness:** every response says how fresh its data is (`meta.data_as_of`, `meta.is_stale`). Live predictions are withheld when the City's feed is stale.
|
|
79
|
+
- **Read-only:** every tool only reads data.
|
|
80
|
+
|
|
81
|
+
**Limitations**
|
|
82
|
+
- Calgary Transit only.
|
|
83
|
+
- Direct routes only; no trip planning with transfers.
|
|
84
|
+
- The City doesn't publish CTrain positions; CTrain arrivals and alerts work.
|
|
85
|
+
- CTrain reliability isn't measured yet: the City's CTrain predictions are an hour off, and
|
|
86
|
+
live arrivals correct for it, but the history waits until the correction is verified.
|
|
87
|
+
- Reliability is computed from history the worker collects, so it needs a few days of running before the numbers mean much. Until then, results say `enough_data: false`.
|
|
88
|
+
|
|
89
|
+
## How it fits together
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
City of Calgary open data your machine / server
|
|
93
|
+
─────────────────────────── ───────────────────────────────────────────
|
|
94
|
+
static GTFS (nightly) ──▶ worker ──▶ Postgres + PostGIS ◀── MCP server ◀── Claude
|
|
95
|
+
GTFS-Realtime (30 s) ──▶ (schedule, live state, (6 tools)
|
|
96
|
+
delay history)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The **worker** has to run all the time: it keeps the live state current and writes the delay
|
|
100
|
+
history that reliability is computed from. The **MCP server** only reads the database.
|
|
101
|
+
|
|
102
|
+
## Quick start (Docker)
|
|
103
|
+
|
|
104
|
+
Needs Docker. This starts the database, runs the migrations, loads the schedule (about a
|
|
105
|
+
minute) and starts polling the live feeds:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
git clone https://github.com/Abiolr/calgary-transit-MCP.git
|
|
109
|
+
cd calgary-transit-MCP
|
|
110
|
+
docker compose up -d
|
|
111
|
+
docker compose logs -f worker # wait for "rt_poll.done" lines
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The MCP server is now at `http://localhost:8000/mcp`.
|
|
115
|
+
|
|
116
|
+
### Connect your assistant
|
|
117
|
+
|
|
118
|
+
**Claude Code:**
|
|
119
|
+
```bash
|
|
120
|
+
claude mcp add --transport http yyc-transit http://localhost:8000/mcp
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Claude Desktop**, or any client that launches servers over stdio: run the server with
|
|
124
|
+
[uv](https://docs.astral.sh/uv/) and point it at the database:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"mcpServers": {
|
|
129
|
+
"yyc-transit": {
|
|
130
|
+
"command": "uvx",
|
|
131
|
+
"args": ["yyc-transit-mcp"],
|
|
132
|
+
"env": { "DATABASE_URL": "postgresql://transit:transit@localhost:5432/transit" }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
To try it without a client, use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
|
|
139
|
+
`npx @modelcontextprotocol/inspector`, then connect to `http://localhost:8000/mcp`.
|
|
140
|
+
|
|
141
|
+
## Install without Docker
|
|
142
|
+
|
|
143
|
+
You need Postgres 16 with PostGIS 3.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
pip install yyc-transit-mcp # or: uv tool install yyc-transit-mcp
|
|
147
|
+
export DATABASE_URL=postgresql://user:pass@host:5432/transit
|
|
148
|
+
yyc-transit-migrate # create or upgrade the schema
|
|
149
|
+
yyc-transit-worker # load the schedule, then poll; keep it running
|
|
150
|
+
yyc-transit-mcp # MCP server over stdio (default)
|
|
151
|
+
yyc-transit-mcp --transport streamable-http --host 0.0.0.0 --port 8000
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
| Command | What it does |
|
|
155
|
+
|---|---|
|
|
156
|
+
| `yyc-transit-migrate` | Creates or upgrades the database schema |
|
|
157
|
+
| `yyc-transit-worker` | Always-on: loads the schedule nightly and polls the live feeds every 30 s |
|
|
158
|
+
| `yyc-transit-ingest --download` | Loads the latest schedule once (the worker does this for you) |
|
|
159
|
+
| `yyc-transit-mcp` | The MCP server (`--transport stdio` or `streamable-http`) |
|
|
160
|
+
| `yyc-transit-agent "question"` | Asks Claude a question through the tools. Needs `pip install "yyc-transit-mcp[agent]"` and `ANTHROPIC_API_KEY` |
|
|
161
|
+
|
|
162
|
+
### Configuration
|
|
163
|
+
|
|
164
|
+
Set these as environment variables, or in a `.env` file in the working directory:
|
|
165
|
+
|
|
166
|
+
| Variable | Default | |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| `DATABASE_URL` | `postgresql://transit:transit@localhost:5432/transit` | Postgres + PostGIS |
|
|
169
|
+
| `RT_POLL_SECONDS` | `30` | How often the worker polls the live feeds |
|
|
170
|
+
| `RT_STALE_AFTER_SECONDS` | `120` | Live data older than this is reported as stale |
|
|
171
|
+
| `GTFS_STATIC_URL`, `GTFS_RT_*_URL` | City of Calgary open data | Feed locations |
|
|
172
|
+
| `ANTHROPIC_API_KEY` | | Only for `yyc-transit-agent` |
|
|
173
|
+
| `AGENT_MODEL` | `claude-haiku-5-5` | Model used by `yyc-transit-agent` |
|
|
174
|
+
|
|
175
|
+
### Hosting
|
|
176
|
+
|
|
177
|
+
Run the worker on an always-on host; if it sleeps, the reliability history gets gaps.
|
|
178
|
+
- **Resource use:** about 70 MB of RAM for the worker and about 300 MB for Postgres.
|
|
179
|
+
- **History growth:** tens of MB a day.
|
|
180
|
+
- **Railway:** a PostGIS template plus this repo's `Dockerfile` (start command
|
|
181
|
+
`yyc-transit-worker`, pre-deploy `yyc-transit-migrate`) works as is.
|
|
182
|
+
|
|
183
|
+
## Evals
|
|
184
|
+
|
|
185
|
+
The repo includes an eval suite that measures how well an LLM uses the tools: 40 rider
|
|
186
|
+
questions covering:
|
|
187
|
+
- stops, arrivals, alerts, vehicles, reliability and comparisons;
|
|
188
|
+
- questions out of scope that it should decline;
|
|
189
|
+
- questions it should answer with honest uncertainty.
|
|
190
|
+
|
|
191
|
+
Ground truth comes from SQL against a frozen database snapshot, never from an LLM.
|
|
192
|
+
|
|
193
|
+
Claude Haiku 5.5, 40 cases × 3 runs:
|
|
194
|
+
|
|
195
|
+
| | Baseline | Now |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| Answer correct | 94.2% (95% CI 88–97%) | **100%** (95% CI 97–100%) |
|
|
198
|
+
| Right tools called | 100% | **100%** |
|
|
199
|
+
| Latency p50 / p95 | 2.6 s / 6.1 s | 2.2 s / 4.3 s |
|
|
200
|
+
| Tool calls per question | 1.2 | 1.2 |
|
|
201
|
+
| Cost of a full run | about $0.08 | about $0.08 |
|
|
202
|
+
|
|
203
|
+
All 7 baseline failures were arrival questions, caused by the tools rather than the model:
|
|
204
|
+
- **City Hall:** a bus stop named "City Hall LRT Station" ranked above the CTrain platforms,
|
|
205
|
+
which were listed as routes "201" and "202".
|
|
206
|
+
- **MAX Teal:** results showed the route code "MT" without the name "MAX Teal".
|
|
207
|
+
|
|
208
|
+
The fixes:
|
|
209
|
+
- CTrain and MAX lines are shown by name (`Red Line (201)`, `MAX Teal (MT)`);
|
|
210
|
+
- station searches list CTrain platforms first;
|
|
211
|
+
- `find_stops` takes a `route`, so a station's many bays narrow to the ones that route serves.
|
|
212
|
+
|
|
213
|
+
The suite is small, so 100% means these 40 questions pass, not that every question will.
|
|
214
|
+
|
|
215
|
+
Results are in [`.claude/hillclimb/transit-agent/`](https://github.com/Abiolr/calgary-transit-MCP/tree/main/.claude/hillclimb/transit-agent)
|
|
216
|
+
(`baseline/`, then `v1/` and `v2/`);
|
|
217
|
+
how to run the suite is in [CONTRIBUTING.md](https://github.com/Abiolr/calgary-transit-MCP/blob/main/CONTRIBUTING.md#evals).
|
|
218
|
+
|
|
219
|
+
## More
|
|
220
|
+
|
|
221
|
+
- [How it works](https://github.com/Abiolr/calgary-transit-MCP/blob/main/docs/how-it-works.md): schema, the live feed's quirks and how they're cleaned, measurements
|
|
222
|
+
- [CONTRIBUTING.md](https://github.com/Abiolr/calgary-transit-MCP/blob/main/CONTRIBUTING.md): development setup, tests, evals
|
|
223
|
+
- [CHANGELOG.md](https://github.com/Abiolr/calgary-transit-MCP/blob/main/CHANGELOG.md)
|
|
224
|
+
|
|
225
|
+
## Data & licence
|
|
226
|
+
|
|
227
|
+
Contains information licensed under the
|
|
228
|
+
Open Government Licence – City of Calgary
|
|
229
|
+
([City of Calgary open data](https://data.calgary.ca)).
|
|
230
|
+
Every tool response carries this attribution. The data is fetched from the City at run time
|
|
231
|
+
and isn't included in this package.
|
|
232
|
+
|
|
233
|
+
The code is MIT licensed; see [LICENSE](https://github.com/Abiolr/calgary-transit-MCP/blob/main/LICENSE). This project is not affiliated with
|
|
234
|
+
Calgary Transit or the City of Calgary.
|