~/blog/guide/mcp-security
MCP and security
What you give away when you give an agent tools. On the supply chain, hardening and the incidents already on record.
What this guide covers
MCP is how an agent reaches past its chat window: your files, your databases, your terminal, whatever service you connected last week. Every one of those connections is what makes the work worth doing, and a door you are holding open. This cluster is about the doors. What fits through them, who else knows they are there, and how to shut the ones you do not need without throwing the tooling away.
I use MCP daily and my own setup leans on it heavily. That is why I take the weak spots seriously, rather than in spite of it. If you think the protocol is hype, none of this concerns you. If you ship with it, all of it does.
What you are handing over
Start with the plain question: what can an agent do with the permissions you already gave it? Usually more than you pictured. Censys found thousands of MCP servers sitting open on the internet, and an open MCP server is worse than an open database is why that phrasing is not dramatic. A database leaks. A tool server executes. We learned this for databases fifteen years ago and are now paying tuition twice.
The same question points outwards. Your coding agent read your .env, then uploaded your whole repo follows what actually leaves your machine during an ordinary session, which is more than the file you had open. And the door does not have to be technical: in they just asked the bot nicely the support agent is the attack surface and the exploit is a polite sentence.
Where your servers come from
The second layer is supply chain. The MCP supply chain is the new npm is the overview: a config-to-command RCE in every official SDK, poisoned registries, an ecosystem replaying the npm playbook at double speed. That playbook is in active use. They didn't push a new version, they moved yours is someone rewriting hundreds of existing git tags to point at malicious code without publishing anything at all, which is where your lockfile stops helping you. A commit hash cannot be moved like that, and Plugin4Shell shows why that is still not enough: four coding agents asked git for the pinned commit and never checked what they ended up with, and my own CI runner did the same.
The same playbook now runs a step earlier, at the name itself. Slopsquatting is what happens when a model invents a package name consistently enough that somebody registers it first. The defence everyone recommends is to check that the package exists, and that answers the wrong question in both directions.
The scale of it is easy to wave away, so one in four puts a number on the security debt nobody is counting.
Vetting and hardening
Then the handwork. How to vet an MCP server is the checklist I actually run: who publishes it, what the tool descriptions tell the model, which permissions it asks for and why it claims to need them. For the sharpest case, an agent sitting next to your data, safe SQL access for Claude does it with SELECT-only access, query validation and field redaction.
If a scanner is doing that checking for you, MCP server security scores is the measured account of what those grades are worth: 74,101 servers sorted by what actually backs each signal, an independent study finding fewer than half of scanner alerts hold up, and the state no dashboard shows you, which is that nobody read the source.
Prompt injection defence covers the attack that needs no vulnerability whatsoever, only text your agent happens to read. And if you publish a server rather than consume one, MCP server authentication is the resource-server model the spec actually asks for.
The pattern underneath all of it: constrain at the system level. A rule in a prompt is a suggestion. A wall is a guarantee.
Sandboxes, and what still gets out
Sandboxing Claude Code is how I run mine. A box still full of live tokens only moves the problem, so credential masking is the settings walkthrough for handing the agent's shell a placeholder and letting the proxy re-attach the real secret on the way out, including what that control does not cover. Every agent sandbox has the hole that makes it useful is the week two of those boxes failed, one at Anthropic and one at OpenAI, where both escapes climbed a single privilege level inside a boundary that already held the prize.
The agents left notes for each other is the sequel and the more useful half: OpenAI's own 74-day timeline of the Hugging Face incident, where the channel the agents coordinated through was an internal package registry, and the boundary that gave way was time rather than space.
When it goes wrong anyway, you want the next hour to be boring. The incident-response runbook is that hour in five phases, starting with the session transcript and ending at the permission that allowed it.
That hour only starts once somebody notices, which is what audit logging for AI agents is for: the three trails Claude Code already writes to your own disk, why the compliance feed your security team queries contains none of them, and how to settle in advance what is allowed to wake a human up.
The second machine that runs your code
Your laptop is not the only place your code executes, and nobody is sitting at the other one. CI runner security when an agent writes your workflow is this guide applied to the pipeline: why the hardening advice everyone repeats quietly assumes one platform, what a runner holding no credentials at all is still worth to an attacker, and the table in Anthropic's own documentation showing that a repository's restrictions are dropped in a headless run while the code that repository supplies still runs.
The incidents are not hypothetical
Nobody was driving documents the first recorded intrusion an agent ran by itself, from CVE to drained database, four pivots, under an hour. Even the malware is AI slop is the same story from the other side: an npm package that went straight for Claude's working directory. The friction was the feature is what happens when a vendor removes the clicking-through that was quietly acting as your last check, and ThePrimeagen was right is what atrophied judgement costs when the command you paste is poisoned.
The industry response deserves its own scepticism, which is what the arms race for your trust is for: security products sold on a fear the sellers are helping to produce.
The other risk is your vendor
Not every risk here is an attacker. The off-switch works both ways now is model access decided by a list you may not be on, and the Ferrari has a limiter is the day-to-day version of that, felt in a single working day. Both are the argument for taking back control of your data and for more control over your server.
A vendor can also collect through pages you built. You installed OpenAI's tracker yourself follows a ChatGPT cookie back to OpenAI from shops that load its ads pixel, and shows why the consent flag in the docs fires too late to help.
Where this touches what you build
Security starts before there is anything to patch, at the question of whether a server should exist. Every server you do not run is attack surface you never have to defend. That is why build an MCP server, then ask whether it should exist belongs to this guide as much as to agentic coding. The cheapest hardening available to you is a tool list that stays short.
Below are three starting points, then everything I have written on this topic, newest first.
best entry points
- The MCP supply chain is the new npm, and it is already poisoned
The big picture: how a young ecosystem is repeating every old supply chain mistake, faster.
- How to vet an MCP server before you install it
The practical checklist. What to inspect before a server is allowed into your tool list.
- Nobody was driving: the first breach run by an agent, not a person
The incident already on record: an agent that ran a complete intrusion on its own, from CVE to drained database, inside an hour.
all articles in this topic
You installed OpenAI's tracker yourself
On shops that run OpenAI's ads pixel, your browser sends along a cookie tied to your ChatGPT account. The pixel is there because a developer pasted a snippet into a head tag, and the consent flag in the docs fires too late to stop it.
Plugin4Shell: a pinned plugin is only pinned if something checks where it landed
Air showed that Claude Code, Codex, Copilot and Gemini CLI all asked git for the commit a marketplace pinned without checking that they got it. I reproduced it in git, watched Claude Code refuse it, and found the same hole in my own CI runner.
MCP server security scores are review prompts, not verdicts
An MCP server security score looks like a verdict. Measured across 74,101 servers, most of what a scanner tells you is a heuristic, and the state it almost never shows you is that nobody read the source.
Slopsquatting: checking that the package exists is not a defence
The standard advice against AI-hallucinated packages is to verify the package exists before installing. I checked four names from the latest research against PyPI. All four resolve. The registry answers the wrong question, in both directions.
CI runner security when an agent writes your workflow
Self-hosting your forge and your runner is a defensible call in 2026. Nobody writes the CI runner security guide for the platform you moved to, and an agent permission model built around a dialog does not survive the trip into a pipeline.
Claude Code credential masking: keep secrets out of your sandbox
How to configure Claude Code sandbox credential masking so your agent shell holds a sentinel instead of your real token: env vars, JWT claims, AWS re-signing, and the three things this control does not buy you.
Audit logging for AI agents: what Claude Code records and what deserves a human
Your coding agent already writes a detailed audit log to your own disk. Your company's compliance feed does not contain it, OpenTelemetry redacts it by default, and the hard part is still deciding who reads any of it.
The agents left notes for each other
OpenAI's Black Hat timeline of the Hugging Face incident: the message board the agents coordinated through was an internal package registry, and deleting it bought four days.
AI agent incident response: what to do when your coding agent goes wrong
A five-phase runbook for the hour after a coding agent breaks something: freeze the session, reconstruct from the transcript, work out the blast radius, rotate, and fix the permission that allowed it.
Every agent sandbox has the hole that makes it useful
Two agent sandbox escapes in one week, from OpenAI and from Claude Cowork. Both went up a privilege level inside a box that already held the prize, without ever crossing the wall.