MCP security: risks of MCP servers and best practices
An MCP server is a program or service that your coding agent trusts, and a local one runs on your Mac with the same privileges as your agent. Anthropic does not security-audit or manage any MCP server, so the first move is yours. Add a new one for a single project, which is the default scope in Claude Code, and read its launch command before you say yes. The full checklist is below. Basics: what is an MCP server.
01What MCP security covers
MCP stands for Model Context Protocol, an open-source standard for connecting AI applications to external systems. An MCP server is the program that exposes capabilities to the agent, and these programs typically run with high trust and broad permissions inside agent toolchains. MCP security is the question of what happens when you connect one you did not write: what code starts, what text the model reads from it, and what the agent may do with the result.
Three things can go wrong, and each has a different fix. The code can be bad. The text it returns, or its tool descriptions, can steer the model. Or your agent's approval settings can be too loose.
02Eight ways a server goes wrong
| Risk | What it means in practice | Case |
|---|---|---|
| Code runs with your agent's rights | A local server is a program downloaded and executed on the same machine as your agent. Attackers can execute any command with the agent's privileges | Checklist item 3 |
| Malicious start command | An attacker puts a "startup" command into an agent's configuration | Checklist item 2 |
| Poisoned tool description | Instructions hidden in a tool description are invisible to you but visible to the model | MCP tool poisoning |
| A server changes after you trust it | A server was reportedly modified to add a blind copy of every email to an outside domain | postmark-mcp, on the tool poisoning page |
| Fetched content steers the model | Servers that fetch external content can expose you to prompt injection | Checklist item 6 |
| Approved config swapped | In Cursor 1.2.4 and below, a collaborator's approved harmless server could be silently replaced by a malicious command; fixed in version 1.3 | CVE-2025-54136 |
| Config written by injected text | An attacker could chain an injected prompt to write the settings file and run code without your approval, fixed in version 1.3.9 | CVE-2025-54135 |
| Install link hides the command | A crafted MCP deep link, a link that opens the app and starts an install, bypassed the install warning and hid the commands | CVE-2025-64106 |
A CVE is a public number for a known security hole. Prompt injection means text an attacker plants so the model treats it as an order; the basics are on prompt injection.
03What each agent asks before it uses a server
The agents differ, so do not assume that the checks of one apply to another.
| Agent | When it asks | What stays open |
|---|---|---|
| Claude Code | Prompts for approval in interactive sessions before using a project-scoped server from .mcp.json. A cloned repository cannot approve its own servers | When it runs from a script with no one to answer, it cannot show that prompt and loads project servers without asking. .mcp.json does not show every server a session can load |
| Cursor | Every MCP connection needs approval, and after that each tool call needs its own approval unless you pre-approve the tool | An older version had the swap flaw above |
| Codex | Destructive app or MCP tool calls always need approval when the tool advertises a destructive annotation, a label the tool sets about its own behavior | Project-defined MCP servers can run commands outside the sandbox |
The sandbox is a fence the agent builds around the commands it runs. In Claude Code it covers shell commands only, so MCP servers run outside it. The fence does deny writes to Claude Code's own config files, including .mcp.json, so a command cannot add a server for itself. Mechanics are on Claude Code sandbox. For Docker MCP security there is one thing to know: Docker Sandboxes run the coding agent itself in isolated microVMs, small virtual machines that each get their own filesystem and network. A script can also gate MCP tools by name, with the matcher mcp__.*; examples are on Claude Code hooks.
04MCP security best practices: a checklist before you connect
Go through the list once per server, and again when it changes. Each item is short on purpose, so you can keep it next to your terminal.
- Who wrote it? Anthropic reviews connectors against listing criteria for its directory, but does not security-audit any MCP server. Find the author and the source code yourself.
- What does it run? Read the exact launch command with all its arguments. For one-click setup of a local server, the specification says the agent must show the exact command that will run, without truncation. If yours hides part of it, do not accept.
- Local or remote? A local one is code on your Mac. A remote one is an address you send data to. Decide which risk you accept.
- Which scope? Claude Code's default scope loads the server only in the project where you added it and keeps it private to you. Start there instead of sharing it with every project.
- What can it reach? Give it no token with more rights than the job needs, and keep secrets out of the project folder it can see.
- What does it return? Servers that fetch external content can expose you to prompt injection. For ones that read the web, tickets or email, keep the agent's approval prompts on.
- Is the whole config visible? Reviewing
.mcp.jsondoes not show every server a session can load. List what is connected with the commands in the next section. - Is it clean after an update? A server can change after you trust it. Re-read the launch command and the tool list when it updates.
05See what is actually connected
Run claude mcp list in your shell to see every configured server, and claude mcp get <name> for the details of one. The list shows a health status next to each server, such as Connected, Needs authentication or Failed to connect. Inside Claude Code, /mcp shows server status. Anything on that list that you do not recognize deserves a look at who added it and in which scope. The full command reference is on Claude Code MCP.
06Block a server you do not want
If a project's .mcp.json brings a server you do not trust, add its name to disabledMcpjsonServers in your settings, which blocks it in every permission mode. To switch off one of your own servers in a project without deleting it, toggle it off in the /mcp panel; Claude Code records that in the project's disabledMcpServers list and does not connect to it. A cloned repository cannot approve its own servers: approvals committed to a project's .claude/settings.json are ignored in an untrusted folder.
07If you already ran a server you doubt
For the one real case, postmark-mcp, the advice was: uninstall it, rotate any credentials ever sent through it, and review email logs for BCC traffic to the reported domain. The same steps fit any server you doubt, with its own logs. Do the rotating from a device you trust. For a remote server in Claude Code, removing it deletes the stored sign-in tokens on your machine but does not revoke them at the service that issued them, so run claude mcp logout <name> before claude mcp remove <name> to revoke them where the service supports it. The postmark-mcp case is on MCP tool poisoning.
08MCP security in short
Start with one server, in one project, with its launch command read in full. The checks differ by agent, and Claude Code does not ask in claude -p runs, so the decision you make before the first connection carries most of the weight. The permission side is on Claude Code permissions, and the wider view on AI agent security and prompt injection in coding agents.
If you also want a record of what a server starts after you connect it, the free, open-source core of Artificial Immunity watches MCP servers and program starts on your Mac and reports what it finds.
FAQ
What is MCP in security?
It is the connection point where an agent starts to trust outside code and outside text. MCP stands for Model Context Protocol, an open-source standard for connecting AI applications to external systems. A local server is a program downloaded and executed on your machine, and it can run arbitrary code with your agent's privileges.
Is MCP a security risk?
It can be. The protocol is only a standard, but each server you connect is a program or a service that your agent trusts. Claude Code's docs say to verify you trust each one before connecting it, because servers that fetch external content can expose you to prompt injection.
What are the downsides of using an MCP server?
A local one runs with the same privileges as your agent, its tool descriptions are text the model reads and you may not see, and Anthropic does not security-audit or manage any MCP server. It can also change after you trust it.
How do I secure an MCP server I build myself?
The specification asks authors of local servers to use the stdio transport, which limits access to just the agent, and asks agents to run server commands in a sandboxed environment with minimal default privileges. It also forbids token passthrough: accepting a token from the agent without checking that it was issued to your server and passing it on to another API.
What are some common problems with MCP servers?
Malicious start commands in a configuration, poisoned tool descriptions, approved configurations that were swapped later in Cursor 1.2.4 and below, and servers that run outside the sandbox.
How do I stop Claude Code from using a server from a project's .mcp.json?
Add its name to disabledMcpjsonServers in your settings, which blocks it in every permission mode.
What are the best practices for MCP?
Check who wrote it and read its launch command, add it for one project instead of everywhere, keep secrets out of reach, and review what the agent may do with it. The checklist on this page has all eight steps.
Related guides
Sources
- MCP specification: security best practices
- Claude Code docs: MCP
- Claude Code docs: security
- Claude Code docs: sandboxing
- Claude Code docs: hooks
- Cursor docs: agent security
- OpenAI Codex docs: approvals and security
- OpenAI Codex docs: non-interactive mode
- NVD: CVE-2025-54135
- NVD: CVE-2025-54136
- Cursor security advisories (GitHub API)
- Invariant Labs: tool poisoning attacks
- Snyk: malicious MCP server on npm (postmark-mcp)
- Artificial Immunity