Skip to main content
Glama
lmanchu

Weather MCP Server

by lmanchu

get_current_weather

Retrieve real-time weather conditions for any city, including temperature in Celsius or Fahrenheit, using the OpenWeather API.

Instructions

Get current weather information 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 handler function that implements the get_current_weather tool by fetching data from the OpenWeatherMap API, handling errors, formatting the weather information into a user-friendly text response, and returning it in the MCP content format.
      async getCurrentWeather(city, units = 'metric') {
        const url = `${API_BASE_URL}/weather?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';
        const speedUnit = units === 'metric' ? 'm/s' : 'mph';
    
        const weatherText = `
    🌤️ Current Weather in ${data.name}, ${data.sys.country}
    
    Temperature: ${data.main.temp}${tempUnit} (feels like ${data.main.feels_like}${tempUnit})
    Condition: ${data.weather[0].main} - ${data.weather[0].description}
    Humidity: ${data.main.humidity}%
    Wind Speed: ${data.wind.speed} ${speedUnit}
    Pressure: ${data.main.pressure} hPa
    Visibility: ${(data.visibility / 1000).toFixed(1)} km
    
    Last updated: ${new Date(data.dt * 1000).toLocaleString()}
        `.trim();
    
        return {
          content: [
            {
              type: 'text',
              text: weatherText,
            },
          ],
        };
      }
  • Input schema for the get_current_weather tool, defining the expected parameters: city (required string) and units (optional string enum: metric or imperial, default metric).
    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:77-96 (registration)
    Registration of the get_current_weather tool in the ListToolsRequestSchema handler, providing name, description, and input schema.
    {
      name: 'get_current_weather',
      description: 'Get current weather information 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:126-127 (registration)
    Registration/dispatch logic in the CallToolRequestSchema handler that maps tool calls for 'get_current_weather' to the handler function.
    case 'get_current_weather':
      return await this.getCurrentWeather(args.city, args.units || 'metric');
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