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
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | City 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¤t=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¤t=temperature_2m,precipitation,rain`) const weatherData = await getCurrentWeather.json() return { content: [ { type: 'text', text: JSON.stringify(weatherData, null, 2) } ] } } )