(Note · · 5 min read)

Your MCP server turns model output into shell commands

An MCP server is an API whose caller is a language model, and whose arguments can be influenced by anything that model has read. A tool that pastes those arguments into a shell command is not a convenience wrapper; it is remote code execution with extra steps.

By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka

Where the arguments actually come from

It is tempting to think of tool arguments as coming from the user. They come from the model, which composes them from everything in its context: the user's request, yes, but also the web page it just fetched, the ticket it read, the rows it queried. Any of those can contain text written by someone else.

So treat every argument as untrusted input from the internet, because at one remove that is exactly what it is. The usual rules apply with full force, and the usual mistake is assuming they do not because the caller is your own agent.

Never build a command string

Security reviews of MCP servers in 2026 put shell command injection at the top of their findings, and the cause is consistently the same: a server constructing a command by interpolating tool arguments without sanitisation. A filename argument containing a semicolon stops being a filename.

The difference that matters
// hands over the machine
exec(`convert ${input} -resize 800 ${output}`)

// passes arguments as arguments, never as syntax
execFile("convert", [input, "-resize", "800", output])

Pass arguments as a list to a named executable. No shell, no interpolation, no quoting scheme you invented. Where a shell genuinely is required, the requirement is usually a sign the tool is too broad and should be several narrower ones.

Validate the schema, and mean it

Declare each argument's type and constraints and reject anything that does not match, before the tool body runs. A path argument should be resolved and checked to sit inside an allowed directory, rather than trusted because it looked relative. An identifier should match a pattern. An enum should be an enum.

Return structured errors rather than raw stack traces. A stack trace tells the model, and anyone influencing it, about your filesystem layout and dependency versions.

Give the server its own narrow identity

Whatever credentials the server holds are the blast radius of any flaw in it. Give it its own scoped identity with the minimum access its tools need, rather than reusing the application's keys, and enforce permissions in the server rather than relying on instructions in a prompt. A prompt is a request; the check in your code is the control.

Log which tool was called, with which arguments, on whose behalf, and keep those logs long enough to investigate something discovered later. The question after an incident is always what it did, and an agent that cannot answer that is an agent you cannot clear.

The short version

  • Tool arguments are untrusted input, because the model composes them from content it has read.
  • Never interpolate them into a shell command. Pass an argument list to a named binary.
  • Validate types, patterns and path boundaries before the tool body runs.
  • Return structured errors, never stack traces.
  • Scope the server's own credentials to the minimum, and enforce permissions in code.
  • Record every call with its arguments, and keep it.

Common questions

Why are MCP tool arguments considered untrusted?

Because the model composes them from everything in its context, including web pages, tickets and database rows written by other people. An argument is therefore untrusted input from the internet at one remove, even when the request began with your own user.

What is the most common MCP server vulnerability?

Shell command injection. 2026 security reviews report it as the most frequent finding, caused by servers building command strings from tool arguments without sanitisation. Pass arguments as a list to a named executable instead of interpolating them into a command.

Can I control an MCP server's permissions through the prompt?

No. A prompt is a request, not a control. Enforce permissions in the server's own code, give the server a scoped identity with the minimum access its tools require, and never reuse the application's main credentials.

What should an MCP tool return when something goes wrong?

A structured error describing what failed in terms the model can act on. Raw stack traces leak filesystem layout and dependency versions to the model and to anyone able to influence it.

Need something like this built?