devto 2026-07-06 원문 보기 ↗
If you've heard about the Model Context Protocol (MCP) but aren't sure how to build something with it, this guide is for you.
In my previous article, I explained what MCP is and why it matters. If you haven't read it yet, I recommend starting there first.
Understanding the concepts is one thing. Building an AI agent that actually uses MCP is another.
In this guide, you'll build a simple AI agent that communicates with an MCP server, uses external tools, and returns useful responses. More importantly, you'll understand why each component exists and how they work together.
By the end, you'll have a solid foundation that you can extend into more advanced AI applications.
Imagine asking an AI assistant:
"What's the weather in Toronto today?"
Instead of guessing the answer, the AI contacts a weather tool, retrieves real information, and responds naturally.
That entire interaction is made possible through the Model Context Protocol.
Our simple AI agent will:
Although we'll use a weather example, this same architecture is used for:
Before getting started, make sure you have:
We'll also use the official MCP Python SDK.
Before writing code, it's helpful to understand how requests flow through an MCP application.
┌──────────┐
│ User │
└────┬─────┘
│
▼
┌───────────────┐
│ Claude Desktop│
└────┬──────────┘
│
▼
┌───────────────┐
│ MCP Client │
└────┬──────────┘
│
▼
┌───────────────┐
│ MCP Server │
└────┬──────────┘
│
▼
┌───────────────┐
│ Custom Tool │
└────┬──────────┘
│
▼
Structured Data
│
▼
Claude generates
natural response
│
▼
User
Each component has a specific responsibility.
| Component | Responsibility |
|---|---|
| User | Asks a question |
| Claude | Understands the request |
| MCP Client | Sends tool requests |
| MCP Server | Exposes available tools |
| Tool | Performs the requested task |
| Claude | Generates the final response |
Create a new project folder.
mkdir weather-agent
cd weather-agent
Create a virtual environment.
python -m venv .venv
Activate it.
.venv\Scripts\activate
source .venv/bin/activate
Install the MCP SDK.
pip install mcp
Every MCP server exposes one or more tools.
A tool is simply a function that AI models can call whenever they need information or need to perform an action.
Examples include:
Let's build a weather tool.
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Weather Server")
@mcp.tool()
def get_weather(city: str):
return f"The weather in {city} is sunny and 24°C."
if __name__ == "__main__":
mcp.run()
Although this example returns hardcoded data, the same structure works with real APIs.
Let's break down what happened.
mcp = FastMCP("Weather Server")
Creates an MCP server.
@mcp.tool()
Registers a Python function as an MCP tool.
def get_weather(city: str):
Defines the tool that Claude can call.
mcp.run()
Starts the MCP server.
Once the server is running, Claude automatically discovers every registered tool.
You never explicitly tell Claude when to use the tool.
Claude decides that based on the user's request.
Claude Desktop needs to know where your MCP server is running.
Update your MCP configuration.
{
"mcpServers": {
"weather": {
"command": "python",
"args": [
"/path/to/weather_server.py"
]
}
}
}
Restart Claude Desktop.
If everything is configured correctly, Claude will automatically discover your new weather tool.
Now ask Claude:
What's the weather in Toronto today?
Behind the scenes, this workflow takes place.
User asks question
│
▼
Claude understands request
│
▼
Needs external data?
│
Yes
│
▼
Calls Weather Tool
│
▼
Receives result
│
▼
Writes natural response
│
▼
Returns answer
Notice something important.
Claude isn't writing Python code.
It's deciding when a tool should be used.
That decision-making process is what makes AI agents so powerful.
Without MCP:
Question
↓
LLM guesses
↓
Possible hallucination
With MCP:
Question
↓
LLM calls tool
↓
Gets real data
↓
Returns reliable answer
Instead of relying only on its training data, the model can interact with external systems whenever necessary.
Once you've built one tool, adding more is straightforward.
For example:
calculate(expression)
read_file(filename)
query_database(sql_query)
send_email()
search_documents(question)
The AI chooses which tool to call based on the user's request.
AI models only call tools when they determine a tool is necessary.
Whenever possible, return structured data such as JSON.
Structured responses are easier for language models to understand.
A single tool should perform one clear task.
Smaller tools are easier to maintain and easier for AI models to use correctly.
Validate inputs and return meaningful error messages.
Reliable tools lead to reliable AI applications.
Now that you've built a simple MCP server, try extending it with real-world integrations.
Some ideas include:
Each project builds on the same MCP foundation you've learned here.
Building your first MCP server is more than just another Python project.
It introduces a practical pattern for connecting language models with real tools and real data.
Instead of expecting an AI model to know everything, you allow it to discover and use specialized tools whenever they're needed.
As AI applications continue to evolve, protocols like MCP will become an important part of modern software development. Learning these concepts now will prepare you to build assistants that can search documents, interact with APIs, query databases, automate workflows, and solve real-world problems.
Start with one tool.
Then add another.
Before long, you'll have an AI agent capable of handling tasks that go far beyond simple conversation.
If you found this guide helpful, consider following me for more articles on AI Engineering, MCP, LangGraph, RAG, FastAPI, and Full Stack development.
🔗 LinkedIn: https://www.linkedin.com/in/sushyamnagallapati/
Happy building!