An MCP server is an API. The difference is who calls it: not a front end you wrote, but a model that decides which tool to call and with what arguments, based on whatever text it read last. That text might be a user's request, a web page, an issue comment or a file planted to steer it. So every argument is chosen by something you do not control, and every result lands in a context window you do not control either.
Most MCP server bugs so far are ordinary API bugs in that setting. This post covers the four rules that prevent them, with the parts of the MCP specification that apply.
Rule 1: authenticate and authorize every call
The MCP authorization specification (revision 2026-07-28) makes authorization optional, then sets firm rules once you use it:
- Servers on an HTTP transport should follow the OAuth 2.1 based flow, and "authorization MUST be included in every HTTP request from client to server". There is no "authenticated once per session" shortcut.
- Servers "MUST validate that access tokens were issued specifically for them as the intended audience". A valid token for another service is not a valid token for yours.
- Servers "MUST NOT accept or transit any other tokens". If your server calls an upstream API, it gets its own token for that API. Forwarding the caller's token is the token passthrough problem the security best practices describe.
- Invalid or expired tokens get
401; insufficient scope gets403with aWWW-Authenticatechallenge naming the scopes required. - Servers on stdio "SHOULD NOT follow this specification, and instead retrieve credentials from the environment".
Authorization still has to happen per tool and per object. A token with files:read should not reach a delete_file tool, and a user who can read their own tickets should not get someone else's because the model passed a different ID.
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("tickets")
@mcp.tool()
def get_ticket(ticket_id: str) -> dict:
"""Return one support ticket owned by the calling user."""
user = current_user() # from the validated token, never from arguments
require_scope(user, "tickets:read")
ticket = db.tickets.get(id=ticket_id, owner_id=user.id) # scope the query to the caller
if ticket is None:
raise ValueError("ticket not found") # same answer for missing and forbidden
return public_fields(ticket)The helpers are your own code. What matters is that identity comes from the validated token, not a user_id argument the model can fill in.
If the server runs locally over HTTP, the transport rules also apply: validate Origin, bind to 127.0.0.1 and require authentication. Our post on localhost not being a security boundary covers why.
Rule 2: treat every argument as hostile
The spec's tools section says servers "MUST" validate all tool inputs, implement proper access controls, rate limit invocations and sanitize outputs (tools, security considerations). In practice that means the same sink discipline as any web handler, applied to arguments a prompt injection can choose.
Paths. The reference filesystem MCP server had exactly this bug. CVE-2025-53110 (High, CVSS 4.0 score 7.3) allowed "access to unintended files in cases where the prefix matches an allowed directory": a string prefix check let /allowed_dir_evil pass as inside /allowed_dir. Fixed in 2025.7.1. Compare paths by component after resolving them:
from pathlib import Path
ROOT = Path("/srv/workspace").resolve()
def safe_path(user_path: str) -> Path:
p = (ROOT / user_path).resolve() # collapses .. and follows symlinks
if not p.is_relative_to(ROOT): # component-wise, not a string prefix
raise ValueError("path is outside the workspace")
return pCommands. Never build a shell string. Pass an argument list, put -- before user-supplied values so they cannot become options, and allowlist the subcommands a tool may run. A git tool that accepts arbitrary arguments is a remote code execution tool, because options such as --upload-pack run programs.
URLs. A fetch_url tool is a server-side request forgery primitive. Allowlist hosts or schemes, resolve the host and refuse private, loopback and link-local addresses (including cloud metadata endpoints), and do not follow redirects to hosts outside the list.
Queries. Parameterize, and give the tool a database role that can only read what it needs.
Sizes and rates. Cap argument lengths, result sizes, execution time and calls per minute.
Rule 3: return clean results
A tool result goes straight into the model's context, and from there it can be summarized to a user, written to a file or passed to another tool. Treat it as output to an untrusted party.
- No secrets. Do not return environment variables, connection strings, tokens, API keys or whole configuration objects. Select the fields you mean to return rather than serializing a record.
- No internals. Return a short error message, not a stack trace with file paths and SQL.
- Mark untrusted content. When a tool returns text it fetched (a web page, an email, an issue body), label it as fetched content so the client and the model can treat instructions inside it as data. It does not stop prompt injection, but your server stops presenting attacker text as its own.
Rule 4: keep tool descriptions fixed
Tool names, descriptions and input schemas are instructions to the model. They should be string literals in your source, reviewed like code.
- Do not build descriptions from configuration, database rows or anything a user can edit. A description built from input is a prompt injection channel into every client that connects.
- Do not change what
tools/listreturns at run time based on time, request count or remote flags. A tool that behaves after approval and changes later is the "rug pull" pattern. - Keep the advertised
inputSchemain step with what the handler actually accepts, and reject unknown arguments. - Treat annotations such as "read-only" as claims, not controls: enforce in the handler whatever the annotation promises.
A pre-release checklist
| Check | Question to ask |
|---|---|
| Authentication | Is a token checked on every request, for audience as well as signature? |
| Authorization | Does every tool check scope, and every object lookup filter by the caller? |
| Token handling | Does the server use its own credentials upstream, never the caller's token? |
| Paths | Are paths resolved and compared by component, with symlinks followed? |
| Commands | Argument lists only, -- before user values, subcommands allowlisted? |
| Network | Are outbound hosts allowlisted and private addresses refused? |
| Results | Are fields selected, secrets and stack traces excluded? |
| Descriptions | Literal, unchanging, and matching the handler? |
| Limits | Rate, size and time limits on every tool? |
What Vulkro checks
vulkro scan-mcp-server reads the source of MCP servers written in Python (the official SDK and FastMCP) and TypeScript or JavaScript (@modelcontextprotocol/sdk):
| Rule | Fires when |
|---|---|
MCP-SERVER-001 |
A tool description is built from non-literal input |
MCP-SERVER-002 |
A handler passes a caller-supplied path, URL, env name or command to a sink without validation |
MCP-SERVER-003 |
tools/list returns descriptions computed at request time |
MCP-SERVER-004 |
A handler contains a subprocess call, eval, raw SQL or a similar sink |
MCP-SERVER-005 |
The advertised inputSchema does not match the handler's parameters |
MCP-SERVER-006 |
The server is mounted at / or home, or fetches with no host allowlist |
MCP-SERVER-007 |
A handler returns secrets or sensitive values into the model's context |
MCP-SERVER-008 |
A destructive tool has no auth check |
vulkro scan-mcp-server src/
vulkro scan . # adds MCP-SRC-001 (tool argument to a command, git, path, fetch or SQL sink)A full scan also reports llm-tool-unscoped-record-access, a tool that reads or writes a record by a model-chosen ID with no owner scope. The MCP detectors lean toward missing a case rather than flagging a well-built server, so pair them with review.
FAQ
Does an MCP server need authentication if it runs locally over stdio?
The specification says stdio servers should take credentials from the environment rather than follow the OAuth flow, because the client launches the server as a child process. A local server on HTTP is different: any web page can reach it, so it needs Origin checks and authentication.
What is token passthrough in MCP?
It is when an MCP server accepts a token that was not issued for it, or forwards the caller's token to an upstream API. The specification forbids both: validate the audience of every token, and use the server's own credentials for upstream calls.
How do I stop prompt injection reaching my MCP server's tools?
You cannot stop the model being steered, so make the tools safe to call with hostile arguments: authorize per tool and per object, validate paths, commands, URLs and queries, and limit what a single call can do or return.
See the AI coding agents use case and the vulkro scan-mcp-server docs, or start a 14-day trial. Related: agent tools are entry points and MCP servers are the new attack surface.