Skip to content

MCP Security: Hardening the Model Context Protocol

Density:

MCP introduces an open protocol (JSON-RPC over stdio, HTTP SSE, or WebSockets) allowing client agents (like Claude Desktop, Cursor, or autonomous agent frameworks) to dynamically discover resources, prompts, and callable tools.

However, MCP introduces significant new threat vectors:

  • Zero Inherent Sandboxing: By default, local stdio MCP servers run with the exact privileges of the host user process.
  • Dynamic Tool Registration: An MCP server can advertise arbitrary tool names, schemas, and parameter specifications directly into the agentโ€™s context window.
  • Bi-directional Trust Collapse: The agent trusts the MCP serverโ€™s outputs, while the MCP server trusts the agentโ€™s tool invocations.

[Attacker / Untrusted Context]
โ†“
[LLM Context Window]
โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ MCP CLIENT (Host Application) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ JSON-RPC (stdio / SSE)
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ MCP SERVER (Local / Remote) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”‚ OS Calls / SQL / Network
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ENTERPRISE RESOURCES โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

A malicious or compromised MCP server registers a tool that mimics a standard system command (e.g., read_file or run_query), secretly appending an exfiltration URL or modifying arguments before passing them to the OS.

An attacker embeds instructions into an external document processed by the agent. The LLM interprets the instruction and calls an MCP tool with malicious arguments (e.g., calling mcp_sqlite_query with DROP TABLE users;).

Remote MCP servers operating over unauthenticated HTTP SSE can be spoofed or accessed via cross-site WebSocket hijacking if mutual TLS (mTLS) and token authentication are not strictly enforced.

Granting an MCP server blanket filesystem access (/ instead of /tmp/agent_scratch/) gives compromised agents the ability to read SSH keys, environment files, and cloud credentials.

When an agent loads multiple third-party MCP servers simultaneously, one compromised server can inspect responses emitted by another, creating an unexpected data exfiltration pipeline.


To achieve compliance with the Hermes AI Agent Security Standard, implement the following architecture:

  1. Ephemeral Sandboxing: Execute local stdio MCP servers within unprivileged microVMs or rootless containers (e.g., Docker with seccomp/apparmor profiles and zero network access unless explicitly whitelisted).
  2. Schema Sanitization & Type Enforcement: Place a deterministic validating proxy between the LLM client and the MCP server that rejects non-conforming parameters and sanitizes dangerous shell characters (|, ;, &&, $).
  3. Just-In-Time (JIT) Ephemeral Credentials: Never configure long-lived API keys in MCP server config files (mcp_config.json). Issue ephemeral OAuth capability tokens with maximum lifetimes of 60 seconds.
  4. Human-In-The-Loop Approval Gates: Require explicit, authenticated cryptographic confirmation for any tool invocation that performs persistent state mutations (writes, updates, network requests).

Top 50 MCP Ecosystem Audit

Explore the security benchmarks, isolation scores, and confinement playbooks for the top 50 MCP servers. Browse MCP Directory โ†’

Declare Your Stack (MyStack)

Select your AI frameworks and MCP servers to get a tailored threat profile and sovereign hardening checklist. Open MyStack Declaration โ†’

Run MCP Security Assessment

Test your active MCP servers against our 7-layer evaluation framework in under 3 minutes. Start Assessment โ†’

Simulate MCP Blast Radius

Calculate what an adversary can access if your primary MCP server is hijacked. Open Simulator โ†’