Weather Israel MCP Server

Weather Israel MCP Server

Enables users to query weather forecasts for Israeli cities through natural language using browser automation and Gemini.

Category
访问服务器

README

🌤️ Weather Israel — Agentic MCP Server with Browser Automation

An AI-powered weather assistant that autonomously controls a browser to fetch real-time Israeli weather forecasts using the Model Context Protocol (MCP) and Playwright.

Python MCP Playwright Gemini


📌 Overview

This project implements a custom MCP (Model Context Protocol) Server that gives an LLM autonomous browser control capabilities. Instead of relying on a traditional weather API, the system opens a real browser, navigates to an Israeli weather website, searches for a city, and extracts the live forecast — just like a human would.

The LLM (Gemini 2.5 Flash) acts as the orchestrating agent, deciding which tools to invoke and in what sequence, creating a fully autonomous agentic pipeline.

Why is this interesting?

  • No API needed — scrapes data directly from the web using browser automation
  • Agentic architecture — the LLM decides which tools to call and when
  • MCP standard — uses Anthropic's open protocol for tool communication
  • RAG pattern — extracts page content and feeds it back to the LLM for reasoning

🎯 Project Goals

  • Implement a custom MCP Server from scratch
  • Use Playwright to add browser automation capabilities to an LLM
  • Demonstrate agentic tool-calling with multi-step orchestration
  • Build a complete RAG pipeline — retrieve data → augment context → generate response

🏗️ Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         User Query                               │
│              "What's the weather in Tel Aviv?"                    │
└─────────────────────────┬───────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│                    host.py (Orchestrator)                         │
│              Gemini 2.5 Flash + Tool Calling                     │
└─────────────────────────┬───────────────────────────────────────┘
                          │ MCP Protocol
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│               weather_Israel.py (MCP Server)                     │
│                                                                  │
│   Tool 1: open_weather_forecast_israel()                         │
│   Tool 2: enter_weather_forecast_city_israel(city)               │
│   Tool 3: select_weather_forecast_city_israel()                  │
│   Tool 4: get_weather_page_content()                             │
└─────────────────────────┬───────────────────────────────────────┘
                          │ Playwright
                          ▼
┌─────────────────────────────────────────────────────────────────┐
│              weather2day.co.il (Live Website)                     │
│         Real-time weather data scraped from browser               │
└─────────────────────────────────────────────────────────────────┘

🛠️ Tech Stack

Technology Purpose
Python 3.13+ Core language
MCP SDK Model Context Protocol — exposes tools to the LLM
Playwright Headless browser automation (Chromium)
Gemini 2.5 Flash LLM for reasoning and tool orchestration
httpx HTTP client for Gemini REST API calls
uv Modern Python package manager

📁 Project Structure

MCP/
├── weather_Israel.py     # MCP Server — Israeli weather tools (Playwright)
├── weather_USA.py        # MCP Server — US weather tools (API-based)
├── host.py               # Orchestrator — Gemini + MCP client integration
├── client.py             # Generic MCP client connector
├── pyproject.toml        # Dependencies and project metadata
├── .env.example          # Environment variable template
├── .gitignore            # Git ignore rules
├── uv.lock               # Locked dependencies
└── README.md             # This file

🔧 MCP Tools — weather_Israel.py

# Tool Description
1 open_weather_forecast_israel() Launches Chromium and navigates to the weather website
2 enter_weather_forecast_city_israel(city) Types the city name into the search field using keyboard simulation
3 select_weather_forecast_city_israel() Clicks the first autocomplete result from the dropdown
4 get_weather_page_content() Extracts and cleans the visible text from the forecast page

⚡ Prerequisites

  • Python 3.13 or higher
  • uv package manager (pip install uv)
  • Gemini API Key from Google AI Studio

📦 Installation

1. Clone the repository

git clone https://github.com/yael3222664-alt/MCP.git
cd MCP

2. Install dependencies

uv sync

3. Install Chromium for Playwright

uv run playwright install chromium

4. Configure environment variables

Create a .env file in the project root:

GEMINI_API_KEY=your_gemini_api_key_here

Get your free API key at Google AI Studio


🚀 Running the Application

python -m uv run host.py

You'll see:

MCP Client Started!
Type your queries or 'quit' to exit.

Query: 

💬 Example Queries & Output

Query:

מה מזג האוויר בבני ברק?

Agent Actions:

[Calling tool weather_Israel__open_weather_forecast_israel with args {}]
[Calling tool weather_Israel__enter_weather_forecast_city_israel with args {'city': 'בני ברק'}]
[Calling tool weather_Israel__select_weather_forecast_city_israel with args {}]
[Calling tool weather_Israel__get_weather_page_content with args {}]

Response:

The current temperature in Bnei Brak is 30°C with wind speed of 15 km/h 
and gusts up to 37 km/h from the west. Humidity is at 52%.

Hourly forecast for today:
• 14:00 — 30°C, humidity 52%, wind 15 km/h
• 15:00 — 30°C, humidity 52%, wind 15 km/h
• 16:00 — 29°C, humidity 54%, wind 14 km/h
...

More examples:

What's the weather in Jerusalem?
מה התחזית לחיפה?
How's the weather in Tel Aviv today?
What are the weather alerts in California?  (uses USA tools)

� How It Works — Step by Step

  1. User asks a question → "What's the weather in Tel Aviv?"
  2. Gemini analyzes the query and identifies the required tools
  3. Tool 1 → Playwright opens a headless Chromium browser and navigates to the weather site
  4. Tool 2 → Playwright types the city name into the search field (character by character to trigger autocomplete)
  5. Tool 3 → Playwright clicks the first matching result in the dropdown
  6. Tool 4 → Playwright extracts all visible text from the forecast page
  7. Gemini receives the raw page content and formulates a clean, structured answer
  8. User gets a natural language response with temperature, wind, humidity, and hourly forecast

🧠 Key Design Decisions

  • Keyboard simulation (keyboard.type()) instead of fill() — triggers the website's JavaScript autocomplete
  • Direct REST API calls to Gemini with httpx(verify=False) — bypasses SSL issues in restricted network environments
  • Global browser state — shared between tool calls so the same page instance persists across the multi-step workflow
  • Graceful error handling — each tool validates state and returns clear error messages

🐛 Troubleshooting

Issue Solution
uv: command not found Use python -m uv instead of uv
GEMINI_API_KEY not found Create .env file with your API key
429 Too Many Requests Rate limit — wait 1 minute or use a different API key
Browser doesn't open Run uv run playwright install chromium
SSL errors The code already disables SSL verification for restricted networks

📚 Resources


📄 License

This project is open source and available for educational purposes.


Built with Playwright 🎭 and the Model Context Protocol 🤖

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选