getFlightPriceByCities
Retrieve flight prices between cities using IATA codes and departure date to compare travel costs and plan trips.
Instructions
Get flight price information by departure city, arrival city, and departure date. All city codes must be valid IATA 3-letter codes (e.g. HFE for Hefei, CAN for Guangzhou). Date must be in YYYY-MM-DD format.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dep_city | Yes | Departure city IATA 3-letter code (e.g. HFE for Hefei) | |
| arr_city | Yes | Arrival city IATA 3-letter code (e.g. CAN for Guangzhou) | |
| dep_date | Yes | Departure 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 |
Implementation Reference
- dist/index.js:250-268 (handler)The handler function that executes the core logic of the 'getFlightPriceByCities' tool. It invokes the flight service method, formats the response as MCP content (JSON stringified), and handles errors by returning an error message.}, async ({ dep_city, arr_city, dep_date }) => { try { const flightPrices = await flightService.getFlightPriceByCities(dep_city, arr_city, dep_date); return { content: [ { type: "text", text: JSON.stringify(flightPrices, null, 2) } ] }; } catch (error) { console.error('Error getting flight prices by cities:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; }
- dist/index.js:239-249 (schema)Zod schema for validating the tool's input parameters: departure city code, arrival city code (both IATA 3-letter uppercase), and departure date in YYYY-MM-DD format.dep_city: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Departure city IATA 3-letter code (e.g. HFE for Hefei)"), arr_city: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Arrival city IATA 3-letter code (e.g. CAN for Guangzhou)"), dep_date: z.string() .regex(/^\d{4}-\d{2}-\d{2}$/) .describe("Departure 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"),
- dist/index.js:238-269 (registration)The server.tool registration for 'getFlightPriceByCities', including the tool name, description, input schema, and handler function.server.tool("getFlightPriceByCities", "Get flight price information by departure city, arrival city, and departure date. All city codes must be valid IATA 3-letter codes (e.g. HFE for Hefei, CAN for Guangzhou). Date must be in YYYY-MM-DD format.", { dep_city: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Departure city IATA 3-letter code (e.g. HFE for Hefei)"), arr_city: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Arrival city IATA 3-letter code (e.g. CAN for Guangzhou)"), dep_date: z.string() .regex(/^\d{4}-\d{2}-\d{2}$/) .describe("Departure 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 ({ dep_city, arr_city, dep_date }) => { try { const flightPrices = await flightService.getFlightPriceByCities(dep_city, arr_city, dep_date); return { content: [ { type: "text", text: JSON.stringify(flightPrices, null, 2) } ] }; } catch (error) { console.error('Error getting flight prices by cities:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } });
- dist/services/openalService.js:92-98 (helper)Helper method in OpenAlService class that performs the actual API request to the backend endpoint 'getFlightPriceByCities' by calling makeRequest with the parameters.async getFlightPriceByCities(dep_city, arr_city, dep_date) { return this.makeRequest('getFlightPriceByCities', { dep_city, arr_city, dep_date }); }