get_weather_by_address
Retrieve weather details for a specific address, including real-time conditions, hourly forecasts, and daily predictions. Customize output with language, unit preferences, and forecast steps.
Instructions
根据地址获取天气信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | 地址,如"北京市海淀区" | |
| daily_steps | No | 每日预报天数 (1-15) | |
| hourly_steps | No | 小时预报数量 (1-360) | |
| language | No | 语言 | zh_CN |
| unit | No | 单位制 (metric: 公制, imperial: 英制) | metric |
Implementation Reference
- src/index.ts:420-448 (handler)Handler for the get_weather_by_address tool: validates input using isValidAddressArgs, geocodes the address to longitude/latitude using GeocodeService, fetches comprehensive weather data using CaiyunWeatherService.getWeather, formats it, and returns as JSON text content.case 'get_weather_by_address': { if (!this.isValidAddressArgs(args)) { throw new McpError( ErrorCode.InvalidParams, '无效的地址参数' ); } const { address, daily_steps = 5, hourly_steps = 24 } = args; // 将地址转换为经纬度 const [longitude, latitude] = await this.geocodeService.geocode(address); const weatherData = await weatherService.getWeather( longitude, latitude, daily_steps, hourly_steps ); return { content: [ { type: 'text', text: JSON.stringify(weatherService.formatWeatherData(weatherData), null, 2), }, ], }; }
- src/index.ts:119-154 (schema)Input schema for get_weather_by_address tool defining required 'address' parameter and optional forecast steps, language, and unit preferences.inputSchema: { type: 'object', properties: { address: { type: 'string', description: '地址,如"北京市海淀区"', }, daily_steps: { type: 'number', description: '每日预报天数 (1-15)', minimum: 1, maximum: 15, default: 5, }, hourly_steps: { type: 'number', description: '小时预报数量 (1-360)', minimum: 1, maximum: 360, default: 24, }, language: { type: 'string', enum: ['zh_CN', 'en_US'], description: '语言', default: 'zh_CN', }, unit: { type: 'string', enum: ['metric', 'imperial'], description: '单位制 (metric: 公制, imperial: 英制)', default: 'metric', }, }, required: ['address'], },
- src/index.ts:116-155 (registration)Registration of the get_weather_by_address tool in the ListTools response, including name, description, and full input schema.{ name: 'get_weather_by_address', description: '根据地址获取天气信息', inputSchema: { type: 'object', properties: { address: { type: 'string', description: '地址,如"北京市海淀区"', }, daily_steps: { type: 'number', description: '每日预报天数 (1-15)', minimum: 1, maximum: 15, default: 5, }, hourly_steps: { type: 'number', description: '小时预报数量 (1-360)', minimum: 1, maximum: 360, default: 24, }, language: { type: 'string', enum: ['zh_CN', 'en_US'], description: '语言', default: 'zh_CN', }, unit: { type: 'string', enum: ['metric', 'imperial'], description: '单位制 (metric: 公制, imperial: 英制)', default: 'metric', }, }, required: ['address'], }, },
- src/index.ts:639-647 (helper)Helper function to validate arguments for the get_weather_by_address tool, checking types for address and optional numeric parameters.private isValidAddressArgs(args: any): args is { address: string; daily_steps?: number; hourly_steps?: number } { return ( typeof args === 'object' && args !== null && typeof args.address === 'string' && (args.daily_steps === undefined || typeof args.daily_steps === 'number') && (args.hourly_steps === undefined || typeof args.hourly_steps === 'number') ); }