Skip to main content
Glama
marcusbai

Caiyun Weather MCP Server

by marcusbai

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
NameRequiredDescriptionDefault
addressYes地址,如"北京市海淀区"
daily_stepsNo每日预报天数 (1-15)
hourly_stepsNo小时预报数量 (1-360)
languageNo语言zh_CN
unitNo单位制 (metric: 公制, imperial: 英制)metric

Implementation Reference

  • 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), }, ], }; }
  • 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'], }, },
  • 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') ); }

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