Skip to main content
Glama

search_google_flights_calendar

Find flight options and prices using Google Flights by specifying departure, arrival, dates, and travel preferences to plan trips efficiently.

Input Schema

NameRequiredDescriptionDefault
adultsNo成人数量
arrival_idYes目的地ID
childrenNo儿童数量
currencyNo货币
departure_idYes出发地ID
flight_typeYes航班类型
glNo地理位置
hlNo语言
outbound_dateYes出发日期
outbound_date_endNo出发日期结束
outbound_date_startNo出发日期开始
return_dateNo返程日期
return_date_endNo返程日期结束
return_date_startNo返程日期开始
stopsNo中转次数
travel_classNo舱位等级

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "adults": { "description": "成人数量", "type": "string" }, "arrival_id": { "description": "目的地ID", "type": "string" }, "children": { "description": "儿童数量", "type": "string" }, "currency": { "description": "货币", "type": "string" }, "departure_id": { "description": "出发地ID", "type": "string" }, "flight_type": { "description": "航班类型", "type": "string" }, "gl": { "description": "地理位置", "type": "string" }, "hl": { "description": "语言", "type": "string" }, "outbound_date": { "description": "出发日期", "type": "string" }, "outbound_date_end": { "description": "出发日期结束", "type": "string" }, "outbound_date_start": { "description": "出发日期开始", "type": "string" }, "return_date": { "description": "返程日期", "type": "string" }, "return_date_end": { "description": "返程日期结束", "type": "string" }, "return_date_start": { "description": "返程日期开始", "type": "string" }, "stops": { "description": "中转次数", "type": "string" }, "travel_class": { "description": "舱位等级", "type": "string" } }, "required": [ "flight_type", "departure_id", "arrival_id", "outbound_date" ], "type": "object" }

Implementation Reference

  • The handler function for the 'search_google_flights_calendar' tool. It validates inputs based on flight_type, constructs parameters for the searchapi.io API with engine 'google_flights_calendar', calls makeSearchapiRequest, and returns the JSON-formatted result.
    async (args) => { const params = { engine: 'google_flights_calendar', flight_type: args.flight_type, departure_id: args.departure_id, arrival_id: args.arrival_id, outbound_date: args.outbound_date }; // 检查航班类型,确保提供必要参数 if (args.flight_type === 'round_trip' && !args.return_date) { return { content: [{ type: 'text', text: JSON.stringify({ error: '往返航班需要提供return_date参数' }) }], isError: true }; } else if (args.flight_type === 'round_trip') { params.return_date = args.return_date; } // 添加可选参数 const optionalParams = [ 'outbound_date_start', 'outbound_date_end', 'return_date_start', 'return_date_end', 'gl', 'hl', 'currency', 'adults', 'children', 'travel_class', 'stops' ]; for (const key of optionalParams) { if (args[key] !== undefined) { params[key] = args[key]; } } const result = await makeSearchapiRequest(params); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
  • Zod schema defining the input parameters for the 'search_google_flights_calendar' tool, including required fields like flight_type, departure_id, arrival_id, outbound_date, and various optional parameters.
    { flight_type: z.string().describe('航班类型'), departure_id: z.string().describe('出发地ID'), arrival_id: z.string().describe('目的地ID'), outbound_date: z.string().describe('出发日期'), return_date: z.string().optional().describe('返程日期'), outbound_date_start: z.string().optional().describe('出发日期开始'), outbound_date_end: z.string().optional().describe('出发日期结束'), return_date_start: z.string().optional().describe('返程日期开始'), return_date_end: z.string().optional().describe('返程日期结束'), gl: z.string().optional().describe('地理位置'), hl: z.string().optional().describe('语言'), currency: z.string().optional().describe('货币'), adults: z.string().optional().describe('成人数量'), children: z.string().optional().describe('儿童数量'), travel_class: z.string().optional().describe('舱位等级'), stops: z.string().optional().describe('中转次数') },
  • src/index.js:324-380 (registration)
    Registration of the 'search_google_flights_calendar' tool using server.tool(), including name, schema, and handler function.
    server.tool( 'search_google_flights_calendar', { flight_type: z.string().describe('航班类型'), departure_id: z.string().describe('出发地ID'), arrival_id: z.string().describe('目的地ID'), outbound_date: z.string().describe('出发日期'), return_date: z.string().optional().describe('返程日期'), outbound_date_start: z.string().optional().describe('出发日期开始'), outbound_date_end: z.string().optional().describe('出发日期结束'), return_date_start: z.string().optional().describe('返程日期开始'), return_date_end: z.string().optional().describe('返程日期结束'), gl: z.string().optional().describe('地理位置'), hl: z.string().optional().describe('语言'), currency: z.string().optional().describe('货币'), adults: z.string().optional().describe('成人数量'), children: z.string().optional().describe('儿童数量'), travel_class: z.string().optional().describe('舱位等级'), stops: z.string().optional().describe('中转次数') }, async (args) => { const params = { engine: 'google_flights_calendar', flight_type: args.flight_type, departure_id: args.departure_id, arrival_id: args.arrival_id, outbound_date: args.outbound_date }; // 检查航班类型,确保提供必要参数 if (args.flight_type === 'round_trip' && !args.return_date) { return { content: [{ type: 'text', text: JSON.stringify({ error: '往返航班需要提供return_date参数' }) }], isError: true }; } else if (args.flight_type === 'round_trip') { params.return_date = args.return_date; } // 添加可选参数 const optionalParams = [ 'outbound_date_start', 'outbound_date_end', 'return_date_start', 'return_date_end', 'gl', 'hl', 'currency', 'adults', 'children', 'travel_class', 'stops' ]; for (const key of optionalParams) { if (args[key] !== undefined) { params[key] = args[key]; } } const result = await makeSearchapiRequest(params); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } );
  • Helper function used by all search tools, including search_google_flights_calendar, to make API requests to searchapi.io and handle errors.
    async function makeSearchapiRequest(params) { // 确保API Key被添加到参数中 params.api_key = SEARCHAPI_API_KEY; try { const response = await axios.get(SEARCHAPI_URL, { params, timeout: 30000 // 30秒超时 }); return response.data; } catch (error) { let errorDetail = null; if (error.response) { try { errorDetail = error.response.data; } catch (e) { errorDetail = error.response.statusText; } } const errorMessage = `调用searchapi.io时出错: ${error.message}`; if (errorDetail) { return { error: `${errorMessage}, 详情: ${JSON.stringify(errorDetail)}` }; } return { error: errorMessage }; } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lianshuang-photo/searchapi-mcp-nodejs'

If you have feedback or need assistance with the MCP directory API, please join our Discord server