Skip to main content
Glama
marcusbai

Caiyun Weather MCP Server

by marcusbai

get_weather_alert

Retrieve real-time weather alerts for specific coordinates, supporting multiple languages and unit systems. Ideal for monitoring severe weather conditions and ensuring safety.

Instructions

获取天气预警信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNo语言zh_CN
latitudeYes纬度
longitudeYes经度
unitNo单位制 (metric: 公制, imperial: 英制)metric

Implementation Reference

  • The main handler for the 'get_weather_alert' tool in the CallToolRequestSchema. Validates input, calls CaiyunWeatherService.getAlert(), formats the response using formatAlertData(), and returns the JSON string.
    case 'get_weather_alert': {
      if (!this.isValidLocationArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          '无效的位置参数'
        );
      }
      
      const { longitude, latitude } = args;
      
      const weatherData = await weatherService.getAlert(longitude, latitude);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(weatherService.formatAlertData(weatherData), null, 2),
          },
        ],
      };
  • Input schema and metadata definition for the 'get_weather_alert' tool, returned in ListToolsRequestSchema response.
    {
      name: 'get_weather_alert',
      description: '获取天气预警信息',
      inputSchema: {
        type: 'object',
        properties: {
          longitude: {
            type: 'number',
            description: '经度',
          },
          latitude: {
            type: 'number',
            description: '纬度',
          },
          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'],
      },
    },
  • Helper method in CaiyunWeatherService that fetches weather alert data from Caiyun API by calling the /weather endpoint with alert: true.
    async getAlert(longitude: number, latitude: number): Promise<CaiyunWeatherResponse> {
      try {
        const url = `${this.baseUrl}/${this.apiKey}/${longitude},${latitude}/weather`;
        const response = await axios.get<CaiyunWeatherResponse>(url, {
          params: {
            alert: true,
            dailysteps: 1,
            hourlysteps: 1,
            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 that formats the alert data from the API response into a structured object with alert details.
    formatAlertData(data: CaiyunWeatherResponse) {
      const alert = data.result.alert;
      if (!alert) {
        return {
          location: data.location,
          server_time: new Date(data.server_time * 1000).toISOString(),
          alerts: []
        };
      }
    
      return {
        location: data.location,
        server_time: new Date(data.server_time * 1000).toISOString(),
        alerts: alert.content.map(item => ({
          title: item.title,
          description: item.description,
          code: item.code,
          source: item.source,
          location: item.location,
          region: {
            province: item.province,
            city: item.city,
            county: item.county,
            adcode: item.adcode
          },
          pub_time: new Date(item.pubtimestamp * 1000).toISOString()
        }))
      };
    }
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. The description only states what the tool does ('获取天气预警信息') without revealing any behavioral traits such as data freshness, rate limits, authentication needs, error handling, or what happens if no alerts are found. This is a significant gap for a tool with no annotation coverage.

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 ('获取天气预警信息') with zero waste. It's front-loaded and appropriately sized for the tool's purpose, though it could benefit from more detail without sacrificing conciseness.

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 alert tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., alert types, severity, timestamps) or behavioral aspects like data sources or limitations. This leaves gaps for an AI agent to understand the tool fully.

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?

Schema description coverage is 100%, with all parameters well-documented in the schema (e.g., latitude/longitude for location, language and unit with enums). The description adds no additional meaning beyond what the schema provides, such as explaining how parameters affect the alert retrieval. Baseline 3 is appropriate since the schema does the heavy lifting.

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 weather alert information) states a clear verb ('获取') and resource ('天气预警信息'), but it's vague about what constitutes 'weather alert information' and doesn't distinguish this tool from its siblings (e.g., get_daily_forecast, get_realtime_weather). It's functional but lacks specificity about the type of alerts or their scope.

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 its siblings (e.g., get_weather_by_location, get_daily_forecast). There's no mention of alternatives, prerequisites, or specific contexts for weather alerts, leaving the agent to infer usage based on the tool name alone.

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