🛠️ Lab 10 — Build an API-Backed CLI and MCP Server (50 pts)

Goal: Build one small integration three ways: a shared API client, an agent-friendly CLI, and a local MCP server. You will use the free, no-key-required National Weather Service (NWS) API, then verify the CLI from the terminal and the MCP server with the MCP Inspector.

Steps:

  1. Create the project. Install uv if needed, then run uv init weather-agent-tools && cd weather-agent-tools.
  2. Add dependencies. Run uv add httpx typer rich "mcp[cli]". You may use argparse instead of Typer if you prefer the standard library.
  3. Build the shared API layer. Create weather_core.py with functions such as get_alerts(state: str), get_forecast(latitude: float, longitude: float), and format_compact_alerts(...). Use httpx, set a timeout, and return predictable Python dictionaries/lists rather than raw response objects.
  4. Add config and a doctor check. Support a WEATHER_USER_AGENT environment variable or simple config value. Write a doctor() function that checks whether config is present and whether https://api.weather.gov is reachable.
  5. Build the CLI. Create weather_cli.py with commands:
  6. Make the CLI agent-friendly. Ensure each command has useful --help text, predictable exit codes, and a structured output mode. Do not hard-code secrets. If something fails, write the error to stderr and exit nonzero.
  7. Build the MCP wrapper. Create weather_mcp.py using FastMCP. Reuse the functions in weather_core.py; do not duplicate API logic. Expose:
  8. Test the CLI. Run at least:
  9. Test the MCP server. Launch the MCP Inspector with uv run mcp dev weather_mcp.py (or the equivalent Inspector command). Confirm it lists your tools/resources/prompts, then invoke both tools with valid arguments.
  10. Reflect on the design. In 250-350 words, explain what belongs in the API client layer, what belongs in the CLI layer, and what belongs in the MCP layer. Also explain one command you designed for an agent rather than only for a human.

Deliverables: Submit your source files (weather_core.py, weather_cli.py, weather_mcp.py), screenshots or terminal logs showing the three CLI commands running, an MCP Inspector screenshot showing both tools listed and one successful tool call, and your written reflection.