LLMs to AI Agents

Why Do We Need Agents?

An LLM is very good at understanding and generating output. However, it has some limitations.

For example: if we want an LLM to find today’s weather, create a report, and save it as a PDF — a normal LLM can explain how this could be done, but it cannot actually perform all these actions by itself.

This is where we need other components. An AI agent combines the intelligence of an LLM with the ability to plan tasks, use tools, remember information, and complete actions.

An LLM thinks, while an agent thinks and acts.

What Is an AI Agent?

An AI agent is a system built around an LLM. The LLM acts as the brain, while other components give it additional abilities.

A typical AI agent contains:

  • An LLM for reasoning
  • Memory to remember useful information
  • Tools that allow it to interact with other applications

All these parts work together to complete a user’s request.

System prompt: Hidden instructions given to the AI by the platform or application. They define the assistant’s behavior, capabilities, safety rules, and priorities. Users typically cannot see or edit these prompts.

User prompt: The message that the user types to the AI. This is the direct request or question the assistant responds to.

What Are Skills?

A skill is a reusable set of instructions that teaches an agent how to perform a particular task. Instead of explaining every detail each time, the agent loads the required skill whenever it receives a similar request.

For example, a UGC image generation skill tells the agent to:

  • Create a natural, human-like photo
  • Keep the lighting realistic
  • Use authentic facial expressions and poses
  • Avoid an AI-generated look
  • Match the product and target audience

Because of the skill, the agent consistently follows the same quality and structure every time.

Simple Prompt vs. Skills

A simple prompt works well for one-time tasks. For example, a user wants to generate a UGC image — the LLM generates it using only the instructions given in that prompt.

However, if the user needs similar images many times, writing detailed instructions for every request becomes repetitive. A skill stores those instructions permanently, so the agent automatically loads the UGC image generation skill whenever it’s needed.

What Are Tools?

A tool is something an agent can use to perform an action outside the LLM.

Examples:

  • Search Tool
  • Database Tool

API Basics

An API is a way for one software application to communicate with another.

Example: ChatGPT → Weather API → Temperature

Traditional API Calls

A traditional API call is when a developer writes code that directly communicates with another application’s API to get data or perform an action.

For example, if you’re building a weather app:

  1. The user asks for today’s weather.
  2. Your application sends a request to the Weather API.
  3. The Weather API returns the weather information.
  4. Your application displays it to the user.

Frameworks

A framework is a platform that manages the workflow between the LLM, memory, tools, and MCPs.

FrameworkBest ForLanguage
AgnoSimple, production-ready AI agentsPython
LangChainBuilding LLM applications with tools and memoryPython, JavaScript
LangGraphMulti-agent systems and complex workflowsPython, JavaScript
CrewAITeams of collaborating AI agentsPython
LlamaIndexConnecting AI to your own documents and dataPython
Microsoft AutoGenMulti-agent conversations and automationPython
HayStackSearch, RAG, and question answeringPython
Semantic KernelEnterprise AI applicationsPython, C#, Java

How API Calls Work in Frameworks

AI frameworks such as Agno, LangGraph, CrewAI, and the OpenAI Agent SDK help developers build AI agents. When an agent needs information from an external service (such as a Weather API or Gmail API), the framework manages the API call.

AI frameworks make it easier to build AI applications, but when it comes to connecting AI with external tools and services, another challenge appears. This is where Model Context Protocol (MCP) comes in.

What Are MCPs?

MCP stands for Model Context Protocol. It allows AI agents to connect with external tools and applications.

By using MCP, an agent can interact with services such as Google Drive, GitHub, databases, email applications, or many other software systems. Without MCP, the agent would only generate output. With MCP, it can actually perform tasks using external tools.

The Problem Before MCP

Problem 1: Too much code for every service

When building an AI app — for example, a Travel Planning AI App — you may need many services:

  • Weather API (for weather info)
  • Google Drive (to store/access files)
  • GitHub (to work with repo files)
  • Database (to store user data/memory)
  • Flight API (to check flight status)

Without MCP, you had to write separate code for every single API. Each API has its own way of sending a request, its own way of sending back a response, and its own documentation. So the developer had to learn and write code for every service separately — a big disadvantage.

Problem 2: Rewriting code for every framework

AI apps are often built using agentic AI frameworks like LangGraph, OpenAI Agent SDK, CrewAI, and Agno — and integration code often had to be rewritten for each one.

The Solution: MCP

Instead of connecting your app directly to each API, you connect it to an MCP Server.

Example:

  • Weather API → becomes Weather MCP Server
  • Google Drive → becomes Google Drive MCP Server
  • Database → becomes Database MCP Server

Now, no matter which framework you use (LangGraph, CrewAI, OpenAI SDK, Agno), you only need to write a small piece of code to connect to the MCP server. The MCP server handles everything else.

Benefit: You don’t need to write separate code again and again. You just connect, and the MCP server does the rest.

How API Calls Work in MCP

MCP does not replace APIs. Instead, it uses APIs behind the scenes to communicate with external applications.

In a traditional approach, developers must write a separate integration for every API, such as Gmail, GitHub, or Google Drive — handling authentication, requests, responses, and errors for each service.

With MCP, developers do not need to write these integrations themselves. The MCP server handles the integrations and communicates with the external APIs on behalf of the AI agent.

Skills vs. MCPs

Skills and MCPs work together, but they have different purposes.

  • A skill tells the agent how to perform a task.
  • An MCP gives the agent access to the tools needed to perform that task.

Together, these components enable AI agents to complete complex tasks that a standalone LLM cannot perform on its own.

Main Components of MCP

MCP follows a client-server architecture with three main participants:

MCP Host — The Host is the AI application, such as Claude Desktop. It manages communication with one or more MCP servers.

MCP Client

  • Lives inside the AI application
  • Acts like a bridge between the AI app and the MCP server
  • Without an MCP client, your app cannot connect to any MCP server
  • One MCP client can connect to a single MCP server or multiple MCP servers

MCP Server

  • Provides tools that the AI app can use
  • Example: a Google Drive MCP Server may expose tools like Find Files, Read File, Upload File, and Create Folder

How It Actually Works

  1. When the AI app starts, the MCP client connects to all MCP servers.
  2. Each MCP server tells the client: “these are my available tools.”
  3. The MCP client collects this list of tools and gives it to the AI app, specifically to the LLM.
  4. The user asks a question (example: “What is the weather in Lahore today?”).
  5. The question goes to the LLM first.
  6. The LLM checks: do I already know the answer? LLMs are trained on data up to a certain point in time, so they don’t know real-time/current information like today’s weather.
  7. Since the LLM doesn’t know the current weather, it looks at the list of available tools.
  8. The LLM finds a matching tool (example: “Get Current Weather” from the Weather MCP Server) and decides to use it.
  9. The LLM sends a tool request to the MCP client.
  10. The MCP client identifies which MCP server owns that tool, and connects to the Weather MCP Server.
  11. The Weather MCP Server uses the actual Weather API to fetch real data.
  12. The result goes back to the MCP server, gets converted to a standard message format, and is sent back to the MCP client, then given to the LLM.

The LLM converts this into a human-readable answer and shows it to the user.

Types of MCP Servers

1. Local MCP Server Both your AI app and the MCP server run on the same computer. Example: you have an AI app and 3 MCP servers, all on your laptop.

2. Remote MCP Server Your AI app with MCP client is on your laptop, but the MCP server is located somewhere else — on the cloud/internet. You connect to it through the internet.

3. Custom MCP Server Used when a ready-made MCP server doesn’t exist for your specific need. Example: your company has a private database, so you build your own custom MCP server for it to keep company data private. A custom MCP server can be hosted locally (making it a local server) or remotely on a cloud.

Layers in MCP

MCP is divided into two layers: the Data Layer and the Transport Layer.

The Data Layer defines what is communicated between the MCP client and the MCP server. The Transport Layer is the communication channel that carries the messages defined by the Data Layer.

How Messages Travel:

1. Standard I/O (stdio) — Used when the MCP client and MCP server are on the same local machine. Messages travel through standard input/output.

2. Streamable HTTP — Used when the MCP server is remote, on the cloud, and you connect via the internet. “Streamable” means the server can send continuous updates instead of just one single response — for example, analyzing a GitHub repository might take time, so instead of waiting silently, the server can send updates like “25% complete… 50% complete… Done!” This is useful for AI tasks because they are often long-running operations, not instant one-time requests.


Let’s Build an MCP: My First Weather Server and Client

What You Need Before Starting

  • Node.js installed on your system
  • A code editor, such as VS Code
  • Basic comfort using the terminal / command prompt

To check Node.js is installed, open your terminal and type:

node -v

What you should see: v18.19.0

Step 1: Create the Project Folder

First, make a new folder for the project. Now turn this folder into a Node.js project by running:

npm init -y

This creates a file called package.json. It simply keeps track of the project’s settings and the packages (libraries) it uses.

Step 2: Install the Required Packages

Our programs need three outside packages (libraries). Install them by running this command:

npm install @modelcontextprotocol/sdk zod axios readline

Step 3: Build the Server (server.js)

3.1 Import the tools we need

javascript

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import axios from "axios";

3.2 Create the server

javascript

const server = new McpServer({
  name: "weather-server",
  version: "1.0.0"
});

This line creates the MCP server itself and gives it a name and version number, like a name tag.

3.3 Give the server a “tool”

An MCP server does nothing on its own — it needs “tools,” which are just tasks it knows how to do. We give it one tool called getWeather:

javascript

server.tool(
  "getWeather",
  "Get current weather for a given city name",
  {
    city: z.string().describe("Name of the city, e.g. 'Lahore' or 'London'")
  },
  async ({ city }) => {
    // ... code to fetch the weather goes here
  }
);

3.4 Look up the city’s location

Before we can get weather, we need to know exactly where the city is (its latitude and longitude). We use a free API called Open-Meteo to look this up:

javascript

const geoRes = await axios.get(
  `https://geocoding-api.openmeteo.com/v1/search?name=${encodeURIComponent(city)}&count=1`
);
if (!geoRes.data.results || geoRes.data.results.length === 0) {
  return {
    content: [{ type: "text", text: `Could not find location: ${city}` }]
  };
}
const { latitude, longitude, name, country } = geoRes.data.results[0];

This sends the city name to the Open-Meteo “geocoding” service, which sends back coordinates. If the city can’t be found, we politely say so instead of crashing.

3.5 Fetch the actual weather

Now that we have the coordinates, we ask a second API for the current weather at that exact spot:

javascript

const weatherRes = await axios.get(
  `https://api.openmeteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current_weather=true`
);
const temp = weatherRes.data.current_weather.temperature;

3.6 Send the answer back

javascript

return {
  content: [
    {
      type: "text",
      text: `Current temperature in ${name}, ${country}: ${temp}°C`
    }
  ]
};

If anything goes wrong along the way (no internet, bad response, etc.), we catch the error and reply with a friendly message instead of letting the program crash:

javascript

catch (error) {
  return {
    content: [{ type: "text", text: "Failed to fetch weather." }]
  };
}

3.7 Start the server

Finally, we tell the server how to “listen” for a client. Here it uses stdio, which just means the server talks to the client through the terminal input/output, instead of a website address:

javascript

const transport = new StdioServerTransport();
await server.connect(transport);
console.log("Weather MCP Server is running...");

Step 4: Build the Client (client.js)

Now we build the client — the program the user actually runs. It starts the server, asks the user for a city, and shows the weather.

4.1 Import the tools we need

javascript

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import readline from "readline";

4.2 Tell the client how to start the server

javascript

const transport = new StdioClientTransport({
  command: "node",
  args: ["server.js"]
});

4.3 Create the client

javascript

const client = new Client(
  { name: "weather-client", version: "1.0.0" },
  { capabilities: {} }
);

4.4 A small helper to ask the user a question

This function simply prints a question in the terminal and waits for the user to type an answer and press Enter:

javascript

function askQuestion(query) {
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  return new Promise((resolve) =>
    rl.question(query, (ans) => {
      rl.close();
      resolve(ans);
    })
  );
}

4.5 Put it all together

javascript

async function main() {
  await client.connect(transport);
  console.log("Connected to server!");

  const city = await askQuestion("Enter city name: ");

  const result = await client.callTool({
    name: "getWeather",
    arguments: { city }
  });

  console.log(result.content[0].text);
  await client.close();
}

main().catch((err) => {
  console.error("Error:", err);
});

Step 5: Run the Program

Make sure both files (server.js and client.js) are saved in the same folder. Then, in your terminal, run:

node client.js

You do NOT need to run server.js separately — the client starts it for you automatically.

What you should see in the terminal:

Weather MCP Server is running...
Connected to server!
Enter city name: Lahore
Current temperature in Lahore, Punjab: 34°C

How to Connect Your WhatsApp to Claude AI

After building a Weather MCP, let’s do another fun one using MCP — this time connecting WhatsApp to Claude!

Have you ever wished you could ask an AI to search your WhatsApp messages, find old chats, or even send messages for you? There’s a tool called WhatsApp MCP that lets you do exactly that with Claude, Anthropic’s AI assistant.

What You’ll Need

This only works on your computer using the “Claude Desktop” app — it won’t work through the Claude website in a browser. Before starting, you need to install a few free programs:

  • Go – a programming language the tool is built with
  • Python – another programming language it needs
  • Git – lets you download the project from GitHub
  • MSYS2 – gives Windows a “C compiler” (a tool needed to build part of the program)
  • uv – a Python helper tool
  • Claude Desktop app – the actual AI app

Step 1: Install Go

  • Go to https://go.dev/dl/
  • Download the Windows installer (the .msi file)
  • Open it and click Next → Next → Install
  • Close and reopen PowerShell (search “PowerShell” in your Start menu)
  • Check it worked by typing:
go version

You should see something like: go version go1.26.5 windows/amd64

Step 2: Install Python

  • Go to https://www.python.org/downloads/
  • Click the yellow “Download Python” button
  • Open the installer
  • Important: On the first screen, check the box that says “Add python.exe to PATH”
  • Click Install Now
  • Close and reopen PowerShell, then check:
python --version

Step 3: Install Git

  • Go to https://git-scm.com/download/win
  • Download and open the installer
  • Keep clicking Next on every screen with default settings, then Install
  • Close and reopen PowerShell, then check:
git --version

Step 4: Install MSYS2 (Windows only)

This gives Windows the ability to “compile” certain code.

  • Go to https://www.msys2.org/ and download the installer
  • Install it with default settings (a blue terminal window will open at the end)
  • In that blue window, type the command below, press Enter, and let it finish (it might ask you to close and reopen the window — that’s normal):
pacman -Syu
  • Reopen “MSYS2 UCRT64” from the Start menu, then type:
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain

When it asks for a selection, just press Enter. When it asks to confirm, type Y and press Enter. Let it download everything.

Now add it to Windows’ PATH:

  • Press the Windows key, type “environment variables”, click “Edit the system environment variables”
  • Click Environment Variables
  • Under the top box, click Path, then Edit
  • Click New and type: C:\msys64\ucrt64\bin
  • Click OK on everything to save
  • Restart your computer (this makes sure it works)
  • Open a new PowerShell and check:
gcc --version

Step 5: Install Claude Desktop

Step 6: Install uv

In PowerShell, run:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Close and reopen PowerShell, then find where it installed:

where.exe uv

Write down this path — you’ll need it later. It usually looks like:

C:\Users\YourName\.local\bin\uv.exe

Step 7: Download the WhatsApp MCP Project

In PowerShell:

cd Desktop
git clone https://github.com/f0rty-two/whatsapp-mcp.git
cd whatsapp-mcp

Step 8: Start the WhatsApp Bridge

This is the part that actually connects to your WhatsApp account.

cd whatsapp-bridge
go env -w CGO_ENABLED=1
go run main.go

The first time, it will download some files, then show a QR code right in the PowerShell window. Scan it with your phone:

  1. Open WhatsApp on your phone
  2. Tap the three dots (⋮) or Settings
  3. Tap Linked Devices
  4. Tap Link a Device
  5. Scan the QR code shown in PowerShell

Once scanned, you’ll see messages saying it connected successfully.

Leave this PowerShell window open — don’t close it! This window is your live connection to WhatsApp. If you close it, the connection stops.

Step 9: Get the Project’s Folder Path

Open a new PowerShell window (leave the bridge one running) and type:

cd Desktop\whatsapp-mcp\whatsapp-mcp-server
pwd

Write down the path it shows, something like:

C:\Users\YourName\Desktop\whatsapp-mcp\whatsapp-mcp-server

Step 10: Tell Claude Desktop About It

In this new PowerShell window, create the settings folder (just in case it doesn’t exist):

mkdir "$env:APPDATA\Claude" -Force

Open the settings file:

notepad "$env:APPDATA\Claude\claude_desktop_config.json"

Paste this in, replacing the two paths with the ones you wrote down earlier in Step 6 and Step 9:

json

{
  "mcpServers": {
    "whatsapp": {
      "command": "PASTE_YOUR_UV_PATH_HERE",
      "args": [
        "--directory",
        "PASTE_YOUR_PROJECT_FOLDER_PATH_HERE",
        "run",
        "main.py"
      ]
    }
  }
}

Press Ctrl+S to save, then close Notepad.

Step 11: Restart Claude Desktop

  • Open Task Manager (press Ctrl + Shift + Esc)
  • Search for “Claude”, select it, click End task
  • Reopen Claude Desktop from the Start menu

To check it worked:

  • Click Settings in Claude Desktop
  • Click Developer in the sidebar
  • You should see “whatsapp” listed with a status that says running

Step 12: Try It Out!

In the Claude Desktop chat box, try asking:

  • “List my WhatsApp chats”
  • “Search my WhatsApp contacts for [a name]”
  • “Show me my last message with [a contact]”

Claude should now be able to read and interact with your WhatsApp through this connection.

That’s it! You’ve successfully connected WhatsApp to Claude.

Leave a Reply

Your email address will not be published. Required fields are marked *