Skip to main content
Glama
mcp-weather-israel-playwright

mcp-weather-israel-playwright

by esty783

MCP with Playwright - 天気 (イスラエル)

このプロジェクトは、Malka Baruch のコース「MCP with Playwright」の MCP (Model Context Protocol) 課題です。

プロジェクトの目的

MCP サーバーは、Playwright を使用して実際のブラウザを操作し、https://www.weather2day.co.il/forecast からデータをスクレイピングすることで、イスラエルの都市の天気予報を提供します。目的は、LLM(Claude)が公開された Tools を通じてブラウザを制御し、従来の API なしでライブの Web データを取得できるようにすることです。

Related MCP server: MCP Playwright Weather Israel

実装した内容

Tools(MCP サーバー - weather_Israel.py):

  1. open_weather_forecast_israel()

    • Chromium ブラウザを(headless=False で)起動し、天気予報サイトに移動します。ブラウザと Page インスタンスをグローバルコンテキストに保持し、Tool 呼び出し間で永続化します。

  2. enter_weather_search_israel(city: str)

    • 指定された都市名をサイトの検索フィールドに入力し、オートコンプリートリストが表示されるのを待ちます。

  3. select_weather_forecast_city_israel()

    • 最初のオートコンプリート結果を選択(または Enter キーを押下)し、予報ページが読み込まれるのを待ちます。

  4. extract_weather_data_israel()

    • 読み込まれたページから表示されている予報テキストを抽出し、広告や UI ノイズを除去してクリーンアップします。これにより、LLM は有用な天気データのみを受け取ります。

実行方法

  1. project-template フォルダから:

cd C:\Users\user1\Downloads\dovrot-ai-projects-master\dovrot-ai-projects-master\8-mcp\project-template
uv sync
uv run playwright install chromium
  1. ホスト(ターミナルチャットインターフェース)を起動:

uv run host.py
  1. ホストのチャットプロンプトで、次のような質問をします:

  • 「מה התחזית בתל אביב היום?」

  • 「תן חיזוי גשם בתל אביב מחר」

ホストはリクエストを weather-Israel MCP にルーティングし、LLM が Tools を順番に(開く→入力→選択→抽出)呼び出して予報を取得し、返します。

提出手順

  • リポジトリを公開の GitHub リポジトリとしてプッシュしてください。

  • この README.md に目的と実行手順を記載してください。

  • .env には実際の API キーをコミットしないでください。.env.example をプレースホルダーとともに使用してください。

注意事項とトラブルシューティング

  • Anthropic SDK(Claude)で実行する場合は、環境変数 ANTHROPIC_API_KEY が設定されていることを確認してください。

  • Playwright のセレクターが機能しなくなった場合(サイト変更)、weather_Israel.py 内のセレクターをサイトの HTML(DevTools で検査)に合わせて更新してください。


この README は、コースの提出ガイドライン(目的、実行手順、サンプルクエリ)に従っています。

Available Tools

4 tools
enter_weather_search_israelA

Enter the city name into the search field and wait for autocomplete results.

This uses the shared Page in _PLAYWRIGHT_CONTEXT so open_weather_forecast_israel should be called first.

Inputs: city (required). Returns: result

extract_weather_data_israelA

Extract and clean the visible forecast text from the current page.

This expects that a forecast page is already loaded in the shared Page (i.e., after select_weather_forecast_city_israel). It will attempt to extract the main forecast container text and remove obvious noise like advertisements, links, and short UI strings.

Inputs: no named parameters. Returns: result

open_weather_forecast_israelA

Open the forecast site and keep the browser/page open for subsequent tools.

Inputs: no named parameters. Returns: result

select_weather_forecast_city_israelA

Select the first autocomplete result (or press Enter) and wait for forecast page to load.

Inputs: no named parameters. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool has a distinct step in a clear workflow: open site, search, select city, extract data. No overlapping responsibilities.

    Naming Consistency5/5

    All tools follow a consistent verb_weather_forecast_city_israel snake_case pattern, making the purpose of each clear.

    Tool Count5/5

    With 4 tools, the set is well-scoped for the specific task of fetching a weather forecast for an Israeli city. No unnecessary tools or omissions.

    Completeness4/5

    The tools cover the primary workflow, but lack error recovery or reset capabilities (e.g., no tool to handle failed city lookup or restart from scratch). Still sufficient for the intended use case.

    Related MCP Connectors

    Related MCP Servers