Thursday, July 23, 2026

How to Build Your First MCP Server Using Python and a Free Weather API

Large Language Models (LLMs) are incredibly smart, but they suffer from one massive limitation: they are frozen in time. They do not know today's weather, current stock prices, or what is sitting in your local database.

The Model Context Protocol (MCP) fixes this problem. Think of MCP like a universal USB-C port for AI agents. It provides a standardized framework that allows LLMs (like Kiro) to safely interact with external tools, data resources, and APIs.

In this guide, we will build a functional MCP server from scratch using Python to connect to a free Weather Service API. By the end of this post, your AI assistant will be able to fetch live, real-time weather forecasts directly through your machine.

🛠️ Prerequisites

Before jumping into the code, make sure you have the following ready on your system:
  • Python 3.11 or above
  • uv (a lightning-fast Python package installer and manager)
  • Kiro (or any MCP-compatible AI client)

🚀 Step 1: Set Up Your Project Environment

We will use uv to initialize our project workspace and automatically manage our virtual environment. Open your terminal and execute the following commands:

# Create a new project directory and navigate into it
mkdir weather-mcp-server && cd weather-mcp-server

# Initialize a new Python project
uv init

# Add the essential dependencies: FastMCP for the protocol and HTTPX for API requests
uv add "mcp[cli]" httpx

This sets up a clean environment and creates a pyproject.toml file managing your dependencies.

💻 Step 2: Write the MCP Server Code

Now, create a file named server.py inside your project directory. We will use Anthropic's high-level FastMCP framework to abstract away the underlying protocol complexities. Paste the following code into your server.py file:

Why this works so well:

The @mcp.tool() Decorator: This registers your function as an executable tool available to the AI model.

Docstrings Matter: The text inside """ """ acts as the direct documentation for the LLM. The model reads this description to automatically figure out when and how to use your tool.

🔗 Step 3: Connect to Kiro

To give your everyday AI assistant access to your live weather tool, you need to add it to your local client configuration file. Refer mcp.json above.

Restart Kiro completely.

🎉 Step 4: See It In Action!

Try asking:"What is the weather like in Seattle right now?"

Kiro will recognize that it needs real-time information, check its available tools, trigger your local Python script, and summarize the live API data right inside your chat window!

No comments: