Skip to main content
Glama
panchocorderos

Weather MCP Server

get-weather

Fetch current weather data for any city using the Open-Meteo API. Provide a city name to get temperature, conditions, and forecasts.

Instructions

Tool to fetch the weather for a given city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesCity name

Implementation Reference

  • main.ts:18-46 (handler)
    Handler function that fetches geocoding data for the city, then retrieves current weather data from Open-Meteo API and returns it as JSON string.
    async ({ city }) => {
      const response = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${city}&count=10&language=en&format=json`);
      const data = await response.json();
    
      if (data.results.length === 0) {
        return {
          content: [
            {
              type: "text",
              text: `No weather data found for ${city}`,
            }
          ]
        };
      }
    
      const {latitude, longitude} = data.results[0];
    
      const weatherResponse = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true&precipitation=true&hourly=temperature_2m¤t=precipitation,temperature_2m,rain,is_day`);
      const weatherData = await weatherResponse.json();
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(weatherData, null, 2)
          }
        ]
      };
    }
  • main.ts:15-17 (schema)
    Zod schema defining the input parameter 'city' as a string.
    {
      city: z.string().describe("City name"),
    },
  • main.ts:12-47 (registration)
    Registration of the 'get-weather' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool(
      "get-weather",
      "Tool to fetch the weather for a given city",
      {
        city: z.string().describe("City name"),
      },
      async ({ city }) => {
        const response = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${city}&count=10&language=en&format=json`);
        const data = await response.json();
    
        if (data.results.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No weather data found for ${city}`,
              }
            ]
          };
        }
    
        const {latitude, longitude} = data.results[0];
    
        const weatherResponse = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true&precipitation=true&hourly=temperature_2m¤t=precipitation,temperature_2m,rain,is_day`);
        const weatherData = await weatherResponse.json();
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(weatherData, null, 2)
            }
          ]
        };
      }
    );
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/panchocorderos/poc-mcp'

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