searchTrainTickets
Find train tickets between departure and arrival cities for a specific travel date in YYYY-MM-DD format using the Variflight Tripmatch MCP Server.
Instructions
Search for train tickets between two cities on a specific date. Date must be in YYYY-MM-DD format.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | Travel date in YYYY-MM-DD format. IMPORTANT: If user input only cotains month and date, you should use getTodayDate tool to get the year. For today's date, use getTodayDate tool instead of hardcoding | |
| from | Yes | Departure city name (e.g. 合肥) | |
| to | Yes | Arrival city name (e.g. 北京) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"date": {
"description": "Travel date in YYYY-MM-DD format. IMPORTANT: If user input only cotains month and date, you should use getTodayDate tool to get the year. For today's date, use getTodayDate tool instead of hardcoding",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"type": "string"
},
"from": {
"description": "Departure city name (e.g. 合肥)",
"type": "string"
},
"to": {
"description": "Arrival city name (e.g. 北京)",
"type": "string"
}
},
"required": [
"from",
"to",
"date"
],
"type": "object"
}
Implementation Reference
- dist/index.js:217-236 (handler)MCP tool handler function for searchTrainTickets: fetches data from flightService.getTrainTickets and returns JSON-formatted content or error response.}, async ({ from, to, date }) => { try { const trainTickets = await flightService.getTrainTickets(from, to, date); return { content: [ { type: "text", text: JSON.stringify(trainTickets, null, 2) } ] }; } catch (error) { console.error('Error searching train tickets:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } });
- dist/index.js:212-217 (schema)Zod input schema validating 'from' (departure city), 'to' (arrival city), and 'date' (YYYY-MM-DD format) parameters.from: z.string().describe("Departure city name (e.g. 合肥)"), to: z.string().describe("Arrival city name (e.g. 北京)"), date: z.string() .regex(/^\d{4}-\d{2}-\d{2}$/) .describe("Travel date in YYYY-MM-DD format. IMPORTANT: If user input only cotains month and date, you should use getTodayDate tool to get the year. For today's date, use getTodayDate tool instead of hardcoding"), }, async ({ from, to, date }) => {
- dist/index.js:211-236 (registration)Registration of the searchTrainTickets tool on the MCP server instance, specifying name, description, schema, and handler.server.tool("searchTrainTickets", "Search for train tickets between two cities on a specific date. Date must be in YYYY-MM-DD format.", { from: z.string().describe("Departure city name (e.g. 合肥)"), to: z.string().describe("Arrival city name (e.g. 北京)"), date: z.string() .regex(/^\d{4}-\d{2}-\d{2}$/) .describe("Travel date in YYYY-MM-DD format. IMPORTANT: If user input only cotains month and date, you should use getTodayDate tool to get the year. For today's date, use getTodayDate tool instead of hardcoding"), }, async ({ from, to, date }) => { try { const trainTickets = await flightService.getTrainTickets(from, to, date); return { content: [ { type: "text", text: JSON.stringify(trainTickets, null, 2) } ] }; } catch (error) { console.error('Error searching train tickets:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } });
- dist/services/openalService.js:80-86 (helper)Supporting method in OpenAlService (instantiated as flightService) that performs the API call to the 'trainStanTicket' endpoint with mapped parameters (cdep=from, carr=to).async getTrainTickets(from, to, date) { return this.makeRequest('trainStanTicket', { 'cdep': from, 'carr': to, date }); }