Skip to main content
Glama
marcusbai

Caiyun Weather MCP Server

by marcusbai

get_hourly_forecast

Retrieve hyperlocal hourly weather forecasts for specific coordinates, with customizable language, unit system, and forecast duration up to 360 hours.

Instructions

获取小时级天气预报

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hourly_stepsNo小时预报数量 (1-360)
languageNo语言zh_CN
latitudeYes纬度
longitudeYes经度
unitNo单位制 (metric: 公制, imperial: 英制)metric

Implementation Reference

  • src/index.ts:216-252 (registration)
    Registration of the get_hourly_forecast tool in the ListTools response, including description and input schema.
    { name: 'get_hourly_forecast', description: '获取小时级天气预报', inputSchema: { type: 'object', properties: { longitude: { type: 'number', description: '经度', }, latitude: { type: 'number', description: '纬度', }, 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: ['longitude', 'latitude'], }, },
  • Handler case in CallToolRequestSchema for executing get_hourly_forecast: validates args, calls CaiyunWeatherService.getHourly, formats response.
    case 'get_hourly_forecast': { if (!this.isValidLocationArgs(args)) { throw new McpError( ErrorCode.InvalidParams, '无效的位置参数' ); } const { longitude, latitude, hourly_steps = 24 } = args; const weatherData = await weatherService.getHourly(longitude, latitude, hourly_steps); return { content: [ { type: 'text', text: JSON.stringify(weatherService.formatHourlyData(weatherData), null, 2), }, ], }; }
  • Core handler: Makes HTTP request to Caiyun API hourly forecast endpoint with validated parameters.
    async getHourly(longitude: number, latitude: number, hourlysteps: number = 24): Promise<CaiyunWeatherResponse> { try { const url = `${this.baseUrl}/${this.apiKey}/${longitude},${latitude}/hourly`; const response = await axios.get<CaiyunWeatherResponse>(url, { params: { hourlysteps: Math.min(Math.max(hourlysteps, 1), 360), lang: this.language, unit: this.unit } }); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`彩云天气API错误: ${error.response?.data?.error || error.message}`); } throw error; }
  • Helper function that processes and structures the raw hourly forecast data for output.
    formatHourlyData(data: CaiyunWeatherResponse) { const hourly = data.result.hourly; if (!hourly) { throw new Error('没有小时级天气预报数据'); } return { location: data.location, server_time: new Date(data.server_time * 1000).toISOString(), description: hourly.description, forecast: hourly.temperature.map((temp, index) => ({ time: temp.datetime, temperature: temp.value, apparent_temperature: hourly.apparent_temperature?.[index]?.value, weather: this.getSkyconText(hourly.skycon[index].value), weather_code: hourly.skycon[index].value, wind: { speed: hourly.wind[index].speed, direction: hourly.wind[index].direction }, humidity: hourly.humidity[index].value, cloudrate: hourly.cloudrate[index].value, pressure: hourly.pressure[index].value, visibility: hourly.visibility[index].value, precipitation: { value: hourly.precipitation[index].value, probability: hourly.precipitation[index].probability, type: this.getPrecipitationTypeText(hourly.precipitation[index].type) }, air_quality: { aqi: hourly.air_quality.aqi[index].value.chn, pm25: hourly.air_quality.pm25[index].value, trend: hourly.air_quality.aqi[index].trend, primary_pollutant: hourly.air_quality.primary_pollutant?.[index]?.value } })) }; }

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/marcusbai/caiyun-weather-mcp'

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