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
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | City 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',