getWeatherForecast
Retrieve weather forecast data for any location using geographic coordinates to support planning and decision-making.
Instructions
Get weather forecast for a specific location using coordinates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/plugins/weatherPlugin.ts:24-41 (handler)The core handler function for the getWeatherForecast tool. Validates input arguments using WeatherForecastSchema and simulates a weather API call to return formatted forecast data.async (args: { [x: string]: any }) => { const { latitude, longitude }: WeatherForecastArgs = validateToolArgs( WeatherForecastSchema, args ); // Simulate weather API call (replace with actual API) const forecast = await simulateWeatherAPI(latitude, longitude); return { content: [ { type: 'text', text: `Weather forecast for coordinates (${latitude}, ${longitude}):\n${forecast}`, }, ], }; }
- src/schemas/toolSchemas.ts:46-49 (schema)Zod schema defining the input parameters for getWeatherForecast: latitude and longitude numbers (referencing common schemas).export const WeatherForecastSchema = z.object({ latitude: LatitudeSchema, longitude: LongitudeSchema, });
- src/plugins/weatherPlugin.ts:17-42 (registration)Tool registration call within registerWeatherTools function, including name, metadata, and inline handler. Called from src/server.ts.server.registerTool( 'getWeatherForecast', { title: 'Get Weather Forecast', description: 'Get weather forecast for a specific location using coordinates', }, async (args: { [x: string]: any }) => { const { latitude, longitude }: WeatherForecastArgs = validateToolArgs( WeatherForecastSchema, args ); // Simulate weather API call (replace with actual API) const forecast = await simulateWeatherAPI(latitude, longitude); return { content: [ { type: 'text', text: `Weather forecast for coordinates (${latitude}, ${longitude}):\n${forecast}`, }, ], }; } );
- src/plugins/weatherPlugin.ts:76-96 (helper)Helper function simulating a weather API call, generating mock forecast data including temperature, conditions, and location info.async function simulateWeatherAPI( latitude: number, longitude: number ): Promise<string> { // Simulate API delay await new Promise(resolve => setTimeout(resolve, 100)); // Generate mock forecast based on coordinates const temperature = Math.round( 20 + latitude * 0.5 + (Math.random() * 10 - 5) ); const conditions = ['Sunny', 'Cloudy', 'Rainy', 'Partly Cloudy']; const condition = conditions[Math.floor(Math.random() * conditions.length)]; return ` π€οΈ Current Conditions: ${condition} π‘οΈ Temperature: ${temperature}Β°C Location: ${latitude.toFixed(4)}, ${longitude.toFixed(4)} β° Updated: ${new Date().toLocaleString()} `.trim(); }