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
          }
        }))
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('get') but doesn't describe any behavioral traits such as whether this is a read-only operation, potential rate limits, authentication needs, or what the output format might be. For a tool with no annotations, this leaves significant gaps in understanding how it behaves.

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 a single, efficient sentence ('获取小时级天气预报') that is front-loaded and wastes no words. It directly states the purpose without unnecessary elaboration, making it appropriately sized for its minimal content.

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 complexity of a weather forecasting tool with 5 parameters and no output schema, the description is incomplete. It lacks details on what the forecast includes (e.g., temperature, precipitation), how results are structured, or any behavioral context, which is insufficient for an agent to fully understand the tool's operation without relying heavily on the schema alone.

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 input schema has 100% description coverage, with clear documentation for all 5 parameters (e.g., 'hourly_steps' as '小时预报数量 (1-360)'). The description adds no additional meaning beyond what the schema provides, so it meets the baseline of 3 where the schema does the heavy lifting without compensating for any gaps.

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

Purpose3/5

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

The description '获取小时级天气预报' (Get hourly weather forecast) clearly states the verb ('get') and resource ('hourly weather forecast'), making the basic purpose understandable. However, it doesn't distinguish this tool from its siblings like 'get_daily_forecast' or 'get_minutely_forecast' beyond the temporal granularity implied by 'hourly', which is minimal differentiation.

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. It doesn't mention sibling tools like 'get_daily_forecast' for daily forecasts or 'get_realtime_weather' for current conditions, leaving the agent to infer usage based on the name alone without explicit context or exclusions.

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