
tfl-ts
io.github.ghcpuman902由 GitHub 账号 ghcpuman902 发布v2.15.2更新于 Oct 30, 2026
Read-only Transport for London data: line status, arrivals, journeys, stop lookup.
概览
只读的伦敦交通局(TfL)MCP 服务器,可查询线路状态、到站信息、行程规划与站点查找,并提供离线文档与站点拓扑。
- 可以做什么
- 查询线路状态与运营中断,并规划站点之间的行程
- 搜索车站与公交站,解析线路 ID 或站点 ID
- 获取站点实时到站信息,带缓存与限流
- 读取随包附带的离线文档、静态站点顺序与枢纽信息
- 查看支持的模式并解析线路标识,无需调用 TfL
- 适用场景
- 当助手需要回答伦敦交通问题——当前线路状态、下一班到站或行程规划——或需要查找 TfL 线路与站点标识时适用。静态工具可离线使用,因此没有 API 密钥时也可用于查阅文档和站点拓扑。
- 运行要求
- 以 stdio 方式在本地运行,通常通过 npx 加 mcp 子命令启动,因此需要 Node.js。实时工具需要在环境变量 TFL_APP_KEY 中提供 TfL API 主密钥;静态工具(docs、resolve_line_id、get_supported_modes)无需密钥。可选环境变量 TFL_MCP_MIN_INTERVAL_MS 设置对外请求的最小间隔(默认 250 毫秒)。实时数据需要网络访问。
安装
在 SourceWeft 中
- 打开 控制台中的 tfl-ts,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
TfL API TypeScript Client
[npm version] [License: MIT] [TypeScript] [Node.js] [CI]
[tfl CLI checking central and victoria, then listing the journey endpoints] [Board at tfl.manglekuo.com, with line status and live arrivals]Typed TfL client: friendly wrappers, 84 raw REST endpoints, and offline station topology for 20 rail lines.
Built with tfl-ts → Board
How this compares
Counts use the 84 operations in the committed OpenAPI snapshot (ENDPOINT_COUNT in src/generated/endpoints.ts, pathCount in src/generated/openapi/spec.meta.json). Checked against each repo's source and the package.json published to npm on 16 October 2026.
tfl-ts publishes .d.ts files. Runtime dependencies: none. typescript is a peer dependency, for people compiling against the types. Station order and hubs ship in tfl-ts/meta, with no network call. tfl mcp is the local MCP server.
tfl-unified-api 2.0.2 is JavaScript, with no types field. It depends on moment, request, and request-promise-native. The Line module calls ten of the 84 paths: meta modes, severity, disruption categories, service types, route sequence, route by id, lines by mode, status by id, status over a date range, and status by mode. getRoutesByServiceType builds /Line/Route/{types}, which sits outside those 84 paths. db/lineColors.json is line colours, not stations.
tfl-journey-planner 1.1.2 is LiveScript compiled to JavaScript, with no types field. It depends on request and querystring. The module calls GET /Journey/JourneyResults/{from}/to/{to} only.
@daanrongen/tfl-mcp 1.4.3 is written in TypeScript. The published tarball is dist/main.js, package.json, and README.md, and package.json has no types field. It depends on @modelcontextprotocol/sdk, effect, and zod. Its tools call 59 of the 84 paths. They also call /Road/all/Disruption (the snapshot path is /Road/all/Disruption/{disruptionIds}), /Vehicle/EmissionSurcharge, and /Vehicle/UlezCompliance.
@pipeworx/mcp-tfl 0.1.2 sets "types": "src/index.ts", and that file is in the tarball. It depends on @modelcontextprotocol/sdk and tsx. Six tools call 8 of the 84 paths.
Station order ships with tfl-ts, in tfl-ts/meta.
Install and first call
Get a Primary key from the TfL API Portal. Subscribe to "500 Requests per min", then Profile → Show.
Line names, station order, and colours ship in the package. Status, arrivals, and journeys hit TfL at runtime.
On the portal you'll see two keys (Primary and Secondary); either works. app_id has been unused since Jan 2021.
Pass credentials in the constructor instead
Quick starts
Node
Next.js
Server Component with ISR (~60s). Boards and explorer: tfl-components · tfl.manglekuo.com/docs/explorer. Tube boards use official line colours; bus boards use route-number chips. Do not mix. See examples/README.md.
The roundel ships a placeholder unless NEXT_PUBLIC_ALLOW_TFL_ROUNDEL=true (you accept trademark responsibility).
Agent / MCP
Read-only MCP (npx tfl-ts mcp), cached and rate-limited. Static tools never call TfL. The npm bin is tfl (dist/cjs/bin/tfl.js); mcp is the stdio subcommand. Setup: docs/mcp.md.
Tools: get_supported_modes, resolve_line_id, docs, resolve_stop_id, get_line_status, get_arrivals, plan_journey.
No repo access, or lost your context? npx tfl-ts docs ls lists every bundled agent doc (this README, CLAUDE.md, docs/agent.md, docs/mcp.md, …). docs cat <id> prints one, and docs find <query> / docs grep <pattern> search across all of them — offline, no API key. The local MCP docs tool reads the same catalogue.
Gotchas
- Line IDs are lowercase slugs:
'central','victoria','elizabeth'. Not display names like'Central'. - Stop IDs look like
'940GZZLUOXC'. Resolve withstopPoint.search()orplace.search(). - Bus stops accept 5-digit NaPTAN-style codes in search (for example
'51800'). - Prefer static constants (
LINE_NAMES,STATION_SEQUENCES, mode lists) before live calls. - Cache status for about 30 to 60s. Do not poll arrivals faster than about 10 to 15s per stop.
accidentStatsandairQualityare deprecated.- National Rail arrivals aren't live through TfL:
STATION_HUBStracks Southeastern, South Western Railway, and similar operators for topology, butgetArrivals()returns an empty array for them, not an error. - Tube boards use official line colours; bus boards use route-number chips. Do not mix patterns.
- Roundel trademark: placeholder unless the consumer opts in.
- A line can carry several
lineStatuses. Do not read[0]. UsegetWorstCurrentStatus(line.lineStatuses)for the operative row. validityPeriods[].isNowfollowsdisruption.category === 'RealTime'. It is not a clock check. Planned engineering can be in force today withisNow: false.validityPeriods[].toDateis the window end, not when trains resume. Weekend engineering often ends at00:29Z(01:29 London, end of the traffic day). Overnight-split slices on one row are one possession; do not treat the first overlappingtoDateas the next train.- Severity 20 is scheduled closure (Waterloo & City weekends, end of traffic day), not an unplanned Closed (1).
sortLinesBySeverityAndOrderranks it after incidents. - Circle / H&C / Met
lineIdflips along shared track. UsewithSharedTrackIdentity. Do not rewrite rawlineId.
Before and after
getDetailedStatus() returns shorter types and renamed fields (severity, from, closureType, originName) instead of TfL's generated shapes:
Use getStatus({ detail: true }) or client.raw.line.* for exact TfL field names.
Station sequences
Tube, Elizabeth line, DLR, Overground, Tram, and river-bus pier topology. No credentials, no network. Identity, order, and branches only (no status or arrivals). River piers are not in STATION_HUBS — poll the NaptanFerryPort id. Live topology: client.line.getRouteSequence(). Also on the client: client.line.STATION_SEQUENCES.
Station hubs and normalised arrivals
STATION_HUBS maps each physical station to its sibling StopPoint ids and the specific id that carries arrivals for each line — Liverpool Street's tube id (940GZZLULVT) and rail id (910GLIVST) both resolve to one HUBLST entry, with Central on the tube id and Elizabeth line on the rail id. No credentials, no network.
resolveArrivalsStopId returns undefined when the hub doesn't carry that line, rather than the interchange id — polling the interchange id itself returns zero arrivals from TfL. Third-party National Rail operators (Southeastern, South Western Railway, c2c, and similar) show up in the hub's topology but never return live predictions: TfL's Arrivals API only covers tube, DLR, tram, Overground, and Elizabeth line.
client.stopPoint.getNormalizedArrivals() is getArrivals() plus a cleaned destination (falls through empty or literal "null" towards to destinationName, common on Elizabeth line, Overground, and some bus termini) and platform (compass bound, cleaned label, isUnknown for TfL's literal "Platform Unknown"):
getArrivals() and client.raw.* are unchanged.
client.stopPoint.get and getByGeoPoint lift Direction additional properties onto the stop: towards, compassPoint, and compassBearingDegrees. smsCode is filled from the first-class field or bag SmsCode. Facility keys stay in additionalProperties as TfL strings. parseAdditionalPropertyValue turns a bag value into null / boolean / number / date / text ("yes", "null", unix ms InstallDate). client.raw.stopPoint.* is unlifted. Do not use Prediction bearing (vehicle heading) as the stop flag; a painted stopLetter of W is Stop W, not west.
On Circle / Hammersmith & City / Metropolitan shared track, TfL assigns lineId per station, not per train. The same vehicleId can be circle at Victoria and hammersmith-city at Liverpool Street. withSharedTrackIdentity(stopRows, lineIds, networkArrivals) adds sharedTrackIdentity (canonicalLineId from an exclusive-segment hit, or ambiguous + rawLineIds). It does not rewrite raw lineId. line.getArrivals({ lineIds }) with no stopPointId is the network-wide poll that evidence needs.
Colours, severity, and detailed types
Northern defaults to outline dark contrast. Pass { darkContrastMode: 'white' } for white fill/text. See CHANGELOG.md (2.4.0). Raw escape hatch: client.raw.line.statusByIds({ ids: ['central'] }).
Realtime
Poll arrivals with the same app_key as REST. No SignalR. Details: docs/REALTIME.md.
Module index
Zero runtime dependencies (Node, browser, and edge with fetch).
Deeper docs
All of the above ship in the npm package and are readable offline via npx tfl-ts docs ls|cat|find|grep or the MCP docs tool — no clone required.
Playground demos under playground/demo/ are for clones, not package consumers.
Architecture
pnpm run build compiles TypeScript to CJS and ESM. No network, no OpenAPI regeneration.
Contributing
Useful scripts: pnpm run generate, pnpm run check, pnpm run check -- --only=drift, pnpm exec tfl list. See LLM_context.md and .cursor/skills/tfl-ts-maintainer/SKILL.md.
License
MIT. Not affiliated with Transport for London.
来源:README.md,提交 cb241b6
工具
0版本历史
1- v2.15.2最新Oct 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分