🛠️ Build Your First AI Agent
Hanieh Zahiremami

Hanieh Zahiremami @hani__8725b7a

About: A mechatronics engineer building cool ai agents!

Location:
New York
Joined:
Mar 18, 2025

🛠️ Build Your First AI Agent

Publish Date: May 29
7 3

We’ve seen a lot of excitement around AI agents—but most tutorials focus on text generation and chat interfaces. What if you want your agents to actually do things? Automate tasks? Connect to tools like GitHub, Slack, or a local database?

That’s exactly what MCP Agent is built for.

This blog is for anyone who's been curious about agents and wants to build one—starting from scratch. We'll walk you through the basics using the open-source MCP Agent framework and help you build an agent that uses LLMs to reason and act across multiple tools.

If you're new to the Model Context Protocol (MCP), no worries. We’ll start simple and explain what matters as we go.

🌐 What is MCP?

The Model Context Protocol (MCP) is an open standard for connecting LLMs to real tools in a structured, consistent way.

It helps you:

  • Automate real-world tasks using LLMs
  • Connect to tools like GitHub, Supabase, Slack, or your filesystem
  • Build workflows that span across multiple services

Think of it as Zapier, but for AI agents — with native support for LLMs and tool calling.


🧰 Why MCP Agent?

MCP Agent is an open-source Python SDK for building apps and agents on top of MCP.

With it, you can:

  • Build agents that go beyond chat
  • Compose and control complex workflows
  • Deploy agents locally or as production-ready APIs

Here's the block diagram of how the app would run:

Block diagram of how the app would run


⚙️ Install and Clone

# Option 1 (Recommended)
uv init
uv add mcp-agent

# Option 2
pip install mcp-agent

# Clone the examples repo
git clone https://github.com/lastmile-ai/mcp-agent.git
cd mcp-agent/examples
Enter fullscreen mode Exit fullscreen mode

🛠️ Tutorial: Build a Simple App

We’ll start by calling the filesystem server to write a local file.

📁 Project structure:

simple_app/
├── main.py
├── mcp_agent.config.yaml
├── mcp_agent.secrets.yaml
└── pyproject.toml
Enter fullscreen mode Exit fullscreen mode

🧾 mcp_agent.config.yaml

mcp:
  servers:
    filesystem:
      command: "npx"
      args: ["-y", "@modelcontextprotocol/server-filesystem", "YOUR_PATH_HERE"]
Enter fullscreen mode Exit fullscreen mode

🔐 mcp_agent.secrets.yaml

secrets:
  filesystem:
    root_path: "YOUR_PATH_HERE"
Enter fullscreen mode Exit fullscreen mode

Replace YOUR_PATH_HERE with your actual project directory.

📦 pyproject.toml

[project]
name = "simple-app"
version = "0.1.0"
dependencies = ["mcp-agent>=0.0.20"]
Enter fullscreen mode Exit fullscreen mode

Install dependencies:

pip install -e .
Enter fullscreen mode Exit fullscreen mode

🧪 Example: Adding Intelligence with a Simple Agent

Here’s a simplified example of building an intelligent agent that can browse and write files.

import asyncio
from mcp_agent.app import MCPApp
from mcp_agent.agents.agent import Agent
from mcp_agent.mcp.mcp_connection_manager import MCPConnectionManager
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
from mcp_agent.workflows.llm.augmented_llm import RequestParams

app = MCPApp(name="simple_agent")

async def run_agent():
    async with app.run() as agent_app:
        context = agent_app.context
        logger = agent_app.logger

        async with MCPConnectionManager(context.server_registry):
            agent = Agent(
                name="simple_agent",
                instruction="""You are a smart agent that opens a browser and saves results to a file.""",
                server_names=["playwright", "filesystem"]
            )

            llm = await agent.attach_llm(OpenAIAugmentedLLM)
            request_params = RequestParams(model="gpt-4o")

            prompt = """1. Use Playwright to open a site.
2. Extract page title.
3. Save title to a file using Filesystem server."""

            result = await llm.generate_str(prompt, request_params=request_params)
            print("✅ Result:", result)
            await agent.close()

if __name__ == "__main__":
    asyncio.run(run_agent())
Enter fullscreen mode Exit fullscreen mode

💡 This template can be extended to coordinate multiple tools, add prompt customization, and integrate workflows like scraping, data cleaning, and automated reporting.

▶️ Run Your App

python main.py
Enter fullscreen mode Exit fullscreen mode

You should see output.txt created in your project directory.


🧯 Common Issues

Problem Fix
Server not found Check the spelling in config.yaml
Permission errors Double-check your root path
Timeout Make sure Node.js is installed
Tool not available Confirm the tool exists on the server

👥 Join the Community

Let us know what you build. We’re excited to see where you take it!

Comments 3 total

  • Nathan Tarbert
    Nathan TarbertMay 30, 2025

    pretty cool to see something that actually shows you how to connect ai to real tools - for me, sticking with basics and making actual things work is always harder than the flashy demos tbh. you think most people get stuck on setup or is it just the overwhelm from options?

    • Hanieh Zahiremami
      Hanieh ZahiremamiMay 30, 2025

      Thanks! Honestly, I got stuck on the setup at first — but once I figured out the most basic thing I could build, everything else started to click and became way easier and I got to build the fancy things.

Add comment