Blog
AI / LLM2026-11-28 · 6 min read

Securing MCP servers: the vulnerability classes to check

The Model Context Protocol (MCP) lets an AI agent call your tools and read your resources. The official SDKs are maintained by security-aware teams and the common issues in the transport layer already have CVEs and fixes. That is the point most people miss: the SDK is not your attack surface — your handlers are. The protocol hands attacker-influenced text straight into code you wrote.

Where the agent's input becomes an exploit

Every tool and resource handler receives arguments the model produced, and the model can be steered by untrusted content (a web page it read, a document it ingested). Treat those arguments as hostile input:

  • Command injection: a tool that builds a shell command from an argument. Use an argv list, never shell=True / a string command. On Windows, beware .bat/.cmd argument re-parsing.
  • Path traversal: a "read file" resource handler that joins an argument onto a base directory. Resolve the final path and verify it stays inside the allowed root; reject .. and absolute paths.
  • SSRF: a "fetch URL" tool that requests a user-supplied URL server-side. Allow-list the scheme (http/https only), and block internal, loopback and link-local (169.254.169.254) addresses after resolving the host.
  • Deserialization / RCE: a tool that loads a model, a pickle, or runs generated code without a sandbox.

Transport and auth: use the SDK's guarantees

If you expose MCP over HTTP rather than stdio, you inherit a web attack surface the SDK can only partly cover:

  • Enable DNS-rebinding protection (validate Host/Origin). Older SDK versions shipped it off by default — a localhost server then becomes reachable from any web page the victim visits.
  • Authenticate the principal on every request, not just at connect; keep the SDK current (several transport/auth fixes landed across 2025–2026).
  • Pin the OAuth flow's issuer and redirect URLs; do not trust server-supplied metadata without validation.

A fast self-check

  1. List every tool and resource handler. For each, name the dangerous sink it can reach (shell, filesystem, network, deserializer).
  2. For each sink, confirm the argument is validated before it reaches the sink — not just type-checked by the schema.
  3. If HTTP transport: DNS-rebinding on, auth per-request, SDK up to date.
  4. Assume the agent is adversarial (prompt injection is real); your controls must hold even when the model is fully attacker-steered.

We audit MCP servers and AI tool code with multi-layer, file:line proof — tracing the agent's input to each sink. Want yours reviewed? Get in touch or take the security self-assessment.