// agent_security
MCP server security
The Model Context Protocol made it trivial to hand an agent new tools. It also made it trivial to hand an agent someone else's instructions, your credentials and a way to send data out. This is the threat model, and the controls that matter, for both sides of the connection.
The short version
An MCP server is code that runs with your agent's privileges and text that goes straight into your model's context. Both halves are attack surface: the code can do damage directly, and the text — tool descriptions, tool results, resources — can steer the model into doing damage for it.
The durable defenses are least privilege per tool, audience-bound authorization, human approval for side effects, pinned and reviewed servers, and never letting one agent combine private data, untrusted content and a way to send data out.
Where the attacks come from
via content
Prompt injection through tool output
via metadata
Tool poisoning
via updates
Rug pulls
via naming
Tool shadowing
via credentials
Token passthrough and confused deputies
via the host
Local server exposure
The lethal trifecta
The single most useful rule for agent security: an agent is exploitable for data theft when it has all three of access to private data, exposure to untrusted content, and a way to communicate externally. Injected instructions in the untrusted content tell it to read the private data and send it out.
MCP makes the trifecta easy to assemble by accident — connect a mailbox server, a web fetcher and anything that can make an HTTP request, and you have all three. No filter reliably stops injection, so the robust fix is architectural: make sure no single agent session holds all three capabilities, or require a human in the loop at the point where data would leave.
Filters are not a boundary
If you build MCP servers
- 01
Authorize remote servers properly
Follow the specification’s OAuth-based authorization for HTTP servers. Validate every token’s audience and accept only tokens issued for your server; never pass a client’s token through to an upstream API — obtain your own credentials for that. - 02
Scope each tool to the least it needs
Separate read tools from write tools, and narrow scopes per tool rather than per server. A “search tickets” tool should not share a credential that can delete them. - 03
Treat tool arguments as hostile input
Arguments come from a model that may be following injected instructions. Validate them against a schema, never interpolate them into shell commands or queries, and constrain file paths to an allowed root. - 04
Label untrusted content in results
When a tool returns third-party text — web pages, emails, user uploads — mark it as untrusted data in the result so hosts and models can treat it accordingly. Return the minimum needed. - 05
Mark and gate side effects
Use tool annotations to declare destructive or non-idempotent tools, but enforce confirmation server-side for anything irreversible. Annotations are hints to the host, not a control. - 06
Harden the transport
For local HTTP servers, bind to localhost and validate the Origin header to block DNS-rebinding attacks from web pages. Rate-limit, and log every call with the caller identity, arguments and result status.
If you connect agents to MCP servers
- 01
Allowlist and pin
Connect only servers you have reviewed, pinned to a version or digest. Unpinned “latest” installs are an unreviewed code update on every launch. - 02
Show and diff tool descriptions
Surface full tool descriptions to users, and alert when a server’s tool list or descriptions change between sessions — that is how rug pulls are caught. - 03
Sandbox local servers
Run them in a container or sandbox with only the directories and network destinations they need. A filesystem server does not need the internet. - 04
Split the trifecta across sessions
Keep agents that read untrusted content away from tools holding private data or sending data out, or insert a human approval step where data would cross that line. - 05
Require approval for side effects
Sending, paying, deleting, publishing and changing permissions should need a person’s confirmation that shows the actual arguments, not a summary written by the model.
Checklist
| Control | Server builders | Agent / host operators |
|---|---|---|
| Authorization | Audience-validated tokens; no passthrough | Per-server credentials, never shared broadly |
| Privilege | Least-privilege scopes per tool | Only connect tools the task needs |
| Untrusted content | Label third-party text in results | Never combine with private data + egress unattended |
| Side effects | Server-side confirmation for irreversible actions | Human approval showing real arguments |
| Supply chain | Signed releases, changelog of tool changes | Pin versions; diff tool definitions |
| Isolation | Constrain paths; no shell interpolation | Sandbox local servers; restrict network |
| Visibility | Audit log of every call | Log tool calls per session; alert on anomalies |
MCP security FAQ
Is MCP secure?
The protocol defines authorization for remote servers and publishes security best practices, but it cannot make a given deployment safe. Most real risk comes from what a server is allowed to do, what untrusted content reaches the model, and whether anyone reviews third-party servers before connecting them.
What is tool poisoning in MCP?
Tool poisoning is hiding instructions in a tool’s description or metadata. The model reads tool descriptions as part of its context, so a malicious server can tell it to read files, leak data or call other tools — often in text the user never sees in the host’s interface.
What is an MCP rug pull?
A server that behaves well when you approve it and changes its tool definitions later. Because many hosts approve a server once, a changed description or a new tool can go unnoticed. Pin versions and alert on any change to a server’s tool list or descriptions.
Should an MCP server pass the user’s token to upstream APIs?
No. The MCP specification forbids token passthrough: a server must only accept tokens issued for it, and must obtain its own credentials for any upstream service. Forwarding a client’s token lets a server act with privileges it was never granted and breaks audit trails.
How do I safely use third-party MCP servers?
Treat each one as code you are about to run with your agent’s privileges: review it, pin its version, run local servers in a sandbox with restricted filesystem and network access, show users every tool description, require approval for actions with side effects, and never connect a server that reads untrusted content to an agent that also holds private data and can send it somewhere.
Sources
- Model Context ProtocolSecurity best practices (specification)
- Model Context ProtocolAuthorization (specification)
- Model Context ProtocolTransports: Streamable HTTP security
- OWASP GenAI Security ProjectOWASP Top 10 for LLM Applications
- Simon WillisonThe lethal trifecta for AI agents
- Invariant LabsMCP security notification: tool poisoning attacks