Home Serverless Model Context Protocol (MCP) Demo with Gemini CLI
Post
Cancel

Serverless Model Context Protocol (MCP) Demo with Gemini CLI


This article was originally published on Medium by me

Overview

This article walks through a working example of deploying a Model Context Protocol (MCP) using FastMCP and connecting it to Gemini CLI.

The goal is to build a simple weather forecast MCP server that responds to latitude and longitude queries, and then connect it directly to Gemini CLI for interactive use.

By the end, you will have:

  • A working FastMCP bridge (mcp_weather.py)
  • The MCP tooling installed and accessible from Gemini CLI
  • Example commands to retrieve weather forecasts with get_forecast
  • A demonstration of chaining get_forecast and get_alerts together within Gemini CLI

What is MCP?

MCP (Model Context Protocol) is an open standard that allows AI assistants like Claude or Gemini to connect to external data sources and tools through standardized servers.


Step 1: The Weather Tooling using MCP

The core function is get_forecast().
Its docstring acts as a semantic contract between the MCP server and the AI client, describing how to call it and what it returns.

1
2
3
4
5
6
7
8
9
10
11
12
# mcp_weather.py
import asyncio
import logging
from typing import Any, Optional
import httpx
from fastmcp import FastMCP

logger = logging.getLogger("weather")
mcp = FastMCP("weather")
NWS_API_BASE = "https://api.weather.gov"
OPEN_METEO_BASE = "https://api.open-meteo.com/v1/forecast"
USER_AGENT = "weather-app/1.0"

Alerts tool

1
2
3
4
5
6
7
8
9
10
11
@mcp.tool()
async def get_alerts(state: str) -> str:
    """Get weather alerts for a US state."""
    url = f"{NWS_API_BASE}/alerts/active/area/{state}"
    data = await make_request_with_retries(url)
    if not data or "features" not in data:
        return "Unable to fetch alerts or no alerts found."
    if not data["features"]:
        return "No active alerts for this state."
    alerts = [feature["properties"]["event"] for feature in data["features"]]
    return "\n".join(alerts)

Forecast tool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@mcp.tool()
async def get_forecast(latitude: float, longitude: float) -> str:
    """Retrieve a concise weather forecast for a given geographic location."""
    # Primary: National Weather Service
    try:
        points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
        points_data = await make_request_with_retries(points_url)
        if points_data:
            forecast_url = points_data.get("properties", {}).get("forecast")
            if forecast_url:
                forecast_data = await make_request_with_retries(forecast_url)
                periods = forecast_data.get("properties", {}).get("periods", [])
                if periods:
                    summary = []
                    for p in periods[:5]:
                        name = p.get("name", "Unknown")
                        temp = p.get("temperature")
                        unit = p.get("temperatureUnit", "")
                        wind = f"{p.get('windSpeed', '')} {p.get('windDirection', '')}"
                        details = p.get("detailedForecast", "")
                        summary.append(f"{name}: {temp}°{unit}, {wind}, {details}")
                    return "\n".join(summary)
    except Exception as e:
        logger.error(f"Error: {e}")
    return "Unable to fetch forecast."

Step 2: Installing the MCP Bridge

Once your bridge is built, make it available to an MCP-compatible client such as Gemini CLI.

Install using uv

1
2
3
4
pip install uv
uv add "fastmcp==2.13.0.2"

uv run fastmcp install gemini-cli mcp_weather.py

You should see a success message:
Successfully installed 'weather' in Gemini CLI.


Step 3: Start Gemini CLI

Run:

1
2
gemini
/mcp list

The CLI will confirm your installed tools.

To view details about each tool:

1
/mcp desc

If updates don’t appear, try:

1
/mcp refresh

Step 4: Try It — Get the Weather Forecast!

Example:

1
/mcp run get_forecast latitude=44.0 longitude=-72.7

Press “1” to confirm.

You should receive a detailed forecast for Vermont.


Step 5: Chain Forecast and Alerts

You can chain multiple MCP tools together in Gemini CLI.
For example:

Get weather forecast for Bangor, Maine.
If temperature < 10°C, then get weather alerts for Maine.

1
2
/mcp run get_forecast latitude=44.8 longitude=-68.8
/mcp run get_alerts state=ME

Code and Repository

Full source code is available here:
👉 GitHub - galois17/azure-container-apps-mcp-server-demo

Clone and run locally:

1
2
uv sync
uv run fastmcp install gemini-cli mcp_weather.py

Conclusion

This demo shows how straightforward it is to connect real-world data to an AI interface using Model Context Protocol (MCP) and Gemini CLI.

With just a few lines of Python and the FastMCP library, you built a working weather bridge (mcp_weather.py) that exposes live data as callable tools.
You installed the tooling into Gemini CLI, explored the get_forecast command, and chained it with get_alerts to produce richer, contextual outputs.

This post is licensed under CC BY 4.0 by the author.