🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsProfi-Edelstahlpfanne von WMF jetzt zum halben Preis erhältlich(15.09.2026 um 08:05 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🕵️ SicherheitslückenBurn Out, Or Fade Away(14.09.2026 um 14:25 Uhr)
🪟 Windows TippsProfi-Edelstahlpfanne von WMF jetzt zum halben Preis erhältlich(15.09.2026 um 08:05 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 6 Min Lesezeit
0

Building Your First AI Agent with MCP: A Step-by-Step Guide

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

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.









What You'll Build



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:




  • Receive a user's question

  • Decide whether a tool is required

  • Call an MCP server

  • Receive structured data

  • Generate a final response



Although we'll use a weather example, this same architecture is used for:




  • AI coding assistants

  • Customer support agents

  • Document search applications

  • Database assistants

  • Internal company chatbots









Prerequisites



Before getting started, make sure you have:




  • Python 3.11 or later

  • Claude Desktop

  • Visual Studio Code (recommended)

  • Basic Python knowledge



We'll also use the official MCP Python SDK.









Understanding the Architecture



Before writing code, it's helpful to understand how requests flow through an MCP application.




CODE
┌──────────┐
│ 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








Step 1: Create a Project



Create a new project folder.




CODE
mkdir weather-agent
cd weather-agent






Create a virtual environment.




CODE
python -m venv .venv






Activate it.






Windows






CODE
.venv\Scripts\activate









macOS/Linux






CODE
source .venv/bin/activate






Install the MCP SDK.




CODE
pip install mcp












Step 2: Build Your First MCP Server



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:




  • Weather lookup

  • Calculator

  • File reader

  • SQL database query

  • Email sender



Let's build a weather tool.




CODE
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.









Step 3: Understanding the Code



Let's break down what happened.




CODE
mcp = FastMCP("Weather Server")






Creates an MCP server.




CODE
@mcp.tool()






Registers a Python function as an MCP tool.




CODE
def get_weather(city: str):






Defines the tool that Claude can call.




CODE
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.









Step 4: Connect Claude Desktop



Claude Desktop needs to know where your MCP server is running.



Update your MCP configuration.




CODE
{
"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.









Step 5: Test Your Agent



Now ask Claude:




What's the weather in Toronto today?




Behind the scenes, this workflow takes place.




CODE
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.









Why MCP Matters



Without MCP:




CODE
Question



LLM guesses



Possible hallucination






With MCP:




CODE
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.









Expanding Your Agent



Once you've built one tool, adding more is straightforward.



For example:






Calculator






CODE
calculate(expression)









File Reader






CODE
read_file(filename)









SQL Database






CODE
query_database(sql_query)









Email Sender






CODE
send_email()









Document Search






CODE
search_documents(question)






The AI chooses which tool to call based on the user's request.









Common Beginner Mistakes






1. Expecting every prompt to use a tool



AI models only call tools when they determine a tool is necessary.









2. Returning unstructured text



Whenever possible, return structured data such as JSON.



Structured responses are easier for language models to understand.









3. Building large tools



A single tool should perform one clear task.



Smaller tools are easier to maintain and easier for AI models to use correctly.









4. Ignoring error handling



Validate inputs and return meaningful error messages.



Reliable tools lead to reliable AI applications.









Next Steps



Now that you've built a simple MCP server, try extending it with real-world integrations.



Some ideas include:




  • Connect a real weather API

  • Search local documents

  • Query a PostgreSQL database

  • Build a GitHub assistant

  • Connect Google Calendar

  • Build a file management assistant

  • Create a multi-agent system with LangGraph



Each project builds on the same MCP foundation you've learned here.









Final Thoughts



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.









Thanks for Reading



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!

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Burn Out, Or Fade Away
1 Quelle
Windows 11 KB5129195 is out after Microsoft confirms major issues with the September 2026 update, but it won’t fix AMD GPU errors
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Building Your First AI Agent with MCP: A Step-by-Step Guide

Thematisch verwandte Begriffe: Building, Your, First, Agent · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...