Skip to main content
Glama

fetch-weather

Retrieve current weather data for a specific city using the MCP Weather Server's integration with Claude AI and Postgres database, supporting custom Model Context Protocol.

Instructions

Tool to fetch the weather of a city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesNombre de la ciudad

Implementation Reference

  • main.ts:20-49 (handler)
    Handler function that fetches weather data: first geocodes the city using Open-Meteo geocoding API, then retrieves current weather forecast.
    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.length === 0) { return { content: [ { type: "text", text: `No se encontró información del clima 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&current=temperature_2m,is_day,precipitation,rain&forecast_days=1`) const weatherData = await weatherResponse.json(); return { content: [ { type: "text", text: JSON.stringify(weatherData, null, 2), }, ], }; }
  • main.ts:17-19 (schema)
    Input schema defined with Zod: requires a 'city' string parameter.
    { city: z.string().describe('Nombre de la ciudad'), },
  • main.ts:14-50 (registration)
    Registration of the 'fetch-weather' tool on the McpServer instance.
    server.tool( 'fetch-weather', 'Tool to fetch the weather of a city', { city: z.string().describe('Nombre de la ciudad'), }, 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.length === 0) { return { content: [ { type: "text", text: `No se encontró información del clima 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&current=temperature_2m,is_day,precipitation,rain&forecast_days=1`) const weatherData = await weatherResponse.json(); return { content: [ { type: "text", text: JSON.stringify(weatherData, null, 2), }, ], }; } );

Other Tools

Related 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/FacuPVe/intro-mcp'

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