Skip to main content
Glama

comboios-mcp

An unofficial Model Context Protocol server for Portuguese trains run by Comboios de Portugal (CP). It lets an assistant such as Claude or ChatGPT find stations, search journeys with fares, read live departure boards and train positions, report service alerts and, optionally, sell a ticket through CP's own payment system.

Not affiliated with CP – Comboios de Portugal. The server uses the same undocumented back end as the cp.pt website, with the public credentials that website ships to every browser. It can stop working whenever CP changes that back end. Tickets are issued and charged by CP. Use it with respect for CP's services: the server caches aggressively and limits itself to one upstream request per second.

What it can do

Tool

Purpose

procurar_estacao

Find stations by name (fuzzy, accents optional) and return their CP codes (94-xxxx).

info_estacao

Line, address, step-free access and facilities of a station.

horarios

Journeys between two stations on a date: times, legs, changes and fares, with filters for time window, class, passengers, service and direct trains.

mostrar_horarios

The same search shown as interactive cards in the chat (MCP Apps), each with a buy button. The assistant uses it only when the user wants to compare trains or buy.

precos

Fares for 1st and 2nd class, optionally for one train.

partidas_chegadas

Live departures or arrivals for a station, including the first trains after midnight on late requests.

estado_comboio

Live status of a train: delay, last station passed and every stop. Falls back to Infraestruturas de Portugal if CP fails.

perturbacoes

Current alerts (strikes, works, disruptions) with a text filter.

classes_e_regras

Travel classes, booking horizon, passenger limits and service codes.

comprar_bilhete

With payments enabled: a link to the purchase page for a journey option. It reserves nothing by itself.

link_compra

With payments disabled: a link that opens the same search on cp.pt.

Station arguments accept a name or a code; an ambiguous name such as "Lisboa" returns the candidates instead of a guess. Dates are YYYY-MM-DD and times HH:MM, in Europe/Lisbon.

Related MCP server: mcp-swisstransport

Use the public instance

Add the server as a custom connector. No sign-in is needed.

  • Claude (web, desktop, mobile): Settings → Connectors → Add custom connector → https://comboios.noodg.com/mcp

  • ChatGPT and other MCP clients: add https://comboios.noodg.com/mcp as a remote MCP server (Streamable HTTP).

The landing page at https://comboios.noodg.com explains the service and what data goes where.

Run your own

Requires Node.js 20 or later.

npm install
npm run build

Local, over stdio

Claude Code:

claude mcp add comboios -- node /absolute/path/to/comboios-mcp/dist/index.js

Claude Desktop (claude_desktop_config.json); use the full path to node, because the app does not read your shell's PATH:

{
  "mcpServers": {
    "comboios": { "command": "/opt/homebrew/bin/node", "args": ["/absolute/path/to/comboios-mcp/dist/index.js"] }
  }
}

Locally, payments are disabled and buying goes through a cp.pt link.

Local, over HTTP

HTTP mode binds to 127.0.0.1 and requires a bearer token of at least 16 characters.

CP_MCP_TOKEN="$(openssl rand -hex 24)" node dist/index.js --http --port 8787

Hosted on Vercel

vercel.json deploys api/mcp.js (the MCP endpoint at /mcp), api/pay.js and public/ (landing and purchase pages). The "Other" framework preset is required; Vercel's "Node" preset would run the stdio CLI.

Variable

Purpose

PAYMENTS_ENABLED

1 turns on the purchase page and comprar_bilhete. Off by default.

PAY_TOKEN_KEY

32 random bytes, base64. Encrypts purchase and pre-fill tokens. Required with payments.

PUBLIC_BASE_URL

Public origin, e.g. https://comboios.example.com. Defaults to the Vercel production URL.

CP_LOG_LEVEL

debug, info (default), warn or error.

openssl rand -base64 32 | tr -d '\n' | vercel env add PAY_TOKEN_KEY production --sensitive

Buying tickets

When PAYMENTS_ENABLED=1, horarios gives each option sold online a buy_url, and comprar_bilhete returns the same link, optionally with the passenger names, email and phone pre-filled. The page then:

  1. Shows the journey and price, and asks for the passenger names, an email for the ticket and consent. Nothing is reserved before the buyer clicks Continue.

  2. Creates the sale at CP. On trains with seat reservation (Alfa Pendular, Intercidades), shows the seat CP assigned, the occupancy of each carriage and a seat map, and lets the buyer change seats.

  3. Opens CP's own Checkout.com payment form (card, MB WAY or PayPal). Card details never reach this server.

  4. Confirms the sale with CP and offers the PDF ticket, which CP also emails.

Safeguards: personal details are forwarded to CP and not stored or logged; the sale's identifiers travel in an AES-256-GCM token, so the server keeps no state; writes to CP are never retried; a sale is released if CP rejects the details; cancelling is refused whenever a payment may exist. Each direction of a return trip is a separate ticket.

If you run a public instance with payments enabled, you are operating an unofficial checkout for CP tickets on your own domain. You are responsible for that service, its users' data and its support. Consider asking CP for permission first, and keep PAYMENTS_ENABLED off if in doubt.

Disclaimer

This software and the public instance are provided "as is", without warranty of any kind. To the extent permitted by applicable law, the authors and operators accept no liability for any loss or damage arising from their use, including wrong, incomplete or outdated information, failed, duplicated or incorrect purchases, missed trains, or changes and outages of CP's services. Tickets, prices, refunds and travel conditions are CP's responsibility; for any problem with a purchase, contact CP with the purchase reference. See also the license.

Privacy

Searching, timetables, live information and alerts need no personal data. The purchase page sends the details the buyer types to CP to issue the ticket and does not keep them. Hosting providers keep standard request logs.

How it works

  • Credentials are the public values in https://www.cp.pt/fe-config.json, fetched at runtime, cached for 6 hours and refreshed once on a 401. They are never logged or stored.

  • All upstream calls share one token bucket (1 request per second, burst 3), a 20 s timeout and two retries on network errors and 502/503/504.

  • Caches: stations and catalog data 24 h, alerts 10 min, journeys 2 min, live boards 15 s.

  • Journey option ids are self-contained (2026-11-30_94-30007_94-2006_c2_p1_out521), so any server instance can resolve them.

  • The in-chat view (ui/horarios.ts) uses MCP Apps. It is bundled into a single HTML resource with no network access; the buy button asks the host to open the purchase page.

docs/findings.md records what was verified against the live back end, docs/deeplink.md and docs/payment-lab.md how the purchase flow was worked out.

Development

Command

Purpose

npm test

Unit and protocol tests against recorded fixtures (no network).

npm run test:live

Live contract tests, one call per tool (CP_LIVE=1).

npm run probe

One call per upstream endpoint, printing [OK ] or [ERR].

npm run record-fixtures

Re-record test/fixtures/ from live responses.

npm run inspector

Open the MCP Inspector on the built server.

node lab/mock/server.mjs

Purchase page and in-chat view against fixtures, at http://localhost:8791 (/comprar?o=demo, /ui-host).

Contributions are welcome; see CONTRIBUTING.md. Report security issues as described in SECURITY.md.

License

MIT

Available Tools

10 tools
classes_e_regrasClasses, rules and service codesB
Read-onlyIdempotent

Travel classes, booking horizon (days ahead), passenger limits and the service codes (AP, IC, ...) CP uses.

Inputs: no named parameters.

estado_comboioLive train statusA
Read-only

Live status of a train by number: delay, last station passed, and every stop with scheduled/expected times and platform. The date is the departure date at the train's origin (default today; just after midnight it also checks yesterday's run).

Inputs: train_number (required), date.

horariosSearch journeys (timetable + fares)A
Read-only

Search CP train journeys between two stations on a date, with times, transfers, legs and fares (EUR per passenger). Times are HH:MM local; arrives_next_day marks journeys that cross midnight; duration comes from CP. cp_url opens the same search on cp.pt. Each option has an id to pass to link_compra; copy it exactly.

Inputs: to (required), from (required), date, lang, +7 more.

info_estacaoStation infoA
Read-onlyIdempotent

Details for one station: line, address, step-free access and facilities (ticket office, WC, parking, metro, ...).

Inputs: station (required).

mostrar_horariosShow journey options (interactive)A
Read-only

Same search as horarios, but also shows the options to the user as interactive cards in the chat, each with a buy button. Use it only when the user wants to see and compare trains to pick one, or wants to buy. Do NOT use it for quick factual questions (next train, a price, a single time), for checks you make for yourself, or when you will answer in one sentence; use horarios for those. Do not call both for the same search.

Inputs: to (required), from (required), date, lang, +7 more.

partidas_chegadasLive departures/arrivals boardA
Read-only

Live departures or arrivals for a station, with scheduled and expected times, delay in minutes (null = no real-time data yet) and platform. Late-evening requests also include the first trains after midnight; each row carries its own date.

Inputs: station (required), date, view, limit, +1 more.

perturbacoesService alerts and disruptionsA
Read-onlyIdempotent

Current CP service alerts (strikes, works, disruptions). Expired alerts are dropped unless include_expired. Use include_body for the full text (larger response). query filters title, subtitle and body (accent-insensitive).

Inputs: lang, query, include_body, homepage_only, +1 more.

precosFares by classB
Read-onlyIdempotent

Fares only (EUR per passenger) for each journey option, for 1st and 2nd class. Optionally restrict to one train number or one class.

Inputs: to (required), from (required), date, lang, +8 more.

procurar_estacaoSearch stationsA
Read-onlyIdempotent

Find CP stations by name (accent-insensitive, fuzzy). Returns a ranked list with CP station codes (94-xxxx) to use in other tools.

Inputs: query (required), limit.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 10 tools

    Disambiguation4/5

    Most tools target distinct resources or actions (station lookup vs. station details, live departures vs. train status, alerts, rules, purchase link). The main overlap is horarios and mostrar_horarios, which perform the same search with different presentation, and precos partially overlaps with horarios by returning fares. Descriptions explicitly warn not to call both search tools together, which mitigates but does not eliminate the ambiguity.

    Naming Consistency3/5

    All names are consistently snake_case and in Portuguese, which keeps them readable. However, the naming convention is mixed: some tools use verb_noun (procurar_estacao, mostrar_horarios), while many are bare nouns or noun phrases (horarios, precos, perturbacoes, estado_comboio). The pattern is not fully predictable across the set.

    Tool Count5/5

    Ten tools is well within the appropriate range for a focused train-information server. Each tool covers a meaningful capability: station discovery, journey search, fares, live status, disruptions, travel rules, and a purchase handoff. The horarios/mostrar_horarios pair is a presentation variant, but it still serves a distinct user-facing purpose.

    Completeness5/5

    The surface covers the full read-only travel lifecycle: find stations, inspect facilities, search journeys, compare fares, check live departures/arrivals and train status, review disruptions and travel rules, and hand off to cp.pt for purchase. No obvious operational gaps remain for the stated purpose, and the purchase handoff is intentionally scoped to avoid payment/reservation responsibilities.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables querying Swiss public transport data (stations, departures, connections) from the Transport Open Data API via natural language through an MCP gateway.
      79 npm
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      Connects AI assistants to Swiss Federal Railways (SBB/CFF/FFS) data: train schedules, station search, ticket prices, and direct ticket purchase links.
      6
      78 npm
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Lets an AI assistant plan public transport journeys across Germany and other countries, with legs, platforms, delays and alerts, plus stop departures, full trip details, place search, and live DB station boards. Tickets and prices are not included.
      AGPL 3.0