Skip to main content
Glama
marcusbai

Caiyun Weather MCP Server

by marcusbai

get_weather_by_location

Retrieve weather data by latitude and longitude, including real-time conditions, daily and hourly forecasts, with customizable units and language options. Powered by the Caiyun Weather MCP Server.

Instructions

根据经纬度获取天气信息

Input Schema

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

Implementation Reference

  • src/index.ts:73-115 (registration)
    Tool registration in ListToolsRequestSchema handler, including name, description, and input schema definition.
      name: 'get_weather_by_location',
      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,
          },
          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'],
      },
    },
  • MCP CallToolRequestSchema handler case for get_weather_by_location: validates args, calls CaiyunWeatherService.getWeather and formatWeatherData, returns formatted JSON as text content.
    case 'get_weather_by_location': {
      if (!this.isValidLocationArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          '无效的位置参数'
        );
      }
      
      const { longitude, latitude, daily_steps = 5, hourly_steps = 24 } = args;
      
      const weatherData = await weatherService.getWeather(
        longitude, 
        latitude, 
        daily_steps, 
        hourly_steps
      );
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(weatherService.formatWeatherData(weatherData), null, 2),
          },
        ],
      };
    }
  • Core implementation in CaiyunWeatherService.getWeather: makes API call to Caiyun weather endpoint with location and forecast steps, returns raw API response.
    async getWeather(
      longitude: number, 
      latitude: number, 
      dailysteps: number = 5, 
      hourlysteps: number = 24,
      alert: boolean = true
    ): Promise<CaiyunWeatherResponse> {
      try {
        const url = `${this.baseUrl}/${this.apiKey}/${longitude},${latitude}/weather`;
        const response = await axios.get<CaiyunWeatherResponse>(url, {
          params: {
            dailysteps: Math.min(Math.max(dailysteps, 1), 15),
            hourlysteps: Math.min(Math.max(hourlysteps, 1), 360),
            alert,
            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 formatWeatherData: combines and formats realtime, minutely, hourly, daily, and alert data from API response into structured output.
    formatWeatherData(data: CaiyunWeatherResponse) {
      const result: any = {
        location: data.location,
        server_time: new Date(data.server_time * 1000).toISOString(),
        forecast_keypoint: data.result.forecast_keypoint
      };
    
      if (data.result.realtime) {
        result.realtime = this.formatRealtimeData(data);
      }
    
      if (data.result.minutely) {
        result.minutely = this.formatMinutelyData(data);
      }
    
      if (data.result.hourly) {
        result.hourly = this.formatHourlyData(data);
      }
    
      if (data.result.daily) {
        result.daily = this.formatDailyData(data);
      }
    
      if (data.result.alert) {
        result.alert = this.formatAlertData(data);
      }
    
      return result;
    }
  • Validation helper isValidLocationArgs used in the tool handler to check longitude, latitude, and optional steps.
    private isValidLocationArgs(args: any): args is { longitude: number; latitude: number; daily_steps?: number; hourly_steps?: number } {
      return (
        typeof args === 'object' &&
        args !== null &&
        typeof args.longitude === 'number' &&
        typeof args.latitude === 'number' &&
        (args.daily_steps === undefined || typeof args.daily_steps === 'number') &&
        (args.hourly_steps === undefined || typeof args.hourly_steps === 'number')
      );
    }
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 ('获取天气信息' - get weather information) without mentioning any behavioral traits like rate limits, authentication requirements, error conditions, response format, or what specific weather data is returned. For a tool with 6 parameters and no annotations, this is a significant gap in behavioral transparency.

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 sentence that gets straight to the point with zero wasted words. It's appropriately sized for the tool's purpose and front-loaded with the essential information about what the tool does and what inputs it requires.

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 has 6 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what weather information is returned (temperature, precipitation, wind, etc.), the format of the response, any limitations or constraints, or how it differs from the multiple sibling weather tools. For a weather API tool with rich parameters but no structured output documentation, the description should provide more context about what users can expect.

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 6 parameters thoroughly with descriptions, defaults, ranges, and enums. The description adds no additional parameter information beyond what's in the schema. According to the scoring rules, when schema_description_coverage is high (>80%), the baseline is 3 even with no param info in the description.

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 weather information based on latitude and longitude) clearly states the verb ('获取' - get) and resource ('天气信息' - weather information), with the specific input method ('根据经纬度' - based on latitude and longitude). It distinguishes from some siblings like get_weather_by_address that use addresses instead of coordinates, but doesn't fully differentiate from get_realtime_weather which might also use coordinates.

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?

No explicit guidance on when to use this tool versus alternatives. The description implies it uses latitude/longitude coordinates, which distinguishes it from get_weather_by_address, but doesn't explain when to choose this over get_realtime_weather, get_daily_forecast, or other weather-related siblings. No context about prerequisites or exclusions is provided.

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