Title: Lab 10 — Build an API-Backed CLI and MCP Server
Course: AIINFRA 300: Agentic AI & the Model Context Protocol (MCP) > Section: Week 10 — Building Agent-Native CLI Tools and MCP Servers

🛠️ 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:
  - doctor — prints setup/API status; support --json.
  - alerts STATE — returns active alerts for a two-letter state code; support --json and an optional --limit.
  - forecast LATITUDE LONGITUDE — returns a compact forecast for a point; support --json.
  - Optional: brief STATE — a compound command that calls alerts and produces a short operational summary.
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:
  - a get_alerts(state: str) tool,
  - a get_forecast(latitude: float, longitude: float) tool,
  - a data://nws_state_codes resource,
  - a severe_weather_briefing(state: str) prompt.
8. Test the CLI. Run at least:
  - uv run python weather_cli.py doctor --json
  - uv run python weather_cli.py alerts CA --json --limit 3
  - uv run python weather_cli.py forecast 34.0522 -118.2437 --json
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.