Skip to main content
Glama
shanggqm

HeFeng Weather MCP Server

by shanggqm

get-weather

Retrieve weather forecasts for locations in China, including real-time conditions and hourly or daily predictions based on latitude/longitude coordinates.

Instructions

获取中国国内的天气预报

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYes逗号分隔的经纬度信息 (e.g., 116.40,39.90)
daysNo预报天数,now为实时天气,24h为24小时预报,72h为72小时预报,168h为168小时预报,3d为3天预报,以此类推now

Implementation Reference

  • Main execution logic for the 'get-weather' tool within the CallToolRequestSchema handler. It validates input using WeatherArgumentsSchema, fetches data from HeFeng API based on the 'days' parameter (now, hourly, or daily forecast), handles errors, and returns formatted weather text.
    if (name === "get-weather") {
        const { location, days } = WeatherArgumentsSchema.parse(args);
    
        if (days === 'now') {
            // Get current weather data
            const weatherUrl = `${HEFENG_API_BASE}/weather/now?location=${location}&key=${HEFENG_API_KEY}`;
            const weatherData = await makeHeFengRequest<HeFengWeatherNowResponse>(weatherUrl);
    
            if (!weatherData || !weatherData.now) {
                return {
                    content: [{ type: "text", text: `无法获取 ${location} 的天气数据` }],
                };
            }
    
            const { now } = weatherData;
            const weatherText = `地点: ${location}\n` +
                `观测时间: ${now.obsTime}\n` +
                `天气: ${now.text}\n` +
                `温度: ${now.temp}°C\n` +
                `体感温度: ${now.feelsLike}°C\n` +
                `风向: ${now.windDir}\n` +
                `风力: ${now.windScale}级`;
    
            return { content: [{ type: "text", text: weatherText }] };
        } else if (['24h', '72h', '168h'].includes(days)) {
            // Get hourly forecast data
            const weatherUrl = `${HEFENG_API_BASE}/weather/${days}?location=${location}&key=${HEFENG_API_KEY}`;
            const weatherData = await makeHeFengRequest<HeFengWeatherHourlyResponse>(weatherUrl);
    
            if (!weatherData || !weatherData.hourly) {
                return {
                    content: [{ type: "text", text: `无法获取 ${location} 的逐小时天气预报数据` }],
                };
            }
    
            const hoursText = weatherData.hourly.map(hour => {
                return `时间: ${hour.fxTime}\n` +
                    `天气: ${hour.text}\n` +
                    `温度: ${hour.temp}°C\n` +
                    `湿度: ${hour.humidity}%\n` +
                    `风向: ${hour.windDir} ${hour.windScale}级\n` +
                    `------------------------`;
            }).join('\n');
    
            return {
                content: [{
                    type: "text",
                    text: `地点: ${location}\n${days}小时预报:\n${hoursText}`
                }],
            };
        } else {
            // Get daily forecast weather data
            const daysNum = parseInt(days);
            const weatherUrl = `${HEFENG_API_BASE}/weather/${days}?location=${location}&key=${HEFENG_API_KEY}`;
            const weatherData = await makeHeFengRequest<HeFengWeatherDailyResponse>(weatherUrl);
    
            if (!weatherData || !weatherData.daily) {
                return {
                    content: [{ type: "text", text: `无法获取 ${location} 的天气预报数据` }],
                };
            }
    
            const forecastText = weatherData.daily.map(day => {
                return `日期: ${day.fxDate}\n` +
                    `白天天气: ${day.textDay}\n` +
                    `夜间天气: ${day.textNight}\n` +
                    `最高温度: ${day.tempMax}°C\n` +
                    `最低温度: ${day.tempMin}°C\n` +
                    `白天风向: ${day.windDirDay} ${day.windScaleDay}级\n` +
                    `夜间风向: ${day.windDirNight} ${day.windScaleNight}级\n` +
                    `------------------------`;
            }).join('\n');
    
            return {
                content: [{
                    type: "text",
                    text: `地点: ${location}\n${daysNum}天预报:\n${forecastText}`
                }],
            };
        }
    } else {
  • src/index.ts:44-63 (registration)
    Registration of the 'get-weather' tool in the ListToolsRequestSchema handler, providing name, description, and input schema.
    {
        name: "get-weather",
        description: "获取中国国内的天气预报",
        inputSchema: {
            type: "object",
            properties: {
                location: {
                    type: "string",
                    description: "逗号分隔的经纬度信息 (e.g., 116.40,39.90)",
                },
                days: {
                    type: "string",
                    enum: ["now", "24h", "72h", "168h", "3d", "7d", "10d", "15d", "30d"],
                    description: "预报天数,now为实时天气,24h为24小时预报,72h为72小时预报,168h为168小时预报,3d为3天预报,以此类推",
                    default: "now"
                }
            },
            required: ["location"],
        },
    },
  • Zod schema used for validating the input arguments to the 'get-weather' tool.
    const WeatherArgumentsSchema = z.object({
        location: z.string(), // Location name or coordinates
        days: z.enum(['now', '24h', '72h', '168h', '3d', '7d', '10d', '15d', '30d']).default('now'), // 预报天数
    });
  • Helper function for making HTTP requests to the HeFeng weather API, used by the get-weather handler.
    async function makeHeFengRequest<T>(url: string): Promise<T | null> {
        const headers = {
            Accept: "application/json",
        };
    
        try {
            const response = await fetch(url, { headers });
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            return (await response.json()) as T;
        } catch (error) {
            console.error("Error making HeFeng request:", error);
            return null;
        }
    }
  • TypeScript interfaces defining the structure of responses from the HeFeng weather API for now, daily, and hourly forecasts.
    interface HeFengWeatherNowResponse {
        now: {
            obsTime: string;
            temp: string;
            feelsLike: string;
            text: string;
            windDir: string;
            windScale: string;
        };
    }
    
    interface HeFengWeatherDailyResponse {
        daily: Array<{
            fxDate: string;
            tempMax: string;
            tempMin: string;
            textDay: string;
            textNight: string;
            windDirDay: string;
            windScaleDay: string;
            windDirNight: string;
            windScaleNight: string;
        }>;
    }
    
    interface HeFengWeatherHourlyResponse {
        hourly: Array<{
            fxTime: string;
            temp: string;
            text: string;
            windDir: string;
            windScale: string;
            humidity: string;
        }>;
    }
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. It mentions geographic restriction (China) but doesn't cover other important traits: whether this is a read-only operation, potential rate limits, authentication needs, error handling, or what the output format looks like. 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 directly states the tool's purpose without unnecessary words. It's appropriately sized for a simple weather tool and front-loads the essential information. Every word earns its place.

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 no annotations and no output schema, the description is incomplete for a tool with 2 parameters. It doesn't explain what weather data is returned (e.g., temperature, precipitation), how results are structured, or any behavioral constraints. For a weather forecasting tool, users need to know what to expect beyond just 'forecast'.

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 both parameters thoroughly. The description adds no additional parameter information beyond what's in the schema. It doesn't explain parameter relationships, provide examples beyond the schema's enum descriptions, or clarify edge cases. Baseline 3 is appropriate when the schema does all the work.

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 tool's purpose: '获取中国国内的天气预报' (Get weather forecast for China). It specifies both the action (get weather forecast) and the geographic scope (China), though it doesn't distinguish from siblings since none exist. The description is specific but could be more precise about what type of weather data is returned.

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

Usage Guidelines3/5

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

The description implies usage context (weather forecasting for China) but provides no explicit guidance on when to use this tool versus alternatives. With no sibling tools, there's no need to differentiate, but it doesn't mention prerequisites, limitations, or ideal use cases beyond the basic scope.

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

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/shanggqm/hefeng-mcp-weather'

If you have feedback or need assistance with the MCP directory API, please join our Discord server