Skip to main content
Glama

obtener-clima

Get real-time weather data for any city by providing its name. This tool resolves geographic coordinates and fetches current conditions.

Instructions

Herramienta para obtener el clima en tiempo real

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesCity name

Implementation Reference

  • main.ts:16-45 (handler)
    Handler function that performs geocoding for the city, fetches current weather data from Open-Meteo API, and returns formatted JSON response or error message if city not found.
    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 pudo encontrar la información de ${city}` } ] } } const { latitude, longitude } = data.results[0] const getCurrentWeather = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m&current=temperature_2m,precipitation,rain`) const weatherData = await getCurrentWeather.json() return { content: [ { type: 'text', text: JSON.stringify(weatherData, null, 2) } ] } }
  • main.ts:13-15 (schema)
    Input schema defining the 'city' parameter as a string using Zod.
    { city: z.string().describe('City name') },
  • main.ts:10-46 (registration)
    Registration of the 'obtener-clima' tool with MCP server, including name, description, input schema, and handler function.
    server.tool( 'obtener-clima', 'Herramienta para obtener el clima en tiempo real', { 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.length === 0) { return { content: [ { type: 'text', text: `No se pudo encontrar la información de ${city}` } ] } } const { latitude, longitude } = data.results[0] const getCurrentWeather = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m&current=temperature_2m,precipitation,rain`) const weatherData = await getCurrentWeather.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/JunLovin/weather-mcp'

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