~/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.
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.
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.
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.
- An open MCP server is worse than an open database
Why an unsecured MCP server gives away more than an open database ever did.
All articles in this topic
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.
MCP server authentication: OAuth, scopes and rate limits
You built an MCP server. The tutorial ended where security starts. How to add OAuth, scoped tokens and rate limits to your own server, with TypeScript and Laravel examples, so it does not join the 12,500 open ones.
Your coding agent read your .env, then uploaded your whole repo
A wire-level capture caught the Grok Build CLI shipping an entire repository, git history and an unredacted .env, to a vendor bucket. How to check what your own coding agent sends, and which secrets never belong on an agent box.
Prompt injection defense for developers who ship agents
Prompt injection defense that survives contact: not the poisoned-webpage demo, but the real attack surface of your setup, tool results, file contents and MCP tool descriptions, and the controls that actually hold.
Sandboxing Claude Code: put your agent in a box that holds
How to sandbox Claude Code: the built-in /sandbox, the sandbox runtime, dev containers and VMs compared, and why permission prompts are consent, not containment.