MCP_Weather_Server

stivluc/MCP_Weather_Server

3.2

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.

Tools
  1. get_weather

    Get current weather conditions for any city

  2. get_forecast

    Get 5-day weather forecast for any city

  3. 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

  1. Clone the repository
git clone https://github.com/yourusername/mcp-weather-server.git
cd mcp-weather-server
  1. Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set API key
export API_KEY=your_openweathermap_api_key_here
  1. 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

  1. Sign up at OpenWeatherMap
  2. Get your free API key
  3. 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 York
  • weather://london - Weather data for London
  • weather://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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes (ensure MCP protocol compliance)
  4. Test with MCP clients
  5. Submit a pull request

๐Ÿ“„ License

This project is open source and available under the .

๐ŸŽ‰ MCP Features in Action

  1. Tool Integration โ†’ AI can call weather tools directly
  2. Resource Access โ†’ Structured weather data via URIs
  3. Real-time Data โ†’ Live weather information through MCP
  4. Error Handling โ†’ Graceful MCP error responses
  5. Protocol Compliance โ†’ Full MCP specification support

Built to learn about MCP.