Built as a Node.js application using ES modules for weather data retrieval and processing
Distributed and managed as an npm package with standard installation and build processes
Implemented with full TypeScript support providing type-safe weather data structures and comprehensive interfaces for API responses
Uses Zod schema validation to ensure data integrity and type safety for weather API responses and parameters
MCP Weather Server
A Model Context Protocol (MCP) server that provides detailed weather information for any city using the Open-Meteo API.
Features
- 🌤️ Real-time weather data for any city worldwide
- 📅 7-day weather forecast with daily temperatures and precipitation
- 🌬️ Air quality information including European Air Quality Index
- 📍 Automatic geocoding - just provide a city name
- 🌡️ Current conditions including temperature, humidity, and precipitation
- 📊 Hourly forecast for the next 24 hours
- 🌅 Sunrise and sunset times for planning outdoor activities
- 🎯 Human-readable weather descriptions instead of raw codes
- ⚡ Robust error handling with retry logic and timeouts
- 🛡️ Type-safe with full TypeScript support
- 🎨 Structured JSON output for easy programmatic access
Installation
Usage
Development
Production
Build
Testing with MCP Inspector
You can test the weather server using the MCP Inspector, a GUI tool for testing MCP servers.
1. Install and Run MCP Inspector
2. Configure the Server
In the MCP Inspector settings:
- Command:
npx
- Arguments:
tsx main.ts
3. Test the Tools
Once connected, you can test all three tools:
get-weather: Get current weather conditions and hourly forecast
- Select the
get-weather
tool from the available tools list - Enter a city name (e.g., "New York", "London", "Tokyo")
- Click "Call Tool" to see current weather data
get-forecast: Get 7-day weather forecast
- Select the
get-forecast
tool from the available tools list - Enter a city name
- Click "Call Tool" to see 7-day forecast with daily temperatures and sunrise/sunset times
get-air-quality: Get air pollution data
- Select the
get-air-quality
tool from the available tools list - Enter a city name
- Click "Call Tool" to see air quality index and pollutant levels
The inspector will display the JSON response with all the structured data for each tool.
API
The server provides three tools for comprehensive weather and air quality information:
1. get-weather
Get detailed current weather information for any city.
Parameters:
city
(string, required): The name of the city to get weather for- Examples: "New York", "London", "Tokyo", "Paris"
2. get-forecast
Get 7-day weather forecast for any city.
Parameters:
city
(string, required): The name of the city to get forecast for- Examples: "New York", "London", "Tokyo", "Paris"
3. get-air-quality
Get air pollution data for any city.
Parameters:
city
(string, required): The name of the city to get air quality for- Examples: "New York", "London", "Tokyo", "Paris"
Example Outputs
get-weather
Output
Returns structured JSON data with current conditions and hourly forecast:
get-forecast
Output
Returns 7-day forecast with daily temperatures, precipitation, and sunrise/sunset times:
get-air-quality
Output
Returns air pollution data with European Air Quality Index and pollutant levels:
Improvements Made
1. Enhanced Data Structure
- Replaced raw API JSON with structured, processed weather data
- Added both raw values and formatted strings for flexibility
- Included location details with coordinates and full names
- Provided hourly forecast in a structured array format
- Maintained backward compatibility with original API response
2. Robust Error Handling
- Implemented retry logic with exponential backoff
- Added request timeouts to prevent hanging requests
- Better error messages for different failure scenarios
- Graceful handling of city not found errors
3. Type Safety
- Added comprehensive TypeScript interfaces for all API responses
- Proper type checking for geocoding and weather data
- Better IntelliSense support and compile-time error detection
4. Configuration Management
- Centralized configuration object for easy maintenance
- Configurable timeouts, retry counts, and API endpoints
- Easy to modify settings without touching core logic
5. Performance & Reliability
- Request timeout handling (10 seconds)
- Automatic retry for failed requests (up to 3 attempts)
- Proper URL encoding for city names
- Abort controller for request cancellation
6. Data Processing
- Weather code mapping to human-readable descriptions
- Proper formatting for temperatures, precipitation, and times
- Location name formatting with state/province when available
- Timezone-aware time formatting
7. Code Organization
- Separated concerns into utility functions
- Clear function naming and documentation
- Modular design for easy testing and maintenance
- Consistent error handling patterns
Technical Details
- Framework: Model Context Protocol (MCP) SDK
- Language: TypeScript
- APIs: Open-Meteo (geocoding and weather)
- Transport: StdioServerTransport
- Validation: Zod schema validation
- Runtime: Node.js with ES modules
Error Handling
The server handles various error scenarios:
- City not found: Returns a helpful message with spelling suggestions
- Network errors: Retries up to 3 times with exponential backoff
- API errors: Provides user-friendly error messages
- Timeout errors: Aborts requests after 10 seconds
License
ISC
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Provides comprehensive weather information including current conditions, 7-day forecasts, and air quality data for any city worldwide using the Open-Meteo API. Features real-time weather data, hourly forecasts, sunrise/sunset times, and European Air Quality Index with human-readable descriptions.
Related MCP Servers
- -securityAlicense-qualityProvides real-time weather data, forecasts, and historical weather information from OpenWeatherMap API for Claude Desktop, enabling natural language queries about current conditions, forecasts, air quality, and weather alerts worldwide.Last updated -7PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that retrieves current weather information for specified cities using the Open-Meteo API, requiring no API key.Last updated -316PythonApache 2.0
- -securityFlicense-qualityProvides current weather and air quality data for any city using WeatherAPI, easily integrating with MCP clients like n8n and Claude Desktop App.Last updated -681JavaScript
- -securityAlicense-qualityWeather forecast server which returns 7 days of detailed weather anywhere in the world, using the OpenWeatherMap One Call API 3.0.Last updated -3PythonMIT License