searchFlightsByDepArr
Search for flights between airports or cities using IATA codes and specific dates to find available travel options.
Instructions
Search for flights between airports or cities by date. For cities with multiple airports, use depcity and arrcity parameters; otherwise use dep and arr parameters. Date must be in YYYY-MM-DD format. For today's date, use the getTodayDate tool. All airport/city codes must be valid IATA 3-letter codes (e.g.BJS for city of Beijing, PEK for Beijing Capital Airport).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dep | No | Departure airport IATA 3-letter code (e.g. PEK for Beijing, CAN for Guangzhou) | |
| depcity | No | Departure city IATA 3-letter code (e.g. BJS for Beijing, CAN for Guangzhou) | |
| arr | No | Arrival airport IATA 3-letter code (e.g. SHA for Shanghai, HFE for Hefei) | |
| arrcity | No | Arrival city IATA 3-letter code (e.g. SHA for Shanghai, BJS for Beijing) | |
| date | 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 |
Implementation Reference
- dist/index.js:37-56 (handler)The MCP tool handler function that invokes the flight service's getFlightsByDepArr method, handles errors, and returns the flight data as formatted text content.}, async ({ dep, depcity, arr, arrcity, date }) => { try { const flights = await flightService.getFlightsByDepArr(dep, depcity, arr, arrcity, date); return { content: [ { type: "text", text: JSON.stringify(flights, null, 2) } ] }; } catch (error) { console.error('Error searching flights by dep/arr:', error); return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true }; } });
- dist/index.js:14-36 (schema)Zod schema defining the input parameters for the tool: dep, depcity, arr, arrcity, date with validation rules.dep: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Departure airport IATA 3-letter code (e.g. PEK for Beijing, CAN for Guangzhou)") .optional(), depcity: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Departure city IATA 3-letter code (e.g. BJS for Beijing, CAN for Guangzhou)") .optional(), arr: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Arrival airport IATA 3-letter code (e.g. SHA for Shanghai, HFE for Hefei)") .optional(), arrcity: z.string() .length(3) .regex(/^[A-Z]{3}$/) .describe("Arrival city IATA 3-letter code (e.g. SHA for Shanghai, BJS for Beijing)") .optional(), date: 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")
- dist/index.js:13-13 (registration)Registration of the 'searchFlightsByDepArr' tool with name, description, schema, and handler on the MCP server.server.tool("searchFlightsByDepArr", "Search for flights between airports or cities by date. For cities with multiple airports, use depcity and arrcity parameters; otherwise use dep and arr parameters. Date must be in YYYY-MM-DD format. For today's date, use the getTodayDate tool. All airport/city codes must be valid IATA 3-letter codes (e.g.BJS for city of Beijing, PEK for Beijing Capital Airport).", {
- dist/services/openalService.js:22-30 (helper)Helper method in OpenAlService that performs the API request to fetch flights by departure and arrival details.async getFlightsByDepArr(dep, depcity, arr, arrcity, date) { return this.makeRequest('flights', { dep, depcity, arr, arrcity, date, }); }
- dist/services/openalService.js:3-21 (helper)Core helper method for making HTTP POST requests to the external flight API, used by getFlightsByDepArr.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(); }