MCP Weather Forecast Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Weather Forecast Server what's the weather in Tel Aviv?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Weather Forecast Server
A Model Context Protocol (MCP) server that enables LLMs to retrieve weather forecasts from Israeli websites using browser automation with Playwright. This project demonstrates how to build MCP tools that maintain state across sequential tool calls, allowing an LLM to control a browser interactively.
Project Overview
This project implements an MCP server using the official Anthropic MCP SDK in Python. It provides tools for:
Opening a browser and navigating to an Israeli weather forecast website
Entering city names into search fields
Selecting cities from autocomplete dropdowns
Extracting weather data from the loaded page
The key feature is the global state mechanism that persists browser and page instances across different tool calls, enabling sequential operations on the same browser page.
Related MCP server: Weather Israel MCP Server
Architecture
Components
host.py: Main chat host that manages MCP clients and orchestrates tool calls with Anthropic's Claude API
weather_Israel.py: MCP server implementing browser automation tools for Israeli weather forecasts
weather_USA.py: MCP server implementing API-based weather tools for USA weather data
client.py: MCP client implementation for connecting to MCP servers via stdio transport
Global State Management
The weather_Israel.py module uses a BrowserState class to maintain global browser and page instances:
playwright: The Playwright async contextbrowser: The Chromium browser instance (headless=False for visibility)page: The browser page for navigation and interaction
This state persists across tool calls, allowing sequential operations like:
Open browser → 2. Enter city → 3. Select city → 4. Extract data
Prerequisites
Python 3.13 or higher
uvpackage managerAnthropic API key (set in
.envfile)
Installation
Clone the repository and navigate to the project directory:
cd project-templateInstall dependencies using
uv:
uv syncInstall Playwright Chromium browser:
uv run playwright install chromiumSet up your environment variables:
# Edit .env and add your ANTHROPIC_API_KEYUsage
Running the MCP Server
Start the interactive chat host:
uv run host.pyThis will:
Connect to the configured MCP servers (weather_Israel.py and weather_USA.py)
Start an interactive chat loop
Allow you to ask questions that trigger tool calls
Example Questions
Once the host is running, you can ask questions like:
Israeli Weather:
"What is the weather in Jerusalem today?"
"Tell me the forecast for Tel Aviv"
"What's the current temperature in Haifa?"
USA Weather:
"Are there any weather alerts for California?"
"What's the forecast for New York City?"
"Get the weather forecast for latitude 37.7749, longitude -122.4194"
How It Works
When you ask a question, the system:
Sends your query to Claude via the Anthropic API
Claude determines which tools to call based on your question
The host executes the tools in sequence (e.g., open browser → enter city → select → extract)
Results are returned to Claude for final response generation
The answer is displayed in the chat
MCP Tools
weather_Israel.py Tools
open_weather_forecast_israel()
Launches a Chromium browser (headless=False) and navigates to https://www.weather2day.co.il/forecast.
enter_weather_forecast_city_israel(city: str)
Locates the search input field and types the given city name into it.
Parameter:
city- The name of the Israeli city (e.g., "Jerusalem", "Tel Aviv")
select_weather_forecast_city_israel()
Waits for the autocomplete dropdown to appear and clicks the first city in the list.
extract_weather_forecast_israel()
Extracts weather data from the loaded page, cleans up HTML and whitespace, and returns the text for LLM processing.
weather_USA.py Tools
get_alerts_in_USA(state: str)
Gets weather alerts for a USA state.
Parameter:
state- Two-letter USA state code (e.g., CA, NY)
get_forecast_in_USA(latitude: float, longitude: float)
Gets weather forecast for a location in USA.
Parameters:
latitude- Latitude of the locationlongitude- Longitude of the location
Development
Adding New MCP Servers
To add a new MCP server:
Create a new Python file (e.g.,
weather_Europe.py)Import FastMCP and create an instance:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("weather-Europe")Define tools using the
@mcp.tool()decorator:
@mcp.tool()
async def your_tool_name(param: str) -> str:
"""Tool description"""
# Your implementation
return resultAdd the main entry point:
def main():
mcp.run(transport="stdio")
if __name__ == "__main__":
main()Register the server in
host.pyby adding it to themcp_clientslist:
self.mcp_clients: list[MCPClient] = [
MCPClient("./weather_USA.py"),
MCPClient("./weather_Israel.py"),
MCPClient("./weather_Europe.py") # Add your new server
]Debugging
The browser runs in headless mode by default. Set
headless=FalseinBrowserState.ensure_browser()to see the browser actions.Check the console output for tool execution logs and error messages.
Use the
@mcp.tool()decorator's docstring to provide clear descriptions for the LLM.
Troubleshooting
Browser not launching: Ensure Playwright Chromium is installed with uv run playwright install chromium
Timeout errors: The website might be slow or loading differently. Adjust timeout values in the tool functions.
Selector not found: The website structure may have changed. Update the CSS selectors in the tool functions.
API errors: Verify your Anthropic API key is correctly set in the .env file.
License
This project is part of an academic project for learning MCP (Model Context Protocol) implementation.
Acknowledgments
Built with Anthropic MCP SDK
Powered by Anthropic Claude
Browser automation powered by Playwright
Dependency management with uv
Available Tools
4 toolsenter_weather_forecast_city_israelA
Locates the search input field and types the given city name into it.
Args: city: The name of the Israeli city to search for (e.g., "Jerusalem", "Tel Aviv")
Inputs: city (required). Returns: result
extract_weather_forecast_israelA
Extracts the current weather and forecast information from the loaded page.
This tool scrapes the weather data from the page, cleans up excessive whitespaces and HTML, and returns the text for the LLM to use in answering user questions.
Inputs: no named parameters. Returns: result
open_weather_forecast_israelA
Launches a Chromium browser and navigates to the Israeli weather forecast website.
This tool opens the browser (headless=False for visibility) and loads the forecast page.
Inputs: no named parameters. Returns: result
select_weather_forecast_city_israelA
Waits for the autocomplete dropdown to appear and clicks the first city in the list.
This tool should be called after entering a city name to select it from the dropdown.
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
Scored across 4 tools
Each tool serves a distinct stage of a linear workflow: opening the site, entering a city, selecting from autocomplete, and extracting data. There is no overlap in purpose, and the descriptions clearly delineate when each should be used.
All tool names follow the same verb_noun pattern (open_, enter_, select_, extract_) with a consistent 'weather_forecast_israel' suffix. This makes the sequence and intent of each tool predictable and uniform.
Four tools is ideal for this focused browser automation workflow. Each tool maps to a necessary step in the process, with no redundant or missing steps for the stated purpose.
The tools cover the full lifecycle from opening the forecast page to extracting the desired weather data. There are no obvious gaps that would prevent an agent from successfully retrieving a forecast for any Israeli city.
Maintenance
Related MCP Connectors
Current weather and forecast lookup as an agent tool.
Get current weather for any city and create images from your prompts. Streamline planning, reports…
Provides cloud browser automation capabilities using Stagehand and Browserbase, enabling LLMs to i…
Control a real browser from AI agents: navigate, click, type, screenshot, read the page.
Related MCP Servers
- FlicenseAqualityDmaintenanceEnables users to query weather information for Israel via Playwright browser automation and for the USA via a weather API, allowing an LLM to access real-time weather data and alerts.4-
- FlicenseBqualityDmaintenanceEnables users to query weather forecasts for Israeli cities through natural language using browser automation and Gemini.4-
- FlicenseAqualityDmaintenanceEnables LLMs to fetch Israeli weather forecasts by controlling a real browser via Playwright, simulating human interactions like typing and clicking on a weather website.4-
- FlicenseAqualityDmaintenanceEnables LLMs to fetch Israeli weather forecasts by automating a browser to navigate Weather2Day, providing tools for city search and content extraction.4-