AI Agent and MCP Security: How Agents Get Attacked and How to Defend Them

✨ AI Summary
By Updated

An AI agent is a language model that can act: it reads information, decides what to do next and calls tools to do it. That is what makes agents useful, and it is also what makes them a security problem. A chatbot that is tricked says something wrong. An agent that is tricked does something wrong, with whatever access it was given.

This guide explains how agents and the Model Context Protocol (MCP) work, where they fail, what real incidents have shown, and the controls that limit the damage. Each section links to a lab where you can see the behaviour for yourself.

How an agent works

Every agent runs the same loop. The model receives a goal, reads its context, picks a tool, reads the tool’s result, and repeats until it decides the task is finished. Four parts matter for security:

  • The model. It makes every decision, and it cannot reliably tell an instruction from information.
  • The context. The system prompt, the conversation, retrieved documents, tool descriptions and tool results, all in one stream of text.
  • The tools. Email, files, browsers, code execution, databases, payment and admin APIs.
  • The identity. The credentials the agent’s tools run with, which decide what a mistake can reach.

What MCP is and why it matters

The Model Context Protocol is an open standard, introduced by Anthropic in late 2024, for connecting AI applications to tools and data. An MCP server describes its tools in plain language, and the model reads those descriptions to decide when and how to call them. Thousands of servers now exist, many written by third parties and installed with one command.

Two things follow. Tool descriptions are text the model trusts, so whoever writes them can influence the model. And an MCP server is software running with your credentials, so it deserves the same scrutiny as any other dependency.

Where agents fail

WeaknessWhat happensMain control
Indirect prompt injectionContent the agent reads contains instructions, and the agent follows themTreat all fetched content as untrusted; limit what the agent can do after reading it
Excessive agencyThe agent has more tools or permissions than the task needsLeast privilege, per task
Confused deputyThe agent uses its own higher privileges on behalf of a lower-privileged userRun tools with the user’s permissions, checked in code
Tool poisoningA tool’s description carries hidden instructions for the modelReview and pin tool definitions; alert when they change
Unsafe tool output handlingA tool result is passed to a shell, browser or database without checksValidate output like any other untrusted input
Memory poisoningFalse information is stored and shapes later sessionsControl what is written to memory; let users see and clear it
Agent-to-agent trustOne compromised agent passes instructions to othersAuthenticate and limit messages between agents
Supply chainA malicious or vulnerable MCP server, plugin or package is installedVet sources, pin versions, sandbox

The common thread is in the OWASP Top 10 for LLM Applications: prompt injection is the way in, and excessive agency decides how bad the result is. OWASP also published a separate Top 10 for Agentic Applications in December 2025.

the agent hijack lab and the confused deputy lab.

The dangerous combination

An agent becomes high-risk when it has three things at once: access to private data, exposure to content an attacker can write, and a way to send data out. Any two are manageable. All three mean a single poisoned document, email or web page can lead to a leak. When you review an agent, look for this combination first, and remove one of the three wherever you can.

Real cases

  • GitHub MCP server, May 2025. Researchers at Invariant Labs showed that a crafted issue in a public repository could lead an agent connected to GitHub to pull data from the same user’s private repositories and publish it. Nothing in the server was broken in the usual sense. The agent had broad access and read untrusted text.
  • EchoLeak, June 2025. Aim Security disclosed CVE-2025-32711 in Microsoft 365 Copilot, described as a zero-click flaw: a single email could cause the assistant to send out internal data without the user doing anything. Microsoft fixed it on the server side and said it had seen no customer impact.
  • Tool poisoning, 2025. Invariant Labs also demonstrated that instructions hidden in an MCP tool’s description are read by the model but rarely shown to the user, so a server can steer an agent while looking harmless in the interface.

Each case is the dangerous combination in practice: private data, untrusted content and a way out.

How to test an agent

Test only systems you own or have written permission to test.

  1. List every tool and its permissions. For each one, write down what it can read, what it can change and whose credentials it uses.
  2. List every source of text. Web pages, emails, files, tickets, tool descriptions, tool results, memory, other agents.
  3. Mark the dangerous combinations. Where can untrusted text reach a tool that reads private data or sends data out?
  4. Define failures in advance. For example: the agent calls a tool the user did not ask for, or acts on another user’s data.
  5. Test each path and record tool calls. The evidence is the sequence of calls, not the chat text.
  6. Check the approvals. Confirm that risky actions pause for a person, and that the prompt shows what will really happen.
  7. Retest after changes. A new tool, a new server version or a model update can reopen a closed path.

Our AI red teaming guide covers how a full engagement runs.

Defences that hold up

DefenceWhat it doesIts limit
Least privilege per taskThe agent gets only the tools and scopes this task needsTakes design effort for every workflow
User-scoped credentialsTools act with the requesting user’s permissions, enforced in codeHarder for shared or background agents
Human approval for risky actionsSending, paying, deleting and sharing wait for a personPeople stop reading if asked too often
Breaking the combinationAn agent that has read untrusted content loses access to private data or to outbound toolsReduces what a single agent can do
SandboxingCode execution and browsing run in an isolated environment with limited network accessDoes not protect data placed inside the sandbox
Vetting and pinning MCP serversOnly reviewed servers at fixed versions; changes to tool descriptions raise an alertOngoing work as servers update
Short-lived, narrow tokensA leaked credential expires quickly and reaches littleNeeds identity infrastructure
Logging every tool callUnusual sequences are noticed and can be investigatedDetects; does not prevent

The rule is the same as for prompt injection: assume the model can be talked into anything, and make sure that what it can then do is small. Related reading: prompt injection in agentic workflows and identity for AI agents.

Frequently asked questions

Is MCP insecure?

The protocol is a way to connect tools; it does not decide how much access you grant. Most MCP incidents come from broad permissions, unvetted servers and agents reading untrusted content, not from the protocol itself.

How is agent security different from chatbot security?

A chatbot’s worst case is usually bad output. An agent’s worst case is a bad action: data sent, records changed, code run. The model weakness is the same; the consequences are larger.

Can a better model fix this?

Newer models resist injection more often, but none resist it every time. Safe design assumes the model will sometimes be fooled.

Should agents ever run without human approval?

For low-risk, reversible actions inside a narrow scope, yes. For anything that sends, pays, deletes or shares, keep a person in the loop.

Where can I practise legally?

On systems built for it. The SecurityElites labs include agent and tool-abuse scenarios against live models, and the SE-ARTCP certification tests the skill hands-on.

⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment