weather-chat-mcp

weather-chat-mcp

Enables LLMs to fetch Israeli weather forecasts by controlling a real browser via Playwright, simulating human interactions like typing and clicking on a weather website.

Category
访问服务器

README

🌦️ Weather Israel MCP Server (Playwright)

The MCP that puts the LLM's hand on the mouse.
Weather forecasts Made in Israel — not through a boring API, but the Israeli way: open a browser, poke your nose into the site, type, click... and get a forecast.


🎯 What is this project?

In the classic Weather MCP example, the LLM pulls weather data through a US API. Nice, but... who really cares about a forecast somewhere in the USA when you need the current temperature in Tel Aviv or Jerusalem?

This project builds an Israeli MCP Server that gives the LLM a completely human ability: to control a real browser. Instead of calling an API, the Agent:

  1. Opens a real Chromium browser (in headless=False mode, so you can watch it live!).
  2. Types a city name into the search field of weather2day.co.il.
  3. Picks the city from the autocomplete dropdown dynamically.
  4. Scrapes the page content, cleans it, and feeds it back to the LLM so it can answer on its own (Retrieval-Augmented Generation / RAG).

The big idea: Everything a human user does with two hands — the LLM learns to do with four Tools.


🧠 What you'll learn

  • Build your own MCP Server for any purpose or targeted website.
  • Expose Python functions as Tools for an LLM using the FastMCP decorator.
  • Use Playwright to give an LLM physical control over a browser (mouse & keyboard simulation).
  • Build RAG (Retrieval-Augmented Generation): Stream live, freshly-scraped page content directly into the model's context.
  • Sync & Stability: Handle dynamic web element loading and prevent flakiness in browser automation.

📂 Project Structure

project-template/ ├── weather_Israel.py # MCP Server — Israel forecast via Playwright ├── host.py # Terminal chat — connects the LLM to the MCP server ├── client.py # Generic MCP Client (stdio communication) ├── pyproject.toml # Project dependencies and metadata (uv) └── .env # Environment variables (OpenAI API key)


🛠️ Technologies Used

  • Python 3.13+
  • FastMCP (MCP SDK) - Anthropic's official framework for building Model Context Protocol servers easily.
  • Playwright (Python Async API) - Advanced browser automation and control library.
  • OpenAI API - The brain of the Agent (powered by gpt-4o-mini), deciding which tools to call and interpreting the results.

🧩 The Four Tools of the Israeli MCP

The manual steps a human performs on the website are broken down into 4 modular tools that the LLM calls sequentially:

Tool What it does Human equivalent
open_weather_forecast_israel Launches Chromium in non-headless mode and navigates to the forecast site. Open a browser and go to the site.
enter_weather_forecast_city_israel(city) Finds the search field, clears it, and types the city name char-by-char to trigger autocomplete. Click the search bar and type the city name.
select_weather_forecast_city_israel Detects the dropdown list, clicks the first auto-complete suggestion, and waits for the city page to load. Click on the correct city from the suggestions.
get_forecast_content_israel Scrapes the loaded page, cleans up redundant spaces and empty lines, and feeds it back to the LLM. Read the forecast details on the screen.

Why not just search Google?
Running a Google search through automated browsers quickly triggers CAPTCHA challenges. By guiding the Agent through a direct, targeted flow on a specific website, we bypass bot detection completely and guarantee a seamless run.


🛡️ Loop Protection (מנגנון מניעת לולאות)

During development, we identified that LLMs can sometimes get stuck in an infinite loop, calling the same tool repeatedly (such as trying to open the browser over and over).

To prevent this, we implemented a strict Loop Protection Mechanism inside host.py:

  • The host keeps track of all executed tools within the current turn.
  • If the LLM tries to invoke the same tool more than once per turn, the call is blocked and a system message is returned: "This action has already been completed in this turn. Please proceed to the next step."
  • This forces the LLM to progress linearly: Open ➔ Type ➔ Select ➔ Scrape.

🚀 Setup & Run (שלב אחר שלב)

This project is managed using uv for ultra-fast dependency management.

  1. Install dependencies and set up the environment: Command: uv sync

  2. Install the Chromium browser for Playwright: Command: uv run playwright install chromium

  3. Configure your API key: Create a .env file in the project root and add your OpenAI API key: OPENAI_API_KEY=your_actual_api_key_here (The .env file is already listed in .gitignore to ensure your secret key is never pushed to public repositories).

  4. Start the Chat Agent: Command: uv run host.py

    Type your query in the terminal, press Enter, and watch the browser open and perform the actions on its own! To exit, simply type "quit".


💬 Example Questions to Try

The Agent will analyze your request and trigger the correct sequence of tools automatically. Try asking:

  • "מה מזג האוויר בירושלים היום?" (What's the weather in Jerusalem today?)
  • "Check the temperature in Tel Aviv for the upcoming days"
  • "האם צפוי לרדת גשם בחיפה מחר? מה אחוזי הלחות?"

💭 A Closing Thought

Playwright was born long before the GenAI era — originally designed as a testing automation tool for developers. But with the rise of AI Agents, it has taken center stage. Suddenly, giving an LLM "hands and a mouse" to interact with the real web has become the ultimate way to bridge the gap between static knowledge and real-world actions.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选