An autonomous AI Agent built with the Model Context Protocol (MCP) and Playwright, designed to fetch real-time weather forecasts in Israel directly from Weather2Day using browser automation.
Instead of relying on standard APIs, this project implements a custom MCP Server that places an LLM (Gemini) "in the driver's seat" of a real browser.
The agent can:
- Open a Chromium browser via Playwright and navigate to the weather portal.
- Locate the search input (
#city_search_forecast) and type the requested Israeli city. - Select the city from the dropdown list.
- Extract the forecast text from the resulting page and feed it back to the LLM (implementing a local RAG approach) so it can answer the user's question naturally.
- Model Context Protocol (MCP): The official protocol for exposing local tools to LLMs.
- Playwright: Microsoft's browser automation library for handling UI interactions.
- Google Gemini API (
google.generativeai): The core LLM powering the agent's decision-making and response generation. - Python & Asyncio: Managing asynchronous execution and server-client communication.
Make sure you have uv installed on your machine.
Clone the repository and install dependencies:
uv syncInstall the Playwright browser binaries:
Bash uv run playwright install chromium
Create a .env file in the root directory and add your Google Gemini API key:
קטע קוד
GOOGLE_API_KEY=your_gemini_api_key_here
Bash uv run host.py
"What is the weather like in Jerusalem?"
"Can you check the forecast for Tel Aviv?"