Skip to main content
Glama
lmanchu

Weather MCP Server

by lmanchu

get_weather_forecast

Retrieve a 5-day weather forecast for any city with temperature data in Celsius or Fahrenheit units.

Instructions

Get 5-day weather forecast for a specific city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesCity name (e.g., "Taipei", "Tokyo", "New York")
unitsNoTemperature units: "metric" (Celsius) or "imperial" (Fahrenheit)metric

Implementation Reference

  • The main handler function that fetches the 5-day weather forecast from the OpenWeatherMap API, groups data by day, computes high/low temps and dominant condition, and formats a textual response.
    async getWeatherForecast(city, units = 'metric') {
      const url = `${API_BASE_URL}/forecast?q=${encodeURIComponent(city)}&units=${units}&appid=${API_KEY}`;
    
      const response = await fetch(url);
    
      if (!response.ok) {
        if (response.status === 404) {
          throw new Error(`City "${city}" not found`);
        }
        throw new Error(`Weather API error: ${response.statusText}`);
      }
    
      const data = await response.json();
    
      // Format the response
      const tempUnit = units === 'metric' ? '°C' : '°F';
    
      // Group forecasts by day
      const dailyForecasts = {};
    
      data.list.forEach(item => {
        const date = new Date(item.dt * 1000).toLocaleDateString();
        if (!dailyForecasts[date]) {
          dailyForecasts[date] = [];
        }
        dailyForecasts[date].push(item);
      });
    
      // Build forecast text
      let forecastText = `📅 5-Day Weather Forecast for ${data.city.name}, ${data.city.country}\n\n`;
    
      Object.entries(dailyForecasts).slice(0, 5).forEach(([date, forecasts]) => {
        const temps = forecasts.map(f => f.main.temp);
        const maxTemp = Math.max(...temps);
        const minTemp = Math.min(...temps);
        const conditions = forecasts.map(f => f.weather[0].main);
        const mostCommon = conditions.sort((a,b) =>
          conditions.filter(v => v===a).length - conditions.filter(v => v===b).length
        ).pop();
    
        forecastText += `${date}:\n`;
        forecastText += `  High: ${maxTemp.toFixed(1)}${tempUnit} | Low: ${minTemp.toFixed(1)}${tempUnit}\n`;
        forecastText += `  Condition: ${mostCommon}\n\n`;
      });
    
      return {
        content: [
          {
            type: 'text',
            text: forecastText.trim(),
          },
        ],
      };
    }
  • Input schema defining the required 'city' parameter and optional 'units' parameter (metric or imperial) for the tool.
    inputSchema: {
      type: 'object',
      properties: {
        city: {
          type: 'string',
          description: 'City name (e.g., "Taipei", "Tokyo", "New York")',
        },
        units: {
          type: 'string',
          description: 'Temperature units: "metric" (Celsius) or "imperial" (Fahrenheit)',
          enum: ['metric', 'imperial'],
          default: 'metric',
        },
      },
      required: ['city'],
    },
  • index.js:97-116 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
    {
      name: 'get_weather_forecast',
      description: 'Get 5-day weather forecast for a specific city',
      inputSchema: {
        type: 'object',
        properties: {
          city: {
            type: 'string',
            description: 'City name (e.g., "Taipei", "Tokyo", "New York")',
          },
          units: {
            type: 'string',
            description: 'Temperature units: "metric" (Celsius) or "imperial" (Fahrenheit)',
            enum: ['metric', 'imperial'],
            default: 'metric',
          },
        },
        required: ['city'],
      },
    },
  • index.js:129-130 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes calls to the getWeatherForecast method.
    case 'get_weather_forecast':
      return await this.getWeatherForecast(args.city, args.units || 'metric');
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. It states what the tool does but lacks behavioral details such as rate limits, error handling, data sources, or response format. For a tool with no annotations, this is a significant gap in transparency, leaving the agent with incomplete operational 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 sentence with zero waste. It front-loads the core purpose ('Get 5-day weather forecast') and specifies the key constraint ('for a specific city'). Every word earns its place, making it highly concise and well-structured.

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. It covers the basic purpose but lacks details on behavior, response format, or error handling. For a tool with 2 parameters and no structured support, the description should provide more context to be fully helpful to an agent.

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 fully documents both parameters (city and units). The description adds no additional parameter semantics beyond implying the forecast is for a city, which is already covered. Baseline 3 is appropriate as the schema does the heavy lifting, but the description doesn't compensate or add value.

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 verb ('Get') and resource ('5-day weather forecast') with a specific scope ('for a specific city'). It distinguishes from the sibling tool 'get_current_weather' by specifying forecast vs. current weather, though it doesn't explicitly name the sibling. The purpose is unambiguous but could be slightly more explicit about the differentiation.

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 by specifying '5-day forecast' vs. the sibling 'get_current_weather', suggesting this tool is for future predictions rather than current conditions. However, it doesn't provide explicit guidance on when to choose this over the sibling or any prerequisites. The usage is reasonably inferred but not clearly stated.

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/lmanchu/weather-mcp-server'

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