Weather MCP Server
by Amann001
Weather MCP Server
A mini project demonstrating how to build and use a Model Context Protocol (MCP) server with Python.
Features
Weather Alerts Tool
Weather Forecast Tool
SSE Transport
STDIO Transport
MCP Client Integration
Docker Support
Async Python Implementation
Project Structure
mcpcrashcourse/
│
├── server/
│ └── mcpserver/
│ ├── server.py
│ ├── client-sse.py
│ ├── client-stdio.py
│ ├── Dockerfile
│ └── requirements.txt
│
├── weather.py
├── weather.json
├── client.py
├── README.md
├── pyproject.toml
└── uv.lockTools
get_alerts
Returns active weather alerts for a US state.
Example:
get_alerts("CA")get_forecast
Returns forecast information based on latitude and longitude.
Example:
get_forecast(
latitude=37.7749,
longitude=-122.4194
)Transports
STDIO
Used for local MCP communication.
SSE
Used for remote communication through HTTP.
Running the Server
STDIO
uv run server/mcpserver/server.pySSE
Configure transport as:
mcp.run(transport="sse")Then:
uv run server/mcpserver/server.pyRunning Clients
SSE Client
uv run server/mcpserver/client-sse.pySTDIO Client
uv run server/mcpserver/client-stdio.pyDocker
Build:
docker build -t weather-mcp .Run:
docker run weather-mcpTechnologies Used
Python
MCP
FastMCP
HTTPX
AsyncIO
Docker
SSE
STDIO
Learning Outcomes
Building MCP tools
Creating MCP servers
Working with MCP clients
Using SSE transport
Using STDIO transport
Tool invocation
Agent-tool communication
Dockerizing MCP applications