MCP Weather Agent
An MCP server that exposes geocoding, current weather, and multi-day forecast as typed, structured tools for AI agents via the Open-Meteo API.
README
MCP Weather Agent
An MCP (Model Context Protocol) server that turns a public REST API into tools an AI agent can call directly — geocode a place name, then pull current conditions or a multi-day forecast, with typed inputs and typed, structured outputs instead of free text.
This is a small, self-contained example of the same pattern used to build production agent-tool servers for enterprise systems: typed tool schemas, input validation, retry/timeout handling on outbound calls, and structured logging, so an agent's tool calls are predictable and debuggable.
Why this exists
Most "AI agent" demos either hardcode a single API call or let the model free-form parse HTML. Neither scales past a toy example. This project shows the pattern that does: each capability is a small, independently testable tool with a strict input/output contract, and the server itself knows nothing about how an agent decides to call it — that separation is what lets the same server work behind Claude Desktop, Claude Code, or a custom LangGraph agent without changes.
Architecture
Agent (Claude Desktop / Claude Code / LangGraph, etc.)
│ MCP protocol (stdio transport)
▼
FastMCP server (server.py)
├─ geocode_location(location_name) → GeocodeResponse
├─ get_current_weather(lat, lon) → CurrentWeather
└─ get_forecast(lat, lon, days) → ForecastResponse
│ validated params → httpx call w/ retry+timeout
▼
Open-Meteo REST API (geocoding + forecast, no API key required)
Each tool's return value is a Pydantic model, not a string — so a calling
agent (or a downstream function in a larger pipeline) can read
result.temperature_c directly instead of re-parsing prose.
Design decisions & trade-offs
- Open-Meteo over a keyed provider: no API key means anyone cloning this repo can run it in under a minute. A production system would swap in whatever provider the business already pays for.
- Structured Pydantic outputs over raw JSON passthrough: costs a bit of mapping code per tool, but means malformed upstream responses fail loudly at the boundary instead of silently confusing the agent three steps later.
- Bounded retries in
_get_json, not a retry library: for a 3-tool demo a dependency liketenacityis unnecessary weight; the same slot is where you'd add exponential backoff or circuit-breaking for a heavier-traffic service. - stdio transport by default: simplest to run locally via Claude
Desktop/Claude Code. Swapping to Streamable HTTP (see
mcp.server.fastmcpdocs) is a one-line change tomcp.run(transport=...)when you need a server other machines can call.
Running it
python -m venv .venv
source .venv/bin/activate # .venv\Scripts\activate on Windows
pip install -e ".[dev]"
pytest # run the offline unit test suite
python -m mcp_weather_agent.server # run the server over stdio
Connecting it to Claude Desktop or Claude Code
Add to your MCP config (see examples/claude_desktop_config.json):
{
"mcpServers": {
"weather-agent": {
"command": "python",
"args": ["-m", "mcp_weather_agent.server"],
"cwd": "/absolute/path/to/mcp-weather-agent"
}
}
}
Restart the client, and the three tools (geocode_location,
get_current_weather, get_forecast) become available for the agent to call.
Tools
| Tool | Input | Output |
|---|---|---|
geocode_location |
location_name: str, max_results: int |
Ranked list of name/country/lat/lon candidates |
get_current_weather |
latitude: float, longitude: float |
Current temperature, apparent temp, wind, precipitation |
get_forecast |
latitude: float, longitude: float, days: int |
Daily high/low/precipitation for up to 16 days |
Testing
tests/test_server.py monkeypatches the HTTP layer so the suite runs fully
offline and fast — useful for CI, and for making sure tool-shape regressions
(a renamed field, a missing key) get caught before an agent ever sees them.
Possible extensions
- Swap stdio for Streamable HTTP transport and deploy behind auth for multi-client access.
- Add a
severe_weather_alertstool against a provider that supports it. - Add response caching (short TTL) to cut duplicate calls when an agent re-checks the same location across a multi-step plan.
License
MIT — see LICENSE.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.