OpenWeatherMap MCP Server
Integrates OpenWeatherMap API with MCP to provide weather data, forecasts, air quality, maps, alerts, and geocoding via natural language.
README
OpenWeatherMap MCP Server
A comprehensive OpenWeatherMap API integration server based on Model Context Protocol (MCP), providing AI assistants with full weather data access capabilities.
π Key Features
Core Weather Functions
- π‘οΈ Current Weather Query - Real-time weather data including temperature, humidity, wind speed, pressure, etc.
- π Weather Forecast - 5-day/3-hour interval detailed weather forecasts with trend analysis
- π Air Quality Monitoring - Real-time air quality index and pollutant concentration data
- πΊοΈ Weather Maps - Multi-layer weather map tiles (clouds, precipitation, temperature, etc.)
- β οΈ Weather Alerts - Government-issued weather warnings and safety advisories
- π Historical Weather - Historical weather data queries and multi-day comparison analysis
Smart City Name Query
- π§ Intelligent Fallback - Automatically handles both Chinese and English city names
- π Auto-Geocoding - When direct city name query fails, automatically uses geocoding to get coordinates
- π Universal Support - Works with city names in any language through geocoding API
Additional Features
- π Geocoding - Place name to coordinates conversion with fuzzy search support
- π Reverse Geocoding - Coordinates to place name conversion
- π Multi-Unit Support - Metric, Imperial, and Standard unit systems
- π Multi-Language Support - Chinese, English, and many other languages
π¦ Installation
Prerequisites
- Node.js 18.0.0 or higher
- OpenWeatherMap API key
Get API Key
- Visit OpenWeatherMap
- Register an account and get a free API key
- Set environment variable:
export OPENWEATHER_API_KEY="your_api_key_here"
Installation Methods
Method 1: NPM Global Installation
npm install -g openweather-mcp
Method 2: Build from Source
git clone https://github.com/QianJue-CN/OpenWeatherMCP.git
cd OpenWeatherMCP
npm install
npm run build
π Usage
Run as MCP Server
# Set API key
export OPENWEATHER_API_KEY="your_api_key_here"
# Start server
npx openweather-mcp
Configure in Claude Desktop
Add to Claude Desktop configuration file:
{
"mcpServers": {
"openweather": {
"command": "npx",
"args": ["openweather-mcp"],
"env": {
"OPENWEATHER_API_KEY": "your_api_key_here"
}
}
}
}
Use with Other MCP Clients
Any MCP protocol-compatible client can connect to this server.
π οΈ Available Tools
1. Current Weather Query (get_current_weather)
Get real-time weather information for specified location.
Parameters:
city(optional): City name, e.g., "Beijing" or "εδΊ¬" or "Beijing,CN"lat(optional): Latitude (-90 to 90)lon(optional): Longitude (-180 to 180)zip(optional): Postal code, e.g., "10001,US"units(optional): Unit system (metric/imperial/standard)lang(optional): Language code (zh_cn/en/es/fr/de/ja/ko/ru)
Smart City Name Support:
- β "εδΊ¬" (Chinese) β Automatically works
- β "Beijing" (English) β Automatically works
- β "δΈζ΅·" (Chinese) β Automatically works
- β "Shanghai" (English) β Automatically works
Example:
{
"city": "εδΊ¬",
"units": "metric",
"lang": "zh_cn"
}
2. Weather Forecast (get_weather_forecast)
Get 5-day weather forecast data.
Parameters:
- Location parameters same as above
cnt(optional): Number of forecast time points (max 40)
Example:
{
"lat": 39.9042,
"lon": 116.4074,
"cnt": 16,
"units": "metric"
}
3. Air Quality (get_air_quality)
Get air quality data.
Parameters:
lat: Latitudelon: Longitudestart(optional): Start timestamp (for historical data)end(optional): End timestamp (for historical data)
4. Weather Maps (get_weather_map)
Get weather map tiles.
Parameters:
layer: Layer type (clouds_new/precipitation_new/pressure_new/wind_new/temp_new)z: Zoom level (0-10)x: Tile X coordinatey: Tile Y coordinate
5. Weather Alerts (get_weather_alerts)
Get weather warning information.
Parameters:
lat: Latitudelon: Longitude
6. Historical Weather (get_historical_weather)
Query historical weather data.
Parameters:
lat: Latitudelon: Longitudedt: Unix timestamp for query dateunits: Unit systemlang: Language code
7. Geocoding (geocoding)
Get coordinates from place names.
Parameters:
q: Location query stringlimit: Number of results to return (1-5)
8. Reverse Geocoding (reverse_geocoding)
Get place names from coordinates.
Parameters:
lat: Latitudelon: Longitudelimit: Number of results to return (1-5)
π Usage Examples
Query Beijing Current Weather
{
"tool": "get_current_weather",
"parameters": {
"city": "εδΊ¬",
"units": "metric",
"lang": "zh_cn"
}
}
Get Shanghai 5-Day Weather Forecast
{
"tool": "get_weather_forecast",
"parameters": {
"city": "δΈζ΅·",
"units": "metric",
"lang": "zh_cn"
}
}
Query Air Quality
{
"tool": "get_air_quality",
"parameters": {
"lat": 39.9042,
"lon": 116.4074
}
}
π How Smart City Name Query Works
- Direct Query: First attempts to query weather using the provided city name directly
- Auto Fallback: If direct query fails (404 error), automatically triggers geocoding
- Coordinate Conversion: Converts city name to precise coordinates via geocoding API
- Re-query: Uses obtained coordinates to re-query weather data
- Seamless Experience: The entire process is transparent to users, no manual handling required
This means you can use city names in any language:
- Chinese: εδΊ¬γδΈζ΅·γεΉΏε·γζ·±ε³
- English: Beijing, Shanghai, Guangzhou, Shenzhen
- Other languages: ζ±δΊ¬γγ½γ¦γ«γParis, London
π§ Development
Project Structure
src/
βββ index.ts # MCP server entry point
βββ types/
β βββ weather.ts # Weather data type definitions
β βββ mcp.ts # MCP tool type definitions
βββ services/
β βββ openweather.ts # OpenWeatherMap API service
βββ tools/
βββ current-weather.ts # Current weather tool
βββ forecast.ts # Weather forecast tool
βββ air-pollution.ts # Air quality tool
βββ weather-maps.ts # Weather maps tool
βββ weather-alerts.ts # Weather alerts tool
βββ historical-weather.ts # Historical weather tool
Build and Test
# Install dependencies
npm install
# Build project
npm run build
# Development mode (watch file changes)
npm run dev
# Run tests
npm test
# Code linting
npm run lint
π Supported Location Formats
City Names
"εδΊ¬"- Chinese city name"Beijing"- English city name"Beijing,CN"- City name + country code"New York,US"- Full format
Coordinates
- Latitude: -90 to 90
- Longitude: -180 to 180
- Example:
lat: 39.9042, lon: 116.4074
Postal Codes
"10001,US"- US postal code"100000,CN"- Chinese postal code
π Data Formats
Temperature Units
metric: Celsius (Β°C)imperial: Fahrenheit (Β°F)standard: Kelvin (K)
Wind Speed Units
metric: Meters per second (m/s)imperial: Miles per hour (mph)
Language Support
zh_cn: Simplified Chineseen: Englishes: Spanishfr: Frenchde: Germanja: Japaneseko: Koreanru: Russian
β οΈ Important Notes
- API Limits: Free accounts have call limits, please use reasonably
- Historical Data: Historical weather data requires paid subscription
- One Call API: Weather alerts feature requires One Call API 3.0 subscription
- Network Connection: Ensure server can access OpenWeatherMap API
π€ Contributing
Issues and Pull Requests are welcome!
π License
MIT License
π Related Links
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.