getFlightPriceByCities
Retrieve flight prices by specifying departure and arrival cities using IATA codes and a departure date in YYYY-MM-DD format. Ideal for comparing airfare between specific locations.
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
| Name | Required | Description | Default |
|---|---|---|---|
| arr_city | Yes | Arrival city IATA 3-letter code (e.g. CAN for Guangzhou) | |
| dep_city | Yes | Departure city IATA 3-letter code (e.g. HFE for Hefei) | |
| 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 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"arr_city": {
"description": "Arrival city IATA 3-letter code (e.g. CAN for Guangzhou)",
"maxLength": 3,
"minLength": 3,
"pattern": "^[A-Z]{3}$",
"type": "string"
},
"dep_city": {
"description": "Departure city IATA 3-letter code (e.g. HFE for Hefei)",
"maxLength": 3,
"minLength": 3,
"pattern": "^[A-Z]{3}$",
"type": "string"
},
"dep_date": {
"description": "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",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"type": "string"
}
},
"required": [
"dep_city",
"arr_city",
"dep_date"
],
"type": "object"
}
Implementation Reference
- dist/index.js:250-269 (handler)The MCP tool handler function that calls the OpenAlService to get flight prices by cities and returns the JSON-formatted response or 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 input schema defining parameters dep_city, arr_city, and dep_date with validation rules.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)Complete registration of the getFlightPriceByCities tool with MCP server, including description, input schema, and handler.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 function in OpenAlService class that makes the underlying API request to the getFlightPriceByCities endpoint.async getFlightPriceByCities(dep_city, arr_city, dep_date) { return this.makeRequest('getFlightPriceByCities', { dep_city, arr_city, dep_date }); }