Weather Server Example
A more realistic MCP server that demonstrates multi-tool registration with simulated weather data.
Source: examples/WeatherServer/
Features
- Tool:
get_alerts— returns simulated weather alerts for a US state - Tool:
get_forecast— returns simulated weather forecast with location parameters
Running
bash
cmake --preset debug
cmake --build --preset debug
build/debug/examples/WeatherServer/WeatherServerKey Concepts
The WeatherServer demonstrates:
- Multiple tool registration — registering two distinct tools (
get_alerts,get_forecast) with different signatures and logic - Tool parameters — accessing
argumentsfromCallToolRequestParamsto read input values (state,latitude,longitude) - Text-based responses — returning
TextContentresults from tool handlers - Default fallback — handling missing data with a default response instead of structured errors