get_current_weather
Retrieve real-time weather data for any specified location using the Weather MCP Server. Input a location name to fetch current conditions instantly.
Instructions
Get current weather information for a specified location
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| location | Yes | Location name (e.g., Hong Kong, Tokyo, London) |
Implementation Reference
- src/weather-service.ts:8-26 (handler)Core handler function that implements the get_current_weather tool logic: normalizes the input location, fetches mock weather data if available, or generates random data, and adds a current timestamp.async getCurrentWeather(location: string): Promise<WeatherData> { // Normalize location name using location mapping const normalizedLocation = this.normalizeLocation(location); if (mockWeatherData[normalizedLocation]) { return { ...mockWeatherData[normalizedLocation], timestamp: new Date().toISOString() }; } // If location not found, return random weather data const randomData = getRandomWeatherData(); return { ...randomData, location: location, timestamp: new Date().toISOString() }; }
- src/types.ts:1-13 (schema)TypeScript interface defining the structure of the WeatherData returned by the get_current_weather tool.export interface WeatherData { location: string; temperature: number; humidity: number; windSpeed: number; windDirection: string; condition: string; description: string; pressure: number; visibility: number; uvIndex: number; timestamp: string; }
- src/index.ts:38-51 (registration)Tool registration in the stdio MCP server (index.ts): defines name, description, and input schema for list tools response.{ name: 'get_current_weather', description: 'Get current weather information for a specified location', inputSchema: { type: 'object', properties: { location: { type: 'string', description: 'Location name (e.g., Hong Kong, Tokyo, London)', }, }, required: ['location'], }, },
- src/index.ts:117-128 (registration)Tool call handler dispatch in stdio MCP server: handles 'get_current_weather' case by calling the weather service and formatting response.case 'get_current_weather': { const { location } = args as { location: string }; const weather = await this.weatherService.getCurrentWeather(location); return { content: [ { type: 'text', text: JSON.stringify(weather, null, 2), }, ], }; }
- src/weather-service.ts:110-122 (helper)Helper method used by the handler to normalize location strings for lookup in mock data.private normalizeLocation(location: string): string { const lowerLocation = location.toLowerCase().trim(); // Check if location exists in mapping if (locationMapping[lowerLocation]) { return locationMapping[lowerLocation]; } // Fallback to original normalization return lowerLocation .replace(/\s+/g, '-') .replace(/[^a-z0-9-]/g, ''); }