Skip to main content
Glama
itsPatH

Basic MCP Weather Tool

by itsPatH

fetch-weather

Get current weather data for any city using the Open-Meteo API. Provide a city name to receive temperature and conditions information.

Instructions

Tool to fetch weather information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesCity name

Implementation Reference

  • main.ts:19-47 (handler)
    Handler function that performs geocoding for the city using Open-Meteo API, then fetches current and hourly weather data, returning it as JSON text.
      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 || data.results.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: `No se encontró información para la ciudad: ${city}.`,
              }
            ]
          };
        }
    
        const { latitude, longitude } = data.results[0];
    
        const weatherResponse = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m¤t=temperature_2m,precipitation,is_day,rain&forecast_days=1`);
        const weatherData = await weatherResponse.json();
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(weatherData, null, 2),
            }
          ]
        };
      }
    );
  • main.ts:16-18 (schema)
    Input schema defining 'city' as a required string parameter.
    {
      city: z.string().describe('City name'),
    },
  • main.ts:13-15 (registration)
    Registration of the 'fetch-weather' tool with MCP server, including name, description, schema, and handler.
    server.tool(
      'fetch-weather',
      'Tool to fetch weather information',
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/itsPatH/basicMCP'

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