getFlightAndTrainTransferInfo
Find flight and train transfer options between cities using IATA airport codes and departure dates. Query transportation connections for multi-modal travel planning.
Instructions
Get flight and train transfer info by departure city and arrival city and departure date. Date format: YYYY-MM-DD. IMPORTANT: For today's date, you MUST use getTodayDate tool instead of hardcoding any date. Airport codes should be IATA 3-letter codes.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| depdate | Yes | Flight 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 | |
| depcity | Yes | Departure airport IATA 3-letter code (e.g. BJS for Beijing, CAN for Guangzhou) | |
| arrcity | Yes | Arrival airport IATA 3-letter code (e.g. SHA for Shanghai, LAX for Los Angeles) |
Implementation Reference
- dist/index.js:107-126 (handler)The inline asynchronous handler function for the MCP tool 'getFlightAndTrainTransferInfo'. It calls OpenAlService.getTransferInfo and formats the JSON response or error.
}, async ({ depcity, arrcity, depdate }) => { try { const flights = await flightService.getTransferInfo(depcity, arrcity, depdate); return { content: [ { type: "text", text: JSON.stringify(flights, null, 2) } ] }; } catch (error) { console.error('Error searching flights by number:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } }); - dist/index.js:96-107 (schema)Zod input schema validation for the tool parameters: depdate, depcity, arrcity.
depdate: z.string() .regex(/^\d{4}-\d{2}-\d{2}$/) .describe("Flight 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"), depcity: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Departure airport IATA 3-letter code (e.g. BJS for Beijing, CAN for Guangzhou)"), arrcity: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Arrival airport IATA 3-letter code (e.g. SHA for Shanghai, LAX for Los Angeles)"), }, async ({ depcity, arrcity, depdate }) => { - dist/index.js:95-95 (registration)The server.tool call that registers the 'getFlightAndTrainTransferInfo' tool with MCP server, providing name, description, schema, and handler.
server.tool("getFlightAndTrainTransferInfo", "Get flight and train transfer info by departure city and arrival city and departure date. Date format: YYYY-MM-DD. IMPORTANT: For today's date, you MUST use getTodayDate tool instead of hardcoding any date. Airport codes should be IATA 3-letter codes. ", { - dist/services/openalService.js:43-50 (helper)The OpenAlService method getTransferInfo that implements the core logic by making an API request to the 'transfer' endpoint.
async getTransferInfo(depcity, arrcity, depdate) { return this.makeRequest('transfer', { depcity, arrcity, depdate, "fromMCP": 1 }); } - dist/services/openalService.js:3-21 (helper)The base makeRequest method in OpenAlService used by getTransferInfo to call the external API.
async makeRequest(endpoint, params) { const url = new URL(config.api.baseUrl); const request_body = { endpoint: endpoint, params: params }; const response = await fetch(url.toString(), { method: 'post', headers: { 'X-VARIFLIGHT-KEY': config.api.apiKey || '', 'Content-Type': 'application/json', }, body: JSON.stringify(request_body), }); if (!response.ok) { throw new Error(`API request failed: ${response.status} ${response.statusText}`); } return response.json(); }