Skip to main content
Glama
marcusbai

Caiyun Weather MCP Server

by marcusbai

get_realtime_weather

Retrieve real-time weather data by specifying coordinates, language, and unit system using the Caiyun Weather MCP Server. Ideal for accurate, location-based weather insights.

Instructions

获取实时天气数据

Input Schema

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

Implementation Reference

  • Core handler function getRealtime that makes the API call to retrieve realtime weather data from Caiyun API.
    async getRealtime(longitude: number, latitude: number): Promise<CaiyunWeatherResponse> {
      try {
        const url = `${this.baseUrl}/${this.apiKey}/${longitude},${latitude}/realtime`;
        const response = await axios.get<CaiyunWeatherResponse>(url, {
          params: {
            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;
      }
    }
  • MCP tool dispatch handler for 'get_realtime_weather': validates input, calls service, formats and returns response.
    case 'get_realtime_weather': {
      if (!this.isValidLocationArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          '无效的位置参数'
        );
      }
      
      const { longitude, latitude } = args;
      
      const weatherData = await weatherService.getRealtime(longitude, latitude);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(weatherService.formatRealtimeData(weatherData), null, 2),
          },
        ],
      };
    }
  • Input schema definition for the 'get_realtime_weather' tool, specifying required longitude/latitude and optional language/unit.
      name: 'get_realtime_weather',
      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'],
      },
    },
  • src/index.ts:156-185 (registration)
    Registration of the 'get_realtime_weather' tool in the ListToolsRequestSchema handler.
    {
      name: 'get_realtime_weather',
      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 function to format realtime weather data into a structured, human-readable JSON response.
    formatRealtimeData(data: CaiyunWeatherResponse) {
      const realtime = data.result.realtime;
      if (!realtime) {
        throw new Error('没有实时天气数据');
      }
    
      return {
        location: data.location,
        server_time: new Date(data.server_time * 1000).toISOString(),
        temperature: realtime.temperature,
        apparent_temperature: realtime.apparent_temperature,
        humidity: realtime.humidity,
        weather: this.getSkyconText(realtime.skycon),
        weather_code: realtime.skycon,
        wind: {
          speed: realtime.wind.speed,
          direction: realtime.wind.direction
        },
        pressure: realtime.pressure,
        visibility: realtime.visibility,
        precipitation: {
          local: {
            intensity: realtime.precipitation.local.intensity,
            type: this.getPrecipitationTypeText(realtime.precipitation.local.type)
          },
          nearest: realtime.precipitation.nearest ? {
            intensity: realtime.precipitation.nearest.intensity,
            type: this.getPrecipitationTypeText(realtime.precipitation.nearest.type),
            distance: realtime.precipitation.nearest.distance
          } : {
            intensity: 0,
            type: this.getPrecipitationTypeText('none'),
            distance: 0
          }
        },
        air_quality: {
          aqi: realtime.air_quality.aqi.chn,
          pm25: realtime.air_quality.pm25,
          pm10: realtime.air_quality.pm10,
          o3: realtime.air_quality.o3,
          so2: realtime.air_quality.so2,
          no2: realtime.air_quality.no2,
          co: realtime.air_quality.co,
          description: realtime.air_quality.description.chn,
          trend: realtime.air_quality.trend,
          primary_pollutant: realtime.air_quality.primary_pollutant
        },
        life_index: {
          comfort: realtime.life_index.comfort?.desc || '暂无数据',
          ultraviolet: realtime.life_index.ultraviolet?.desc || '暂无数据',
          sport: realtime.life_index.sport?.desc || '暂无数据',
          travel: realtime.life_index.travel?.desc || '暂无数据',
          cold: realtime.life_index.cold?.desc || '暂无数据',
          carWashing: realtime.life_index.carWashing?.desc || '暂无数据',
          dressing: realtime.life_index.dressing?.desc || '暂无数据'
        }
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. '获取实时天气数据' only states what the tool does, not how it behaves - no information about authentication needs, rate limits, error conditions, response format, or whether it's a read-only operation. For a tool with no annotations, this is insufficient behavioral context.

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 Chinese phrase that directly states the tool's purpose with zero wasted words. It's appropriately sized for a straightforward weather data retrieval tool and front-loads the essential information.

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?

For a tool with 4 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what 'real-time' means (current conditions? recent observations?), doesn't describe the return format, and provides no behavioral context. Given the complexity of weather data and lack of structured metadata, the description should do more to compensate.

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%, so the schema already documents all parameters thoroughly. The description adds no additional parameter information beyond what's in the schema - no examples, no explanation of coordinate precision, no context about when to use which language or unit options. Baseline 3 is appropriate when schema does the heavy lifting.

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 '获取实时天气数据' clearly states the purpose as 'get real-time weather data' with a specific verb ('get') and resource ('real-time weather data'). It distinguishes from siblings like forecast tools by specifying 'real-time', but doesn't explicitly contrast with other real-time tools like get_weather_by_address.

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 siblings like get_weather_by_address and get_weather_by_location that likely serve similar real-time purposes, there's no indication of when to choose coordinate-based vs address-based approaches or how this differs from other real-time weather tools.

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