AI agents: tool calling, MCP and security

12 articles, in reading order.

An agent is an LLM in a loop: it decides which tool to call, reads the result, and decides again. The model is the easy part. The engineering is in the tools it calls, the errors it reads, the permissions it holds, and the attacks that arrive through the text it processes.

These articles go from how the tool-calling loop works to securing and auditing agents that act on real systems.

How agents work

  1. How LLM tool calling works: the loop, the schema, and the mistakes that break agents

    Tool calling (function calling) lets a model ask your code to run a function. The request–execute–return loop step by step, how to write tool schemas and descriptions models use correctly, and the errors, limits and safety checks every agent needs.

  2. What is the Model Context Protocol (MCP)? Tools, resources, transports and auth, explained by someone who built a server

    MCP is an open protocol that lets AI assistants call tools and read data from other systems. How it works (JSON-RPC, tools, resources, prompts), stdio vs Streamable HTTP, OAuth for remote servers, and what to get right when you build one.

  3. Single agent or multi-agent? What I learned building a multi-agent financial intelligence system

    Multi-agent LLM systems add coordination, cost and new failure modes. When splitting work across agents helps, when one agent with good tools is better, and three design lessons from Cuttlefish: timeouts, failing closed and audit trails.

  4. Your AI agent thinks its tasks were deleted: how to write tool errors for LLM agents

    An agent saw 'task not found' and recreated its schedules, causing duplicates. Tool errors for LLMs must say why and what to do next. Lessons from NanoClaw and an MCP server.

Testing and accountability

  1. How to evaluate AI agents: task success, tool-call accuracy, cost, and running each task more than once

    Agents are non-deterministic and take many steps, so one demo proves nothing. How to build an agent test set, score outcomes in code, check tool calls and trajectories, measure cost and steps, and run each task several times.

  2. A tamper-evident audit log for AI agents: three bugs in my hash chain, and the fix

    Cuttlefish logs every agent action to a SHA-256 hash chain. Reviewing it, I found hashes nobody could recompute, parallel agents forking the chain, and a 'recent entries' query returning the oldest. Here's a version that verifies.

Security

  1. Prompt injection from scraped data: guarding an LLM that writes outreach emails

    LeadForge feeds Google Maps listings into an LLM that drafts cold emails. Anyone can write a listing, so it's untrusted input. The three layers I use: delimited data, output validation with a template fallback, and send gates that fail closed.

  2. Canary tokens for LLM apps: detecting system prompt leaks and injected exfiltration

    Put a random canary string in your system prompt and check every model output and tool call for it. How to detect leaked instructions, including spaced-out and base64 copies and leaks through tool arguments, in tested Python, and what a canary can and can't tell you.

  3. How to build a secure MCP server with OAuth 2.1: lessons from a CRM connector

    How I let Claude and other AI clients read a CRM safely: OAuth 2.1 with PKCE, single-use codes, row-level security as the only authorization, and read-only tools.

  4. Localhost is not authentication: fixing a CWE-306 webhook in an AI agent framework

    NanoClaw's loopback webhook accepted any local POST, letting other processes forge button clicks (CWE-306, CVSS 6.6). My fix, the maintainers' simpler one, and why theirs was better.

  5. Securing a voice AI agent's webhook: what my first version got right, and what I'd change

    A 24/7 AI phone agent posts every call to a webhook. How HI Agent's backend verifies Vapi, stores repeated call events idempotently, and emails one summary per call, plus the fixes I'd make.

  6. One phone number, two users: normalising WhatsApp sender IDs across Baileys and the Cloud API

    Baileys sends 15551234567@s.whatsapp.net, the WhatsApp Cloud API sends 15551234567, so one person became two users with different roles. Canonical IDs and a merge migration fix it.

Common questions

How does LLM tool calling work?

You describe each tool to the model with a name and a JSON schema. The model replies with a tool call instead of text, your code runs the tool and sends the result back, and the loop repeats until the model answers. The model never runs code itself; your application does.

What is the Model Context Protocol (MCP)?

An open protocol for connecting AI applications to tools and data sources. A server exposes tools, resources and prompts in a standard way, so any MCP-compatible client can use them without custom integration code.

How do you detect a system prompt leak?

Put a random canary string in the system prompt and check every model output and tool call argument for it, including spaced-out and encoded copies. A match means an injection succeeded; block the response and investigate. It catches copying, not paraphrase.

Should you use one agent or several?

Start with one agent and good tools. Split into several only when parts of the work need different instructions, tools or permissions, can run in parallel, or should independently check another agent's output. Each extra agent adds coordination, latency, cost and new ways to fail.

Other guides