stivluc/MCP_Weather_Server
If you are the rightful owner of MCP_Weather_Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The MCP Weather Server is a Model Context Protocol server that provides weather data tools and resources using the OpenWeatherMap API.
get_weather
Get current weather conditions for any city
get_forecast
Get 5-day weather forecast for any city
search_cities
Search and geocode cities worldwide
๐ค๏ธ MCP Weather Server
A Model Context Protocol (MCP) server that provides weather data tools and resources using OpenWeatherMap API.
๐ฏ What is MCP?
Model Context Protocol (MCP) is a standardized way for AI assistants to connect to external tools and data sources. This weather server implements the MCP protocol to provide:
- ๐ ๏ธ MCP Tools:
get_weather
,get_forecast
,search_cities
- ๐ MCP Resources: Weather data for popular cities and search functionality
- ๐ Real-time Data: Live weather information from OpenWeatherMap API
- ๐ Structured Access: JSON-based weather data through MCP protocol
โจ MCP Features
Tools Available
- get_weather: Get current weather conditions for any city
- get_forecast: Get 5-day weather forecast for any city
- search_cities: Search and geocode cities worldwide
Resources Available
- weather://new-york: Weather data for New York
- weather://london: Weather data for London
- weather://tokyo: Weather data for Tokyo
- weather://paris: Weather data for Paris
- weather://sydney: Weather data for Sydney
- weather://los-angeles: Weather data for Los Angeles
- weather://berlin: Weather data for Berlin
- weather://search: General search functionality
๐ Quick Start
Running the MCP Server
- Clone the repository
git clone https://github.com/yourusername/mcp-weather-server.git
cd mcp-weather-server
- Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies
pip install -r requirements.txt
- Set API key
export API_KEY=your_openweathermap_api_key_here
- Run the MCP server
python run_mcp_server.py
Using with Claude Desktop
Add this configuration to your Claude Desktop MCP settings:
{
"mcpServers": {
"weather": {
"command": "python",
"args": ["/path/to/your/project/mcp_weather_server.py"],
"env": {
"API_KEY": "your_openweathermap_api_key_here"
}
}
}
}
Get OpenWeatherMap API Key
- Sign up at OpenWeatherMap
- Get your free API key
- Use it in the environment variable
API_KEY
๐๏ธ MCP Architecture
- Protocol: Model Context Protocol (MCP) over stdio
- Transport: JSON-RPC communication
- Server: Python with mcp library
- API: OpenWeatherMap for weather data and geocoding
- Tools: 3 MCP tools (get_weather, get_forecast, search_cities)
- Resources: 8 MCP resources (popular cities + search)
๐ Project Structure
mcp-weather-server/
โโโ mcp_weather_server.py # Main MCP server implementation
โโโ run_mcp_server.py # Server runner script
โโโ mcp_config.json # MCP configuration example
โโโ requirements.txt # Python dependencies (mcp library)
โโโ app.py # Legacy Flask app (for reference)
โโโ README.md # This file
โโโ .env # Environment variables (API_KEY)
๐ง MCP Tools Usage
get_weather Tool
{
"name": "get_weather",
"arguments": {
"city": "London",
"units": "metric"
}
}
get_forecast Tool
{
"name": "get_forecast",
"arguments": {
"city": "Tokyo",
"units": "imperial"
}
}
search_cities Tool
{
"name": "search_cities",
"arguments": {
"query": "New York",
"limit": 5
}
}
๐ MCP Resources Access
Resources can be accessed via URI patterns:
weather://new-york
- Weather data for New Yorkweather://london
- Weather data for Londonweather://search
- General search information
๐ก๏ธ Security
- โ API keys properly externalized via environment variables
- โ MCP server runs in isolated process
- โ Input validation on all tool parameters
- โ Error handling for API failures
- โ No hardcoded secrets in repository
๐งช Testing the MCP Server
You can test the server functionality by running it directly:
# Test the server
python run_mcp_server.py
# The server communicates via stdio using JSON-RPC
# It's designed to be used by MCP clients like Claude Desktop
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes (ensure MCP protocol compliance)
- Test with MCP clients
- Submit a pull request
๐ License
This project is open source and available under the .
๐ MCP Features in Action
- Tool Integration โ AI can call weather tools directly
- Resource Access โ Structured weather data via URIs
- Real-time Data โ Live weather information through MCP
- Error Handling โ Graceful MCP error responses
- Protocol Compliance โ Full MCP specification support
Built to learn about MCP.