Real-time weather forecasts for locations across Malaysia from MET Malaysia
š¦ļø Malaysian Weather MCP Server
A production-ready MCP (Model Context Protocol) server that brings real-time Malaysian weather forecasts to your favorite AI assistant.
This project implements a local MCP server that fetches live weather data from MET Malaysia's API and integrates it seamlessly with any MCP-compatible client (Claude Desktop, Cursor, Cline, etc.). Users can ask their AI assistant about Malaysian weather in natural language, and it will use this server to fetch accurate, up-to-date forecasts.
What is MCP?
Model Context Protocol (MCP) is a standard that allows AI assistants to interact with external tools and services. By integrating this MCP server with your AI assistant, you enable it to:
- Query real-time weather data
- Access current and future forecasts for any Malaysian location
- Provide weather information in natural conversation
- Use weather data to inform responses and recommendations
What This Project Does
- Fetches Weather Data: Automatically updates Malaysian weather forecasts from MET Malaysia every 15 minutes
- Exposes MCP Tools: Provides two tools (
check_weather_today,check_7day_forecast) that your AI assistant can call - Manages Data: Stores forecasts in a local MySQL database with automatic cleanup
- Runs Locally: Everything runs on your machine - no cloud dependencies
- Works with Any MCP Client: Add a simple config to your favorite AI tool and start asking about weather!
Quick Overview
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Your Local Machine ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā Your MCP Client (Claude, Cursor, Cline, etc) ā
ā ā ā
ā MCP Server (weather-by-met) ā This Project ā
ā āā server.py (MCP server) ā
ā āā scheduler.py (Updates weather data) ā
ā āā MySQL DB (Stores forecasts) ā
ā ā ā
ā MET Malaysia API (weather data source) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
User: "What's the weather in Kuala Lumpur?"
ā
AI asks MCP Server ā MCP queries database ā AI responds
šÆ Features
- Real-time Weather Data: Automatically fetches weather forecasts every 15 minutes
- 7-Day Forecasts: Access forecasts for up to 7 days ahead
- Multi-Location Support: Query weather for states, districts, towns, recreation centres, and divisions across Malaysia
- AI-Friendly Format: Returns structured data that works with any AI assistant
- Optimized Database: Efficient MySQL storage with automatic cleanup of old records
- Telegram Alerts: Error notifications sent to your Telegram channel for immediate awareness
- Production-Ready: Comprehensive error handling and logging
š Quick Start
Get up and running in 5 minutes! This will set everything up locally on your machine.
Prerequisites
Before starting, ensure you have:
- Python 3.8+ - Install from python.org
- MySQL 8.0+ - Install from mysql.com (or use Homebrew:
brew install mysql) - An MCP Client - One of: Claude Desktop, Cursor IDE, Cline VSCode extension, or any MCP-compatible client
- Git - For cloning this repository
Installation Steps
Step 1: Clone the Repository
git clone https://github.com/zhenkai-dev/weather-by-met.git
cd weather-by-met
Step 2: Install Python Dependencies
pip install -r requirements.txt
This installs:
fastmcp- MCP server frameworkmysql-connector-python- MySQL database driverpydantic- Input validationrequests- For API calls- And other utilities
Step 3: Set Up MySQL Database
# Create a .env file from the template
cp .env.example .env
Now edit .env with your MySQL credentials:
# macOS/Linux
nano .env
# Windows - use Notepad or your editor
Content of .env:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_mysql_password_here
DB_NAME=weather_by_met
Then initialize the database:
python init_db.py
This creates the weather_by_met database and weather_forecasts table automatically.
Step 4: Start the Scheduler (Keep Running)
In one terminal, start the scheduler to fetch weather data:
python scheduler.py
You'll see output like:
[2025-11-10 10:30:00] Starting scheduler...
[2025-11-10 10:30:05] ā Fetched weather for 38 locations
[2025-11-10 10:30:07] ā Scheduler ready - will update every 15 minutes
Keep this terminal running in the background. It will:
- Fetch weather data immediately
- Update every 15 minutes automatically
- Clean old records daily at 12:05 AM (Malaysia Time)
Step 5: Configure Your MCP Client
Choose your MCP client below and follow the configuration steps.
Option A: Claude Desktop
Step 5.1: Open config file
macOS/Linux: ```b
Tools (2)
check_weather_todayFetches the current weather conditions for a specified location in Malaysia.check_7day_forecastRetrieves a seven-day weather forecast for a specified location in Malaysia.Environment Variables
DB_HOSTrequiredMySQL database host addressDB_USERrequiredMySQL database usernameDB_PASSWORDrequiredMySQL database passwordDB_NAMErequiredMySQL database nameConfiguration
{"mcpServers": {"weather-by-met": {"command": "python", "args": ["/path/to/weather-by-met/server.py"]}}}