Skip to main content
Glama
marcusbai

Caiyun Weather MCP Server

by marcusbai

get_daily_forecast

Retrieve daily weather forecasts for up to 15 days by providing latitude, longitude, and optional parameters like language and unit system. Supports Chinese and English.

Instructions

获取天级天气预报

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daily_stepsNo每日预报天数 (1-15)
languageNo语言zh_CN
latitudeYes纬度
longitudeYes经度
unitNo单位制 (metric: 公制, imperial: 英制)metric

Implementation Reference

  • MCP tool handler for 'get_daily_forecast': validates input parameters, calls CaiyunWeatherService.getDaily(), formats the response using formatDailyData(), and returns JSON stringified content.
    case 'get_daily_forecast': {
      if (!this.isValidLocationArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          '无效的位置参数'
        );
      }
      
      const { longitude, latitude, daily_steps = 5 } = args;
      
      const weatherData = await weatherService.getDaily(longitude, latitude, daily_steps);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(weatherService.formatDailyData(weatherData), null, 2),
          },
        ],
      };
    }
  • src/index.ts:253-289 (registration)
    Tool registration in the MCP server's tools list, including name, description, and input schema definition.
    {
      name: 'get_daily_forecast',
      description: '获取天级天气预报',
      inputSchema: {
        type: 'object',
        properties: {
          longitude: {
            type: 'number',
            description: '经度',
          },
          latitude: {
            type: 'number',
            description: '纬度',
          },
          daily_steps: {
            type: 'number',
            description: '每日预报天数 (1-15)',
            minimum: 1,
            maximum: 15,
            default: 5,
          },
          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'],
      },
    },
  • Core helper method in CaiyunWeatherService that makes API call to Caiyun weather service for daily forecast data.
    async getDaily(longitude: number, latitude: number, dailysteps: number = 5): Promise<CaiyunWeatherResponse> {
      try {
        const url = `${this.baseUrl}/${this.apiKey}/${longitude},${latitude}/daily`;
        const response = await axios.get<CaiyunWeatherResponse>(url, {
          params: {
            dailysteps: Math.min(Math.max(dailysteps, 1), 15),
            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 method to format the raw daily forecast data from Caiyun API into a structured, readable object with mapped weather descriptions and indices.
    formatDailyData(data: CaiyunWeatherResponse) {
      const daily = data.result.daily;
      if (!daily) {
        throw new Error('没有每日天气预报数据');
      }
    
      return {
        location: data.location,
        server_time: new Date(data.server_time * 1000).toISOString(),
        forecast: daily.temperature.map((temp, index) => ({
          date: temp.date,
          temperature: {
            max: temp.max,
            min: temp.min,
            avg: temp.avg
          },
          temperature_day: daily.temperature_08h_20h?.[index] ? {
            max: daily.temperature_08h_20h[index].max,
            min: daily.temperature_08h_20h[index].min,
            avg: daily.temperature_08h_20h[index].avg
          } : undefined,
          temperature_night: daily.temperature_20h_32h?.[index] ? {
            max: daily.temperature_20h_32h[index].max,
            min: daily.temperature_20h_32h[index].min,
            avg: daily.temperature_20h_32h[index].avg
          } : undefined,
          weather: this.getSkyconText(daily.skycon[index].value),
          weather_code: daily.skycon[index].value,
          weather_day: this.getSkyconText(daily.skycon_08h_20h[index].value),
          weather_day_code: daily.skycon_08h_20h[index].value,
          weather_night: this.getSkyconText(daily.skycon_20h_32h[index].value),
          weather_night_code: daily.skycon_20h_32h[index].value,
          wind: {
            speed: daily.wind[index].avg.speed,
            direction: daily.wind[index].avg.direction
          },
          wind_day: daily.wind_08h_20h?.[index] ? {
            speed: daily.wind_08h_20h[index].avg.speed,
            direction: daily.wind_08h_20h[index].avg.direction
          } : undefined,
          wind_night: daily.wind_20h_32h?.[index] ? {
            speed: daily.wind_20h_32h[index].avg.speed,
            direction: daily.wind_20h_32h[index].avg.direction
          } : undefined,
          humidity: daily.humidity[index].avg,
          cloudrate: daily.cloudrate[index].avg,
          pressure: daily.pressure[index].avg,
          visibility: daily.visibility[index].avg,
          precipitation: {
            max: daily.precipitation[index].max,
            min: daily.precipitation[index].min,
            avg: daily.precipitation[index].avg,
            probability: daily.precipitation[index].probability,
            type: this.getPrecipitationTypeText(daily.precipitation[index].type)
          },
          air_quality: {
            aqi: daily.air_quality.aqi[index].avg.chn,
            pm25: daily.air_quality.pm25[index].avg,
            trend: daily.air_quality.aqi[index].trend,
            primary_pollutant: daily.air_quality.primary_pollutant?.[index]?.value
          },
          astro: {
            sunrise: daily.astro[index].sunrise.time,
            sunset: daily.astro[index].sunset.time
          },
          life_index: {
            comfort: daily.life_index.comfort?.[index]?.desc || '暂无数据',
            ultraviolet: daily.life_index.ultraviolet?.[index]?.desc || '暂无数据',
            carWashing: daily.life_index.carWashing?.[index]?.desc || '暂无数据',
            dressing: daily.life_index.dressing?.[index]?.desc || '暂无数据',
            coldRisk: daily.life_index.coldRisk?.[index]?.desc || '暂无数据',
            sport: daily.life_index.sport?.[index]?.desc,
            travel: daily.life_index.travel?.[index]?.desc
          }
        }))
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. '获取天级天气预报' only states what the tool does, not how it behaves - no information about response format, error conditions, rate limits, authentication needs, or whether it's a read-only operation. This is inadequate for a tool with 5 parameters and no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single Chinese phrase that directly states the tool's purpose. There's zero wasted language, and it's front-loaded with the essential information. Every word earns its place in this minimal description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (5 parameters, no output schema, no annotations), the description is insufficiently complete. It doesn't explain what the forecast contains, how results are structured, error handling, or practical usage context. With multiple similar sibling tools and no output schema, users need more guidance about what to expect from this specific daily forecast tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter information beyond what's already in the schema (which has 100% coverage). The schema fully documents all 5 parameters with descriptions, defaults, ranges, and enums. The description doesn't provide additional context about parameter relationships or usage patterns, so it meets but doesn't exceed the baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '获取天级天气预报' (Get daily weather forecast) clearly states the verb ('get') and resource ('daily weather forecast'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like get_hourly_forecast or get_minutely_forecast, which would require mentioning the specific time granularity distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With multiple sibling forecast tools (hourly, minutely, realtime), there's no indication that this tool is specifically for daily forecasts rather than other timeframes, nor any mention of use cases or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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